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.

dynamic_shape_partition_unittest.cc 3.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "graph/partition/dynamic_shape_partition.h"
  18. #include "compute_graph.h"
  19. #define private public
  20. #define protected public
  21. namespace ge {
  22. namespace {
  23. GeTensorDescPtr CreateTensorDesc(std::initializer_list<int64_t> shape, Format format = FORMAT_NCHW,
  24. DataType data_type = DT_FLOAT) {
  25. GeShape ge_shape{vector<int64_t>(shape)};
  26. GeTensorDescPtr tensor_desc = std::make_shared<GeTensorDesc>();
  27. tensor_desc->SetShape(ge_shape);
  28. tensor_desc->SetFormat(format);
  29. tensor_desc->SetDataType(data_type);
  30. return tensor_desc;
  31. }
  32. class NodeBuilder {
  33. public:
  34. NodeBuilder(const std::string &name, const std::string &type) { op_desc_ = std::make_shared<OpDesc>(name, type); }
  35. NodeBuilder &AddInputDesc(std::initializer_list<int64_t> shape = {1, 1, 224, 224}, Format format = FORMAT_NCHW,
  36. DataType data_type = DT_FLOAT) {
  37. op_desc_->AddInputDesc(CreateTensorDesc(shape, format, data_type)->Clone());
  38. return *this;
  39. }
  40. NodeBuilder &AddOutputDesc(std::initializer_list<int64_t> shape = {1, 1, 224, 224}, Format format = FORMAT_NCHW,
  41. DataType data_type = DT_FLOAT) {
  42. op_desc_->AddOutputDesc(CreateTensorDesc(shape, format, data_type)->Clone());
  43. return *this;
  44. }
  45. NodeBuilder &AddOutputDesc(GeTensorDescPtr tensor_desc) {
  46. op_desc_->AddOutputDesc(tensor_desc->Clone());
  47. return *this;
  48. }
  49. NodePtr Build(const ComputeGraphPtr &graph) {
  50. NodePtr node = graph->AddNode(op_desc_);
  51. return node;
  52. }
  53. private:
  54. OpDescPtr op_desc_;
  55. };
  56. } // namespace
  57. class UtestDynamicShapePartition : public testing::Test {
  58. protected:
  59. void SetUp() {}
  60. void TearDown() {}
  61. };
  62. // test Init_EndGraphTaskInfo_failed
  63. TEST_F(UtestDynamicShapePartition, single_op_scene_success) {
  64. ComputeGraphPtr computeGraph("default");
  65. NodePtr node1 =
  66. NodeBuilder("node1", CONSTANTOP).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph);
  67. NodePtr add_n_node =
  68. NodeBuilder("add_n_node", ADDN).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph);
  69. NodePtr node2 =
  70. NodeBuilder("node2", RELU).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph);
  71. GraphUtils::AddEdge(node1->GetOutDataAnchor(0), add_n_node->GetInDataAnchor(0));
  72. GraphUtils::AddEdge(add_n_node->GetOutDataAnchor(0), node2->GetInDataAnchor(0));
  73. (void)AttrUtils::SetBool(add_n_node->GetOpDesc(), ATTR_SINGLE_OP_SCENE, true);
  74. DynamicShapePartitioner partitioner(computeGraph);
  75. EXPECT_EQ(partitioner.Partition(), SUCCESS);
  76. }
  77. } // namespace ge

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