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.5 kB

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

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