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

Method GetKernelBody

compiler/lib/KernelGen/Arm/ArmCommon/Reduce.cpp:447–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445}
446
447std::string ReduceKernel::GetKernelBody(TContext* context) const {
448 auto mode = context->getAttrStr("mode");
449 size_t axis = context->getAttrInt("axis");
450 auto input = context->getAttrOprand("operand:0");
451 std::stringstream writer;
452 writer << "#include<arm_neon.h>\n";
453 writer << "static inline float max(float a,float b){return a>b?a:b;}\n";
454 writer << "static inline float min(float a,float b){return a<b?a:b;}\n";
455 writer << gen_neon_intrin_compat();
456 writer << GenCommonRet() << " ";
457 writer << GetKernelSignature(context) << "{\n";
458 writer << "const size_t axis = " << axis << ";\n";
459 // clang-format off
460 writer << R"(
461 float* src = (float*)inputs[0]->ptr;
462 float* dst = (float*)outputs[0]->ptr;
463 Layout in_layout = inputs[0]->layout;
464 size_t A = 1, B, C = 1;
465 for (size_t i = 0; i < axis; ++ i)
466 A *= in_layout.dims[i];
467 B = in_layout.dims[axis];
468 for (size_t i = axis + 1; i < in_layout.nr_dim; ++ i)
469 C *= in_layout.dims[i];
470 )";
471 writer << R"(
472 if(C == 1){
473 )"
474 << generate_reducer<true>(mode) << R"(
475 })"
476 << R"(else{
477 )"
478 << generate_reducer<false>(mode) << R"(
479
480 })";
481 writer << R"(
482 return TinyNN_SUCCESS;
483 })";
484 // clang-format on
485 return writer.str();
486}
487
488} // namespace ArmCommon
489} // namespace KernelGen

Callers

nothing calls this directly

Calls 4

gen_neon_intrin_compatFunction · 0.85
GenCommonRetFunction · 0.85
getAttrStrMethod · 0.80
getAttrOprandMethod · 0.80

Tested by

no test coverage detected