From 0771207e2bc5f3ed2591072e9802465f528778cf Mon Sep 17 00:00:00 2001 From: likun104 Date: Mon, 20 Feb 2023 13:01:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvendors-config.ini=E4=B8=AD?= =?UTF-8?q?=E5=B8=A6=E6=9C=89=E7=A9=BA=E6=A0=BC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inc/framework/common/string_util.h | 11 ++- .../om_partition_subgraphs_pass_test.cc | 75 ++++++++++++++++++- .../om_partition_subgraphs_pass_test.cc | 75 ++++++++++++++++++- tf_adapter/util/npu_ops_identifier.cc | 1 + 4 files changed, 154 insertions(+), 8 deletions(-) diff --git a/inc/graphengine/inc/framework/common/string_util.h b/inc/graphengine/inc/framework/common/string_util.h index f03683633..c1216d90a 100644 --- a/inc/graphengine/inc/framework/common/string_util.h +++ b/inc/graphengine/inc/framework/common/string_util.h @@ -45,18 +45,21 @@ class GE_FUNC_VISIBILITY StringUtils { public: static std::string &Ltrim(std::string &s) { #if __cplusplus >= 201103L - (void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); })); + (void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](const int32_t c) { return std::isspace(c) == 0; })); #else - (void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + (void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), + std::not1(std::ptr_fun(std::isspace)))); #endif return s; } // lint -esym(551,*) static std::string &Rtrim(std::string &s) { /*lint !e618*/ #if __cplusplus >= 201103L - (void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); })); + (void)s.erase(std::find_if(s.rbegin(), s.rend(), [](const int32_t c) { return std::isspace(c) == 0; }).base(), + s.end()); #else - (void)s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + (void)s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), + s.end()); #endif return s; } 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 38e070429..53c4eb0e4 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 @@ -212,7 +212,7 @@ TEST_F(OmOptimizationPassTest, StringInputMaxSizeTest) { std::string target_graph = DoRunOmOptimizationPassTest(); EXPECT_EQ(target_graph, "arg_input_0_0->DecodeJpeg;DecodeJpeg->retval_DecodeJpeg_0_0"); } -TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest01) { +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest01) { SetLogLevelForC(0); std::string opp_path = __FILE__; opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; @@ -224,7 +224,78 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest01) { system(("mkdir -p " + path_vendors).c_str()); system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); std::vector vendors; - NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors); + EXPECT_TRUE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 3); + EXPECT_EQ(vendors[0], "customize"); + EXPECT_EQ(vendors[1], "mdc"); + EXPECT_EQ(vendors[2], "lhisi"); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest02) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("echo '' > " + path_config).c_str()); + std::vector vendors; + EXPECT_FALSE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 0); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest03) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority' > " + path_config).c_str()); + std::vector vendors; + EXPECT_FALSE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 0); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest04) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("rm -rf " + path_config).c_str()); + std::vector vendors; + EXPECT_FALSE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 0); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest05) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("echo ' load_priority = customize , mdc , lhisi ' > " + path_config).c_str()); + std::vector vendors; + EXPECT_TRUE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); EXPECT_EQ(vendors.size(), 3); EXPECT_EQ(vendors[0], "customize"); EXPECT_EQ(vendors[1], "mdc"); 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 38e070429..53c4eb0e4 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 @@ -212,7 +212,7 @@ TEST_F(OmOptimizationPassTest, StringInputMaxSizeTest) { std::string target_graph = DoRunOmOptimizationPassTest(); EXPECT_EQ(target_graph, "arg_input_0_0->DecodeJpeg;DecodeJpeg->retval_DecodeJpeg_0_0"); } -TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest01) { +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest01) { SetLogLevelForC(0); std::string opp_path = __FILE__; opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; @@ -224,7 +224,78 @@ TEST_F(OmOptimizationPassTest, NpuOpsIdentifierTest01) { system(("mkdir -p " + path_vendors).c_str()); system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); std::vector vendors; - NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors); + EXPECT_TRUE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 3); + EXPECT_EQ(vendors[0], "customize"); + EXPECT_EQ(vendors[1], "mdc"); + EXPECT_EQ(vendors[2], "lhisi"); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest02) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("echo '' > " + path_config).c_str()); + std::vector vendors; + EXPECT_FALSE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 0); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest03) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority' > " + path_config).c_str()); + std::vector vendors; + EXPECT_FALSE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 0); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest04) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("rm -rf " + path_config).c_str()); + std::vector vendors; + EXPECT_FALSE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); + EXPECT_EQ(vendors.size(), 0); + ClearLogLevelForC(); + system(("rm -rf " + opp_path).c_str()); +} +TEST_F(OmOptimizationPassTest, GetOppPluginVendorsTest05) { + SetLogLevelForC(0); + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1) + "opp_path/"; + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + std::string path_builtin = opp_path + "built-in"; + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_builtin).c_str()); + system(("mkdir -p " + path_vendors).c_str()); + system(("echo ' load_priority = customize , mdc , lhisi ' > " + path_config).c_str()); + std::vector vendors; + EXPECT_TRUE(NpuOpsIdentifier::GetOppPluginVendors(path_config, vendors)); EXPECT_EQ(vendors.size(), 3); EXPECT_EQ(vendors[0], "customize"); EXPECT_EQ(vendors[1], "mdc"); diff --git a/tf_adapter/util/npu_ops_identifier.cc b/tf_adapter/util/npu_ops_identifier.cc index e2b504552..ada3082f3 100644 --- a/tf_adapter/util/npu_ops_identifier.cc +++ b/tf_adapter/util/npu_ops_identifier.cc @@ -74,6 +74,7 @@ bool NpuOpsIdentifier::GetOppPluginVendors(const std::string &vendors_config, st ADP_LOG(ERROR) << "Format of file content is invalid!"; return false; } + (void) for_each(vendors.begin(), vendors.end(), &ge::StringUtils::Trim); return true; } -- Gitee