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.

ge_ir_build_unittest.cc 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Copyright 2019-2020 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 "ir_build/atc_ir_common.h"
  18. #include "graph/testcase/ge_graph/graph_builder_utils.h"
  19. #define protected public
  20. #define private public
  21. #undef private
  22. #undef protected
  23. const string DATA = "Data";
  24. const string AddNYes = "AddNYes";
  25. const string NETOUTPUT = "NetOutput";
  26. using namespace ge;
  27. class UtestIrCommon : public testing::Test {
  28. protected:
  29. void SetUp() {}
  30. void TearDown() {}
  31. };
  32. static ge::OpDescPtr CreateOpDesc(const std::string &name, const std::string &type) {
  33. OpDescPtr op_desc = std::make_shared<ge::OpDesc>(name, type);
  34. ge::GeTensorDesc ge_tensor_desc;
  35. op_desc->AddInputDesc("input", ge_tensor_desc);
  36. op_desc->AddOutputDesc("output", ge_tensor_desc);
  37. return op_desc;
  38. }
  39. static ComputeGraphPtr BuildComputeGraph() {
  40. auto builder = ut::GraphBuilder("test");
  41. auto data1 = builder.AddNode("input1", DATA, 1, 1, FORMAT_NCHW, DT_FLOAT, {1, 2, 3});
  42. auto data2 = builder.AddNode("input2", DATA, 1, 1, FORMAT_NCHW, DT_FLOAT, {4, 10});
  43. auto addn1 = builder.AddNode("addn1", AddNYes, 2, 1);
  44. auto netoutput = builder.AddNode("netoutput", NETOUTPUT, 1, 0);
  45. builder.AddDataEdge(data1, 0, addn1, 0);
  46. builder.AddDataEdge(data2, 0, addn1, 1);
  47. builder.AddDataEdge(addn1, 0,netoutput, 0);
  48. return builder.GetGraph();
  49. }
  50. TEST(UtestIrCommon, update_data_op_shape) {
  51. ge::OpDescPtr op_desc = CreateOpDesc("Data", "Data");
  52. map<string, vector<int64_t>> shape_map;
  53. shape_map["Data"] = {{1,2}};
  54. Status ret = UpdateDataOpShape(op_desc, shape_map);
  55. EXPECT_EQ(ret, ge::SUCCESS);
  56. }
  57. TEST(UtestIrCommon, update_dynamic_shape_range_success) {
  58. ComputeGraphPtr graph = BuildComputeGraph();
  59. std::string input_shape_range = "input1:[1, 2~3, -1];input2:[3~5, 10]";
  60. Status ret = UpdateDynamicInputShapeRange(graph, input_shape_range);
  61. EXPECT_EQ(ret, ge::SUCCESS);
  62. }
  63. TEST(UtestIrCommon, update_dynamic_shape_range_failed) {
  64. ComputeGraphPtr graph = BuildComputeGraph();
  65. // 1
  66. std::string input_shape_range = "input1;[1, 2~3, -1]";
  67. Status ret = UpdateDynamicInputShapeRange(graph, input_shape_range);
  68. EXPECT_EQ(ret, ge::PARAM_INVALID);
  69. // 2
  70. input_shape_range = "input1:[1, 2~3, -1)";
  71. ret = UpdateDynamicInputShapeRange(graph, input_shape_range);
  72. EXPECT_EQ(ret, ge::PARAM_INVALID);
  73. //3
  74. input_shape_range = "input1:[1, 3~2, -1];input2:[3~5, 10]";
  75. ret = UpdateDynamicInputShapeRange(graph, input_shape_range);
  76. EXPECT_EQ(ret, ge::FAILED);
  77. //4
  78. input_shape_range = "input1:[1, 2~-3, -1]";
  79. ret = UpdateDynamicInputShapeRange(graph, input_shape_range);
  80. EXPECT_EQ(ret, ge::PARAM_INVALID);
  81. }

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