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 6.1 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/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. //rt api stub
  37. rtError_t rtGetTaskIdAndStreamID(uint32_t *taskId, uint32_t *streamId) {
  38. return RT_ERROR_NONE;
  39. }
  40. /*
  41. TEST_F(UtestSingleOpModel, test_init_model) {
  42. string model_data_str = "123456789";
  43. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  44. ASSERT_EQ(model.InitModel(), FAILED);
  45. }
  46. void ParseOpModelParamsMock(ModelHelper &model_helper, SingleOpModelParam &param) {}
  47. TEST_F(UtestSingleOpModel, test_parse_input_node) {
  48. string model_data_str = "123456789";
  49. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  50. auto op_desc = make_shared<OpDesc>("Data", "Data");
  51. ASSERT_EQ(model.ParseInputNode(op_desc), PARAM_INVALID);
  52. vector<int64_t> shape{1, 2, 3, 4};
  53. vector<int64_t> offsets{16};
  54. GeShape ge_shape(shape);
  55. GeTensorDesc desc(ge_shape);
  56. op_desc->AddOutputDesc(desc);
  57. op_desc->SetOutputOffset(offsets);
  58. ASSERT_EQ(model.ParseInputNode(op_desc), SUCCESS);
  59. op_desc->AddOutputDesc(desc);
  60. offsets.push_back(32);
  61. op_desc->SetOutputOffset(offsets);
  62. ASSERT_EQ(model.ParseInputNode(op_desc), PARAM_INVALID);
  63. }
  64. */
  65. TEST_F(UtestSingleOpModel, test_parse_output_node) {
  66. string model_data_str = "123456789";
  67. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  68. auto op_desc = make_shared<OpDesc>("NetOutput", "NetOutput");
  69. vector<int64_t> shape{1, 2, 3, 4};
  70. vector<int64_t> offsets{16};
  71. GeShape ge_shape(shape);
  72. GeTensorDesc desc(ge_shape);
  73. op_desc->AddInputDesc(desc);
  74. op_desc->SetInputOffset(offsets);
  75. op_desc->AddOutputDesc(desc);
  76. op_desc->SetOutputOffset(offsets);
  77. ASSERT_NO_THROW(model.ParseOutputNode(op_desc));
  78. ASSERT_NO_THROW(model.ParseOutputNode(op_desc));
  79. }
  80. TEST_F(UtestSingleOpModel, test_set_inputs_and_outputs) {
  81. string model_data_str = "123456789";
  82. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  83. model.input_offset_list_.push_back(0);
  84. model.input_sizes_.push_back(16);
  85. model.output_offset_list_.push_back(0);
  86. model.output_sizes_.push_back(16);
  87. std::mutex stream_mu_;
  88. rtStream_t stream_ = nullptr;
  89. // SingleOp single_op(&stream_mu_, stream_);
  90. //
  91. // ASSERT_EQ(model.SetInputsAndOutputs(single_op), SUCCESS);
  92. }
  93. /*
  94. TEST_F(UtestSingleOpModel, test_build_kernel_task) {
  95. string model_data_str = "123456789";
  96. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  97. model.input_offset_list_.push_back(0);
  98. model.input_sizes_.push_back(16);
  99. model.output_offset_list_.push_back(0);
  100. model.output_sizes_.push_back(16);
  101. auto graph = make_shared<ComputeGraph>("graph");
  102. auto op_desc = make_shared<OpDesc>("AddN", "AddN");
  103. vector<int64_t> shape{16, 16};
  104. GeShape ge_shape(shape);
  105. GeTensorDesc desc(ge_shape);
  106. op_desc->AddInputDesc(desc);
  107. op_desc->AddOutputDesc(desc);
  108. auto node = graph->AddNode(op_desc);
  109. std::mutex stream_mu_;
  110. rtStream_t stream_ = nullptr;
  111. SingleOp single_op(&stream_mu_, stream_);
  112. domi::KernelDef kernel_def;
  113. kernel_def.mutable_context()->set_kernel_type(cce::ccKernelType::TE);
  114. TbeOpTask *task = nullptr;
  115. ASSERT_EQ(model.BuildKernelTask(kernel_def, &task), UNSUPPORTED);
  116. kernel_def.mutable_context()->set_kernel_type(cce::ccKernelType::TE);
  117. ASSERT_EQ(model.BuildKernelTask(kernel_def, &task), INTERNAL_ERROR);
  118. model.op_list_[0] = node;
  119. ASSERT_EQ(model.BuildKernelTask(kernel_def, &task), PARAM_INVALID);
  120. ASSERT_EQ(task, nullptr);
  121. delete task;
  122. }
  123. TEST_F(UtestSingleOpModel, test_init) {
  124. string model_data_str = "123456789";
  125. SingleOpModel op_model("model", model_data_str.c_str(), model_data_str.size());
  126. ASSERT_EQ(op_model.Init(), FAILED);
  127. }
  128. */
  129. /*
  130. TEST_F(UtestSingleOpModel, test_parse_arg_table) {
  131. string model_data_str = "123456789";
  132. SingleOpModel op_model("model", model_data_str.c_str(), model_data_str.size());
  133. TbeOpTask task;
  134. OpDescPtr op_desc;
  135. std::mutex stream_mu_;
  136. rtStream_t stream_ = nullptr;
  137. SingleOp op(&stream_mu_, stream_);
  138. op.arg_table_.resize(2);
  139. auto args = std::unique_ptr<uint8_t[]>(new uint8_t[sizeof(uintptr_t) * 2]);
  140. auto *arg_base = (uintptr_t*)args.get();
  141. arg_base[0] = 0x100000;
  142. arg_base[1] = 0x200000;
  143. task.SetKernelArgs(std::move(args), 16, 1, op_desc);
  144. op_model.model_params_.addr_mapping_[0x100000] = 1;
  145. op_model.ParseArgTable(&task, op);
  146. ASSERT_EQ(op.arg_table_[0].size(), 0);
  147. ASSERT_EQ(op.arg_table_[1].size(), 1);
  148. ASSERT_EQ(op.arg_table_[1].front(), &arg_base[0]);
  149. }
  150. */
  151. TEST_F(UtestSingleOpModel, test_op_task_get_profiler_args) {
  152. string name = "relu";
  153. string type = "relu";
  154. auto op_desc = std::make_shared<ge::OpDesc>(name, type);
  155. op_desc->SetStreamId(0);
  156. op_desc->SetId(0);
  157. TbeOpTask task;
  158. task.op_desc_ = op_desc;
  159. task.model_name_ = "resnet_50";
  160. task.model_id_ = 1;
  161. TaskDescInfo task_desc_info;
  162. uint32_t model_id;
  163. task.GetProfilingArgs(task_desc_info, model_id);
  164. ASSERT_EQ(task_desc_info.model_name, "resnet_50");
  165. ASSERT_EQ(model_id, 1);
  166. }

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