From 6925bc71cee07a6de7fa0db6f9b2b32293b61fc2 Mon Sep 17 00:00:00 2001 From: huangyunlong Date: Mon, 25 Aug 2025 09:32:49 +0800 Subject: [PATCH] set the specified device --- torch_npu/csrc/core/npu/sys_ctrl/npu_sys_ctrl.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/torch_npu/csrc/core/npu/sys_ctrl/npu_sys_ctrl.cpp b/torch_npu/csrc/core/npu/sys_ctrl/npu_sys_ctrl.cpp index 5175ae88bb..4ab9cef46f 100644 --- a/torch_npu/csrc/core/npu/sys_ctrl/npu_sys_ctrl.cpp +++ b/torch_npu/csrc/core/npu/sys_ctrl/npu_sys_ctrl.cpp @@ -139,6 +139,10 @@ NpuSysCtrl::SysStatus NpuSysCtrl::Initialize(int device_id) ASCEND_LOGD("Npu workspace allocator initialize successfully"); c10_npu::option::OptionsManager::IsOomSnapshotEnable(); + if (device_id >= 0) { + NPU_CHECK_ERROR(c10_npu::SetDevice(device_id)); + } + if (c10_npu::option::OptionsManager::CheckAclDumpDateEnable()) { const char *aclConfigPath = "acl.json"; NPU_CHECK_ERROR(aclmdlSetDump(aclConfigPath)); @@ -191,12 +195,6 @@ NpuSysCtrl::SysStatus NpuSysCtrl::LazyInitialize(int device_id) // There's no need to call c10_npu::GetDevice at the start of the process, because device 0 may not be needed auto ret = aclrtGetDevice(&device_id_); - if (ret != ACL_ERROR_NONE) { - device_id_ = (device_id == -1) ? 0 : device_id; - NPU_CHECK_ERROR(c10_npu::SetDevice(device_id_)); - } else { - ASCEND_LOGW("Npu device %d has been set before global init.", device_id_); - } if (c10_npu::IsSupportInfNan()) { c10_npu::acl::AclrtSetDeviceSatMode(aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_INFNAN); -- Gitee