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

Method GetKernelBody

compiler/lib/KernelGen/BareMetal/PowC.cpp:34–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34std::string PowCKernel::GetKernelBody(TContext* context) const {
35 std::stringstream ss;
36 ss << "#include <math.h>\n";
37 std::string dtype =
38 Utils::cvt_dtype_specifier(context->getAttrOprand("operand:0").dtype);
39 if (dtype == "gi_float16_t")
40 ss << gen_fp16_define();
41 ss << GenCommonRet() << " " << GetKernelSignature(context);
42 std::string body_temp = R"({
43 ${dtype}* a_data = (${dtype}*)inputs[0]->ptr;
44 ${dtype}* c_data = (${dtype}*)outputs[0]->ptr;
45 TINYNN_ASSERT(a_data);
46 TINYNN_ASSERT(c_data);
47 const Tensor* a_tensor = inputs[0];
48 const Layout a_layout = a_tensor->layout;
49 size_t nr_elem = 1;
50 for (int i = 0; i < a_layout.nr_dim; ++i) {
51 nr_elem *= a_layout.dims[i];
52 }
53
54 for(size_t i = 0; i < nr_elem; ++i){
55 c_data[i] = powf(a_data[i], ${exp});
56 }
57 return TinyNN_SUCCESS;
58})";
59
60 ss << StringTemplate::StringTemplateArgs()
61 .add("exp", std::to_string(context->getAttrFloat("exp")))
62 .add("dtype", dtype)
63 .render(body_temp);
64 return ss.str();
65}
66
67// vim: syntax=cpp.doxygen

Callers

nothing calls this directly

Calls 8

cvt_dtype_specifierFunction · 0.85
gen_fp16_defineFunction · 0.85
GenCommonRetFunction · 0.85
StringTemplateArgsClass · 0.85
getAttrOprandMethod · 0.80
to_stringFunction · 0.50
renderMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected