MCPcopy Create free account
hub / github.com/MegEngine/MegCC / IsAvailable

Method IsAvailable

compiler/lib/KernelGen/GeneralIntrinsic/Typecvt.cpp:12–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace GeneralIntrinsic;
11
12bool TypecvtKernel::IsAvailable(TContext* context) const {
13 auto src_dtype =
14 SymbolHelper::gen_valid_dtype(context->getAttrOprand("operand:0").dtype);
15 auto dst_dtype =
16 SymbolHelper::gen_valid_dtype(context->getAttrOprand("operand:1").dtype);
17 bool ok_type =
18 (Utils::is_quant_dtype(src_dtype, 8) &&
19 Utils::is_quant_dtype(dst_dtype, 8)) ||
20 (Utils::is_quant_dtype(src_dtype, 8) && Utils::is_float_dtype(dst_dtype)) ||
21 (Utils::is_float_dtype(src_dtype) && Utils::is_quant_dtype(dst_dtype, 8)) ||
22 (Utils::get_dtype_enum(src_dtype) == Utils::DtypeEnum::uint8 &&
23 Utils::is_float_dtype(dst_dtype)) ||
24 (Utils::is_float_dtype(src_dtype) &&
25 Utils::is_float_dtype(dst_dtype, 16)) ||
26 (Utils::is_float_dtype(src_dtype, 16) && Utils::is_float_dtype(dst_dtype));
27 if (Utils::is_quant_dtype(src_dtype)) {
28 CC_ASSERT(context->getAttrOprand("operand:0").scale > 0);
29 }
30 if (Utils::is_quant_dtype(dst_dtype)) {
31 CC_ASSERT(context->getAttrOprand("operand:1").scale > 0);
32 }
33 return ok_type;
34}
35
36//! kernel gen
37std::string TypecvtKernel::GetKernelSymbol(TContext* context) const {

Callers

nothing calls this directly

Calls 4

is_quant_dtypeFunction · 0.85
is_float_dtypeFunction · 0.85
getAttrOprandMethod · 0.80
get_dtype_enumFunction · 0.50

Tested by

no test coverage detected