MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / validate

Method validate

src/cpu/operators/CpuGemm.cpp:216–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216Status CpuGemm::validate(const ITensorInfo *a,
217 const ITensorInfo *b,
218 const ITensorInfo *c,
219 const ITensorInfo *d,
220 float alpha,
221 float beta,
222 const GEMMInfo &gemm_info)
223{
224 ARM_COMPUTE_TRACE_EVENT(ARM_COMPUTE_PROF_CAT_CPU, ARM_COMPUTE_PROF_LVL_CPU, "CpuGemm::validate");
225 ARM_COMPUTE_UNUSED(alpha);
226 ARM_COMPUTE_RETURN_ERROR_ON_SIZE_UNSUPPORTED(a, b, c);
227
228 // When using accumulation(in place summation), for now, the only supported values for alpha and beta are 1 respectively 0.
229 // Do the appropriate checks before proceeding.
230 if (gemm_info.accumulate())
231 {
232 ARM_COMPUTE_RETURN_ERROR_ON_MSG(alpha != 1, "Accumulation is not supported when alpha is different from 1");
233 ARM_COMPUTE_RETURN_ERROR_ON_MSG(
234 (beta != 0 && c != nullptr),
235 "Accumulation is not supported when beta is different from 0 with a non-null bias matrix c");
236 }
237
238 const bool is_c_bias = beta == 1 && c != nullptr;
239 const bool run_addition = c != nullptr && beta != 0 && beta != 1;
240 // Check if we should use the pretransposed_b or original b
241 // TODO: COMPMID-6597
242 // Note that this check should only apply to the non-optimized path. The reason we brought this at the beginning
243 // instead of only for the fallback path is because of the checks performed below, between here and the run_optimised decision
244 // We should simplify this by
245 // 1. Moving the checks between "fix-start" and "fix-end" into their corresponding ops / kernels (e.g. the weights format checks can and should be moved into CpuGemmAssemblyDispatch)
246 // 2. Moving this b_to_use check back into the non-optimized path
247 TensorInfo pretransposed_b = b->clone()->set_tensor_shape(misc::shape_calculator::compute_transposed_shape(*b));
248 const ITensorInfo *b_to_use = gemm_info.pretranspose_B() ? &pretransposed_b : b;
249
250 // TODO: COMPMID-6597 fix-start
251
252 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(a);
253 ARM_COMPUTE_RETURN_ERROR_ON_CPU_BF16_UNSUPPORTED(a);
254 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(a, 1, DataType::BFLOAT16, DataType::F16, DataType::F32);
255
256 if (is_fixed_format_fast_math(gemm_info.weight_format()))
257 {
258 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(a, DataType::F32);
259 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(b_to_use, DataType::BFLOAT16);
260 }
261 else
262 {
263 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(a, b_to_use);
264 }
265
266 const int block_by = arm_compute::block_by(gemm_info.weight_format());
267 // test if im2col has changed the dimensions that are needed for padding
268 if (a->dimension(0) != b_to_use->dimension(1) && block_by > 1)
269 {
270 // have to verify bias
271 const size_t dim0_sz = a->dimension(0);
272 ARM_COMPUTE_RETURN_ERROR_ON_MSG(
273 (dim0_sz % block_by) != 0,

Callers

nothing calls this directly

Calls 15

compute_transposed_shapeFunction · 0.85
block_byFunction · 0.85
GEMMReshapeInfoClass · 0.85
auto_init_if_emptyFunction · 0.85
compute_mm_shapeFunction · 0.85
accumulateMethod · 0.80
pretranspose_BMethod · 0.80
is_a_reshapedMethod · 0.80
is_b_reshapedMethod · 0.80

Tested by

no test coverage detected