| 476 | } |
| 477 | |
| 478 | std::unique_ptr<MegBrainError> CompNode::check_async_error() const { |
| 479 | #if MGB_NEED_MEGDNN_ASYNC_ERROR |
| 480 | auto&& env = CompNodeEnv::from_comp_node(*this); |
| 481 | if (!env.has_user_data<MegDNNHandle>()) { |
| 482 | // comp nodes like fpga do not have megdnn handle |
| 483 | return nullptr; |
| 484 | } |
| 485 | |
| 486 | auto ptr = MegDNNHandle::get(env).async_error_info_devptr(); |
| 487 | if (!ptr) { |
| 488 | // this device type does not need async error report |
| 489 | return nullptr; |
| 490 | } |
| 491 | |
| 492 | megcore::AsyncErrorInfo error_info; |
| 493 | copy_to_host(&error_info, ptr, sizeof(error_info)); |
| 494 | sync(); |
| 495 | if (!error_info.nr_error) |
| 496 | return nullptr; |
| 497 | |
| 498 | // clear previous error |
| 499 | megcore::AsyncErrorInfo zero_info{0, nullptr, "", {0, 0, 0, 0}}; |
| 500 | copy_to_device(ptr, &zero_info, sizeof(zero_info)); |
| 501 | sync(); |
| 502 | |
| 503 | std::string addi_info = |
| 504 | "\nIf you are using megengine in python, you can get more error " |
| 505 | "information by `export MEGENGINE_INTERP_ASYNC_LEVEL=0`."; |
| 506 | |
| 507 | // throw exception |
| 508 | mgb_assert( |
| 509 | error_info.tracker_ptr, "error tracker unavailable. %s", addi_info.c_str()); |
| 510 | return cg::OperatorNodeExcExtraInfo::ExcMaker{ |
| 511 | static_cast<cg::OperatorNodeBase*>(error_info.tracker_ptr)} |
| 512 | .make_unique<MegBrainError>( |
| 513 | ssprintf( |
| 514 | "%u async error%s recorded; first msg: ", |
| 515 | error_info.nr_error, error_info.nr_error > 1 ? "s" : "") + |
| 516 | ssprintf( |
| 517 | error_info.msg, error_info.msg_args[0], |
| 518 | error_info.msg_args[1], error_info.msg_args[2], |
| 519 | error_info.msg_args[3]) + |
| 520 | addi_info); |
| 521 | #else |
| 522 | return nullptr; |
| 523 | #endif |
| 524 | } |
| 525 | |
| 526 | CompNode::DeviceType CompNode::device_type() const { |
| 527 | return static_cast<Impl*>(m_impl)->env().property().type; |
no test coverage detected