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.1 kB

4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <ge/ge_api_types.h>
  18. #include "easy_graph/graph/box.h"
  19. #include "easy_graph/graph/node.h"
  20. #include "easy_graph/builder/graph_dsl.h"
  21. #include "easy_graph/builder/box_builder.h"
  22. #include "easy_graph/layout/engines/graph_easy/graph_easy_option.h"
  23. #include "easy_graph/layout/engines/graph_easy/graph_easy_executor.h"
  24. #include "graph/graph.h"
  25. #include "ge/ge_api.h"
  26. #include "graph/ge_local_context.h"
  27. #include "graph/compute_graph.h"
  28. #include "framework/common/types.h"
  29. #include "graph/debug/ge_attr_define.h"
  30. #include "ge_graph_dsl/graph_dsl.h"
  31. #include "ge_graph_dsl/op_desc/op_desc_cfg_box.h"
  32. #define protected public
  33. #define private public
  34. #include "common/ge_opt_info.h"
  35. #undef private
  36. #undef protected
  37. namespace ge {
  38. class STEST_opt_info : public testing::Test {
  39. protected:
  40. void SetUp() {}
  41. void TearDown() {}
  42. };
  43. TEST_F(STEST_opt_info, get_opt_info_all) {
  44. std::map<std::string, std::string> options = {{ge::SOC_VERSION, "Ascend310"}};
  45. GetThreadLocalContext().SetGlobalOption(options);
  46. /// data1 data2
  47. /// \ /
  48. /// add
  49. // build graph
  50. DEF_GRAPH(g1) {
  51. CHAIN(NODE("data1", DATA)->NODE("add", ADD));
  52. CHAIN(NODE("data2", DATA)->NODE("add"));
  53. });
  54. auto graph = ToGeGraph(g1);
  55. // new session & add graph
  56. Session session(options);
  57. auto ret = session.AddGraph(1, graph, options);
  58. EXPECT_EQ(ret, SUCCESS);
  59. // build input tensor
  60. std::vector<InputTensorInfo> inputs;
  61. // build_graph through session
  62. ret = session.BuildGraph(1, inputs);
  63. EXPECT_EQ(ret, SUCCESS);
  64. std::map<std::string, std::string> graph_options = GetThreadLocalContext().GetAllGraphOptions();
  65. auto itr = graph_options.find("opt_module.fe");
  66. EXPECT_NE(itr, graph_options.end());
  67. EXPECT_EQ(itr->second, "all");
  68. itr = graph_options.find("opt_module.pass");
  69. EXPECT_NE(itr, graph_options.end());
  70. EXPECT_EQ(itr->second, "all");
  71. itr = graph_options.find("opt_module.op_tune");
  72. EXPECT_NE(itr, graph_options.end());
  73. EXPECT_EQ(itr->second, "all");
  74. itr = graph_options.find("opt_module.rl_tune");
  75. EXPECT_NE(itr, graph_options.end());
  76. EXPECT_EQ(itr->second, "all");
  77. itr = graph_options.find("opt_module.aoe");
  78. EXPECT_NE(itr, graph_options.end());
  79. EXPECT_EQ(itr->second, "all");
  80. }
  81. TEST_F(STEST_opt_info, get_opt_info_success) {
  82. std::map<std::string, std::string> options = {{ge::SOC_VERSION, "Ascend910"}};
  83. GetThreadLocalContext().SetGlobalOption(options);
  84. /// data1 data2
  85. /// \ /
  86. /// add
  87. // build graph
  88. DEF_GRAPH(g1) {
  89. CHAIN(NODE("data1", DATA)->NODE("add", ADD));
  90. CHAIN(NODE("data2", DATA)->NODE("add"));
  91. });
  92. auto graph = ToGeGraph(g1);
  93. // new session & add graph
  94. Session session(options);
  95. auto ret = session.AddGraph(1, graph, options);
  96. EXPECT_EQ(ret, SUCCESS);
  97. // build input tensor
  98. std::vector<InputTensorInfo> inputs;
  99. // build_graph through session
  100. ret = session.BuildGraph(1, inputs);
  101. EXPECT_EQ(ret, SUCCESS);
  102. std::map<std::string, std::string> graph_options = GetThreadLocalContext().GetAllGraphOptions();
  103. auto itr = graph_options.find("opt_module.fe");
  104. EXPECT_NE(itr, graph_options.end());
  105. EXPECT_EQ(itr->second, "all");
  106. itr = graph_options.find("opt_module.pass");
  107. EXPECT_NE(itr, graph_options.end());
  108. EXPECT_EQ(itr->second, "all");
  109. itr = graph_options.find("opt_module.op_tune");
  110. EXPECT_NE(itr, graph_options.end());
  111. EXPECT_EQ(itr->second, "all");
  112. }
  113. } // namespace ge

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