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.

single_op_model_unittest.cc 5.0 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 <vector>
  18. #include "cce/taskdown_common.hpp"
  19. #include "graph/load/new_model_manager/model_utils.h"
  20. #include "graph/utils/graph_utils.h"
  21. #include "runtime/rt.h"
  22. #define protected public
  23. #define private public
  24. #include "single_op/single_op_model.h"
  25. #include "single_op/task/tbe_task_builder.h"
  26. #undef private
  27. #undef protected
  28. using namespace std;
  29. using namespace testing;
  30. using namespace ge;
  31. class UtestSingleOpModel : public testing::Test {
  32. protected:
  33. void SetUp() {}
  34. void TearDown() {}
  35. };
  36. TEST_F(UtestSingleOpModel, test_init_model) {
  37. string model_data_str = "123456789";
  38. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  39. ASSERT_EQ(model.InitModel(), FAILED);
  40. }
  41. void ParseOpModelParamsMock(ModelHelper &model_helper, SingleOpModelParam &param) {}
  42. TEST_F(UtestSingleOpModel, test_parse_input_node) {
  43. string model_data_str = "123456789";
  44. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  45. auto op_desc = make_shared<OpDesc>("Data", "Data");
  46. ASSERT_EQ(model.ParseInputNode(op_desc), PARAM_INVALID);
  47. vector<int64_t> shape{1, 2, 3, 4};
  48. vector<int64_t> offsets{16};
  49. GeShape ge_shape(shape);
  50. GeTensorDesc desc(ge_shape);
  51. op_desc->AddOutputDesc(desc);
  52. op_desc->SetOutputOffset(offsets);
  53. ASSERT_EQ(model.ParseInputNode(op_desc), SUCCESS);
  54. op_desc->AddOutputDesc(desc);
  55. offsets.push_back(32);
  56. op_desc->SetOutputOffset(offsets);
  57. ASSERT_EQ(model.ParseInputNode(op_desc), PARAM_INVALID);
  58. }
  59. TEST_F(UtestSingleOpModel, test_parse_output_node) {
  60. string model_data_str = "123456789";
  61. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  62. auto op_desc = make_shared<OpDesc>("NetOutput", "NetOutput");
  63. vector<int64_t> shape{1, 2, 3, 4};
  64. vector<int64_t> offsets{16};
  65. GeShape ge_shape(shape);
  66. GeTensorDesc desc(ge_shape);
  67. op_desc->AddInputDesc(desc);
  68. op_desc->SetInputOffset(offsets);
  69. op_desc->AddOutputDesc(desc);
  70. op_desc->SetOutputOffset(offsets);
  71. ASSERT_NO_THROW(model.ParseOutputNode(op_desc));
  72. ASSERT_NO_THROW(model.ParseOutputNode(op_desc));
  73. }
  74. TEST_F(UtestSingleOpModel, test_set_inputs_and_outputs) {
  75. string model_data_str = "123456789";
  76. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  77. model.input_offset_list_.push_back(0);
  78. model.input_sizes_.push_back(16);
  79. model.output_offset_list_.push_back(0);
  80. model.output_sizes_.push_back(16);
  81. SingleOp single_op;
  82. ASSERT_EQ(model.SetInputsAndOutputs(single_op), SUCCESS);
  83. }
  84. TEST_F(UtestSingleOpModel, test_build_kernel_task) {
  85. string model_data_str = "123456789";
  86. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  87. model.input_offset_list_.push_back(0);
  88. model.input_sizes_.push_back(16);
  89. model.output_offset_list_.push_back(0);
  90. model.output_sizes_.push_back(16);
  91. auto op_desc = make_shared<OpDesc>("AddN", "AddN");
  92. vector<int64_t> shape{16, 16};
  93. GeShape ge_shape(shape);
  94. GeTensorDesc desc(ge_shape);
  95. op_desc->AddInputDesc(desc);
  96. op_desc->AddOutputDesc(desc);
  97. SingleOp single_op;
  98. domi::KernelDef kernel_def;
  99. kernel_def.mutable_context()->set_kernel_type(cce::ccKernelType::CCE_AI_CORE);
  100. OpTask *task = nullptr;
  101. ASSERT_EQ(model.BuildKernelTask(kernel_def, single_op, &task), UNSUPPORTED);
  102. kernel_def.mutable_context()->set_kernel_type(cce::ccKernelType::TE);
  103. ASSERT_EQ(model.BuildKernelTask(kernel_def, single_op, &task), INTERNAL_ERROR);
  104. model.op_list_[0] = op_desc;
  105. ASSERT_EQ(model.BuildKernelTask(kernel_def, single_op, &task), PARAM_INVALID);
  106. ASSERT_EQ(task, nullptr);
  107. delete task;
  108. }
  109. TEST_F(UtestSingleOpModel, test_init) {
  110. string model_data_str = "123456789";
  111. SingleOpModel op_model("model", model_data_str.c_str(), model_data_str.size());
  112. ASSERT_EQ(op_model.Init(), FAILED);
  113. }
  114. TEST_F(UtestSingleOpModel, test_parse_arg_table) {
  115. string model_data_str = "123456789";
  116. SingleOpModel op_model("model", model_data_str.c_str(), model_data_str.size());
  117. TbeOpTask task;
  118. SingleOp op;
  119. op.arg_table_.resize(2);
  120. auto *args = new uintptr_t[2];
  121. args[0] = 0x100000;
  122. args[1] = 0x200000;
  123. task.SetKernelArgs(args, 16, 1);
  124. op_model.model_params_.addr_mapping_[0x100000] = 1;
  125. op_model.ParseArgTable(&task, op);
  126. ASSERT_EQ(op.arg_table_[0].size(), 0);
  127. ASSERT_EQ(op.arg_table_[1].size(), 1);
  128. ASSERT_EQ(op.arg_table_[1].front(), &args[0]);
  129. }

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