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.

permute_pass_unittest.cc 2.5 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "graph/passes/permute_pass.h"
  17. #include <gtest/gtest.h>
  18. #include <string>
  19. using namespace ge;
  20. using namespace domi;
  21. class UTEST_graph_passes_permute_pass : public testing::Test {
  22. protected:
  23. void SetUp() {}
  24. void TearDown() {}
  25. NodePtr AddNode(ComputeGraphPtr graph, const string &name, const string &type, int32_t in_anchors_num = 1,
  26. int32_t out_anchors_num = 1) {
  27. GeTensorDesc tensor_desc(GeShape({1}), FORMAT_NHWC, DT_INT32);
  28. OpDescPtr opdesc = make_shared<OpDesc>(name, type);
  29. for (int32_t i = 0; i < in_anchors_num; i++) {
  30. opdesc->AddInputDesc(tensor_desc);
  31. }
  32. for (int32_t i = 0; i < out_anchors_num; i++) {
  33. opdesc->AddOutputDesc(tensor_desc);
  34. }
  35. NodePtr node = graph->AddNode(opdesc);
  36. return node;
  37. }
  38. ComputeGraphPtr CreatePadGraph() {
  39. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
  40. NodePtr data_node = AddNode(graph, "data_op", DATA);
  41. NodePtr transpose_node = AddNode(graph, "transpose1", PERMUTE);
  42. vector<int64_t> order_list = {0, 3, 1, 2};
  43. AttrUtils::SetListInt(transpose_node->GetOpDesc(), PERMUTE_ATTR_ORDER, order_list);
  44. AttrUtils::SetInt(transpose_node->GetOpDesc(), ATTR_NAME_FORMAT, (int64_t)DT_INT32);
  45. NodePtr conv_node = AddNode(graph, "conv1", CONVOLUTION);
  46. NodePtr conv2_node = AddNode(graph, "conv2", CONVOLUTION);
  47. GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), transpose_node->GetInDataAnchor(0));
  48. GraphUtils::AddEdge(transpose_node->GetOutDataAnchor(0), conv_node->GetInDataAnchor(0));
  49. GraphUtils::AddEdge(conv_node->GetOutDataAnchor(0), conv2_node->GetInDataAnchor(0));
  50. return graph;
  51. }
  52. };
  53. TEST_F(UTEST_graph_passes_permute_pass, transpose_and_conv3) {
  54. ComputeGraphPtr graph = CreatePadGraph();
  55. ge::PermutePass permute_pass;
  56. domi::Status status = permute_pass.Run(graph);
  57. EXPECT_EQ(domi::SUCCESS, status);
  58. }

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