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.

enter_pass_unittest.cc 3.1 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <string>
  17. #include <gtest/gtest.h>
  18. #define private public
  19. #include "graph/passes/enter_pass.h"
  20. #include "common/ge_inner_error_codes.h"
  21. #include "inc/pass_manager.h"
  22. #include "utils/graph_utils.h"
  23. #undef private
  24. namespace ge {
  25. namespace {
  26. class UtestGraphPassesEnterPass : public testing::Test {
  27. protected:
  28. void BuildGraph() {
  29. // Tensor
  30. GeTensorDesc bool_tensor_desc(GeShape(), ge::FORMAT_NCHW, ge::DT_BOOL);
  31. GeTensorDesc scalar_tensor_desc(GeShape(), ge::FORMAT_NCHW, ge::DT_FLOAT);
  32. // const
  33. auto const_op_desc = std::make_shared<OpDesc>("a", "Constant");
  34. const_op_desc->AddOutputDesc(scalar_tensor_desc);
  35. auto const_node_ = graph_->AddNode(const_op_desc);
  36. // enter
  37. auto enter_op_desc = std::make_shared<OpDesc>("Enter", "Enter");
  38. enter_op_desc->AddInputDesc(scalar_tensor_desc);
  39. enter_op_desc->AddOutputDesc(scalar_tensor_desc);
  40. enter_node_ = graph_->AddNode(enter_op_desc);
  41. (void)GraphUtils::AddEdge(const_node_->GetOutDataAnchor(0), enter_node_->GetInDataAnchor(0));
  42. // less
  43. auto x_op_desc = std::make_shared<OpDesc>("x", VARIABLEV2);
  44. x_op_desc->AddOutputDesc(scalar_tensor_desc);
  45. auto x_node = graph_->AddNode(x_op_desc);
  46. auto y_op_desc = std::make_shared<OpDesc>("y", VARIABLEV2);
  47. y_op_desc->AddOutputDesc(scalar_tensor_desc);
  48. auto y_node = graph_->AddNode(y_op_desc);
  49. auto less_op_desc = std::make_shared<OpDesc>("Less", "Less");
  50. less_op_desc->AddInputDesc(scalar_tensor_desc);
  51. less_op_desc->AddInputDesc(scalar_tensor_desc);
  52. less_op_desc->AddOutputDesc(bool_tensor_desc);
  53. auto less_node = graph_->AddNode(less_op_desc);
  54. (void)GraphUtils::AddEdge(x_node->GetOutDataAnchor(0), less_node->GetInDataAnchor(0));
  55. (void)GraphUtils::AddEdge(y_node->GetOutDataAnchor(0), less_node->GetInDataAnchor(1));
  56. (void)GraphUtils::AddEdge(enter_node_->GetOutControlAnchor(), less_node->GetInControlAnchor());
  57. }
  58. ComputeGraphPtr graph_;
  59. EnterPass pass_;
  60. NodePtr enter_node_;
  61. };
  62. } // namespace
  63. TEST_F(UtestGraphPassesEnterPass, null_input) {
  64. NodePtr node = nullptr;
  65. EXPECT_EQ(pass_.Run(node), PARAM_INVALID);
  66. }
  67. TEST_F(UtestGraphPassesEnterPass, run_success) {
  68. graph_ = std::make_shared<ComputeGraph>("UTEST_graph_passes_enter_pass_run_success");
  69. BuildGraph();
  70. EXPECT_NE(enter_node_, nullptr);
  71. EXPECT_EQ(pass_.Run(enter_node_), SUCCESS);
  72. EXPECT_EQ(enter_node_->GetOutControlAnchor()->GetPeerAnchors().empty(), true);
  73. }
  74. } // namespace ge

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