MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / exec_optimized

Method exec_optimized

dnn/src/fallback/reduce/opr_impl.cpp:200–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200bool ReduceImpl::exec_optimized(
201 _megdnn_tensor_in src, _megdnn_tensor_out dst, _megdnn_workspace workspace) {
202 size_t A, B, C;
203 reduce::get_ABC(src.layout, A, B, C, param().axis);
204 bool execed = false;
205 using Mode = param::Reduce::Mode;
206
207#define DISPATCH_FUNC(Reducer, dtype, ctype, comp_type) \
208 if (C == 1) { \
209 using _Reducer = Reducer<dtype, ctype, comp_type, true>; \
210 using _ReducerC1SmallB = Reducer<dtype, ctype, comp_type, false>; \
211 std::function<void( \
212 const ctype*, ctype*, DType, size_t, size_t, size_t, \
213 _megdnn_workspace)> \
214 do_reduce = Exec<_Reducer, true>::do_reduce; \
215 if (B == 2) \
216 do_reduce = ExecC1SmallB<_ReducerC1SmallB, ctype, 2>::do_reduce; \
217 if (B == 3) \
218 do_reduce = ExecC1SmallB<_ReducerC1SmallB, ctype, 3>::do_reduce; \
219 if (B == 4) \
220 do_reduce = ExecC1SmallB<_ReducerC1SmallB, ctype, 4>::do_reduce; \
221 MIDOUT_BEGIN( \
222 megdnn_fallback_reduce_optimized, ctype, dtype, comp_type, \
223 midout_iv(0)) { \
224 MEGDNN_DISPATCH_CPU_KERN_OPR(do_reduce( \
225 reinterpret_cast<ctype*>(src.raw_ptr()), \
226 reinterpret_cast<ctype*>(dst.raw_ptr()), src_type, A, B, C, \
227 workspace)); \
228 execed = true; \
229 } \
230 MIDOUT_END(); \
231 } else { \
232 using _Reducer = Reducer<dtype, ctype, comp_type, false>; \
233 std::function<void( \
234 const ctype*, ctype*, DType, size_t, size_t, size_t, \
235 _megdnn_workspace)> \
236 do_reduce = Exec<_Reducer, false>::do_reduce; \
237 MIDOUT_BEGIN( \
238 megdnn_fallback_reduce_optimized, ctype, dtype, comp_type, \
239 midout_iv(1)) { \
240 MEGDNN_DISPATCH_CPU_KERN_OPR(do_reduce( \
241 reinterpret_cast<ctype*>(src.raw_ptr()), \
242 reinterpret_cast<ctype*>(dst.raw_ptr()), src_type, A, B, C, \
243 workspace)); \
244 execed = true; \
245 } \
246 MIDOUT_END(); \
247 }
248
249#define DISPATCH_MODE_QUANTIZED(dtype, ctype, comp_type) \
250 switch (param().mode) { \
251 case Mode::MEAN: \
252 DISPATCH_FUNC(MeanReducer, dtype, ctype, comp_type); \
253 break; \
254 case Mode::MAX: \
255 DISPATCH_FUNC(maxReducer, dtype, ctype, ctype); \
256 break; \
257 case Mode::MIN: \

Callers

nothing calls this directly

Calls 5

get_ABCFunction · 0.85
categoryMethod · 0.80
paramFunction · 0.50
is_contiguousMethod · 0.45
enumvMethod · 0.45

Tested by

no test coverage detected