From 218b5602baab6e2ca0010f75f9e7f9641ba09e1f 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 b11003c51c..a47d8be28c 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 @@ -140,6 +140,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)); @@ -192,12 +196,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