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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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 <gmock/gmock.h>
  18. #include <vector>
  19. #include "runtime/rt.h"
  20. #define protected public
  21. #define private public
  22. #include "graph/utils/node_utils.h"
  23. #include "hybrid/model/hybrid_model_builder.h"
  24. #include "hybrid/model/hybrid_model.h"
  25. #include "hybrid/node_executor/node_executor.h"
  26. #include "model/ge_model.h"
  27. #include "model/ge_root_model.h"
  28. #include "hybrid/node_executor/aicore/aicore_op_task.h"
  29. #include "framework/common/taskdown_common.h"
  30. #include "framework/common/debug/log.h"
  31. #include "graph/ge_context.h"
  32. #include "hybrid/executor/hybrid_execution_context.h"
  33. #include "hybrid/executor/hybrid_model_executor.h"
  34. #include "hybrid/node_executor/aicore/aicore_task_builder.h"
  35. #include "hybrid/node_executor/aicore/aicore_node_executor.h"
  36. #include "graph/load/model_manager/tbe_handle_store.h"
  37. #include "graph/manager/graph_mem_allocator.h"
  38. #include "hybrid/common/npu_memory_allocator.h"
  39. #include "graph/types.h"
  40. #include "graph/utils/tensor_utils.h"
  41. #include "graph/testcase/ge_graph/graph_builder_utils.h"
  42. #include "single_op/task/build_task_utils.h"
  43. #include "graph/op_desc_impl.h"
  44. #undef private
  45. #undef protected
  46. using namespace std;
  47. using namespace testing;
  48. using namespace ge;
  49. using namespace hybrid;
  50. class UtestGeHybrid : public testing::Test {
  51. protected:
  52. void SetUp() {}
  53. void TearDown() {
  54. NpuMemoryAllocator::allocators_.clear();
  55. }
  56. };
  57. static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") {
  58. auto op_desc = std::make_shared<ge::OpDesc>(name, type);
  59. op_desc->SetStreamId(0);
  60. op_desc->SetId(0);
  61. op_desc->SetWorkspace({});
  62. ;
  63. op_desc->SetWorkspaceBytes({});
  64. op_desc->SetInputOffset({});
  65. op_desc->SetOutputOffset({});
  66. ge::AttrUtils::SetStr(op_desc, ge::TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF_AIVEC");
  67. bool support_dynamic = true;
  68. ge::AttrUtils::GetBool(op_desc, "support_dynamicshape", support_dynamic);
  69. return op_desc;
  70. }
  71. TEST_F(UtestGeHybrid, aicore_op_task_init_success) {
  72. // build aicore task
  73. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  74. domi::TaskDef task_def;
  75. task_def.set_type(RT_MODEL_TASK_ALL_KERNEL);
  76. domi::KernelDefWithHandle *kernel_with_handle = task_def.mutable_kernel_with_handle();
  77. kernel_with_handle->set_original_kernel_key("");
  78. kernel_with_handle->set_node_info("");
  79. kernel_with_handle->set_block_dim(32);
  80. kernel_with_handle->set_args_size(64);
  81. string args(64, '1');
  82. kernel_with_handle->set_args(args.data(), 64);
  83. domi::KernelContext *context = kernel_with_handle->mutable_context();
  84. context->set_op_index(1);
  85. context->set_kernel_type(2); // ccKernelType::TE
  86. uint16_t args_offset[9] = {0};
  87. context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
  88. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  89. std::vector<char> kernelBin;
  90. TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
  91. op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
  92. std::string kernel_name("kernel/Add");
  93. AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
  94. ASSERT_EQ(aicore_task->Init(*op_desc.get(), task_def), SUCCESS);
  95. rtStream_t stream = nullptr;
  96. rtStreamCreate(&stream, 0);
  97. ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
  98. char *handle = "";
  99. aicore_task->handle_ = handle;
  100. aicore_task->tiling_key_ = 1;
  101. ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
  102. }
  103. TEST_F(UtestGeHybrid, aicore_op_task_init_success2) {
  104. // build aicore task
  105. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  106. aicore_task->is_single_op_ = true;
  107. domi::TaskDef task_def;
  108. task_def.set_type(RT_MODEL_TASK_KERNEL);
  109. domi::KernelDef *kernel = task_def.mutable_kernel();
  110. kernel->set_block_dim(32);
  111. kernel->set_args_size(64);
  112. string args(64, '1');
  113. kernel->set_args(args.data(), 64);
  114. domi::KernelContext *context = kernel->mutable_context();
  115. context->set_op_index(1);
  116. context->set_kernel_type(2); // ccKernelType::TE
  117. uint16_t args_offset[9] = {0};
  118. context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
  119. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  120. std::vector<char> kernelBin;
  121. TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
  122. op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
  123. std::string kernel_name("kernel/Add");
  124. AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
  125. ASSERT_EQ(aicore_task->InitWithTaskDef(*op_desc.get(), task_def), SUCCESS);
  126. rtStream_t stream = nullptr;
  127. rtStreamCreate(&stream, 0);
  128. ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
  129. char *handle = "";
  130. aicore_task->handle_ = handle;
  131. aicore_task->tiling_key_ = 1;
  132. ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
  133. }
  134. TEST_F(UtestGeHybrid, task_update_tiling_info) {
  135. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  136. auto graph = make_shared<ComputeGraph>("graph");
  137. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  138. ge::AttrUtils::SetStr(op_desc, "compile_info_key", "key");
  139. ge::AttrUtils::SetStr(op_desc, "compile_info_json", "json");
  140. ge::AttrUtils::SetBool(op_desc, "support_dynamicshape", true);
  141. ge::AttrUtils::SetInt(op_desc, "op_para_size", 1);
  142. ge::AttrUtils::SetStr(op_desc, TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF");
  143. auto node = graph->AddNode(op_desc);
  144. std::unique_ptr<NodeItem> node_item;
  145. NodeItem::Create(node, node_item);
  146. node_item->input_start = 0;
  147. node_item->output_start = 0;
  148. GraphExecutionContext execution_context;
  149. SubgraphContext subgraph_context(nullptr, &execution_context);
  150. auto node_state = subgraph_context.GetOrCreateNodeState(node_item.get());
  151. ASSERT_EQ(aicore_task->InitTilingInfo(*op_desc), SUCCESS);
  152. ASSERT_EQ(aicore_task->UpdateTilingInfo(*node_state->GetTaskContext()), SUCCESS);
  153. }
  154. TEST_F(UtestGeHybrid, index_taskdefs_failed) {
  155. // build aicore task
  156. domi::ModelTaskDef model_task_def;
  157. std::shared_ptr<domi::ModelTaskDef> model_task_def_ptr = make_shared<domi::ModelTaskDef>(model_task_def);
  158. domi::TaskDef *task_def = model_task_def_ptr->add_task();
  159. GeModelPtr ge_model = make_shared<GeModel>();
  160. ge_model->SetModelTaskDef(model_task_def_ptr);
  161. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  162. task_def->set_type(RT_MODEL_TASK_ALL_KERNEL);
  163. domi::KernelDefWithHandle *kernel_with_handle = task_def->mutable_kernel_with_handle();
  164. kernel_with_handle->set_original_kernel_key("");
  165. kernel_with_handle->set_node_info("");
  166. kernel_with_handle->set_block_dim(32);
  167. kernel_with_handle->set_args_size(64);
  168. string args(64, '1');
  169. kernel_with_handle->set_args(args.data(), 64);
  170. domi::KernelContext *context = kernel_with_handle->mutable_context();
  171. context->set_op_index(1);
  172. context->set_kernel_type(2); // ccKernelType::TE
  173. uint16_t args_offset[9] = {0};
  174. context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
  175. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  176. std::vector<char> kernelBin;
  177. TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
  178. op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
  179. std::string kernel_name("kernel/Add");
  180. AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
  181. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
  182. GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph);
  183. ge_root_model->SetModelName("test_name");
  184. HybridModel hybrid_model(ge_root_model);
  185. HybridModelBuilder hybrid_model_builder(hybrid_model);
  186. ASSERT_EQ(hybrid_model_builder.Build(), INTERNAL_ERROR);
  187. ASSERT_EQ(hybrid_model_builder.IndexTaskDefs(graph, ge_model), INTERNAL_ERROR);
  188. }
  189. TEST_F(UtestGeHybrid, parse_force_infershape_nodes) {
  190. const char *const kForceInfershape = "_force_infershape_when_running";
  191. auto graph = make_shared<ComputeGraph>("graph");
  192. OpDescPtr op_desc = CreateOpDesc("Conv2D", "Conv2D");
  193. ge::AttrUtils::SetBool(op_desc, kForceInfershape, true);
  194. auto node = graph->AddNode(op_desc);
  195. std::unique_ptr<NodeItem> new_node;
  196. NodeItem::Create(node, new_node);
  197. GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph);
  198. HybridModel hybrid_model(ge_root_model);
  199. HybridModelBuilder hybrid_model_builder(hybrid_model);
  200. ASSERT_EQ(hybrid_model_builder.ParseForceInfershapeNodes(node, *new_node), SUCCESS);
  201. }
  202. static ComputeGraphPtr BuildDataDirectConnectGraph() {
  203. const char *kRefIndex = "_parent_node_index";
  204. ge::ut::GraphBuilder builder("subgraph");
  205. auto data = builder.AddNode("Data", "Data", 1, 1);
  206. auto netoutput = builder.AddNode("NetOutput", "NetOutput", 1, 1);
  207. (void)AttrUtils::SetInt(netoutput->GetOpDesc()->MutableInputDesc(0), kRefIndex, 0);
  208. builder.AddDataEdge(data, 0, netoutput, 0);
  209. return builder.GetGraph();
  210. }
  211. TEST_F(UtestGeHybrid, data_direct_connect) {
  212. std::unique_ptr<NodeItem> node_item;
  213. auto root_graph = make_shared<ComputeGraph>("root_graph");
  214. OpDescPtr op_desc = CreateOpDesc("PartitionedCall", "PartitionedCall");
  215. auto node = root_graph->AddNode(op_desc);
  216. node->SetOwnerComputeGraph(root_graph);
  217. auto sub_graph = BuildDataDirectConnectGraph();
  218. sub_graph->SetParentGraph(root_graph);
  219. sub_graph->SetParentNode(node);
  220. node->GetOpDesc()->AddSubgraphName("subgraph");
  221. node->GetOpDesc()->SetSubgraphInstanceName(0, "subgraph");
  222. root_graph->AddSubgraph("subgraph", sub_graph);
  223. std::unique_ptr<NodeItem> new_node;
  224. NodeItem::Create(node, new_node);
  225. GeRootModelPtr ge_root_model = make_shared<GeRootModel>(root_graph);
  226. HybridModel hybrid_model(ge_root_model);
  227. HybridModelBuilder hybrid_model_builder(hybrid_model);
  228. auto ret = hybrid_model_builder.IdentifyVariableOutputs(*new_node.get(), sub_graph);
  229. ASSERT_EQ(ret, SUCCESS);
  230. }
  231. TEST_F(UtestGeHybrid, index_taskdefs_success) {
  232. // build aicore task
  233. domi::ModelTaskDef model_task_def;
  234. std::shared_ptr<domi::ModelTaskDef> model_task_def_ptr = make_shared<domi::ModelTaskDef>(model_task_def);
  235. domi::TaskDef *task_def = model_task_def_ptr->add_task();
  236. GeModelPtr ge_model = make_shared<GeModel>();
  237. ge_model->SetModelTaskDef(model_task_def_ptr);
  238. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  239. task_def->set_type(RT_MODEL_TASK_ALL_KERNEL);
  240. domi::KernelDefWithHandle *kernel_with_handle = task_def->mutable_kernel_with_handle();
  241. kernel_with_handle->set_original_kernel_key("");
  242. kernel_with_handle->set_node_info("");
  243. kernel_with_handle->set_block_dim(32);
  244. kernel_with_handle->set_args_size(64);
  245. string args(64, '1');
  246. kernel_with_handle->set_args(args.data(), 64);
  247. domi::KernelContext *context = kernel_with_handle->mutable_context();
  248. context->set_op_index(0);
  249. context->set_kernel_type(2); // ccKernelType::TE
  250. uint16_t args_offset[9] = {0};
  251. context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
  252. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  253. std::vector<char> kernelBin;
  254. TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
  255. op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
  256. std::string kernel_name("kernel/Add");
  257. AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
  258. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
  259. NodePtr node = graph->AddNode(op_desc);
  260. GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph);
  261. HybridModel hybrid_model(ge_root_model);
  262. HybridModelBuilder hybrid_model_builder(hybrid_model);
  263. ASSERT_EQ(hybrid_model_builder.IndexTaskDefs(graph, ge_model), SUCCESS);
  264. }
  265. TEST_F(UtestGeHybrid, init_weight_success) {
  266. NpuMemoryAllocator::allocators_.emplace(make_pair(0, nullptr));
  267. // make graph with sub_graph
  268. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("root_graph");
  269. OpDescPtr op_desc = CreateOpDesc("if", IF);
  270. NodePtr node = graph->AddNode(op_desc);
  271. // make sub graph
  272. ComputeGraphPtr sub_graph = std::make_shared<ComputeGraph>("if_sub_graph");
  273. OpDescPtr const_op_desc = CreateOpDesc("const", CONSTANT);
  274. vector<int64_t> dims_vec_0 = {2, 1, 4, 1, 2};
  275. vector<int32_t> data_vec_0 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
  276. GeTensorDesc tensor_desc_0(GeShape(dims_vec_0), FORMAT_NCHW, DT_INT32);
  277. (void)TensorUtils::SetRealDimCnt(tensor_desc_0, dims_vec_0.size());
  278. ConstGeTensorPtr constTensor_0 =
  279. std::make_shared<GeTensor>(tensor_desc_0, (uint8_t *)&data_vec_0[0], data_vec_0.size() * sizeof(int32_t));
  280. AttrUtils::SetTensor(const_op_desc, ge::ATTR_NAME_WEIGHTS, constTensor_0);
  281. const_op_desc->AddOutputDesc(tensor_desc_0);
  282. NodePtr const_node = sub_graph->AddNode(const_op_desc);
  283. graph->AddSubgraph("sub", sub_graph);
  284. GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph);
  285. GeModelPtr ge_sub_model = make_shared<GeModel>();
  286. //Buffer weight_buffer = Buffer(128,0);
  287. //ge_sub_model->SetWeight(weight_buffer);
  288. ge_root_model->SetSubgraphInstanceNameToModel("sub",ge_sub_model);
  289. HybridModel hybrid_model(ge_root_model);
  290. HybridModelBuilder hybrid_model_builder(hybrid_model);
  291. auto ret = hybrid_model_builder.InitWeights();
  292. ASSERT_EQ(ret,SUCCESS);
  293. Buffer weight_buffer = Buffer(128,0);
  294. ge_sub_model->SetWeight(weight_buffer);
  295. ret = hybrid_model_builder.InitWeights();
  296. ASSERT_EQ(ret,PARAM_INVALID);
  297. }
  298. TEST_F(UtestGeHybrid, hybrid_model_executor) {
  299. ComputeGraphPtr compute_graph = MakeShared<ComputeGraph>("abc");
  300. GeRootModelPtr root_model = MakeShared<ge::GeRootModel>(compute_graph);
  301. HybridModel model(root_model);
  302. model.root_graph_item_.reset(new GraphItem);
  303. HybridModel *model_ptr = &model;
  304. uint32_t device_id = 0;
  305. rtStream_t stream = nullptr;
  306. HybridModelExecutor executor(model_ptr, device_id, stream);
  307. executor.Init();
  308. }
  309. TEST_F(UtestGeHybrid, test_parse_parallel_group) {
  310. NodeExecutorManager::GetInstance().engine_mapping_.emplace("ops_kernel_info_hccl",
  311. NodeExecutorManager::ExecutorType::HCCL);
  312. ComputeGraphPtr compute_graph = MakeShared<ComputeGraph>("test");
  313. OpDescPtr op_desc = CreateOpDesc("AllReduce", "AllReduce");
  314. op_desc->SetId(0);
  315. ge::AttrUtils::SetStr(op_desc, ATTR_NAME_PARALLEL_GROUP, "group_1");
  316. auto node = compute_graph->AddNode(op_desc);
  317. std::unique_ptr<NodeItem> node_item;
  318. NodeItem::Create(node, node_item);
  319. node_item->node_id = 0;
  320. op_desc->SetOpKernelLibName("ops_kernel_info_hccl");
  321. GeRootModelPtr root_model = MakeShared<ge::GeRootModel>(compute_graph);
  322. HybridModel model(root_model);
  323. model.root_graph_ = compute_graph;
  324. HybridModelBuilder builder(model);
  325. ASSERT_EQ(builder.CollectParallelGroups(node_item.get()), SUCCESS);
  326. ASSERT_EQ(builder.node_to_parallel_groups_.size(), 1);
  327. ASSERT_EQ(builder.parallel_group_to_nodes_.size(), 1);
  328. OpDescPtr op_desc_1 = CreateOpDesc("subgraph", "PartitionedCall");
  329. op_desc_1->AddSubgraphName("subgraph");
  330. auto node_1 = compute_graph->AddNode(op_desc_1);
  331. ComputeGraphPtr subgraph = MakeShared<ComputeGraph>("subgraph");
  332. ASSERT_EQ(NodeUtils::SetSubgraph(*node_1, 0, subgraph), GRAPH_SUCCESS);
  333. std::unique_ptr<NodeItem> node_item_1;
  334. NodeItem::Create(node_1, node_item_1);
  335. node_item_1->node_id = 1;
  336. ASSERT_EQ(builder.CollectParallelGroups(node_item_1.get()), SUCCESS);
  337. ASSERT_EQ(builder.node_to_parallel_groups_.size(), 1);
  338. ASSERT_EQ(builder.parallel_group_to_nodes_.size(), 1);
  339. OpDescPtr op_desc_2 = CreateOpDesc("sub_node_1", "AllReduce");
  340. ge::AttrUtils::SetStr(op_desc_2, ATTR_NAME_PARALLEL_GROUP, "group_1");
  341. auto node_2 = subgraph->AddNode(op_desc_2);
  342. ASSERT_TRUE(node_2 != nullptr);
  343. OpDescPtr op_desc_3 = CreateOpDesc("sub_node_2", "AllReduce2");
  344. ge::AttrUtils::SetStr(op_desc_3, ATTR_NAME_PARALLEL_GROUP, "group_2");
  345. auto node_3 = subgraph->AddNode(op_desc_3);
  346. ASSERT_TRUE(node_3 != nullptr);
  347. ASSERT_EQ(builder.CollectParallelGroups(node_item_1.get()), SUCCESS);
  348. ASSERT_EQ(builder.node_to_parallel_groups_.size(), 2);
  349. ASSERT_EQ(builder.parallel_group_to_nodes_.size(), 2);
  350. ASSERT_EQ(builder.parallel_group_to_nodes_["group_1"].size(), 2);
  351. ASSERT_EQ(builder.parallel_group_to_nodes_["group_2"].size(), 1);
  352. builder.parallel_group_to_nodes_.clear();
  353. builder.node_ref_inputs_.clear();
  354. model.node_items_[node] = std::move(node_item);
  355. model.node_items_[node_1] = std::move(node_item_1);
  356. ASSERT_FALSE(model.node_items_[node]->has_observer);
  357. ASSERT_TRUE(model.node_items_[node_1]->dependents_for_execution.empty());
  358. ASSERT_EQ(builder.ParseDependentByParallelGroup(), SUCCESS);
  359. ASSERT_TRUE(model.node_items_[node]->has_observer);
  360. ASSERT_EQ(model.node_items_[node_1]->dependents_for_execution.size(), 1);
  361. ASSERT_EQ(model.node_items_[node_1]->dependents_for_execution[0], node);
  362. // repeat parse
  363. ASSERT_EQ(builder.ParseDependentByParallelGroup(), SUCCESS);
  364. ASSERT_TRUE(model.node_items_[node]->has_observer);
  365. ASSERT_EQ(model.node_items_[node_1]->dependents_for_execution.size(), 1);
  366. ASSERT_EQ(model.node_items_[node_1]->dependents_for_execution[0], node);
  367. }
  368. TEST_F(UtestGeHybrid, unfold_subgraphs_success) {
  369. ComputeGraphPtr merged_graph = nullptr;
  370. ComputeGraphPtr sub_sub_graph1 = std::make_shared<ComputeGraph>("while_cond");
  371. OpDescPtr sub_sub_graph_while_cond_data_op_desc = CreateOpDesc("cond_data", DATA);
  372. NodePtr sub_sub_graph_while_cond_data_node = sub_sub_graph1->AddNode(sub_sub_graph_while_cond_data_op_desc);
  373. ComputeGraphPtr sub_sub_graph2 = std::make_shared<ComputeGraph>("while_body");
  374. /*OpDescPtr sub_sub_graph_while_body_const_op_desc = CreateOpDesc("body_const", CONSTANT);
  375. NodePtr sub_sub_graph_while_body_const_node = sub_sub_graph2->AddNode(sub_sub_graph_while_body_const_op_desc);*/
  376. OpDescPtr sub_sub_graph_while_body_data_op_desc = CreateOpDesc("body_data", DATA);
  377. NodePtr sub_sub_graph_while_body_data_node = sub_sub_graph2->AddNode(sub_sub_graph_while_body_data_op_desc);
  378. sub_sub_graph2->SetGraphUnknownFlag(true);
  379. /*OpDescPtr sub_sub_graph_while_body_add_op_desc = CreateOpDesc("body_add", ADD);
  380. NodePtr sub_sub_graph_while_body_add_node = sub_sub_graph2->AddNode(sub_sub_graph_while_body_add_node);
  381. sub_sub_graph_while_body_add_node->AddLinkFrom(sub_sub_graph_while_body_data_node);
  382. sub_sub_graph_while_body_add_node->AddLinkFrom(sub_sub_graph_while_body_const_node);*/
  383. ComputeGraphPtr sub_graph = std::make_shared<ComputeGraph>("sub_graph");
  384. OpDescPtr sub_graph_while_op_desc = CreateOpDesc("while", WHILE);
  385. NodePtr sub_graph_while_node = sub_graph->AddNode(sub_graph_while_op_desc);
  386. sub_graph->SetGraphUnknownFlag(true);
  387. sub_graph_while_node->GetOpDesc()->AddSubgraphName("while_cond");
  388. sub_graph_while_node->GetOpDesc()->AddSubgraphName("while_body");
  389. sub_graph_while_node->GetOpDesc()->SetSubgraphInstanceName(0, "while_cond");
  390. sub_graph_while_node->GetOpDesc()->SetSubgraphInstanceName(1, "while_body");
  391. ComputeGraphPtr root_graph = std::make_shared<ComputeGraph>("root_graph");
  392. auto partitioned_call_op_desc = MakeShared<OpDesc>("partitioned_call", PARTITIONEDCALL);
  393. auto partitioned_call_node = root_graph->AddNode(partitioned_call_op_desc);
  394. partitioned_call_node->GetOpDesc()->AddSubgraphName("sub_graph");
  395. partitioned_call_node->GetOpDesc()->SetSubgraphInstanceName(0, "sub_graph");
  396. root_graph->AddSubGraph(sub_sub_graph1);
  397. root_graph->AddSubGraph(sub_sub_graph2);
  398. sub_sub_graph1->SetParentGraph(root_graph);
  399. sub_sub_graph2->SetParentGraph(root_graph);
  400. sub_sub_graph1->SetParentNode(sub_graph_while_node);
  401. sub_sub_graph2->SetParentNode(sub_graph_while_node);
  402. root_graph->AddSubGraph(sub_graph);
  403. sub_graph->SetParentNode(partitioned_call_node);
  404. sub_graph->SetParentGraph(root_graph);
  405. GeRootModelPtr root_model = MakeShared<ge::GeRootModel>(root_graph);
  406. HybridModel hybrid_model(root_model);
  407. HybridModelBuilder hybrid_model_builder(hybrid_model);
  408. EXPECT_EQ(hybrid_model_builder.UnfoldSubgraphs(root_graph, merged_graph), SUCCESS);
  409. }
  410. TEST_F(UtestGeHybrid, TestTaskContext) {
  411. auto graph = make_shared<ComputeGraph>("graph");
  412. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  413. GeShape shape({2, 16});
  414. GeTensorDesc tensor_desc(shape);
  415. op_desc->AddInputDesc(tensor_desc);
  416. op_desc->AddInputDesc(tensor_desc);
  417. op_desc->AddOutputDesc(tensor_desc);
  418. auto node = graph->AddNode(op_desc);
  419. std::unique_ptr<NodeItem> node_item;
  420. NodeItem::Create(node, node_item);
  421. node_item->input_start = 0;
  422. node_item->output_start = 0;
  423. GraphExecutionContext execution_context;
  424. GraphItem graph_item;
  425. SubgraphContext subgraph_context(&graph_item, &execution_context);
  426. ASSERT_EQ(subgraph_context.Init(), SUCCESS);
  427. subgraph_context.all_inputs_.resize(2);
  428. subgraph_context.all_outputs_.resize(1);
  429. auto node_state = subgraph_context.GetOrCreateNodeState(node_item.get());
  430. auto task_context = node_state->GetTaskContext();
  431. ASSERT_TRUE(task_context != nullptr);
  432. auto desc = task_context->MutableInputDesc(2);
  433. ASSERT_TRUE(desc == nullptr);
  434. desc = task_context->MutableOutputDesc(0);
  435. ASSERT_TRUE(desc != nullptr);
  436. ASSERT_EQ(desc->GetShape().GetDims(), shape.GetDims());
  437. GeTensorDesc output_desc;
  438. ASSERT_EQ(task_context->GetOutputDesc(0, output_desc), SUCCESS);
  439. ASSERT_EQ(output_desc.GetShape().GetDims(), shape.GetDims());
  440. desc = task_context->MutableInputDesc(0);
  441. ASSERT_TRUE(desc != nullptr);
  442. ASSERT_EQ(desc->GetShape().GetDims(), shape.GetDims());
  443. GeShape new_shape({8, 2});
  444. tensor_desc.SetShape(new_shape);
  445. task_context->UpdateInputDesc(1, tensor_desc);
  446. GeTensorDesc new_desc;
  447. ASSERT_EQ(task_context->GetInputDesc(1, new_desc), SUCCESS);
  448. ASSERT_EQ(new_desc.GetShape().GetDims(), new_shape.GetDims());
  449. }
  450. TEST_F(UtestGeHybrid, hybrid_model_executor_update_args) {
  451. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  452. auto graph = make_shared<ComputeGraph>("graph");
  453. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  454. GeShape shape({2, 16});
  455. GeTensorDesc tensor_desc(shape);
  456. op_desc->AddInputDesc(tensor_desc);
  457. op_desc->AddInputDesc(tensor_desc);
  458. op_desc->AddOutputDesc(tensor_desc);
  459. auto node = graph->AddNode(op_desc);
  460. std::unique_ptr<NodeItem> node_item;
  461. NodeItem::Create(node, node_item);
  462. node_item->input_start = 0;
  463. node_item->output_start = 0;
  464. GraphExecutionContext execution_context;
  465. GraphItem graph_item;
  466. SubgraphContext subgraph_context(&graph_item, &execution_context);
  467. ASSERT_EQ(subgraph_context.Init(), SUCCESS);
  468. subgraph_context.all_inputs_.resize(2);
  469. subgraph_context.all_outputs_.resize(1);
  470. auto node_state = subgraph_context.GetOrCreateNodeState(node_item.get());
  471. auto task_context = node_state->GetTaskContext();
  472. int32_t buffer[1];
  473. aicore_task->tiling_buffer_ = TensorBuffer::Create(buffer, sizeof(buffer));
  474. EXPECT_NE(aicore_task->tiling_buffer_, nullptr);
  475. aicore_task->max_arg_count_ = 0;
  476. EXPECT_EQ(aicore_task->UpdateArgs(*task_context), ACL_ERROR_GE_MEMORY_OPERATE_FAILED);
  477. aicore_task->args_ = std::unique_ptr<uint8_t[]>(new uint8_t[sizeof(uintptr_t) * 2]);
  478. EXPECT_EQ(aicore_task->UpdateArgs(*task_context), SUCCESS);
  479. }
  480. TEST_F(UtestGeHybrid, hybrid_model_executor_check_shape) {
  481. HybridModelExecutor::ExecuteArgs args;
  482. GeTensorDescPtr ge_tensor = make_shared<GeTensorDesc>(GeTensorDesc());
  483. vector<int64_t> dim = {2 , 3};
  484. ge_tensor->SetShape(GeShape(dim));
  485. args.input_desc.push_back(ge_tensor);
  486. // create node
  487. ge::ComputeGraphPtr graph = std::make_shared<ComputeGraph>("God");
  488. OpDescPtr op_desc = std::make_shared<OpDesc>("data", DATA);
  489. GeTensorDesc tensor_desc(GeShape({2, 3}));
  490. std::vector<std::pair<int64_t, int64_t>> shape_range({std::pair<int64_t, int64_t>(1, 3),
  491. std::pair<int64_t, int64_t>(2, 4)});
  492. tensor_desc.SetShapeRange(shape_range);
  493. op_desc->AddInputDesc(tensor_desc);
  494. op_desc->AddOutputDesc(tensor_desc);
  495. NodePtr node = graph->AddNode(op_desc);
  496. std::unique_ptr<NodeItem> new_node;
  497. NodeItem::Create(node, new_node);
  498. new_node->is_dynamic = true;
  499. GraphItem graph_item;
  500. graph_item.input_nodes_.emplace_back(new_node.get());
  501. Status ret = HybridModelExecutor::CheckInputShapeByShapeRange(&graph_item, args);
  502. ASSERT_EQ(ret, ge::SUCCESS);
  503. HybridModelExecutor::ExecuteArgs args1;
  504. ret = HybridModelExecutor::CheckInputShapeByShapeRange(&graph_item, args1);
  505. ASSERT_EQ(ret, ge::INTERNAL_ERROR);
  506. HybridModelExecutor::ExecuteArgs args2;
  507. GeTensorDescPtr ge_tensor2 = make_shared<GeTensorDesc>(GeTensorDesc());
  508. vector<int64_t> dim2 = {-1 , 3};
  509. ge_tensor2->SetShape(GeShape(dim2));
  510. args2.input_desc.push_back(ge_tensor2);
  511. ret = HybridModelExecutor::CheckInputShapeByShapeRange(&graph_item, args1);
  512. ASSERT_EQ(ret, ge::INTERNAL_ERROR);
  513. HybridModelExecutor::ExecuteArgs args3;
  514. ret = HybridModelExecutor::CheckInputShapeByShapeRange(&graph_item, args3);
  515. ASSERT_EQ(ret, ge::INTERNAL_ERROR);
  516. }
  517. TEST_F(UtestGeHybrid, TestOptimizeDependenciesForConstInputs) {
  518. ComputeGraphPtr compute_graph = MakeShared<ComputeGraph>("test");
  519. GeRootModelPtr root_model = MakeShared<ge::GeRootModel>(compute_graph);
  520. HybridModel model(root_model);
  521. model.root_graph_ = compute_graph;
  522. HybridModelBuilder builder(model);
  523. GeShape shape({2, 16});
  524. GeTensorDesc tensor_desc(shape);
  525. std::unique_ptr<NodeItem> const_node_item;
  526. {
  527. OpDescPtr const_op_desc = CreateOpDesc("Constant", "Const");
  528. const_op_desc->AddOutputDesc(tensor_desc);
  529. auto const_node = compute_graph->AddNode(const_op_desc);
  530. NodeItem::Create(const_node, const_node_item);
  531. }
  532. std::unique_ptr<NodeItem> non_const_node_item;
  533. {
  534. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  535. op_desc->AddOutputDesc(tensor_desc);
  536. auto const_node = compute_graph->AddNode(op_desc);
  537. NodeItem::Create(const_node, non_const_node_item);
  538. }
  539. std::unique_ptr<NodeItem> known_node_item;
  540. {
  541. OpDescPtr known_op_desc = CreateOpDesc("known", "PartitionedCall");
  542. known_op_desc->AddOutputDesc(tensor_desc);
  543. known_op_desc->AddOutputDesc(tensor_desc);
  544. auto known_node = compute_graph->AddNode(known_op_desc);
  545. NodeItem::Create(known_node, known_node_item);
  546. }
  547. std::unique_ptr<NodeItem> dst_node_item;
  548. {
  549. OpDescPtr known_op_desc = CreateOpDesc("SomeOp", "SomeOpType ");
  550. known_op_desc->AddOutputDesc(tensor_desc);
  551. known_op_desc->AddOutputDesc(tensor_desc);
  552. auto known_node = compute_graph->AddNode(known_op_desc);
  553. NodeItem::Create(known_node, dst_node_item);
  554. }
  555. float buffer[2 * 16];
  556. unique_ptr<TensorValue> tensor_value(new TensorValue(buffer, sizeof(buffer)));
  557. model.constant_tensors_[const_node_item->node] = std::move(tensor_value);
  558. // Case 1. connect to Const
  559. auto output_id = 1;
  560. builder.host_input_value_dependencies_[dst_node_item.get()].emplace_back(output_id, const_node_item.get());
  561. builder.host_input_value_dependencies_[dst_node_item.get()].emplace_back(0, non_const_node_item.get());
  562. dst_node_item->dependents_for_shape_inference.emplace_back(const_node_item->node);
  563. dst_node_item->dependents_for_shape_inference.emplace_back(non_const_node_item->node);
  564. ASSERT_EQ(builder.OptimizeDependenciesForConstantInputs(), SUCCESS);
  565. ASSERT_EQ(dst_node_item->dependents_for_shape_inference.size(), 1);
  566. ASSERT_EQ(dst_node_item->dependents_for_shape_inference[0], non_const_node_item->node);
  567. // Case 2. connect to known-subgraph, netoutput connect to Const
  568. builder.host_input_value_dependencies_.clear();
  569. dst_node_item->dependents_for_shape_inference.clear();
  570. builder.known_subgraph_constant_output_refs_[known_node_item.get()].emplace(output_id, const_node_item->node);
  571. builder.host_input_value_dependencies_[dst_node_item.get()].emplace_back(output_id, known_node_item.get());
  572. builder.host_input_value_dependencies_[dst_node_item.get()].emplace_back(0, non_const_node_item.get());
  573. dst_node_item->dependents_for_shape_inference.emplace_back(known_node_item->node);
  574. dst_node_item->dependents_for_shape_inference.emplace_back(non_const_node_item->node);
  575. ASSERT_EQ(builder.OptimizeDependenciesForConstantInputs(), SUCCESS);
  576. ASSERT_EQ(dst_node_item->dependents_for_shape_inference.size(), 1);
  577. ASSERT_EQ(dst_node_item->dependents_for_shape_inference[0], non_const_node_item->node);
  578. }
  579. TEST_F(UtestGeHybrid, test_key_for_kernel_bin) {
  580. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  581. OpDesc op_desc("Sum", "Sum");
  582. EXPECT_EQ(aicore_task->GetKeyForTbeKernel(), OP_EXTATTR_NAME_TBE_KERNEL);
  583. EXPECT_EQ(aicore_task->GetKeyForTvmMagic(), TVM_ATTR_NAME_MAGIC);
  584. EXPECT_EQ(aicore_task->GetKeyForTvmMetaData(), TVM_ATTR_NAME_METADATA);
  585. EXPECT_EQ(aicore_task->GetKeyForKernelName(op_desc), "Sum_kernelname");
  586. auto atomic_task = std::unique_ptr<hybrid::AtomicAddrCleanOpTask>(new(std::nothrow)hybrid::AtomicAddrCleanOpTask());
  587. EXPECT_EQ(atomic_task->GetKeyForTbeKernel(), EXT_ATTR_ATOMIC_TBE_KERNEL);
  588. EXPECT_EQ(atomic_task->GetKeyForTvmMagic(), ATOMIC_ATTR_TVM_MAGIC);
  589. EXPECT_EQ(atomic_task->GetKeyForTvmMetaData(), ATOMIC_ATTR_TVM_METADATA);
  590. EXPECT_EQ(atomic_task->GetKeyForKernelName(op_desc), "Sum_atomic_kernelname");
  591. }
  592. TEST_F(UtestGeHybrid, test_op_type) {
  593. auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
  594. aicore_task->op_type_ = "Add";
  595. EXPECT_EQ(aicore_task->GetOpType(), "Add");
  596. auto atomic_task = std::unique_ptr<hybrid::AtomicAddrCleanOpTask>(new(std::nothrow)hybrid::AtomicAddrCleanOpTask());
  597. EXPECT_EQ(atomic_task->GetOpType(), "DynamicAtomicAddrClean");
  598. }
  599. TEST_F(UtestGeHybrid, TestParseDependentInputNodesForHccl) {
  600. NodeExecutorManager::GetInstance().engine_mapping_.emplace("ops_kernel_info_hccl",
  601. NodeExecutorManager::ExecutorType::HCCL);
  602. ComputeGraphPtr compute_graph = MakeShared<ComputeGraph>("test");
  603. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  604. auto node = compute_graph->AddNode(op_desc);
  605. std::unique_ptr<NodeItem> node_item;
  606. NodeItem::Create(node, node_item);
  607. node_item->node_id = 0;
  608. OpDescPtr op_desc_1 = CreateOpDesc("AllReduce", "AllReduce");
  609. op_desc_1->SetOpKernelLibName("ops_kernel_info_hccl");
  610. auto node_1 = compute_graph->AddNode(op_desc_1);
  611. std::unique_ptr<NodeItem> node_item_1;
  612. NodeItem::Create(node_1, node_item_1);
  613. node_item_1->node_id = 1;
  614. node->GetOutControlAnchor()->LinkTo(node_1->GetInControlAnchor());
  615. OpDescPtr op_desc_2 = CreateOpDesc("net_output", NETOUTPUT);
  616. auto node_2 = compute_graph->AddNode(op_desc_2);
  617. std::unique_ptr<NodeItem> node_item_2;
  618. NodeItem::Create(node_2, node_item_2);
  619. node_item_2->node_id = 2;
  620. node_1->GetOutControlAnchor()->LinkTo(node_2->GetInControlAnchor());
  621. GeRootModelPtr root_model = MakeShared<ge::GeRootModel>(compute_graph);
  622. HybridModel model(root_model);
  623. model.root_graph_ = compute_graph;
  624. model.node_items_.emplace(node, std::move(node_item));
  625. model.node_items_.emplace(node_1, std::move(node_item_1));
  626. model.node_items_.emplace(node_2, std::move(node_item_2));
  627. HybridModelBuilder builder(model);
  628. std::vector<std::string> deps;
  629. ASSERT_EQ(builder.ParseDependentInputNodes(*model.node_items_[node_1], deps), SUCCESS);
  630. ASSERT_EQ(builder.ParseDependentInputNodes(*model.node_items_[node_2], deps), SUCCESS);
  631. ASSERT_FALSE(model.GetNodeItem(node)->has_observer);
  632. ASSERT_TRUE(model.GetNodeItem(node_1)->has_observer);
  633. ASSERT_EQ(model.node_items_[node_1]->dependents_for_execution.size(), 0);
  634. ASSERT_EQ(model.node_items_[node_2]->dependents_for_execution.size(), 1);
  635. }
  636. TEST_F(UtestGeHybrid, TestParseDependencies) {
  637. // make graph
  638. ut::GraphBuilder graph_builder = ut::GraphBuilder("graph");
  639. auto data = graph_builder.AddNode("Data", "Data", 0, 1);
  640. auto netoutput = graph_builder.AddNode("Netoutput", "NetOutput", 1, 0);
  641. graph_builder.AddDataEdge(data, 0, netoutput, 0);
  642. auto graph = graph_builder.GetGraph();
  643. GeRootModelPtr root_model = MakeShared<ge::GeRootModel>(graph);
  644. HybridModel model(root_model);
  645. HybridModelBuilder builder(model);
  646. std::unique_ptr<NodeItem> node_item;
  647. NodeItem::Create(netoutput, node_item);
  648. std::unique_ptr<NodeItem> node_item2;
  649. NodeItem::Create(data, node_item2);
  650. model.node_items_.emplace(data, std::move(node_item2));
  651. std::vector<std::string> deps;
  652. deps.push_back("Data");
  653. auto op_desc = netoutput->GetOpDesc();
  654. op_desc->impl_->input_name_idx_["Data"] = 0;
  655. auto data_desc = data->GetOpDesc();
  656. auto tensor = std::make_shared<GeTensor>();
  657. auto tensor_desc = data_desc->MutableInputDesc(0);
  658. AttrUtils::SetTensor(tensor_desc, "_value", tensor);
  659. std::set<NodePtr> dependent_for_shape_inference;
  660. ASSERT_EQ(builder.ParseDependencies(*node_item, deps, dependent_for_shape_inference), SUCCESS);
  661. }
  662. TEST_F(UtestGeHybrid, TestTaskExecuteAsync) {
  663. auto graph = make_shared<ComputeGraph>("graph");
  664. OpDescPtr op_desc = CreateOpDesc("Add", "Add");
  665. GeShape shape({2, 16});
  666. GeTensorDesc tensor_desc(shape);
  667. op_desc->AddInputDesc(tensor_desc);
  668. op_desc->AddInputDesc(tensor_desc);
  669. op_desc->AddOutputDesc(tensor_desc);
  670. auto node = graph->AddNode(op_desc);
  671. std::unique_ptr<NodeItem> node_item;
  672. NodeItem::Create(node, node_item);
  673. node_item->input_start = 0;
  674. node_item->output_start = 0;
  675. GraphExecutionContext execution_context;
  676. GraphItem graph_item;
  677. SubgraphContext subgraph_context(&graph_item, &execution_context);
  678. ASSERT_EQ(subgraph_context.Init(), SUCCESS);
  679. subgraph_context.all_inputs_.resize(2);
  680. subgraph_context.all_outputs_.resize(1);
  681. auto node_state = subgraph_context.GetOrCreateNodeState(node_item.get());
  682. auto task_context = *node_state->GetTaskContext();
  683. ASSERT_NE(BuildTaskUtils::GetTaskInfo(task_context), "");
  684. std::unique_ptr<AiCoreOpTask> task1(new AiCoreOpTask());
  685. std::vector<std::unique_ptr<AiCoreOpTask>> tasks;
  686. AiCoreNodeTask node_task(std::move(tasks));
  687. ASSERT_EQ(node_task.ExecuteAsync(task_context, nullptr), SUCCESS);
  688. }

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