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.

graph_preprocess_unittest.cc 3.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <memory>
  18. #include "common/ge_inner_error_codes.h"
  19. #include "common/types.h"
  20. #include "common/util.h"
  21. #include "graph/passes/graph_builder_utils.h"
  22. #include "graph/utils/attr_utils.h"
  23. #include "graph/debug/ge_attr_define.h"
  24. #define private public
  25. #define protected public
  26. #include "graph/preprocess/graph_preprocess.h"
  27. #include "ge/ge_api.h"
  28. #undef private
  29. #undef protected
  30. using namespace std;
  31. namespace ge {
  32. class UtestGraphPreproces : public testing::Test {
  33. protected:
  34. void SetUp() {
  35. }
  36. void TearDown() {
  37. }
  38. };
  39. ComputeGraphPtr BuildGraph1(){
  40. auto builder = ut::GraphBuilder("g1");
  41. auto data1 = builder.AddNode("data1",DATA,1,1);
  42. auto data_opdesc = data1->GetOpDesc();
  43. AttrUtils::SetInt(data_opdesc, ATTR_NAME_INDEX, 0);
  44. data1->UpdateOpDesc(data_opdesc);
  45. return builder.GetGraph();
  46. }
  47. TEST_F(UtestGraphPreproces, test_dynamic_input_shape_parse) {
  48. ge::GraphPrepare graph_prepare;
  49. graph_prepare.compute_graph_ = BuildGraph1();
  50. // prepare user_input & graph option
  51. ge::GeTensorDesc tensor1;
  52. tensor1.SetFormat(ge::FORMAT_NCHW);
  53. tensor1.SetShape(ge::GeShape({3, 12, 5, 5}));
  54. tensor1.SetDataType(ge::DT_FLOAT);
  55. GeTensor input1(tensor1);
  56. std::vector<GeTensor> user_input = {input1};
  57. std::map<string,string> graph_option = {{"ge.exec.dynamicGraphExecuteMode","dynamic_execute"},
  58. {"ge.exec.dataInputsShapeRange","[3,1~20,2~10,5]"}};
  59. auto ret = graph_prepare.UpdateInput(user_input, graph_option);
  60. EXPECT_EQ(ret, ge::SUCCESS);
  61. // check data node output shape_range and shape
  62. auto data_node = graph_prepare.compute_graph_->FindNode("data1");
  63. auto data_output_desc = data_node->GetOpDesc()->GetOutputDescPtr(0);
  64. vector<int64_t> expect_shape = {3,-1,-1,5};
  65. auto result_shape = data_output_desc->GetShape();
  66. EXPECT_EQ(result_shape.GetDimNum(), expect_shape.size());
  67. for(size_t i =0; i< expect_shape.size(); ++i){
  68. EXPECT_EQ(result_shape.GetDim(i), expect_shape.at(i));
  69. }
  70. }
  71. TEST_F(UtestGraphPreproces, test_check_user_input) {
  72. ge::GraphPrepare graph_prepare;
  73. graph_prepare.compute_graph_ = BuildGraph1();
  74. vector<int64_t> dim = {2, -3};
  75. GeTensor tensor;
  76. tensor.SetTensorDesc(GeTensorDesc(GeShape(dim)));
  77. std::vector<GeTensor> user_input;
  78. user_input.emplace_back(tensor);
  79. Status ret = graph_prepare.CheckUserInput(user_input);
  80. EXPECT_EQ(ret, GE_GRAPH_INIT_FAILED);
  81. }
  82. }

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