| 32 | } |
| 33 | |
| 34 | std::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 |
nothing calls this directly
no test coverage detected