From 25f531d96ea2a94d9f2f575c41cbda2989feba4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E8=B1=AA=E6=9D=B0?= Date: Fri, 21 Feb 2025 13:30:41 +0000 Subject: [PATCH 1/2] =?UTF-8?q?!2932=20custom=5Fopp=5Fpath=20require=20Mer?= =?UTF-8?q?ge=20pull=20request=20!2932=20from=20=E5=94=90=E8=B1=AA?= =?UTF-8?q?=E6=9D=B0/ge=5Fdev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../depends/ge_runner/src/ge_runner_stub.cc | 11 ++++++++++ .../tests/depends/ge_runner/src/ge_stub.h | 2 ++ .../om_partition_subgraphs_pass_test.cc | 21 ++++++++++--------- .../om_partition_subgraphs_pass_test.cc | 21 ++++++++++--------- tf_adapter/util/npu_ops_identifier.cc | 7 ++++--- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc index e170f867f..d3d206a7f 100644 --- a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc +++ b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc @@ -40,7 +40,18 @@ #include "tf_adapter/common/adapter_logger.h" #include "callback_executor.h" +extern "C" const char *aclGetCustomOpLibPath() { + return ge::GetCustomPathStub(); +} + namespace ge { +std::string g_custon_path; +void SetCustomPathStub(std::string path) { + g_custon_path = path; +} +const char* GetCustomPathStub() { + return g_custon_path.c_str(); +} namespace { const std::map data_type_map = { {tensorflow::DataType::DT_FLOAT, ge::DataType::DT_FLOAT}, diff --git a/tf_adapter/tests/depends/ge_runner/src/ge_stub.h b/tf_adapter/tests/depends/ge_runner/src/ge_stub.h index 40da4177c..db5b87665 100644 --- a/tf_adapter/tests/depends/ge_runner/src/ge_stub.h +++ b/tf_adapter/tests/depends/ge_runner/src/ge_stub.h @@ -52,5 +52,7 @@ void RegRunGraphStub(RunGraphStub stub); using RunGraphAsyncStub = std::function&, RunAsyncCallback)>; void RegRunGraphAsyncStub(RunGraphAsyncStub stub); void ClearRegRunGraphAsyncStub(); +void SetCustomPathStub(std::string path); +const char* GetCustomPathStub(); } // namespace ge #endif // COMMON_GRAPH_DEBUG_GE_UTIL_H_ diff --git a/tf_adapter/tests/st/optimizers/testcase/om_partition_subgraphs_pass_test.cc b/tf_adapter/tests/st/optimizers/testcase/om_partition_subgraphs_pass_test.cc index d28de624c..d3dce45b6 100644 --- a/tf_adapter/tests/st/optimizers/testcase/om_partition_subgraphs_pass_test.cc +++ b/tf_adapter/tests/st/optimizers/testcase/om_partition_subgraphs_pass_test.cc @@ -10,6 +10,7 @@ #include "tensorflow/core/platform/logging.h" #include "nlohmann/json.hpp" #include "alog_stub.h" +#include "ge_stub.h" #define private public #include "tf_adapter/util/npu_ops_identifier.h" @@ -342,7 +343,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest04) { opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; std::string custom_opp_path = opp_path + "custom_opp_path"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", custom_opp_path.c_str(), 1); + ge::SetCustomPathStub(custom_opp_path); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; @@ -363,7 +364,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest05) { opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; std::string custom_opp_path = opp_path + "custom_opp_path"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", "", 1); + ge::SetCustomPathStub(""); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; @@ -385,7 +386,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest06) { std::string custom_opp_path_01 = opp_path + "custom_opp_path_01"; std::string custom_opp_path_02 = opp_path + "custom_opp_path_02"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", (custom_opp_path_01 + ":" + custom_opp_path_02).c_str(), 1); + ge::SetCustomPathStub((custom_opp_path_01 + ":" + custom_opp_path_02)); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; @@ -407,7 +408,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest07) { opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; std::string custom_opp_path = opp_path + "custom_opp_path"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", custom_opp_path.c_str(), 1); + ge::SetCustomPathStub(custom_opp_path); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; system(("mkdir -p " + path_builtin).c_str()); @@ -430,12 +431,12 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest08) { std::string custom_opp_path_02 = opp_path + "/custom_opp_path_02"; std::string custom_opp_path_invalid_02 = opp_path + "/custom_opp_path_invalid_02"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", (custom_opp_path_01 + ":" + - custom_opp_path_invalid_01 + ":" + - custom_opp_path_empty + ":" + - custom_opp_path_02 + ":" + - custom_opp_path_invalid_02 - ).c_str(), 1); + ge::SetCustomPathStub((custom_opp_path_01 + ":" + + custom_opp_path_invalid_01 + ":" + + custom_opp_path_empty + ":" + + custom_opp_path_02 + ":" + + custom_opp_path_invalid_02 + )); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; diff --git a/tf_adapter/tests/ut/optimizers/testcase/om_partition_subgraphs_pass_test.cc b/tf_adapter/tests/ut/optimizers/testcase/om_partition_subgraphs_pass_test.cc index 9bba2fdee..974d9fa88 100644 --- a/tf_adapter/tests/ut/optimizers/testcase/om_partition_subgraphs_pass_test.cc +++ b/tf_adapter/tests/ut/optimizers/testcase/om_partition_subgraphs_pass_test.cc @@ -10,6 +10,7 @@ #include "tensorflow/core/platform/logging.h" #include "nlohmann/json.hpp" #include "alog_stub.h" +#include "ge_stub.h" #define private public #include "tf_adapter/util/npu_ops_identifier.h" @@ -348,7 +349,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest04) { opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; std::string custom_opp_path = opp_path + "custom_opp_path"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", custom_opp_path.c_str(), 1); + ge::SetCustomPathStub(custom_opp_path); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; @@ -369,7 +370,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest05) { opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; std::string custom_opp_path = opp_path + "custom_opp_path"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", "", 1); + ge::SetCustomPathStub(""); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; @@ -391,7 +392,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest06) { std::string custom_opp_path_01 = opp_path + "custom_opp_path_01"; std::string custom_opp_path_02 = opp_path + "custom_opp_path_02"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", (custom_opp_path_01 + ":" + custom_opp_path_02).c_str(), 1); + ge::SetCustomPathStub((custom_opp_path_01 + ":" + custom_opp_path_02)); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; @@ -413,7 +414,7 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest07) { opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; std::string custom_opp_path = opp_path + "custom_opp_path"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", custom_opp_path.c_str(), 1); + ge::SetCustomPathStub(custom_opp_path); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; system(("mkdir -p " + path_builtin).c_str()); @@ -436,12 +437,12 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest08) { std::string custom_opp_path_02 = opp_path + "/custom_opp_path_02"; std::string custom_opp_path_invalid_02 = opp_path + "/custom_opp_path_invalid_02"; setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); - setenv("ASCEND_CUSTOM_OPP_PATH", (custom_opp_path_01 + ":" + - custom_opp_path_invalid_01 + ":" + - custom_opp_path_empty + ":" + - custom_opp_path_02 + ":" + - custom_opp_path_invalid_02 - ).c_str(), 1); + ge::SetCustomPathStub((custom_opp_path_01 + ":" + + custom_opp_path_invalid_01 + ":" + + custom_opp_path_empty + ":" + + custom_opp_path_02 + ":" + + custom_opp_path_invalid_02 + )); std::string path_builtin = opp_path + "built-in"; std::string path_vendors = opp_path + "vendors"; std::string path_config = path_vendors + "/config.ini"; diff --git a/tf_adapter/util/npu_ops_identifier.cc b/tf_adapter/util/npu_ops_identifier.cc index d998841c2..169911cd1 100644 --- a/tf_adapter/util/npu_ops_identifier.cc +++ b/tf_adapter/util/npu_ops_identifier.cc @@ -20,6 +20,7 @@ #include "nlohmann/json.hpp" #include "framework/common/string_util.h" +#include "register/register_base.h" #include "tensorflow/core/platform/logging.h" #include "tf_adapter/common/adapter_logger.h" #include "tf_adapter/common/common.h" @@ -82,9 +83,9 @@ bool NpuOpsIdentifier::IsNewOppPathStruct(const std::string &opp_path) { } void NpuOpsIdentifier::GetCustomOpPathFromCustomOppPath(std::vector &custom_ops_json_path_vec) { - ADP_LOG(INFO) << "Start to get custom ops json path from ASCEND_CUSTOM_OPP_PATH schedule."; + ADP_LOG(INFO) << "Start to get custom ops json path from custom opp path schedule."; custom_ops_json_path_vec.clear(); - const char *const custom_opp_path_env = std::getenv("ASCEND_CUSTOM_OPP_PATH"); + const char *const custom_opp_path_env = aclGetCustomOpLibPath(); if (custom_opp_path_env == nullptr) { ADP_LOG(INFO) << "env ASCEND_CUSTOM_OPP_PATH is not defined."; return; @@ -94,7 +95,7 @@ void NpuOpsIdentifier::GetCustomOpPathFromCustomOppPath(std::vector ADP_LOG(WARNING) << "env ASCEND_CUSTOM_OPP_PATH is defined but it's empty."; return; } - ADP_LOG(INFO) << "value of env ASCEND_CUSTOM_OPP_PATH is " << custom_opp_path << "."; + ADP_LOG(INFO) << "value of custom opp path is " << custom_opp_path << "."; std::vector custom_paths = ge::StringUtils::Split(custom_opp_path, ':'); for (const auto &custom_path : custom_paths) { if ((!custom_path.empty()) && (mmIsDir(custom_path.c_str()) == EN_OK)) { -- Gitee From 05dac14a0bccdfad873885e1990f41f46a5e71c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A9=B9=E9=9A=BD?= Date: Mon, 24 Feb 2025 01:22:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?!2936=20del=20dll=20Merge=20pull=20request?= =?UTF-8?q?=20!2936=20from=20=E8=A9=B9=E9=9A=BD/del=5Fdll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tf_adapter/tests/depends/alog/src/alog_stub.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tf_adapter/tests/depends/alog/src/alog_stub.cc b/tf_adapter/tests/depends/alog/src/alog_stub.cc index 98e304609..73d95c7f3 100644 --- a/tf_adapter/tests/depends/alog/src/alog_stub.cc +++ b/tf_adapter/tests/depends/alog/src/alog_stub.cc @@ -26,15 +26,15 @@ #define MSG_LENGTH_STUB 1024 int g_logLevel = 0xffffffff; -DLL_EXPORT void SetLogLevelForC(int logLevel) { +void SetLogLevelForC(int logLevel) { g_logLevel = logLevel; } -DLL_EXPORT void ClearLogLevelForC() { +void ClearLogLevelForC() { g_logLevel = 0xffffffff; } -DLL_EXPORT int CheckLogLevelForC(int moduleId, int logLevel) { +int CheckLogLevelForC(int moduleId, int logLevel) { if (logLevel >= g_logLevel) { return 1; } else { @@ -58,6 +58,6 @@ void DlogRecordForC(int moduleId, int level, const char *fmt, ...) { return; } -DLL_EXPORT int DlogReportFinalize() { +int DlogReportFinalize() { return 0; } \ No newline at end of file -- Gitee