华为计算微信公众号
昇腾AI开发者公众号
华为计算微博
华为计算今日头条
如下代码所示,未初始化mxinit,仍能使用aclrtQueryDeviceStatus查询状态,这是正确的吗?
bool check_npu_health() { const char* socName = aclrtGetSocName(); if (socName != nullptr) { std::cout << "[check_npu_health] aclrtGetSocName=" << socName << std::endl; } else { std::cout << "[check_npu_health] aclrtGetSocName returned nullptr" << std::endl; } // 查询 NPU Device 状态 aclrtDeviceStatus status = ACL_RT_DEVICE_STATUS_END; aclError ret = aclrtQueryDeviceStatus(0, &status); if (ret != ACL_ERROR_NONE) { return false; } return (status == ACL_RT_DEVICE_STATUS_NORMAL); } int main() { // 参考 YoloV3Infer:全局初始化 // APP_ERROR mxRet = MxBase::MxInit(); // if (mxRet != APP_ERR_OK) { // std::cerr << "MxInit failed, ret=" << mxRet << "\n"; // return -1; // } std::signal(SIGINT, HandleSignal); std::signal(SIGTERM, HandleSignal); pthread_t healthThread{}; if (pthread_create(&healthThread, nullptr, &HealthThreadMain, nullptr) != 0) { std::cerr << "pthread_create health thread failed\n"; (void)MxBase::MxDeInit(); return -1; } pthread_t inferThread{}; bool inferThreadCreated = false; if (pthread_create(&inferThread, nullptr, &InferThreadMain, nullptr) == 0) { inferThreadCreated = true; } else { std::cerr << "pthread_create infer thread failed\n"; } while (!g_stop.load(std::memory_order_relaxed)) { sleep(1); } (void)pthread_join(healthThread, nullptr); if (inferThreadCreated) { (void)pthread_join(inferThread, nullptr); } // mxRet = MxBase::MxDeInit(); // if (mxRet != APP_ERR_OK) { // std::cerr << "MxDeInit failed, ret=" << mxRet << "\n"; // return -1; // } return 0; }
我要发帖子
如下代码所示,未初始化mxinit,仍能使用aclrtQueryDeviceStatus查询状态,这是正确的吗?
bool check_npu_health() { const char* socName = aclrtGetSocName(); if (socName != nullptr) { std::cout << "[check_npu_health] aclrtGetSocName=" << socName << std::endl; } else { std::cout << "[check_npu_health] aclrtGetSocName returned nullptr" << std::endl; } // 查询 NPU Device 状态 aclrtDeviceStatus status = ACL_RT_DEVICE_STATUS_END; aclError ret = aclrtQueryDeviceStatus(0, &status); if (ret != ACL_ERROR_NONE) { return false; } return (status == ACL_RT_DEVICE_STATUS_NORMAL); } int main() { // 参考 YoloV3Infer:全局初始化 // APP_ERROR mxRet = MxBase::MxInit(); // if (mxRet != APP_ERR_OK) { // std::cerr << "MxInit failed, ret=" << mxRet << "\n"; // return -1; // } std::signal(SIGINT, HandleSignal); std::signal(SIGTERM, HandleSignal); pthread_t healthThread{}; if (pthread_create(&healthThread, nullptr, &HealthThreadMain, nullptr) != 0) { std::cerr << "pthread_create health thread failed\n"; (void)MxBase::MxDeInit(); return -1; } pthread_t inferThread{}; bool inferThreadCreated = false; if (pthread_create(&inferThread, nullptr, &InferThreadMain, nullptr) == 0) { inferThreadCreated = true; } else { std::cerr << "pthread_create infer thread failed\n"; } while (!g_stop.load(std::memory_order_relaxed)) { sleep(1); } (void)pthread_join(healthThread, nullptr); if (inferThreadCreated) { (void)pthread_join(inferThread, nullptr); } // mxRet = MxBase::MxDeInit(); // if (mxRet != APP_ERR_OK) { // std::cerr << "MxDeInit failed, ret=" << mxRet << "\n"; // return -1; // } return 0; }