From 6826bdc721917b0d52e1614d3989673c109aded1 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 11:07:49 +0800 Subject: [PATCH 1/5] modify default value for acl_Op_init_mode --- torch_npu/csrc/core/npu/register/OptionsManager.cpp | 12 ++++++++++-- torch_npu/csrc/framework/OpCommand.cpp | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/torch_npu/csrc/core/npu/register/OptionsManager.cpp b/torch_npu/csrc/core/npu/register/OptionsManager.cpp index a049743655..3ae3e532f9 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -481,8 +481,16 @@ uint32_t OptionsManager::GetAclOpInitMode() { const static uint32_t acl_op_init_mode = []() -> uint32_t { char* buf_val = std::getenv("ACL_OP_INIT_MODE"); - // Default 0 - int64_t acl_op_init_mode_ = (buf_val != nullptr) ? strtol(buf_val, nullptr, 10) : 0; + // Default 1 for A2/A3; Default 0 for others + static bool default_value_acl_mode = ((GetSocVersion() >= SocVersion::Ascend910B1) && + (GetSocVersion() < SocVersion::Ascend310B1)) || + ((GetSocVersion() >= SocVersion::Ascend910_9391)); + if (default_value_acl_mode) { + int64_t acl_op_init_mode_ = (buf_val != nullptr) ? strtol(buf_val, nullptr, 10) : 1; + } else { + int64_t acl_op_init_mode_ = (buf_val != nullptr) ? strtol(buf_val, nullptr, 10) : 0; + } + std::unordered_map aclOpInitMode = getAclOpInitMode(); if (aclOpInitMode.find(acl_op_init_mode_) == aclOpInitMode.end()) { acl_op_init_mode_ = 0; diff --git a/torch_npu/csrc/framework/OpCommand.cpp b/torch_npu/csrc/framework/OpCommand.cpp index 383dcb8ecf..793582fefe 100644 --- a/torch_npu/csrc/framework/OpCommand.cpp +++ b/torch_npu/csrc/framework/OpCommand.cpp @@ -135,6 +135,8 @@ void OpCommand::Run() aclCmd->SetEnginePriority(); const string &op_name = aclCmd->GetName(); at_npu::aclops::LazyInitAclops(); + auto val = c10_npu::option::GetOption("jitCompile"); + NPU_CHECK_ERROR(AclSetCompileopt(aclCompileOpt::ACL_OP_JIT_COMPILE, val->c_str())); #ifndef BUILD_LIBTORCH const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); #endif -- Gitee From 36273a82e857a8f26871c087976b0e5be1c0c165 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:28:55 +0800 Subject: [PATCH 2/5] fix --- torch_npu/csrc/core/npu/register/OptionsManager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/torch_npu/csrc/core/npu/register/OptionsManager.cpp b/torch_npu/csrc/core/npu/register/OptionsManager.cpp index 3ae3e532f9..996b0bcc1b 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -14,6 +14,7 @@ #include "torch_npu/csrc/core/npu/NPUFunctions.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" #include "torch_npu/csrc/npu/memory_snapshot.h" +#include "torch_npu/csrc/core/npu/NpuVariables.h" namespace c10_npu { namespace option { @@ -482,9 +483,9 @@ uint32_t OptionsManager::GetAclOpInitMode() const static uint32_t acl_op_init_mode = []() -> uint32_t { char* buf_val = std::getenv("ACL_OP_INIT_MODE"); // Default 1 for A2/A3; Default 0 for others - static bool default_value_acl_mode = ((GetSocVersion() >= SocVersion::Ascend910B1) && - (GetSocVersion() < SocVersion::Ascend310B1)) || - ((GetSocVersion() >= SocVersion::Ascend910_9391)); + static bool default_value_acl_mode = ((c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1) && + (c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1)) || + ((c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910_9391)); if (default_value_acl_mode) { int64_t acl_op_init_mode_ = (buf_val != nullptr) ? strtol(buf_val, nullptr, 10) : 1; } else { -- Gitee From 1a995dd5a999f2a7abe68bf54685926095a11cb8 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:47:35 +0800 Subject: [PATCH 3/5] fix --- torch_npu/csrc/core/npu/register/OptionsManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_npu/csrc/core/npu/register/OptionsManager.cpp b/torch_npu/csrc/core/npu/register/OptionsManager.cpp index 996b0bcc1b..ad20033c76 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -494,8 +494,8 @@ uint32_t OptionsManager::GetAclOpInitMode() std::unordered_map aclOpInitMode = getAclOpInitMode(); if (aclOpInitMode.find(acl_op_init_mode_) == aclOpInitMode.end()) { - acl_op_init_mode_ = 0; - TORCH_NPU_WARN_ONCE("Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 0."); + acl_op_init_mode_ = 1; + TORCH_NPU_WARN_ONCE("Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 1."); } return static_cast(acl_op_init_mode_); }(); -- Gitee From c9a56393c76b553873df52b3c2220c316915a2fb Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:52:47 +0800 Subject: [PATCH 4/5] fix --- torch_npu/csrc/core/npu/register/OptionsManager.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/torch_npu/csrc/core/npu/register/OptionsManager.cpp b/torch_npu/csrc/core/npu/register/OptionsManager.cpp index ad20033c76..3f6b980e4a 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -494,8 +494,13 @@ uint32_t OptionsManager::GetAclOpInitMode() std::unordered_map aclOpInitMode = getAclOpInitMode(); if (aclOpInitMode.find(acl_op_init_mode_) == aclOpInitMode.end()) { - acl_op_init_mode_ = 1; - TORCH_NPU_WARN_ONCE("Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 1."); + if (default_value_acl_mode) { + acl_op_init_mode_ = 1; + TORCH_NPU_WARN_ONCE("Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 1."); + } else { + acl_op_init_mode_ = 0; + TORCH_NPU_WARN_ONCE("Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 0."); + } } return static_cast(acl_op_init_mode_); }(); -- Gitee From e6f7e20a99e5980b08f6732f08d33011bd6b8e3a Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 15:07:07 +0800 Subject: [PATCH 5/5] fix --- torch_npu/csrc/core/npu/register/OptionsManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_npu/csrc/core/npu/register/OptionsManager.cpp b/torch_npu/csrc/core/npu/register/OptionsManager.cpp index 3f6b980e4a..dca3fb9d5d 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -500,7 +500,7 @@ uint32_t OptionsManager::GetAclOpInitMode() } else { acl_op_init_mode_ = 0; TORCH_NPU_WARN_ONCE("Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 0."); - } + } } return static_cast(acl_op_init_mode_); }(); -- Gitee