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 e170f867fb30c0cc3b7562e2de78688b4388ecb9..d3d206a7f8ba95c3988eca9e3b76ae8ff586e82f 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 40da4177cfe601402c4715c5fa3fce7ff410790d..db5b876659da87b9a8715bdcf4e95095cce08171 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 d28de624c7898558e310cb1ff636283f08315df4..d3dce45b64323613b1397d1866451887669db598 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 9bba2fdee6a1aac88b7b3bf45efc5ec667ab07db..974d9fa8817277f5fb97aa5444779c01b498cae0 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 d998841c2f80d35a9ff8c452120c61d28264b2e6..169911cd14caab74db3eeefb4ef60ca5e2c197e7 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)) {