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

Method GetKernelBody

compiler/lib/KernelGen/BareMetal/ConvBackDataKernel.cpp:127–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127std::string ConvBackDataGeneral::GetKernelBody(TContext* context) const {
128 std::stringstream ss;
129 std::string noline_mode = context->haveAttr("nonlineMode")
130 ? context->getAttrStr("nonlineMode")
131 : "IDENTITY";
132 auto sparse_str = context->getAttrStr("sparse");
133 auto filter_format_str = get_format(context);
134 auto src_format_str = get_src_foramt(filter_format_str);
135 auto dst_format_str = get_dst_foramt(filter_format_str);
136 auto dst_dtype = context->getAttrOprand("operand:1").dtype;
137 auto flt_dtype = context->getAttrOprand("operand:0").dtype;
138 int src_idx = context->getAttrInt("nr_operands") - 1;
139 std::string src_dtype =
140 context->getAttrOprand("operand:" + std::to_string(src_idx)).dtype;
141
142 auto src_specifier = Utils::cvt_dtype_specifier(src_dtype);
143 auto flt_specifier = Utils::cvt_dtype_specifier(flt_dtype);
144 auto dst_specifier = Utils::cvt_dtype_specifier(dst_dtype);
145 std::string acc_specifier = "float";
146 std::string convert = "";
147 std::string compute_kern = "(*sval) + dval * fval";
148 if (src_specifier == "int8_t" && flt_specifier == "int8_t") {
149 convert = "fp32_to_int8";
150 compute_kern =
151 "((*sval) * scale + dval * dst_scale * fval * "
152 "flt_scale)/scale";
153 }
154
155 uint32_t spatial_start = 2;
156 uint32_t channel_pos = 1;
157 uint32_t batch_pos = 0;
158 uint32_t ocpg_ratio = 1;
159 uint32_t icpg_ratio = 1;
160
161 std::string group_str = "1";
162 if (filter_format_str == "NCHW") {
163 if (sparse_str == "GROUP") {
164 group_str = "filter_weight->layout.dims[0]";
165 }
166 } else if (filter_format_str == "NCHW44") {
167 ocpg_ratio = 4;
168 icpg_ratio = 4;
169 if (sparse_str == "GROUP") {
170 group_str = "filter_weight->layout.dims[0] * 4";
171 }
172 } else if (filter_format_str == "NCHW_NCHW44") {
173 ocpg_ratio = 4;
174 icpg_ratio = 1;
175 CC_ASSERT(sparse_str == "DENSE");
176 } else {
177 CC_ABORT << "not support filter_format_str " << filter_format_str;
178 }
179
180 ss << R"(
181#include <stdbool.h>
182)";
183 ss << gen_inline_addr(filter_format_str, sparse_str);
184 if (src_specifier == "int8_t" && flt_specifier == "int8_t") {

Callers

nothing calls this directly

Calls 15

cvt_dtype_specifierFunction · 0.85
GenCommonRetFunction · 0.85
StringTemplateArgsClass · 0.85
haveAttrMethod · 0.80
getAttrStrMethod · 0.80
getAttrOprandMethod · 0.80
get_formatFunction · 0.70
get_src_foramtFunction · 0.70
get_dst_foramtFunction · 0.70
gen_inline_addrFunction · 0.70
gen_depFunction · 0.70
gen_filter_strideFunction · 0.70

Tested by

no test coverage detected