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

Method do_exec

dnn/test/common/checker.cpp:222–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222void CheckerHelper::do_exec(
223 const TensorLayoutArray& user_layouts, const TensorLayoutArray& deduced_layouts,
224 const OprExec& exec_naive, const OprExec& exec_opr) {
225 m_prev_succ = false;
226
227 // check if user provided layouts are correct
228 for (size_t i = 0; i < deduced_layouts.size(); ++i) {
229 if (user_layouts[i].ndim > 0) {
230 ASSERT_TRUE(deduced_layouts[i].eq_shape(user_layouts[i]))
231 << "User provided shape is "
232 << user_layouts[i].TensorShape::to_string()
233 << "\nExpected shape is "
234 << deduced_layouts[i].TensorShape::to_string();
235 }
236 }
237 auto layouts = user_layouts;
238 for (size_t i = 0; i < layouts.size(); ++i) {
239 if (layouts[i].ndim == 0) {
240 //! in some opr, such as conv_bias has ndim==0
241 layouts[i] = deduced_layouts[i];
242 }
243 }
244
245 // allocate
246 m_tensors_naive = alloc_tensors(m_handle_naive.get(), layouts, m_offset);
247 auto tensors_cur_storage = alloc_tensors(m_handle_cur, layouts, m_offset);
248 auto tensors_cur_host_storage =
249 alloc_tensors(m_handle_naive.get(), layouts, m_offset);
250 auto&& tensors_naive = *m_tensors_naive;
251 auto&& tensors_cur = *tensors_cur_storage;
252 auto&& tensors_cur_host = *tensors_cur_host_storage;
253 std::shared_ptr<TensorValueArray> tensors_extra_opr_impl;
254 if (m_extra_opr_impl) {
255 tensors_extra_opr_impl = alloc_tensors(m_handle_naive.get(), layouts, m_offset);
256 }
257
258 init_naive_values();
259
260 copy_tensors_to_device(tensors_cur, tensors_naive);
261 if (m_extra_opr_impl) {
262 copy_tensors(*tensors_extra_opr_impl, tensors_naive);
263 }
264
265 // execute
266
267 exec_opr(tensors_cur);
268 if (m_expect_exec_fail) {
269 m_expect_exec_fail();
270 m_expect_exec_fail = {};
271 return;
272 }
273 if (m_stable_check) {
274 auto tensors_bak_host_storage =
275 alloc_tensors(m_handle_naive.get(), layouts, m_offset);
276 auto&& tensors_bak_host = *tensors_bak_host_storage;
277 copy_tensors_from_device(tensors_bak_host, tensors_cur);
278 for (int i = 0; i < 10; i++) {
279 exec_opr(tensors_cur);

Callers

nothing calls this directly

Calls 7

copy_tensorsFunction · 0.85
sizeMethod · 0.45
eq_shapeMethod · 0.45
getMethod · 0.45
startMethod · 0.45
stopMethod · 0.45
get_time_in_usMethod · 0.45

Tested by

no test coverage detected