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

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