MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / DispatchMul

Function DispatchMul

tensorflow/lite/experimental/ruy/dispatch.h:384–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382template <Path CompiledPaths, typename LhsScalar, typename RhsScalar,
383 typename DstScalar, typename Spec>
384void DispatchMul(const Matrix<LhsScalar>& lhs, const Matrix<RhsScalar>& rhs,
385 const Spec& spec, Context* context, Matrix<DstScalar>* dst) {
386 static_assert(CompiledPaths != Path::kNone, "Must compile at least one Path");
387 static_assert((CompiledPaths & ~kAllPaths) == Path::kNone,
388 "CompiledPaths must be a subset of ruy::kAllPaths");
389
390 gemmlowp::ScopedProfilingLabel label("Mul");
391
392 EnforceLayoutSupport<Spec>(lhs.layout, rhs.layout, dst->layout);
393 EnforceZeroPointSupport<Spec>(lhs.zero_point, rhs.zero_point,
394 dst->zero_point);
395 EnforceDstSpecSupport<Spec>(spec, dst->zero_point);
396
397 // This should be a constant, for a given machine and CompiledPaths.
398 // There is a back door to override it for testing, but in production it will
399 // always be the "best" Path. I.e. the one with the newest SIMD instructions
400 // available on the present machine, and avoiding Path::kReference unless
401 // no other path is compiled.
402 //
403 // Unfortunately, it is not a *static* constant, since it depends on runtime
404 // detection of the available SIMD instructions.
405 Path the_path = context->GetPathToTake<CompiledPaths>();
406
407 // Production code should probably never execute Path::kReference.
408 // Path::kReference implements a Mul, not a TrMul like the rest of Ruy, so if
409 // that's what we need to do, then get it out of the way before going down the
410 // TrMul path.
411 if (the_path == Path::kReference) {
412 constexpr bool ReferenceMulIsEnabled =
413 (CompiledPaths & Path::kReference) != Path::kNone;
414 CompileTimeEnabledReferenceMul<ReferenceMulIsEnabled>::Run(lhs, rhs, spec,
415 dst);
416 return;
417 }
418
419 // As described in the comment at the top of this file, Ruy internally
420 // converts Mul into TrMul. We handle that here.
421 //
422 // This is Ruy's main code path.
423 constexpr Path TrMulCompiledPaths = CompiledPaths & ~Path::kReference;
424 Matrix<LhsScalar> transposed_lhs(lhs);
425 Transpose(&transposed_lhs);
426 TrMulParams params;
427 CreateTrMulParams<TrMulCompiledPaths>(transposed_lhs, rhs, spec, context, dst,
428 the_path, &params);
429 TrMul(&params, context);
430}
431
432} // namespace ruy
433

Callers

nothing calls this directly

Calls 3

TrMulFunction · 0.85
TransposeFunction · 0.70
RunFunction · 0.50

Tested by

no test coverage detected