From f4a618ee314e7331caf6676a4a0da2b452c42e8a 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 | 11 +++++++++-- torch_npu/csrc/framework/OpCommand.cpp | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/torch_npu/csrc/core/npu/register/OptionsManager.cpp b/torch_npu/csrc/core/npu/register/OptionsManager.cpp index 13454bc47e..b32468ca6e 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -481,8 +481,15 @@ 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 3dee364bd1..380af6cf6e 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 b061f47088b2ed1448554b9cf75b55ffd4034d8f Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:31:56 +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 b32468ca6e..8299fe5371 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 77b2ea48944ee8df096e784b5b49921a6727b637 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:46:24 +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 8299fe5371..eb8e1f428f 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -493,8 +493,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 0b258439f3016cdfc8181b494826b304a717802f Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 14:53:51 +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 eb8e1f428f..eedf57f1ca 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -493,8 +493,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 a2eece725a1f36f2b96b46db4006232855f1838c Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 15:05:30 +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 eedf57f1ca..cc4fa9e667 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -499,7 +499,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 5b455daef39767b86d8266b475262aa46a3a7531 Mon Sep 17 00:00:00 2001 From: GuoGuanghao Date: Sat, 13 Sep 2025 15:06:10 +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 cc4fa9e667..00fb260d9e 100644 --- a/torch_npu/csrc/core/npu/register/OptionsManager.cpp +++ b/torch_npu/csrc/core/npu/register/OptionsManager.cpp @@ -499,7 +499,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