| 29 | } |
| 30 | |
| 31 | std::string ResizeKernel::GetKernelBody(TContext* context) const { |
| 32 | std::stringstream ss; |
| 33 | auto src_dtype = context->getAttrOprand("operand:0").dtype; |
| 34 | auto fmt = context->getAttrStr("format"); |
| 35 | auto specifier = Utils::cvt_dtype_specifier(src_dtype); |
| 36 | auto imode = context->getAttrStr("imode"); |
| 37 | ss << R"( |
| 38 | #include <math.h> |
| 39 | #include <stdalign.h> |
| 40 | )"; |
| 41 | auto coord_str = ResizeHelper::GenCoordHelper(imode, specifier); |
| 42 | auto gen_layout_dims = ResizeHelper::GenLayoutDims(fmt); |
| 43 | auto get_offset = ResizeHelper::GenGetOffset(fmt); |
| 44 | ss << StringTemplate::StringTemplateArgs() |
| 45 | .add("coord_helper_str", coord_str) |
| 46 | .add("get_offset", get_offset) |
| 47 | .render(R"( |
| 48 | static inline float output_converter(float x){ |
| 49 | return x; |
| 50 | } |
| 51 | ${coord_helper_str} |
| 52 | ${get_offset} |
| 53 | #define rep(i, n) for (int i = 0; i < (n); ++i) |
| 54 | )"); |
| 55 | ss << GenCommonRet() << " " << GetKernelSignature(context); |
| 56 | std::string body_temp = R"({ |
| 57 | const Tensor* src_tensor = inputs[0]; |
| 58 | const Tensor* dst_tensor = outputs[0]; |
| 59 | ${specifier}* sptr = (${specifier}*)(src_tensor->ptr); |
| 60 | ${specifier}* dptr = (${specifier}*)(dst_tensor->ptr); |
| 61 | TINYNN_ASSERT(sptr); |
| 62 | TINYNN_ASSERT(dptr); |
| 63 | |
| 64 | const Layout src_layout = src_tensor->layout; |
| 65 | const Layout dst_layout = dst_tensor->layout; |
| 66 | ${gen_layout_dims} |
| 67 | float scale_h = (float)(OH) / IH; |
| 68 | float scale_w = (float)(OW) / IW; |
| 69 | |
| 70 | ${normal_impl} |
| 71 | return TinyNN_SUCCESS; |
| 72 | })"; |
| 73 | auto normal_impl = ResizeHelper::GenNormImpl(fmt); |
| 74 | ss << StringTemplate::StringTemplateArgs() |
| 75 | .add("specifier", specifier) |
| 76 | .add("normal_impl", normal_impl) |
| 77 | .add("gen_layout_dims", gen_layout_dims) |
| 78 | .render(body_temp); |
| 79 | return ss.str(); |
| 80 | } |
| 81 | |
| 82 | bool ResizeKernel::IsCVAvailable(TContext* context) const { |
| 83 | auto src_dtype = context->getAttrOprand("operand:0").dtype; |
no test coverage detected