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.

hcom_util_unittest.cc 3.0 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/utils/attr_utils.h"
  22. #include "graph/debug/ge_attr_define.h"
  23. #include "graph/passes/addn_pass.h"
  24. #define private public
  25. #define protected public
  26. #include "graph/manager/util/hcom_util.h"
  27. #include "ge/ge_api.h"
  28. #undef private
  29. #undef protected
  30. using namespace std;
  31. namespace ge {
  32. namespace {
  33. GeTensorDescPtr CreateTensorDesc(std::initializer_list<int64_t> shape, Format format = FORMAT_NCHW,
  34. DataType data_type = DT_FLOAT) {
  35. GeShape ge_shape{vector<int64_t>(shape)};
  36. GeTensorDescPtr tensor_desc = std::make_shared<GeTensorDesc>();
  37. tensor_desc->SetShape(ge_shape);
  38. tensor_desc->SetFormat(format);
  39. tensor_desc->SetDataType(data_type);
  40. return tensor_desc;
  41. }
  42. class NodeBuilder {
  43. public:
  44. NodeBuilder(const std::string &name, const std::string &type) { op_desc_ = std::make_shared<OpDesc>(name, type); }
  45. NodeBuilder &AddInputDesc(std::initializer_list<int64_t> shape = {1, 1, 224, 224}, Format format = FORMAT_NCHW,
  46. DataType data_type = DT_FLOAT) {
  47. op_desc_->AddInputDesc(CreateTensorDesc(shape, format, data_type)->Clone());
  48. return *this;
  49. }
  50. NodeBuilder &AddOutputDesc(std::initializer_list<int64_t> shape = {1, 1, 224, 224}, Format format = FORMAT_NCHW,
  51. DataType data_type = DT_FLOAT) {
  52. op_desc_->AddOutputDesc(CreateTensorDesc(shape, format, data_type)->Clone());
  53. return *this;
  54. }
  55. NodeBuilder &AddOutputDesc(GeTensorDescPtr tensor_desc) {
  56. op_desc_->AddOutputDesc(tensor_desc->Clone());
  57. return *this;
  58. }
  59. NodePtr Build(const ComputeGraphPtr &graph) {
  60. NodePtr node = graph->AddNode(op_desc_);
  61. return node;
  62. }
  63. private:
  64. OpDescPtr op_desc_;
  65. };
  66. } // namespace
  67. class UtestHcomUtil : public testing::Test {
  68. protected:
  69. void SetUp() {
  70. }
  71. void TearDown() {
  72. }
  73. };
  74. TEST_F(UtestHcomUtil, test_GetHcomCount_succ) {
  75. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
  76. NodePtr node = NodeBuilder("node", HCOMRECEIVE).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph);
  77. auto op_desc = node->GetOpDesc();
  78. HcomOmeUtil hcom_ome_util;
  79. int count = 0;
  80. auto ret = hcom_ome_util.GetHcomCount(op_desc, HCCL_DATA_TYPE_FP32, true, count);
  81. EXPECT_EQ(ret, 0);
  82. }
  83. } // namespace ge

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