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_task_unittest.cc 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "graph/load/model_manager/model_utils.h"
  19. #include "graph/utils/graph_utils.h"
  20. #include "runtime/rt.h"
  21. #define protected public
  22. #define private public
  23. #include "single_op/single_op_model.h"
  24. #include "single_op/task/tbe_task_builder.h"
  25. #include "single_op/task/op_task.h"
  26. #include "single_op/task/tbe_task_builder.h"
  27. #include "external/register/op_tiling_registry.h"
  28. #undef private
  29. #undef protected
  30. using namespace std;
  31. using namespace testing;
  32. using namespace ge;
  33. using namespace optiling;
  34. class UtestSingleOpTask : public testing::Test {
  35. protected:
  36. void SetUp() {}
  37. void TearDown() {}
  38. };
  39. TEST_F(UtestSingleOpTask, test_build_kernel_task) {
  40. string model_data_str = "123456789";
  41. SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
  42. model.input_offset_list_.push_back(0);
  43. model.input_sizes_.push_back(16);
  44. model.output_offset_list_.push_back(0);
  45. model.output_sizes_.push_back(16);
  46. auto graph = make_shared<ComputeGraph>("graph");
  47. auto op_desc = make_shared<OpDesc>("Add", "Add");
  48. std::vector<char> kernelBin;
  49. TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
  50. op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
  51. std::string kernel_name("kernel/Add");
  52. AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
  53. vector<int64_t> shape{16, 16};
  54. GeShape ge_shape(shape);
  55. GeTensorDesc desc(ge_shape);
  56. op_desc->AddInputDesc(desc);
  57. op_desc->AddOutputDesc(desc);
  58. auto node = graph->AddNode(op_desc);
  59. std::mutex stream_mu_;
  60. rtStream_t stream_ = nullptr;
  61. StreamResource stream_resource(0);
  62. SingleOp single_op(&stream_resource, &stream_mu_, stream_);
  63. domi::TaskDef task_def;
  64. task_def.set_type(RT_MODEL_TASK_ALL_KERNEL);
  65. domi::KernelDefWithHandle *kernel_with_handle = task_def.mutable_kernel_with_handle();
  66. kernel_with_handle->set_original_kernel_key("");
  67. kernel_with_handle->set_node_info("");
  68. kernel_with_handle->set_block_dim(32);
  69. kernel_with_handle->set_args_size(64);
  70. string args(64, '1');
  71. kernel_with_handle->set_args(args.data(), 64);
  72. domi::KernelContext *context = kernel_with_handle->mutable_context();
  73. context->set_op_index(1);
  74. context->set_kernel_type(2); // ccKernelType::TE
  75. uint16_t args_offset[9] = {0};
  76. context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
  77. model.op_list_[1] = node;
  78. TbeOpTask task_tmp;
  79. TbeOpTask *task = &task_tmp;
  80. ASSERT_EQ(model.BuildKernelTask(task_def, &task), SUCCESS);
  81. vector<GeTensorDesc> input_desc;
  82. vector<DataBuffer> input_buffers;
  83. vector<GeTensorDesc> output_desc;
  84. vector<DataBuffer> output_buffers;
  85. task->node_ = node;
  86. OpTilingFunc op_tiling_func = [](const TeOpParas &, const OpCompileInfo &, OpRunInfo &) -> bool {return true;};
  87. OpTilingRegistryInterf("Add", op_tiling_func);
  88. ge::AttrUtils::SetStr(op_desc, "compile_info_key", "op_compile_info_key");
  89. ge::AttrUtils::SetStr(op_desc, "compile_info_json", "op_compile_info_json");
  90. char c = '0';
  91. char* buffer = &c;
  92. task->tiling_buffer_ = buffer;
  93. task->max_tiling_size_ = 64;
  94. task->tiling_data_ = "tiling_data";
  95. task->arg_size_ = 64;
  96. uint8_t task_args{0};
  97. task->args_.reset(&task_args);
  98. ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS);
  99. char handle_tmp = '0';
  100. char *handle = &handle_tmp;
  101. task->SetHandle(handle);
  102. ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS);
  103. }

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