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

Method init_cnrt

src/core/impl/comp_node_env.cpp:405–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403} // namespace
404
405void CompNodeEnv::init_cnrt(
406 int dev, CompNode comp_node, const ContinuationCtx<cnrtQueue_t>& cont) {
407 m_comp_node = comp_node;
408 m_cnrt_env.device = dev;
409 m_property.type = DeviceType::CAMBRICON;
410 MGB_CNRT_CHECK(cnrtGetDeviceProperties(&m_cnrt_env.device_info, dev));
411 // FIXME: doc doesn't describe the aligment requirement for device memory
412 // address
413#if CNRT_MAJOR_VERSION >= 5
414 m_property.mem_alignment = 256u;
415#else
416 m_property.mem_alignment = 1u;
417#endif
418 // ensure exception safe
419 bool queue_created = false, cnnl_handle_created = false;
420 bool mem_mgr_created = false;
421 MGB_MARK_USED_VAR(queue_created);
422 MGB_TRY {
423 m_cnrt_env.activate();
424 MGB_CNRT_CHECK(cnrtQueueCreate(&m_cnrt_env.queue));
425 queue_created = true;
426 MGB_CNNL_CHECK(cnnlCreate(&m_cnrt_env.cnnl_handle));
427 // todo: remove this hack for nms opr
428 MGB_CNNL_CHECK(cnnlSetQueue(m_cnrt_env.cnnl_handle, m_cnrt_env.queue));
429 cnnl_handle_created = true;
430 m_user_data_container = std::make_unique<UserDataContainer>();
431 cont.next(m_cnrt_env.queue);
432 m_cnrt_env.mem_mgr = std::make_unique<CambriconMemoryManagerImpl>(m_comp_node);
433 // TODO: initialize megdnn handle
434 mgb_assert(
435 m_property.mem_alignment ==
436 MegDNNHandle::get(*this).handle()->alignment_requirement());
437 }
438 MGB_CATCH(std::exception & exc, {
439 mgb_log_error("cnrt init failed: %s", exc.what());
440 if (cnnl_handle_created) {

Callers 1

initMethod · 0.80

Calls 5

getFunction · 0.85
activateMethod · 0.45
nextMethod · 0.45
alignment_requirementMethod · 0.45
handleMethod · 0.45

Tested by

no test coverage detected