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.

node_state_unittest.cc 3.5 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <gmock/gmock.h>
  18. #include <vector>
  19. #define private public
  20. #define protected public
  21. #include "hybrid/executor/node_state.h"
  22. #include "hybrid/executor/subgraph_context.h"
  23. #include "hybrid/model/graph_item.h"
  24. #include "graph/utils/graph_utils.h"
  25. using namespace std;
  26. using namespace testing;
  27. namespace ge {
  28. using namespace hybrid;
  29. class UtestNodeState : public testing::Test {
  30. protected:
  31. void SetUp() {
  32. }
  33. void TearDown() {
  34. }
  35. };
  36. static NodePtr CreateNode(ComputeGraph &graph, const string &name, const string &type, int in_num, int out_num) {
  37. OpDescPtr op_desc = std::make_shared<OpDesc>(name, type);
  38. op_desc->SetStreamId(0);
  39. static int32_t index = 0;
  40. op_desc->SetId(index++);
  41. GeTensorDesc tensor(GeShape(), FORMAT_ND, DT_INT64);
  42. TensorUtils::SetSize(tensor, 64);
  43. vector<int64_t> input_offset;
  44. for (int i = 0; i < in_num; i++) {
  45. op_desc->AddInputDesc(tensor);
  46. input_offset.emplace_back(index * 64 + i * 64);
  47. }
  48. op_desc->SetInputOffset(input_offset);
  49. vector<int64_t> output_offset;
  50. for (int i = 0; i < out_num; i++) {
  51. op_desc->AddOutputDesc(tensor);
  52. output_offset.emplace_back(index * 64 + in_num * 64 + i * 64);
  53. }
  54. op_desc->SetOutputOffset(output_offset);
  55. op_desc->SetWorkspace({});
  56. op_desc->SetWorkspaceBytes({});
  57. op_desc->SetOpKernelLibName("DNN_VM_RTS_OP_STORE");
  58. return graph.AddNode(op_desc);
  59. }
  60. TEST_F(UtestNodeState, merge_await_shapes_ready) {
  61. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
  62. const auto data0 = CreateNode(*graph, "data", DATA, 1, 1);
  63. const auto data1 = CreateNode(*graph, "data1", DATA, 1, 1);
  64. const auto merge1 = CreateNode(*graph, "merge", STREAMMERGE, 2, 2);
  65. const auto output1 = CreateNode(*graph, "net_output", NETOUTPUT, 1, 1);
  66. GraphUtils::AddEdge(data0->GetOutDataAnchor(0), merge1->GetInDataAnchor(0));
  67. GraphUtils::AddEdge(data1->GetOutDataAnchor(0), merge1->GetInDataAnchor(1));
  68. GraphUtils::AddEdge(merge1->GetOutDataAnchor(0), output1->GetInDataAnchor(0));
  69. GraphItem graph_item;
  70. GraphExecutionContext graph_context;
  71. SubgraphContext subgraph_context(&graph_item, &graph_context);
  72. std::unique_ptr<NodeItem> node_item;
  73. NodeItem::Create(merge1, node_item);
  74. NodeState node_state(*node_item, &subgraph_context);
  75. // Not dynamic.
  76. ASSERT_EQ(node_state.shape_inference_state_.AwaitShapesReady(graph_context), SUCCESS);
  77. // Not set merge index.
  78. node_item->is_dynamic = true;
  79. ASSERT_EQ(node_state.shape_inference_state_.AwaitShapesReady(graph_context), FAILED);
  80. // merge index out of bound.
  81. AttrUtils::SetInt(merge1->GetOpDesc(), ATTR_NAME_MERGE_INPUT_INDEX, 3);
  82. ASSERT_EQ(node_state.shape_inference_state_.AwaitShapesReady(graph_context), FAILED);
  83. AttrUtils::SetInt(merge1->GetOpDesc(), ATTR_NAME_MERGE_INPUT_INDEX, 1);
  84. ASSERT_EQ(node_state.shape_inference_state_.AwaitShapesReady(graph_context), SUCCESS);
  85. }
  86. } // namespace ge

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