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 3.6 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. namespace ge {
  24. class STEST_opt_info : public testing::Test {
  25. protected:
  26. void SetUp() {}
  27. void TearDown() {}
  28. };
  29. TEST_F(STEST_opt_info, get_opt_info_all) {
  30. std::map<std::string, std::string> options = {{ge::SOC_VERSION, "Ascend310"}};
  31. GetThreadLocalContext().SetGlobalOption(options);
  32. /// data1 data2
  33. /// \ /
  34. /// add
  35. // build graph
  36. DEF_GRAPH(g1) {
  37. CHAIN(NODE("data1", DATA)->NODE("add", ADD));
  38. CHAIN(NODE("data2", DATA)->NODE("add"));
  39. };
  40. auto graph = ToGeGraph(g1);
  41. // new session & add graph
  42. Session session(options);
  43. auto ret = session.AddGraph(1, graph, options);
  44. EXPECT_EQ(ret, SUCCESS);
  45. // build input tensor
  46. std::vector<InputTensorInfo> inputs;
  47. // build_graph through session
  48. ret = session.BuildGraph(1, inputs);
  49. EXPECT_EQ(ret, SUCCESS);
  50. std::map<std::string, std::string> graph_options = GetThreadLocalContext().GetAllGraphOptions();
  51. auto itr = graph_options.find("opt_module.fe");
  52. EXPECT_NE(itr, graph_options.end());
  53. EXPECT_EQ(itr->second, "all");
  54. itr = graph_options.find("opt_module.pass");
  55. EXPECT_NE(itr, graph_options.end());
  56. EXPECT_EQ(itr->second, "all");
  57. itr = graph_options.find("opt_module.op_tune");
  58. EXPECT_NE(itr, graph_options.end());
  59. EXPECT_EQ(itr->second, "all");
  60. itr = graph_options.find("opt_module.rl_tune");
  61. EXPECT_NE(itr, graph_options.end());
  62. EXPECT_EQ(itr->second, "all");
  63. itr = graph_options.find("opt_module.aoe");
  64. EXPECT_NE(itr, graph_options.end());
  65. EXPECT_EQ(itr->second, "all");
  66. }
  67. TEST_F(STEST_opt_info, get_opt_info_success) {
  68. std::map<std::string, std::string> options = {{ge::SOC_VERSION, "Ascend910"}};
  69. GetThreadLocalContext().SetGlobalOption(options);
  70. /// data1 data2
  71. /// \ /
  72. /// add
  73. // build graph
  74. DEF_GRAPH(g1) {
  75. CHAIN(NODE("data1", DATA)->NODE("add", ADD));
  76. CHAIN(NODE("data2", DATA)->NODE("add"));
  77. };
  78. auto graph = ToGeGraph(g1);
  79. // new session & add graph
  80. Session session(options);
  81. auto ret = session.AddGraph(1, graph, options);
  82. EXPECT_EQ(ret, SUCCESS);
  83. // build input tensor
  84. std::vector<InputTensorInfo> inputs;
  85. // build_graph through session
  86. ret = session.BuildGraph(1, inputs);
  87. EXPECT_EQ(ret, SUCCESS);
  88. std::map<std::string, std::string> graph_options = GetThreadLocalContext().GetAllGraphOptions();
  89. auto itr = graph_options.find("opt_module.fe");
  90. EXPECT_NE(itr, graph_options.end());
  91. EXPECT_EQ(itr->second, "all");
  92. itr = graph_options.find("opt_module.pass");
  93. EXPECT_NE(itr, graph_options.end());
  94. EXPECT_EQ(itr->second, "all");
  95. itr = graph_options.find("opt_module.op_tune");
  96. EXPECT_NE(itr, graph_options.end());
  97. EXPECT_EQ(itr->second, "all");
  98. }
  99. } // namespace ge

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