You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_ge_opt_info.cc 4.0 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <gtest/gtest.h>
  17. #include "external/ge/ge_api.h"
  18. #include "easy_graph/builder/graph_dsl.h"
  19. #include "graph/compute_graph.h"
  20. #include "framework/common/types.h"
  21. #include "graph/ge_local_context.h"
  22. #include "ge_graph_dsl/graph_dsl.h"
  23. #include "ge_running_env/ge_running_env_faker.h"
  24. #include "easy_graph/layout/graph_layout.h"
  25. #include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"
  26. #include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h"
  27. namespace ge {
  28. class STEST_opt_info : public testing::Test {
  29. protected:
  30. GeRunningEnvFaker ge_env;
  31. EG_NS::GraphEasyExecutor executor;
  32. void SetUp() {
  33. EG_NS::GraphLayout::GetInstance().Config(executor, nullptr);
  34. ge_env.InstallDefault();
  35. }
  36. void TearDown() {}
  37. };
  38. TEST_F(STEST_opt_info, get_opt_info_all) {
  39. std::map<std::string, std::string> options = {{ge::SOC_VERSION, "Ascend310"}};
  40. GetThreadLocalContext().SetGlobalOption(options);
  41. /// data1 data2
  42. /// \ /
  43. /// add
  44. // build graph
  45. DEF_GRAPH(g1) {
  46. CHAIN(NODE("data1", DATA)->NODE("add", ADD));
  47. CHAIN(NODE("data2", DATA)->NODE("add"));
  48. };
  49. auto graph = ToGeGraph(g1);
  50. // new session & add graph
  51. Session session(options);
  52. auto ret = session.AddGraph(1, graph, options);
  53. EXPECT_EQ(ret, SUCCESS);
  54. // build input tensor
  55. std::vector<InputTensorInfo> inputs;
  56. // build_graph through session
  57. ret = session.BuildGraph(1, inputs);
  58. EXPECT_EQ(ret, SUCCESS);
  59. std::map<std::string, std::string> graph_options = GetThreadLocalContext().GetAllGraphOptions();
  60. auto itr = graph_options.find("opt_module.fe");
  61. EXPECT_NE(itr, graph_options.end());
  62. EXPECT_EQ(itr->second, "all");
  63. itr = graph_options.find("opt_module.pass");
  64. EXPECT_NE(itr, graph_options.end());
  65. EXPECT_EQ(itr->second, "all");
  66. itr = graph_options.find("opt_module.op_tune");
  67. EXPECT_NE(itr, graph_options.end());
  68. EXPECT_EQ(itr->second, "all");
  69. itr = graph_options.find("opt_module.rl_tune");
  70. EXPECT_NE(itr, graph_options.end());
  71. EXPECT_EQ(itr->second, "all");
  72. itr = graph_options.find("opt_module.aoe");
  73. EXPECT_NE(itr, graph_options.end());
  74. EXPECT_EQ(itr->second, "all");
  75. }
  76. TEST_F(STEST_opt_info, get_opt_info_success) {
  77. std::map<std::string, std::string> options = {{ge::SOC_VERSION, "Ascend910"}};
  78. GetThreadLocalContext().SetGlobalOption(options);
  79. /// data1 data2
  80. /// \ /
  81. /// add
  82. // build graph
  83. DEF_GRAPH(g1) {
  84. CHAIN(NODE("data1", DATA)->NODE("add", ADD));
  85. CHAIN(NODE("data2", DATA)->NODE("add"));
  86. };
  87. auto graph = ToGeGraph(g1);
  88. // new session & add graph
  89. Session session(options);
  90. auto ret = session.AddGraph(1, graph, options);
  91. EXPECT_EQ(ret, SUCCESS);
  92. // build input tensor
  93. std::vector<InputTensorInfo> inputs;
  94. // build_graph through session
  95. ret = session.BuildGraph(1, inputs);
  96. EXPECT_EQ(ret, SUCCESS);
  97. std::map<std::string, std::string> graph_options = GetThreadLocalContext().GetAllGraphOptions();
  98. auto itr = graph_options.find("opt_module.fe");
  99. EXPECT_NE(itr, graph_options.end());
  100. EXPECT_EQ(itr->second, "all");
  101. itr = graph_options.find("opt_module.pass");
  102. EXPECT_NE(itr, graph_options.end());
  103. EXPECT_EQ(itr->second, "all");
  104. itr = graph_options.find("opt_module.op_tune");
  105. EXPECT_NE(itr, graph_options.end());
  106. EXPECT_EQ(itr->second, "all");
  107. }
  108. } // namespace ge

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示