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

Method GetCVKernelBody

compiler/lib/KernelGen/GeneralIntrinsic/Resize.cpp:241–678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239}
240
241std::string ResizeKernel::GetCVKernelBody(TContext* context) const {
242 auto kernel_sig = GetCVKernelSignature(context);
243 auto src_dtype =
244 Utils::cvt_dtype_specifier(context->getAttrOprand("operand:0").dtype);
245 std::stringstream writer;
246 writer << R"(
247 #include <string.h>
248 #include "tinycv_c.h"
249 )";
250 std::string body_temp = R"(
251 #include <math.h>
252 #include <stdalign.h>
253 #include "${gi_header}"
254 #define rep(i, n) for (int i = 0; i < (n); ++i)
255 ${define_scale}
256 ${output_converter_func}
257
258 static inline void get_nearest_linear_coord(float scale, int size, int idx, float* ah0, int* ih0, float* ah1, int* ih1){
259 if (size == 1) {
260 *ah0 = 1.f;
261 *ih0 = 0;
262 *ah1 = 0.f;
263 *ih1 = 0;
264 }
265
266 float alpha = (idx + 0.5f) / scale - 0.5f;
267 int origin_idx = (int)(floorf(alpha));
268 alpha -= origin_idx;
269
270 if (origin_idx < 0) {
271 origin_idx = 0;
272 alpha = 0;
273 } else if (origin_idx + 1 >= size) {
274 origin_idx = size - 2;
275 alpha = 1;
276 }
277
278 *ah0 = 1 - alpha;
279 *ih0 = origin_idx;
280 *ah1 = alpha;
281 *ih1 = origin_idx + 1;
282 }
283
284 static inline void calc_cache_${func_tag}c3_1(const ${src_dtype}* src, const int src_h_stride, const ${src_dtype}* dst, const int OW,
285 const int* tabsx,
286 const int* tabsy,
287 const ${calc_dtype}* tabrx,
288 const ${calc_dtype}* tabry, int dx,
289 ${calc_dtype}* cache0, ${calc_dtype}* cache1) {
290 (void)tabrx;
291 const ${src_dtype}* psrc1 = src + (tabsx[dx] + 1) * src_h_stride;
292
293 int dy = 0, dy3 = 0;
294
295 for (; dy < OW; ++dy, dy3 += 3) {
296 const ${src_dtype}* pcsrc10 = psrc1 + (tabsy[dy] + 0) * 3;
297 const ${src_dtype}* pcsrc11 = psrc1 + (tabsy[dy] + 1) * 3;
298 ${calc_dtype} ry = tabry[dy];

Callers

nothing calls this directly

Calls 7

cvt_dtype_specifierFunction · 0.85
StringTemplateArgsClass · 0.85
getAttrOprandMethod · 0.80
renderMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected