已合并
fix: 修正内置包注册并更新 fusion pass 示例文档 #3795
duhua创建于 6月30日
fix: 修正内置包注册并更新 fusion pass 示例文档 #3795
已合并
duhua创建于 6月30日
14 个文件变更+67-138
Mexamples/fusion_pass/graph_base_pass/2_move_relu_before_concat_pass/cpp/README.md+3-5
@@ -107,15 +107,13 @@
107 ```107 ```
108 export DUMP_GE_GRAPH=1108 export DUMP_GE_GRAPH=1
109 ```109 ```
110- - 安装es_all.whl110+ - 设置 build 目录环境变量,`BUILD_PATH` 为“程序编译”步骤中生成的 build 目录实际路径:
111 ```111 ```
112- pip install --force-reinstall --upgrade --target ${ASCEND_PATH}/python/site-packages/112+ export BUILD_PATH=/path/to/build
113- ${BUILD_PATH}/es_output/whl/es_all-*****.whl
114 ```113 ```
115- `${BUILD_PATH}`请替换为build目录的实际路径。
116 - 设置环境变量,添加es_all.so的路径114 - 设置环境变量,添加es_all.so的路径
117 ```115 ```
118- LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"116+ export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"
119 ```117 ```
120 - 进入data目录执行.py文件导出air:118 - 进入data目录执行.py文件导出air:
121 ```119 ```
Mexamples/fusion_pass/graph_base_pass/2_move_relu_before_concat_pass/cpp/README_en.md+4-6
@@ -110,18 +110,16 @@ Assume CANN package installation directory is INSTALL_PATH, e.g., `/home/HwHiAiU
110 export DUMP_GE_GRAPH=1110 export DUMP_GE_GRAPH=1
111 ```111 ```
112 112 
113- - Install es_all.whl113+ - Set the build directory environment variable. `BUILD_PATH` is the actual build directory generated in "Program Compilation":
114 114 
115- ```python115+ ```bash
116- pip install --force-reinstall --upgrade --target ${ASCEND_PATH}/python/site-packages/116+ export BUILD_PATH=/path/to/build
117- ${BUILD_PATH}/es_output/whl/es_all-*****.whl
118 ```117 ```
119 118 
120- Replace `${BUILD_PATH}` with actual build directory path.
121 - Set environment variable to add es_all.so path119 - Set environment variable to add es_all.so path
122 120 
123 ```bash121 ```bash
124- LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"122+ export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"
125 ```123 ```
126 124 
127 - Enter data directory and execute .py file to export air:125 - Enter data directory and execute .py file to export air:
Mexamples/fusion_pass/graph_base_pass/2_move_relu_before_concat_pass/python/README.md+5-4
@@ -48,7 +48,7 @@ export ASCEND_GE_PY_PASS_PATH=$PWD/python/src/python_move_relu_before_concat_pas
482. 生成 AIR 模型:482. 生成 AIR 模型:
49 49 
50```bash50```bash
51-cd cpp/data51+cd ../cpp/data
52python es_gen_air.py52python es_gen_air.py
53```53```
54 54 
@@ -77,9 +77,10 @@ cmake --build build --target build_es_all -j$(nproc)
77安装生成的 Python 包,并让当前 Python 进程能找到包和对应的动态库:77安装生成的 Python 包,并让当前 Python 进程能找到包和对应的动态库:
78 78 
79```bash79```bash
80-pip install --force-reinstall --upgrade --target ./build/whl_package ./build/es_output/whl/es_all-1.0.0-py3-none-any.whl80+export BUILD_PATH="$PWD/build"
81-export PYTHONPATH="$PWD/build/whl_package:${PYTHONPATH:-}"81+pip install --force-reinstall --upgrade --target "${BUILD_PATH}/whl_package" "${BUILD_PATH}/es_output/whl/es_all-1.0.0-py3-none-any.whl"
82-export LD_LIBRARY_PATH="$PWD/build/es_output/lib64:${LD_LIBRARY_PATH:-}"82+export PYTHONPATH="${BUILD_PATH}/whl_package:${PYTHONPATH:-}"
83+export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH:-}"
83cd ..84cd ..
84```85```
85 86 
Mexamples/fusion_pass/graph_base_pass/2_move_relu_before_concat_pass/python/README_en.md+5-4
@@ -48,7 +48,7 @@ The following commands are executed in `2_move_relu_before_concat_pass` director
482. Generate AIR model:482. Generate AIR model:
49 49 
50 ```bash50 ```bash
51- cd cpp/data51+ cd ../cpp/data
52 python es_gen_air.py52 python es_gen_air.py
53 ```53 ```
54 54 
@@ -77,9 +77,10 @@ cmake --build build --target build_es_all -j$(nproc)
77Install generated Python package and let current Python process find the package and corresponding dynamic library:77Install generated Python package and let current Python process find the package and corresponding dynamic library:
78 78 
79```bash79```bash
80-pip install --force-reinstall --upgrade --target ./build/whl_package ./build/es_output/whl/es_all-1.0.0-py3-none-any.whl80+export BUILD_PATH="$PWD/build"
81-export PYTHONPATH="$PWD/build/whl_package:${PYTHONPATH:-}"81+pip install --force-reinstall --upgrade --target "${BUILD_PATH}/whl_package" "${BUILD_PATH}/es_output/whl/es_all-1.0.0-py3-none-any.whl"
82-export LD_LIBRARY_PATH="$PWD/build/es_output/lib64:${LD_LIBRARY_PATH:-}"82+export PYTHONPATH="${BUILD_PATH}/whl_package:${PYTHONPATH:-}"
83+export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH:-}"
83cd ..84cd ..
84```85```
85 86 
Mexamples/fusion_pass/pattern_base_pass/3_fuse_matmul_add_pass_with_pattern_matcher_config/cpp/README.md+7-8
@@ -109,15 +109,14 @@
109 ```109 ```
110 export DUMP_GE_GRAPH=1110 export DUMP_GE_GRAPH=1
111 ```111 ```
112- - 安装es_all.whl112+ - 设置 build 目录环境变量,`BUILD_PATH` 为“程序编译”步骤中生成的 build 目录实际路径:
113- ```113+ ```
114- pip install --force-reinstall --upgrade --target ${ASCEND_PATH}/python/site-packages/ ${BUILD_PATH}/es_output/whl/es_all-*****.whl114+ export BUILD_PATH=/path/to/build
115+ ```
116+ - 设置环境变量,添加es_all.so的路径
117+ ```
118+ export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"
115 ```119 ```
116- `${BUILD_PATH}`请替换为build目录的实际路径。
117- - 设置环境变量,添加es_all.so的路径
118- ```
119- export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"
120- ```
1212. 使用ATC离线推理。1202. 使用ATC离线推理。
122 - 进入data目录执行.py文件导出air(文件中使用了 es 的 python 接口来构图):121 - 进入data目录执行.py文件导出air(文件中使用了 es 的 python 接口来构图):
123 ```122 ```
Mexamples/fusion_pass/pattern_base_pass/3_fuse_matmul_add_pass_with_pattern_matcher_config/cpp/README_en.md+6-8
@@ -112,19 +112,17 @@ Assume CANN software package installation directory is INSTALL_PATH, e.g., `/hom
112 export DUMP_GE_GRAPH=1112 export DUMP_GE_GRAPH=1
113 ```113 ```
114 114 
115- - Install es_all.whl115+ - Set the build directory environment variable. `BUILD_PATH` is the actual build directory generated in "Program Compilation":
116 116 
117- ```python117+ ```bash
118- pip install --force-reinstall --upgrade --target ${ASCEND_PATH}/python/site-packages/ ${BUILD_PATH}/es_output/whl/es_all-*****.whl118+ export BUILD_PATH=/path/to/build
119 ```119 ```
120 120 
121- Replace `${BUILD_PATH}` with actual build directory path.
122- 
123 - Set environment variable to add es_all.so path121 - Set environment variable to add es_all.so path
124 122 
125- ```bash123+ ```bash
126- export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"124+ export LD_LIBRARY_PATH="${BUILD_PATH}/es_output/lib64:${LD_LIBRARY_PATH}"
127- ```125+ ```
128 126 
1292. Use ATC offline inference.1272. Use ATC offline inference.
130 - Enter data directory and execute .py file to export air (uses es python interface for graph construction):128 - Enter data directory and execute .py file to export air (uses es python interface for graph construction):
Mgraph_metadef/register/op_tiling/op_tiling_py.cc+2-1
@@ -113,6 +113,7 @@ constexpr size_t kMaxTilingDataSize = 16UL * 1024UL;
113constexpr size_t kWorkspaceHolerSize = 8UL;113constexpr size_t kWorkspaceHolerSize = 8UL;
114const std::string kAttrGroup = "group";114const std::string kAttrGroup = "group";
115const std::string kIsNullOutput = "_is_null_output";115const std::string kIsNullOutput = "_is_null_output";
116+constexpr const char *const kBuiltInPackageName = "built-in";
116 117 
117struct ContextComponent {118struct ContextComponent {
118 std::vector<gert::StorageShape> storage_shapes;119 std::vector<gert::StorageShape> storage_shapes;
@@ -2125,7 +2126,7 @@ extern "C" Status TbeLoadSoAndSaveToRegistry(const char *so_path) {
2125 gert::DefaultOpImplSpaceRegistryV2::GetInstance().SetSpaceRegistry(space_registry_v2);2126 gert::DefaultOpImplSpaceRegistryV2::GetInstance().SetSpaceRegistry(space_registry_v2);
2126 }2127 }
2127 return gert::DefaultOpImplSpaceRegistryV2::GetInstance().GetSpaceRegistry()->AddSoToRegistry(2128 return gert::DefaultOpImplSpaceRegistryV2::GetInstance().GetSpaceRegistry()->AddSoToRegistry(
2128- gert::OppSoDesc({ge::AscendString(so_path)}, ""));2129+ gert::OppSoDesc({ge::AscendString(so_path)}, kBuiltInPackageName));
2129}2130}
2130} // namespace2131} // namespace
2131} // namespace optiling2132} // namespace optiling
Mtests/dflow/runner/st/testcase/init_ge.h+0-3
@@ -15,7 +15,6 @@
15#include "ge/ge_api.h"15#include "ge/ge_api.h"
16#include "ge/ge_api_v2.h"16#include "ge/ge_api_v2.h"
17#include "ge_running_env/ge_running_env_faker.h"17#include "ge_running_env/ge_running_env_faker.h"
18-#include "ge_running_env/scoped_unset_ld_preload.h"
19#include "compiler/session/dflow_api.h"18#include "compiler/session/dflow_api.h"
20namespace ge {19namespace ge {
21 20 
@@ -23,7 +22,6 @@ inline void InitGe() {
23 std::map<AscendString, AscendString> options;22 std::map<AscendString, AscendString> options;
24 options[ge::OPTION_HOST_ENV_OS] = "linux";23 options[ge::OPTION_HOST_ENV_OS] = "linux";
25 options[ge::OPTION_HOST_ENV_CPU] = "x86_64";24 options[ge::OPTION_HOST_ENV_CPU] = "x86_64";
26- ScopedUnsetLdPreload guard;
27 auto init_status = ge::GEInitialize(options);25 auto init_status = ge::GEInitialize(options);
28 if (init_status != SUCCESS) {26 if (init_status != SUCCESS) {
29 std::cout << "ge init failed , ret code:" << init_status << std::endl;27 std::cout << "ge init failed , ret code:" << init_status << std::endl;
@@ -43,7 +41,6 @@ inline void ReInitGe() {
43 std::map<AscendString, AscendString> options;41 std::map<AscendString, AscendString> options;
44 options[ge::OPTION_HOST_ENV_OS] = "linux";42 options[ge::OPTION_HOST_ENV_OS] = "linux";
45 options[ge::OPTION_HOST_ENV_CPU] = "x86_64";43 options[ge::OPTION_HOST_ENV_CPU] = "x86_64";
46- ScopedUnsetLdPreload guard;
47 auto init_status = ge::GEInitializeV2(options);44 auto init_status = ge::GEInitializeV2(options);
48 if (init_status != SUCCESS) {45 if (init_status != SUCCESS) {
49 std::cout << "ge init failed , ret code:" << init_status << std::endl;46 std::cout << "ge init failed , ret code:" << init_status << std::endl;
Dtests/framework/ge_running_env/include/ge_running_env/scoped_unset_ld_preload.h+0-39
@@ -1,39 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-#ifndef GE_RUNNING_ENV_SCOPED_UNSET_LD_PRELOAD_H_
12-#define GE_RUNNING_ENV_SCOPED_UNSET_LD_PRELOAD_H_
13- 
14-#include <cstdlib>
15-#include <string>
16- 
17-class ScopedUnsetLdPreload {
18- public:
19- ScopedUnsetLdPreload() {
20- const char *ld_preload = std::getenv("LD_PRELOAD");
21- if (ld_preload != nullptr) {
22- has_ld_preload_ = true;
23- ld_preload_ = ld_preload;
24- (void)unsetenv("LD_PRELOAD");
25- }
26- }
27- 
28- ~ScopedUnsetLdPreload() {
29- if (has_ld_preload_) {
30- (void)setenv("LD_PRELOAD", ld_preload_.c_str(), 1);
31- }
32- }
33- 
34- private:
35- bool has_ld_preload_{false};
36- std::string ld_preload_;
37-};
38- 
39-#endif // GE_RUNNING_ENV_SCOPED_UNSET_LD_PRELOAD_H_
Mtests/framework/ge_running_env/tests/test_main.cc+11-13
@@ -13,30 +13,28 @@
13#include "common/debug/log.h"13#include "common/debug/log.h"
14#include "ge/ge_api.h"14#include "ge/ge_api.h"
15#include "ge_running_env/ge_running_env_faker.h"15#include "ge_running_env/ge_running_env_faker.h"
16-#include "ge_running_env/scoped_unset_ld_preload.h"
17 16 
18using namespace std;17using namespace std;
19using namespace ge;18using namespace ge;
20 19 
21extern "C" const char *__lsan_default_suppressions() {20extern "C" const char *__lsan_default_suppressions() {
22- return "leak:_PyObject_Malloc\n"21+ return "leak:_PyObject_Malloc\n"
23- "leak:_PyObject_Realloc\n"22+ "leak:_PyObject_Realloc\n"
24- "leak:PyType_GenericAlloc\n"23+ "leak:PyType_GenericAlloc\n"
25- "leak:PyType_Ready\n"24+ "leak:PyType_Ready\n"
26- "leak:PyObject_GC_New\n"25+ "leak:PyObject_GC_New\n"
27- "leak:PyObject_GC_NewVar\n"26+ "leak:PyObject_GC_NewVar\n"
28- "leak:_PyObject_GC_Malloc\n"27+ "leak:_PyObject_GC_Malloc\n"
29- "leak:PyUnicode_New\n"28+ "leak:PyUnicode_New\n"
30- "leak:Py_InitializeEx\n"29+ "leak:Py_InitializeEx\n"
31- "leak:PyImport_ImportModuleLevelObject\n"30+ "leak:PyImport_ImportModuleLevelObject\n"
32- "leak:libpython\n";31+ "leak:libpython\n";
33}32}
34 33 
35int main(int argc, char **argv) {34int main(int argc, char **argv) {
36 map<AscendString, AscendString> options;35 map<AscendString, AscendString> options;
37 options.insert({AscendString("ge.exec.opWaitTimeout"), AscendString("11")});36 options.insert({AscendString("ge.exec.opWaitTimeout"), AscendString("11")});
38 options.insert({AscendString("ge.exec.opExecuteTimeout"), AscendString("11")});37 options.insert({AscendString("ge.exec.opExecuteTimeout"), AscendString("11")});
39- ScopedUnsetLdPreload guard;
40 ge::GEInitialize(options);38 ge::GEInitialize(options);
41 GeRunningEnvFaker::BackupEnv();39 GeRunningEnvFaker::BackupEnv();
42 testing::InitGoogleTest(&argc, argv);40 testing::InitGoogleTest(&argc, argv);
Mtests/ge/st/testcase/dump/utils/dump_test_fixture.h+0-2
@@ -20,7 +20,6 @@
20#include <gtest/gtest.h>20#include <gtest/gtest.h>
21#include "framework/ge_runtime_stub/include/common/dump_checker.h" // DumpCheckRuntimeStub21#include "framework/ge_runtime_stub/include/common/dump_checker.h" // DumpCheckRuntimeStub
22#include "ge_running_env/ge_running_env_faker.h" // GeRunningEnvFaker22#include "ge_running_env/ge_running_env_faker.h" // GeRunningEnvFaker
23-#include "ge_running_env/scoped_unset_ld_preload.h" // GeRunningEnvFaker
24#include "ge/st/stubs/utils/mock_ops_kernel_builder.h" // MockForGenerateTask23#include "ge/st/stubs/utils/mock_ops_kernel_builder.h" // MockForGenerateTask
25#include "ge/st/stubs/utils/taskdef_builder.h" // AiCoreTaskDefBuilder24#include "ge/st/stubs/utils/taskdef_builder.h" // AiCoreTaskDefBuilder
26#include "common/opskernel/ops_kernel_info_types.h"25#include "common/opskernel/ops_kernel_info_types.h"
@@ -58,7 +57,6 @@ template <bool dynamic>
58class DumpST : public ::testing::Test {57class DumpST : public ::testing::Test {
59 public:58 public:
60 static void SetUpTestSuite() {59 static void SetUpTestSuite() {
61- ScopedUnsetLdPreload guard;
62 const std::map<AscendString, AscendString> options = {60 const std::map<AscendString, AscendString> options = {
63 {OPTION_HOST_ENV_OS, "linux"},61 {OPTION_HOST_ENV_OS, "linux"},
64 {OPTION_HOST_ENV_CPU, "x86_64"},62 {OPTION_HOST_ENV_CPU, "x86_64"},
Mtests/ge/ut/ge/graph/passes/atomic_addr_clean_pass_unittest.cc+2-8
@@ -31,18 +31,12 @@
31#include "engines/manager/opskernel_manager/ops_kernel_manager.h"31#include "engines/manager/opskernel_manager/ops_kernel_manager.h"
32#include "graph/debug/ge_attr_define.h"32#include "graph/debug/ge_attr_define.h"
33#include "common/plugin/plugin_manager.h"33#include "common/plugin/plugin_manager.h"
34-#include "ge_running_env/scoped_unset_ld_preload.h"
35 34 
36using namespace testing;35using namespace testing;
37using namespace domi;36using namespace domi;
38 37 
39namespace ge {38namespace ge {
40namespace {39namespace {
41-static Status GEInitializeWithoutLdPreload(const std::map<AscendString, AscendString> &options) {
42- ScopedUnsetLdPreload guard;
43- return GEInitialize(options);
44-}
45- 
46class TestOpsKernelInfoStore : public OpsKernelInfoStore {40class TestOpsKernelInfoStore : public OpsKernelInfoStore {
47 public:41 public:
48 TestOpsKernelInfoStore() = default;42 TestOpsKernelInfoStore() = default;
@@ -109,7 +103,7 @@ class UtestGraphPassesAtomicAddrCleanPass : public Test {
109 ofs.close();103 ofs.close();
110 rename(json_tmp_path.c_str(), json_path.c_str());104 rename(json_tmp_path.c_str(), json_path.c_str());
111 std::map<AscendString, AscendString> options;105 std::map<AscendString, AscendString> options;
112- GEInitializeWithoutLdPreload(options);106+ GEInitialize(options);
113 {107 {
114 std::ifstream ifs(json_backup_path);108 std::ifstream ifs(json_backup_path);
115 if (ifs.is_open()) {109 if (ifs.is_open()) {
@@ -832,7 +826,7 @@ TEST_F(UtestGraphPassesAtomicAddrCleanPass, test_ge_init_fail) {
832 AtomicAddrCleanPass atomi_addr_clean_pass;826 AtomicAddrCleanPass atomi_addr_clean_pass;
833 EXPECT_EQ(atomi_addr_clean_pass.CallCompileOp(node_list), ge::GE_CLI_GE_NOT_INITIALIZED);827 EXPECT_EQ(atomi_addr_clean_pass.CallCompileOp(node_list), ge::GE_CLI_GE_NOT_INITIALIZED);
834 std::map<AscendString, AscendString> options;828 std::map<AscendString, AscendString> options;
835- GEInitializeWithoutLdPreload(options);829+ GEInitialize(options);
836}830}
837 831 
838} // namespace ge832} // namespace ge
Mtests/ge/ut/ge/graph/passes/compile_nodes_pass_unittest.cc+2-8
@@ -22,17 +22,11 @@
22#include "engines/manager/opskernel_manager/ops_kernel_manager.h"22#include "engines/manager/opskernel_manager/ops_kernel_manager.h"
23#include "ge/ge_api.h"23#include "ge/ge_api.h"
24#include "api/gelib/gelib.h"24#include "api/gelib/gelib.h"
25-#include "ge_running_env/scoped_unset_ld_preload.h"
26 25 
27using namespace std;26using namespace std;
28using namespace ge;27using namespace ge;
29 28 
30namespace {29namespace {
31-static Status GEInitializeWithoutLdPreload(const std::map<AscendString, AscendString> &options) {
32- ScopedUnsetLdPreload guard;
33- return GEInitialize(options);
34-}
35- 
36class TestOpsKernelInfoStore : public OpsKernelInfoStore {30class TestOpsKernelInfoStore : public OpsKernelInfoStore {
37 public:31 public:
38 TestOpsKernelInfoStore() = default;32 TestOpsKernelInfoStore() = default;
@@ -99,7 +93,7 @@ class UtestCompileNodesPass : public testing::Test {
99 protected:93 protected:
100 void SetUp() {94 void SetUp() {
101 std::map<AscendString, AscendString> options;95 std::map<AscendString, AscendString> options;
102- GEInitializeWithoutLdPreload(options);96+ GEInitialize(options);
103 ge::GELib::GetInstance()->OpsKernelManagerObj().ops_kernel_store_.clear();97 ge::GELib::GetInstance()->OpsKernelManagerObj().ops_kernel_store_.clear();
104 }98 }
105 void TearDown() {99 void TearDown() {
@@ -150,7 +144,7 @@ TEST_F(UtestCompileNodesPass, not_init_fail) {
150 EXPECT_EQ(pass_.Run(graph_), GE_CLI_GE_NOT_INITIALIZED);144 EXPECT_EQ(pass_.Run(graph_), GE_CLI_GE_NOT_INITIALIZED);
151 EXPECT_EQ(graph_->GetDirectNodesSize(), 3);145 EXPECT_EQ(graph_->GetDirectNodesSize(), 3);
152 std::map<AscendString, AscendString> options;146 std::map<AscendString, AscendString> options;
153- GEInitializeWithoutLdPreload(options);147+ GEInitialize(options);
154}148}
155 149 
156TEST_F(UtestCompileNodesPass, no_kernel_fail) {150TEST_F(UtestCompileNodesPass, no_kernel_fail) {
Mtests/ge/ut/ge/graph_ir/ge_ir_build_unittest.cc+20-29
@@ -9,7 +9,6 @@
9 */9 */
10 10 
11#include <stdio.h>11#include <stdio.h>
12-#include <cstdlib>
13#include <fstream>12#include <fstream>
14#include <gtest/gtest.h>13#include <gtest/gtest.h>
15#include "api/aclgrph/option_utils.h"14#include "api/aclgrph/option_utils.h"
@@ -48,7 +47,6 @@
48#include "ge_running_env/fake_op.h"47#include "ge_running_env/fake_op.h"
49#include "ge_running_env/fake_graph_optimizer.h"48#include "ge_running_env/fake_graph_optimizer.h"
50#include "ge_running_env/fake_engine.h"49#include "ge_running_env/fake_engine.h"
51-#include "ge_running_env/scoped_unset_ld_preload.h"
52 50 
53const string AddNYes = "AddNYes";51const string AddNYes = "AddNYes";
54const char *const kEnvName = "ASCEND_OPP_PATH";52const char *const kEnvName = "ASCEND_OPP_PATH";
@@ -105,13 +103,6 @@ class UtestIrBuild : public testing::Test {
105 103 
106 void TearDown() {}104 void TearDown() {}
107};105};
108- 
109-template <typename Options>
110-static ge::graphStatus AclgrphBuildInitializeWithoutLdPreload(Options &options) {
111- ScopedUnsetLdPreload guard;
112- return ge::aclgrphBuildInitialize(options);
113-}
114- 
115static std::vector<uint8_t> ReadFileToVector(const std::string &path) {106static std::vector<uint8_t> ReadFileToVector(const std::string &path) {
116 std::ifstream file(path, std::ios::binary);107 std::ifstream file(path, std::ios::binary);
117 if (!file.is_open()) {108 if (!file.is_open()) {
@@ -1308,7 +1299,7 @@ TEST(UtestIrBuild, aclgrphBuildInitialize_test) {
1308 global_options[ge::OPTION_EXEC_HCCL_FLAG] = "0";1299 global_options[ge::OPTION_EXEC_HCCL_FLAG] = "0";
1309 global_options[ge::OPTION_HOST_ENV_OS] = "linux";1300 global_options[ge::OPTION_HOST_ENV_OS] = "linux";
1310 global_options[ge::OPTION_HOST_ENV_CPU] = "x86_64";1301 global_options[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1311- ge::graphStatus ret = AclgrphBuildInitializeWithoutLdPreload(global_options);1302+ ge::graphStatus ret = ge::aclgrphBuildInitialize(global_options);
1312 ge::aclgrphBuildFinalize();1303 ge::aclgrphBuildFinalize();
1313 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);1304 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);
1314 1305 
@@ -1317,13 +1308,13 @@ TEST(UtestIrBuild, aclgrphBuildInitialize_test) {
1317 global_options1[ge::OPTION_HOST_ENV_OS] = "linux";1308 global_options1[ge::OPTION_HOST_ENV_OS] = "linux";
1318 global_options1[ge::OPTION_HOST_ENV_CPU] = "x86_64";1309 global_options1[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1319 global_options1[ge::OPTION_SCREEN_PRINT_MODE] = "enable";1310 global_options1[ge::OPTION_SCREEN_PRINT_MODE] = "enable";
1320- ret = AclgrphBuildInitializeWithoutLdPreload(global_options1);1311+ ret = ge::aclgrphBuildInitialize(global_options1);
1321 ge::aclgrphBuildFinalize();1312 ge::aclgrphBuildFinalize();
1322 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);1313 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);
1323 1314 
1324 std::map<AscendString, AscendString> global_options2;1315 std::map<AscendString, AscendString> global_options2;
1325 global_options1["ge.autoTuneMode"] = "RA";1316 global_options1["ge.autoTuneMode"] = "RA";
1326- ret = AclgrphBuildInitializeWithoutLdPreload(global_options1);1317+ ret = ge::aclgrphBuildInitialize(global_options1);
1327 ge::aclgrphBuildFinalize();1318 ge::aclgrphBuildFinalize();
1328 EXPECT_NE(ret, ge::GRAPH_SUCCESS);1319 EXPECT_NE(ret, ge::GRAPH_SUCCESS);
1329 1320 
@@ -1332,7 +1323,7 @@ TEST(UtestIrBuild, aclgrphBuildInitialize_test) {
1332 global_options3["ge.deterministicLevel"] = "1";1323 global_options3["ge.deterministicLevel"] = "1";
1333 global_options3[ge::OPTION_HOST_ENV_OS] = "linux";1324 global_options3[ge::OPTION_HOST_ENV_OS] = "linux";
1334 global_options3[ge::OPTION_HOST_ENV_CPU] = "x86_64";1325 global_options3[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1335- ret = AclgrphBuildInitializeWithoutLdPreload(global_options3);1326+ ret = ge::aclgrphBuildInitialize(global_options3);
1336 auto &options = GetMutableGlobalOptions();1327 auto &options = GetMutableGlobalOptions();
1337 auto it = options.find(ge::DETERMINISTIC);1328 auto it = options.find(ge::DETERMINISTIC);
1338 EXPECT_NE(it, options.end());1329 EXPECT_NE(it, options.end());
@@ -1351,7 +1342,7 @@ TEST(UtestIrBuild, aclgrphBuildInitialize_test) {
1351 global_options4[ge::OP_PRECISION_MODE] = "op_precision.ini";1342 global_options4[ge::OP_PRECISION_MODE] = "op_precision.ini";
1352 global_options4[ge::OPTION_HOST_ENV_OS] = "linux";1343 global_options4[ge::OPTION_HOST_ENV_OS] = "linux";
1353 global_options4[ge::OPTION_HOST_ENV_CPU] = "x86_64";1344 global_options4[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1354- ret = AclgrphBuildInitializeWithoutLdPreload(global_options4);1345+ ret = ge::aclgrphBuildInitialize(global_options4);
1355 options = GetMutableGlobalOptions();1346 options = GetMutableGlobalOptions();
1356 it = options.find(ge::OP_PRECISION_MODE);1347 it = options.find(ge::OP_PRECISION_MODE);
1357 EXPECT_NE(it, options.end());1348 EXPECT_NE(it, options.end());
@@ -1363,13 +1354,13 @@ TEST(UtestIrBuild, aclgrphBuildInitialize_test) {
1363 1354 
1364 std::map<std::string, std::string> global_options5;1355 std::map<std::string, std::string> global_options5;
1365 global_options5[ge::ALLOW_HF32] = "1";1356 global_options5[ge::ALLOW_HF32] = "1";
1366- ret = AclgrphBuildInitializeWithoutLdPreload(global_options5);1357+ ret = ge::aclgrphBuildInitialize(global_options5);
1367 ge::aclgrphBuildFinalize();1358 ge::aclgrphBuildFinalize();
1368 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);1359 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);
1369 1360 
1370 std::map<std::string, std::string> global_options6;1361 std::map<std::string, std::string> global_options6;
1371 global_options6[ge::OPTION_SCREEN_PRINT_MODE] = "0";1362 global_options6[ge::OPTION_SCREEN_PRINT_MODE] = "0";
1372- ret = AclgrphBuildInitializeWithoutLdPreload(global_options6);1363+ ret = ge::aclgrphBuildInitialize(global_options6);
1373 ge::aclgrphBuildFinalize();1364 ge::aclgrphBuildFinalize();
1374 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);1365 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);
1375}1366}
@@ -1379,7 +1370,7 @@ TEST(UtestIrBuild, aclgrphBuildInitialize_test_fail) {
1379 global_options2["ge.optionInvalid"] = "invalid";1370 global_options2["ge.optionInvalid"] = "invalid";
1380 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";1371 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";
1381 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";1372 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1382- EXPECT_EQ(AclgrphBuildInitializeWithoutLdPreload(global_options2), ge::GRAPH_SUCCESS);1373+ EXPECT_EQ(ge::aclgrphBuildInitialize(global_options2), ge::GRAPH_SUCCESS);
1383 ge::aclgrphBuildFinalize();1374 ge::aclgrphBuildFinalize();
1384}1375}
1385 1376 
@@ -1388,7 +1379,7 @@ TEST(UtestIrBuild, check_compression_optimize_conf_test) {
1388 global_options2[ge::COMPRESSION_OPTIMIZE_CONF] = "0";1379 global_options2[ge::COMPRESSION_OPTIMIZE_CONF] = "0";
1389 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";1380 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";
1390 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";1381 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1391- ge::graphStatus ret = AclgrphBuildInitializeWithoutLdPreload(global_options2);1382+ ge::graphStatus ret = ge::aclgrphBuildInitialize(global_options2);
1392 ge::aclgrphBuildFinalize();1383 ge::aclgrphBuildFinalize();
1393 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);1384 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);
1394}1385}
@@ -1398,7 +1389,7 @@ TEST(UtestIrBuild, check_virtual_type_test_success) {
1398 global_options2[ge::VIRTUAL_TYPE] = "1";1389 global_options2[ge::VIRTUAL_TYPE] = "1";
1399 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";1390 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";
1400 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";1391 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1401- ge::graphStatus ret = AclgrphBuildInitializeWithoutLdPreload(global_options2);1392+ ge::graphStatus ret = ge::aclgrphBuildInitialize(global_options2);
1402 ge::aclgrphBuildFinalize();1393 ge::aclgrphBuildFinalize();
1403 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);1394 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);
1404}1395}
@@ -1408,7 +1399,7 @@ TEST(UtestIrBuild, aclgrphBuildInitializeCheckJitCompileTrue) {
1408 global_options2[ge::VIRTUAL_TYPE] = "1";1399 global_options2[ge::VIRTUAL_TYPE] = "1";
1409 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";1400 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";
1410 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";1401 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1411- ge::graphStatus ret = AclgrphBuildInitializeWithoutLdPreload(global_options2);1402+ ge::graphStatus ret = ge::aclgrphBuildInitialize(global_options2);
1412 ge::aclgrphBuildFinalize();1403 ge::aclgrphBuildFinalize();
1413 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);1404 EXPECT_EQ(ret, ge::GRAPH_SUCCESS);
1414 1405 
@@ -1829,7 +1820,7 @@ TEST(UtestIrBuild, aclgrphBuildModelOm2UnsupportedGlobalOptionTest) {
1829 {ge::OPTION_HOST_ENV_OS, "linux"},1820 {ge::OPTION_HOST_ENV_OS, "linux"},
1830 {ge::OPTION_HOST_ENV_CPU, "x86_64"},1821 {ge::OPTION_HOST_ENV_CPU, "x86_64"},
1831 };1822 };
1832- ASSERT_EQ(AclgrphBuildInitializeWithoutLdPreload(global_options), ge::GRAPH_SUCCESS);1823+ ASSERT_EQ(ge::aclgrphBuildInitialize(global_options), ge::GRAPH_SUCCESS);
1833 GE_MAKE_GUARD(finalize_guard, [] { ge::aclgrphBuildFinalize(); });1824 GE_MAKE_GUARD(finalize_guard, [] { ge::aclgrphBuildFinalize(); });
1834 1825 
1835 Graph graph = BuildIrGraph1();1826 Graph graph = BuildIrGraph1();
@@ -1892,7 +1883,7 @@ TEST(UtestIrBuild, check_os_err) {
1892 global_options2[ge::COMPRESSION_OPTIMIZE_CONF] = "0";1883 global_options2[ge::COMPRESSION_OPTIMIZE_CONF] = "0";
1893 global_options2[ge::OPTION_HOST_ENV_OS] = "Linux";1884 global_options2[ge::OPTION_HOST_ENV_OS] = "Linux";
1894 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";1885 global_options2[ge::OPTION_HOST_ENV_CPU] = "x86_64";
1895- ge::graphStatus ret = AclgrphBuildInitializeWithoutLdPreload(global_options2);1886+ ge::graphStatus ret = ge::aclgrphBuildInitialize(global_options2);
1896 ge::aclgrphBuildFinalize();1887 ge::aclgrphBuildFinalize();
1897 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);1888 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);
1898}1889}
@@ -1902,7 +1893,7 @@ TEST(UtestIrBuild, check_cpu_err) {
1902 global_options2[ge::COMPRESSION_OPTIMIZE_CONF] = "0";1893 global_options2[ge::COMPRESSION_OPTIMIZE_CONF] = "0";
1903 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";1894 global_options2[ge::OPTION_HOST_ENV_OS] = "linux";
1904 global_options2[ge::OPTION_HOST_ENV_CPU] = "aaaaa";1895 global_options2[ge::OPTION_HOST_ENV_CPU] = "aaaaa";
1905- ge::graphStatus ret = AclgrphBuildInitializeWithoutLdPreload(global_options2);1896+ ge::graphStatus ret = ge::aclgrphBuildInitialize(global_options2);
1906 ge::aclgrphBuildFinalize();1897 ge::aclgrphBuildFinalize();
1907 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);1898 EXPECT_EQ(ret, ge::GRAPH_PARAM_INVALID);
1908}1899}
@@ -2055,7 +2046,7 @@ TEST(UtestIrBuild, ir_build_oo_init) {
2055 {ge::OPTION_HOST_ENV_CPU, "x86_64"},2046 {ge::OPTION_HOST_ENV_CPU, "x86_64"},
2056 {ge::OO_LEVEL, "O1"},2047 {ge::OO_LEVEL, "O1"},
2057 {OO_CONSTANT_FOLDING, "false"}};2048 {OO_CONSTANT_FOLDING, "false"}};
2058- EXPECT_EQ(AclgrphBuildInitializeWithoutLdPreload(global_options), GRAPH_SUCCESS);2049+ EXPECT_EQ(ge::aclgrphBuildInitialize(global_options), GRAPH_SUCCESS);
2059 2050 
2060 const std::map<std::string, std::string> build_options = {{ge::OO_LEVEL, "O1"}, {OO_CONSTANT_FOLDING, "true"}};2051 const std::map<std::string, std::string> build_options = {{ge::OO_LEVEL, "O1"}, {OO_CONSTANT_FOLDING, "true"}};
2061 EXPECT_NE(ge::aclgrphBuildModel(graph_1, build_options, model_1), GRAPH_SUCCESS);2052 EXPECT_NE(ge::aclgrphBuildModel(graph_1, build_options, model_1), GRAPH_SUCCESS);
@@ -2078,14 +2069,14 @@ TEST(UtestIrBuild, ir_build_oo_init_param_invalid) {
2078 2069 
2079 std::map<std::string, std::string> global_options;2070 std::map<std::string, std::string> global_options;
2080 global_options[OO_LEVEL] = "O4";2071 global_options[OO_LEVEL] = "O4";
2081- EXPECT_NE(AclgrphBuildInitializeWithoutLdPreload(global_options), GRAPH_SUCCESS);2072+ EXPECT_NE(ge::aclgrphBuildInitialize(global_options), GRAPH_SUCCESS);
2082 2073 
2083 global_options[OO_LEVEL] = "O1";2074 global_options[OO_LEVEL] = "O1";
2084 global_options[OO_CONSTANT_FOLDING] = "False";2075 global_options[OO_CONSTANT_FOLDING] = "False";
2085- EXPECT_NE(AclgrphBuildInitializeWithoutLdPreload(global_options), GRAPH_SUCCESS);2076+ EXPECT_NE(ge::aclgrphBuildInitialize(global_options), GRAPH_SUCCESS);
2086 2077 
2087 global_options[OO_CONSTANT_FOLDING] = "0";2078 global_options[OO_CONSTANT_FOLDING] = "0";
2088- EXPECT_NE(AclgrphBuildInitializeWithoutLdPreload(global_options), GRAPH_SUCCESS);2079+ EXPECT_NE(ge::aclgrphBuildInitialize(global_options), GRAPH_SUCCESS);
2089 2080 
2090 std::map<std::string, std::string> build_options;2081 std::map<std::string, std::string> build_options;
2091 build_options[OO_LEVEL] = "O4";2082 build_options[OO_LEVEL] = "O4";
@@ -2120,7 +2111,7 @@ TEST(UtestIrBuild, ir_build_export_compile_stat_valid) {
2120 global_options[OPTION_EXPORT_COMPILE_STAT] = "0";2111 global_options[OPTION_EXPORT_COMPILE_STAT] = "0";
2121 global_options[ge::OPTION_HOST_ENV_OS] = "linux";2112 global_options[ge::OPTION_HOST_ENV_OS] = "linux";
2122 global_options[ge::OPTION_HOST_ENV_CPU] = "x86_64";2113 global_options[ge::OPTION_HOST_ENV_CPU] = "x86_64";
2123- EXPECT_EQ(AclgrphBuildInitializeWithoutLdPreload(global_options), GRAPH_SUCCESS);2114+ EXPECT_EQ(ge::aclgrphBuildInitialize(global_options), GRAPH_SUCCESS);
2124 EXPECT_NE(ge::aclgrphBuildModel(graph_1, build_options, model_1), GRAPH_SUCCESS);2115 EXPECT_NE(ge::aclgrphBuildModel(graph_1, build_options, model_1), GRAPH_SUCCESS);
2125 EXPECT_EQ(GetThreadLocalContext().GetOption(OPTION_EXPORT_COMPILE_STAT, opt_value), ge::GRAPH_SUCCESS);2116 EXPECT_EQ(GetThreadLocalContext().GetOption(OPTION_EXPORT_COMPILE_STAT, opt_value), ge::GRAPH_SUCCESS);
2126 EXPECT_EQ(opt_value, "0");2117 EXPECT_EQ(opt_value, "0");
@@ -2148,7 +2139,7 @@ TEST(UtestIrBuild, ir_build_export_compile_stat_invalid) {
2148 std::string opt_value("-1");2139 std::string opt_value("-1");
2149 std::map<std::string, std::string> global_options;2140 std::map<std::string, std::string> global_options;
2150 global_options[OPTION_EXPORT_COMPILE_STAT] = "3";2141 global_options[OPTION_EXPORT_COMPILE_STAT] = "3";
2151- EXPECT_NE(AclgrphBuildInitializeWithoutLdPreload(global_options), GRAPH_SUCCESS);2142+ EXPECT_NE(ge::aclgrphBuildInitialize(global_options), GRAPH_SUCCESS);
2152 2143 
2153 aclgrphBuildFinalize();2144 aclgrphBuildFinalize();
2154 system(("rm -rf " + opp_path).c_str());2145 system(("rm -rf " + opp_path).c_str());