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

Method IsAvailable

compiler/lib/KernelGen/BareMetal/ElemwiseKernel.cpp:413–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411} // namespace
412
413bool ElmwiseKernel::IsAvailable(TContext* context) const {
414 auto mode = context->getAttrStr("mode");
415 auto nr_operands = context->getAttrInt("nr_operands");
416 auto dtype = context->getAttrOprand("operand:0").dtype;
417 bool nr_operands_ok = nr_operands >= 2 && nr_operands <= 5;
418 bool mode_ok_unary = mode == "RELU" || mode == "SIGMOID" || mode == "EXP" ||
419 mode == "NEGATE" || mode == "ROUND" || mode == "ABS" ||
420 mode == "H_SWISH" || mode == "LOG" || mode == "SILU" ||
421 mode == "ERF" || mode == "SQRT" || mode == "SIN" ||
422 mode == "COS";
423 bool mode_ok_binary =
424 mode == "ADD" || mode == "SUB" || mode == "MUL" || mode == "MAX" ||
425 mode == "MIN" || mode == "LEQ" || mode == "LT" || mode == "FLOOR_DIV" ||
426 mode == "EQ" || mode == "TRUE_DIV" || mode == "FUSE_ADD_RELU" ||
427 mode == "FUSE_ADD_SIGMOID" || mode == "FUSE_ADD_TANH" ||
428 (mode == "MOD" && (dtype == "i32" || dtype == "si32" || dtype == "f32"));
429 bool mode_ok_other = mode == "FUSE_MUL_ADD3" || mode == "FUSE_MUL_ADD4";
430 return nr_operands_ok && (mode_ok_unary || mode_ok_binary || mode_ok_other);
431}
432
433std::string ElmwiseKernel::GetKernelSymbol(TContext* context) const {
434 std::stringstream ss;

Callers

nothing calls this directly

Calls 2

getAttrStrMethod · 0.80
getAttrOprandMethod · 0.80

Tested by

no test coverage detected