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.

ge_hybrid_unittest.cc 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Copyright 2019-2021 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 "runtime/rt.h"
  19. #define protected public
  20. #define private public
  21. #include "hybrid/model/hybrid_model_builder.h"
  22. #include "hybrid/model/hybrid_model.h"
  23. #include "model/ge_model.h"
  24. #include "model/ge_root_model.h"
  25. #include "hybrid/node_executor/aicore/aicore_op_task.h"
  26. #include "framework/common/taskdown_common.h"
  27. #include "framework/common/debug/log.h"
  28. #include "graph/ge_context.h"
  29. #include "hybrid/executor/hybrid_execution_context.h"
  30. #include "hybrid/node_executor/aicore/aicore_task_builder.h"
  31. #include "graph/load/model_manager/tbe_handle_store.h"
  32. #include "graph/types.h"
  33. #undef private
  34. #undef protected
  35. using namespace std;
  36. using namespace testing;
  37. using namespace ge;
  38. class UtestGeHybrid : public testing::Test {
  39. protected:
  40. void SetUp() {}
  41. void TearDown() {}
  42. };
  43. static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") {
  44. auto op_desc = std::make_shared<ge::OpDesc>(name, type);
  45. op_desc->SetStreamId(0);
  46. op_desc->SetId(0);
  47. op_desc->SetWorkspace({});
  48. ;
  49. op_desc->SetWorkspaceBytes({});
  50. op_desc->SetInputOffset({});
  51. op_desc->SetOutputOffset({});
  52. ge::AttrUtils::SetStr(op_desc, ge::TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF_AIVEC");
  53. bool support_dynamic = true;
  54. ge::AttrUtils::GetBool(op_desc, "support_dynamicshape", support_dynamic);
  55. return op_desc;
  56. }
  57. TEST_F(UtestGeHybrid, aicore_op_task_init_success) {
  58. // build aicore task
  59. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  60. domi::TaskDef task_def;
  61. task_def.set_type(RT_MODEL_TASK_ALL_KERNEL);
  62. domi::KernelDefWithHandle *kernel_with_handle = task_def.mutable_kernel_with_handle();
  63. kernel_with_handle->set_original_kernel_key("");
  64. kernel_with_handle->set_node_info("");
  65. kernel_with_handle->set_block_dim(32);
  66. kernel_with_handle->set_args_size(64);
  67. string args(64, '1');
  68. kernel_with_handle->set_args(args.data(), 64);
  69. domi::KernelContext *context = kernel_with_handle->mutable_context();
  70. context->set_op_index(1);
  71. context->set_kernel_type(2); // ccKernelType::TE
  72. uint16_t args_offset[9] = {0};
  73. context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
  74. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  75. std::vector<char> kernelBin;
  76. TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
  77. op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
  78. std::string kernel_name("kernel/Add");
  79. AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
  80. ASSERT_EQ(aicore_task->InitWithTaskDef(*op_desc.get(), task_def), SUCCESS);
  81. rtStream_t stream = nullptr;
  82. rtStreamCreate(&stream, 0);
  83. ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
  84. char *handle = "";
  85. aicore_task->handle_ = handle;
  86. aicore_task->tiling_key_ = 1;
  87. ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
  88. }

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