From 52c6f4b4f9ab89a12428f58771925fdc28ba868e Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 11:07:49 +0800 Subject: [PATCH 1/6] 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 6cb6d736aa..e4fb46f22f 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 93e7869a2ca48f0b7fd401816b19830e7703f40c Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:32:30 +0800 Subject: [PATCH 2/6] 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 e4fb46f22f..00d2221f5e 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 72565b588fcc0dc0d15ecd2ba15ef2f5a3032675 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:46:04 +0800 Subject: [PATCH 3/6] 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 00d2221f5e..583121a918 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 706f4dda973fdc0262275c40f44d6b370958699d Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:54:36 +0800 Subject: [PATCH 4/6] 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 583121a918..ae63bb2683 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 1e7b45da9a4e464a4e57cac4d518f74151d5dd55 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 15:05:11 +0800 Subject: [PATCH 5/6] 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 ae63bb2683..cdee0429fd 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 From 986025ef56c9a5fc38fc569555ec484c283ccf47 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 15:06:30 +0800 Subject: [PATCH 6/6] 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 cdee0429fd..788cf8a075 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