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.

model_manager_unittest.cc 17 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
4 years ago
5 years ago
4 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
4 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
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. #define private public
  18. #define protected public
  19. #include "graph/load/model_manager/model_manager.h"
  20. #include "common/helper/om_file_helper.h"
  21. #include "graph/utils/graph_utils.h"
  22. #include "graph/debug/ge_attr_define.h"
  23. #include "common/op/ge_op_utils.h"
  24. #include "graph/load/graph_loader.h"
  25. #include "graph/load/model_manager/davinci_model.h"
  26. #include "graph/ops_stub.h"
  27. #include "common/profiling/profiling_manager.h"
  28. using namespace std;
  29. using namespace testing;
  30. namespace ge {
  31. const static std::string ENC_KEY = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
  32. class UtestModelManagerModelManager : public testing::Test {
  33. protected:
  34. static Status LoadStub(const uint8_t *data, size_t len, Model &model) {
  35. InitModelDefault(model);
  36. return SUCCESS;
  37. }
  38. static void InitModelDefault(Model &model) {
  39. AttrUtils::SetInt(&model, ATTR_MODEL_MEMORY_SIZE, 0);
  40. AttrUtils::SetInt(&model, ATTR_MODEL_WEIGHT_SIZE, 0);
  41. AttrUtils::SetInt(&model, ATTR_MODEL_STREAM_NUM, 0);
  42. AttrUtils::SetInt(&model, ATTR_MODEL_EVENT_NUM, 0);
  43. AttrUtils::SetStr(&model, ATTR_MODEL_TARGET_TYPE, "MINI"); // domi::MINI
  44. auto computeGraph = std::make_shared<ComputeGraph>("graph");
  45. auto graph = GraphUtils::CreateGraphFromComputeGraph(computeGraph);
  46. model.SetGraph(graph);
  47. }
  48. void SetUp() {}
  49. void TearDown() {}
  50. void CreateGraph(Graph &graph) {
  51. TensorDesc desc(ge::Shape({1, 3, 224, 224}));
  52. uint32_t size = desc.GetShape().GetShapeSize();
  53. desc.SetSize(size);
  54. auto data = op::Data("Data").set_attr_index(0);
  55. data.update_input_desc_data(desc);
  56. data.update_output_desc_out(desc);
  57. auto flatten = op::Flatten("Flatten").set_input_x(data, data.name_out_out());
  58. std::vector<Operator> inputs{data};
  59. std::vector<Operator> outputs{flatten};
  60. std::vector<Operator> targets{flatten};
  61. // Graph graph("test_graph");
  62. graph.SetInputs(inputs).SetOutputs(outputs).SetTargets(targets);
  63. }
  64. void GenUnencryptModelData(ModelData &data) {
  65. const int model_len = 10;
  66. data.model_len = sizeof(ModelFileHeader) + model_len;
  67. data.model_data = new uint8_t[data.model_len];
  68. memset((uint8_t *)data.model_data + sizeof(ModelFileHeader), 10, model_len);
  69. ModelFileHeader *header = (ModelFileHeader *)data.model_data;
  70. header->magic = MODEL_FILE_MAGIC_NUM;
  71. header->version = MODEL_VERSION;
  72. header->is_encrypt = ModelEncryptType::UNENCRYPTED;
  73. header->length = model_len;
  74. header->is_checksum = ModelCheckType::CHECK;
  75. }
  76. void GenEncryptModelData(ModelData &data) {
  77. const int model_len = 10;
  78. data.key = ENC_KEY;
  79. data.model_data = new uint8_t[data.model_len];
  80. uint8_t data_ori[model_len];
  81. memset(data_ori, 10, model_len);
  82. ModelFileHeader *header = (ModelFileHeader *)data.model_data;
  83. header->magic = MODEL_FILE_MAGIC_NUM;
  84. header->version = MODEL_VERSION;
  85. header->is_encrypt = ModelEncryptType::ENCRYPTED;
  86. header->length = 10; // encrypt_len;
  87. }
  88. void LoadStandardModelData(ModelData &data) {
  89. data.model_len = 512;
  90. data.model_data = new uint8_t[data.model_len];
  91. uint8_t *model_data = reinterpret_cast<uint8_t *>(data.model_data);
  92. uint32_t mem_offset = sizeof(ModelFileHeader);
  93. ModelPartitionTable *partition_table = reinterpret_cast<ModelPartitionTable *>(model_data + mem_offset);
  94. partition_table->num = PARTITION_SIZE;
  95. mem_offset += sizeof(ModelPartitionTable) + sizeof(ModelPartitionMemInfo) * 5;
  96. {
  97. Model model;
  98. ComputeGraphPtr graph = make_shared<ComputeGraph>("default");
  99. model.SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph));
  100. model.SetVersion(123);
  101. Buffer buffer;
  102. model.Save(buffer);
  103. EXPECT_TRUE(mem_offset + buffer.GetSize() < 512);
  104. memcpy(model_data + mem_offset, buffer.GetData(), buffer.GetSize());
  105. ModelPartitionMemInfo &partition_info = partition_table->partition[0];
  106. partition_info.type = ModelPartitionType::MODEL_DEF;
  107. partition_info.mem_size = buffer.GetSize();
  108. mem_offset += buffer.GetSize();
  109. }
  110. {
  111. ModelPartitionMemInfo &partition_info = partition_table->partition[1];
  112. partition_info.type = ModelPartitionType::WEIGHTS_DATA;
  113. partition_info.mem_offset = mem_offset;
  114. partition_info.mem_size = 0;
  115. }
  116. {
  117. ModelPartitionMemInfo &partition_info = partition_table->partition[2];
  118. partition_info.type = ModelPartitionType::TASK_INFO;
  119. partition_info.mem_offset = mem_offset;
  120. partition_info.mem_size = 0;
  121. }
  122. {
  123. ModelPartitionMemInfo &partition_info = partition_table->partition[3];
  124. partition_info.type = ModelPartitionType::TBE_KERNELS;
  125. partition_info.mem_offset = mem_offset;
  126. partition_info.mem_size = 0;
  127. }
  128. {
  129. ModelPartitionMemInfo &partition_info = partition_table->partition[4];
  130. partition_info.type = ModelPartitionType::CUST_AICPU_KERNELS;
  131. partition_info.mem_offset = mem_offset;
  132. partition_info.mem_size = 0;
  133. }
  134. EXPECT_TRUE(mem_offset < 512);
  135. ModelFileHeader *header = new (data.model_data) ModelFileHeader;
  136. header->length = mem_offset - sizeof(ModelFileHeader);
  137. data.model_len = mem_offset;
  138. }
  139. };
  140. class DModelListener : public ModelListener {
  141. public:
  142. DModelListener(){};
  143. uint32_t OnComputeDone(uint32_t model_id, uint32_t data_index,
  144. uint32_t resultCode, std::vector<ge::Tensor> &outputs) { return 0; }
  145. };
  146. TEST_F(UtestModelManagerModelManager, case_is_need_hybrid_load) {
  147. ModelManager mm;
  148. uint32_t model_id = 0;
  149. ComputeGraphPtr root_graph = std::make_shared<ComputeGraph>("graph");
  150. ge::GeRootModel model;
  151. EXPECT_EQ(mm.IsNeedHybridLoad(model), false);
  152. model.SetRootGraph(root_graph);
  153. EXPECT_EQ(mm.IsNeedHybridLoad(model), false);
  154. }
  155. TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) {
  156. ModelManager mm;
  157. uint32_t model_id = 0;
  158. ModelData data;
  159. // Load allow listener is null
  160. EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID);
  161. }
  162. TEST_F(UtestModelManagerModelManager, case_load_model_len_too_short) {
  163. ModelManager mm;
  164. ModelData data;
  165. data.model_len = 10;
  166. data.model_data = (void *)&data;
  167. uint32_t model_id = 1;
  168. EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
  169. data.model_data = nullptr;
  170. }
  171. TEST_F(UtestModelManagerModelManager, case_load_model_len_not_match) {
  172. ModelManager mm;
  173. ModelData data;
  174. GenUnencryptModelData(data);
  175. data.model_len = sizeof(ModelFileHeader) + 1;
  176. uint32_t model_id = 1;
  177. EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
  178. delete[](uint8_t *) data.model_data;
  179. }
  180. TEST_F(UtestModelManagerModelManager, case_load_model_encypt_not_match) {
  181. ModelManager mm;
  182. ModelData data;
  183. GenUnencryptModelData(data);
  184. data.key = ENC_KEY;
  185. uint32_t model_id = 1;
  186. EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
  187. delete[](uint8_t *) data.model_data;
  188. }
  189. TEST_F(UtestModelManagerModelManager, case_load_model_encypt_type_unsupported) {
  190. ModelManager mm;
  191. ModelData data;
  192. GenUnencryptModelData(data);
  193. ModelFileHeader *header = (ModelFileHeader *)data.model_data;
  194. header->is_encrypt = 255;
  195. uint32_t model_id = 1;
  196. EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
  197. delete[](uint8_t *) data.model_data;
  198. }
  199. TEST_F(UtestModelManagerModelManager, case_load_model_data_success) {
  200. ModelData data;
  201. LoadStandardModelData(data);
  202. uint32_t model_id = 1;
  203. ModelManager mm;
  204. EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), SUCCESS);
  205. delete[](uint8_t *) data.model_data;
  206. }
  207. /*
  208. shared_ptr<ModelListener> LabelCallBack(new DModelListener());
  209. // test HandleCommand
  210. TEST_F(UtestModelManagerModelManager, command_success1) {
  211. ModelManager manager;
  212. Command cmd;
  213. cmd.cmd_type = "INFERENCE";
  214. EXPECT_EQ(PARAM_INVALID, manager.HandleCommand(cmd));
  215. cmd.cmd_type = "NOT SUPPORT";
  216. EXPECT_EQ(PARAM_INVALID, manager.HandleCommand(cmd));
  217. }
  218. TEST_F(UtestModelManagerModelManager, command_success2) {
  219. ModelManager manager;
  220. Command cmd;
  221. cmd.cmd_type = "dump";
  222. cmd.cmd_params.push_back("status");
  223. cmd.cmd_params.push_back("on");
  224. cmd.cmd_params.push_back("model_name");
  225. cmd.cmd_params.push_back("test_model");
  226. cmd.cmd_params.push_back("path");
  227. cmd.cmd_params.push_back("/test");
  228. cmd.cmd_params.push_back("layer");
  229. cmd.cmd_params.push_back("layer1");
  230. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  231. }
  232. // test profile
  233. TEST_F(UtestModelManagerModelManager, command_profile_success) {
  234. ModelManager manager;
  235. Command cmd;
  236. cmd.cmd_type = "profile";
  237. cmd.cmd_params.push_back("ome");
  238. cmd.cmd_params.push_back("on");
  239. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  240. bool ome_profile_on = PropertiesManager::Instance().GetPropertyValue(OME_PROFILE) == "1";
  241. EXPECT_EQ(true, ome_profile_on);
  242. cmd.cmd_params.clear();
  243. cmd.cmd_params.push_back("ome");
  244. cmd.cmd_params.push_back("off");
  245. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  246. ome_profile_on = PropertiesManager::Instance().GetPropertyValue(OME_PROFILE) == "1";
  247. EXPECT_FALSE(ome_profile_on);
  248. cmd.cmd_params.clear();
  249. cmd.cmd_params.push_back("cce");
  250. cmd.cmd_params.push_back("on");
  251. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  252. bool cce_profile_on = PropertiesManager::Instance().GetPropertyValue(CCE_PROFILE) == "1";
  253. EXPECT_EQ(true, cce_profile_on);
  254. cmd.cmd_params.clear();
  255. cmd.cmd_params.push_back("cce");
  256. cmd.cmd_params.push_back("off");
  257. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  258. cce_profile_on = PropertiesManager::Instance().GetPropertyValue(CCE_PROFILE) == "1";
  259. EXPECT_FALSE(cce_profile_on);
  260. cmd.cmd_params.clear();
  261. cmd.cmd_params.push_back("runtime");
  262. cmd.cmd_params.push_back("on");
  263. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  264. bool rts_profile_on = PropertiesManager::Instance().GetPropertyValue(RTS_PROFILE) == "1";
  265. EXPECT_EQ(true, rts_profile_on);
  266. cmd.cmd_params.clear();
  267. cmd.cmd_params.push_back("runtime");
  268. cmd.cmd_params.push_back("off");
  269. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  270. rts_profile_on = PropertiesManager::Instance().GetPropertyValue(RTS_PROFILE) == "1";
  271. EXPECT_FALSE(rts_profile_on);
  272. cmd.cmd_params.clear();
  273. cmd.cmd_params.push_back("profiler_jobctx");
  274. cmd.cmd_params.push_back("jobctx");
  275. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  276. EXPECT_EQ("jobctx", PropertiesManager::Instance().GetPropertyValue(PROFILER_JOBCTX));
  277. cmd.cmd_params.clear();
  278. cmd.cmd_params.push_back("profiler_target_path");
  279. cmd.cmd_params.push_back("/test/target");
  280. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  281. EXPECT_EQ("/test/target", PropertiesManager::Instance().GetPropertyValue(PROFILER_TARGET_PATH));
  282. cmd.cmd_params.clear();
  283. cmd.cmd_params.push_back("RTS_PATH");
  284. cmd.cmd_params.push_back("/test/rts_path");
  285. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  286. EXPECT_EQ("/test/rts_path", PropertiesManager::Instance().GetPropertyValue(RTS_PROFILE_PATH));
  287. }
  288. // test acl profiling
  289. TEST_F(UtestModelManagerModelManager, command_profiling) {
  290. ModelManager manager;
  291. Command cmd;
  292. cmd.cmd_type = "profiling";
  293. cmd.cmd_params.push_back("config");
  294. cmd.cmd_params.push_back("on");
  295. EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
  296. }
  297. TEST_F(UtestModelManagerModelManager, command_profile_failed) {
  298. ModelManager manager;
  299. Command cmd;
  300. cmd.cmd_type = "profile";
  301. cmd.cmd_params.push_back("ome");
  302. EXPECT_EQ(PARAM_INVALID, manager.HandleCommand(cmd));
  303. }
  304. // test Start
  305. TEST_F(UtestModelManagerModelManager, start_fail) {
  306. ModelManager manager;
  307. manager.model_map_[2] = nullptr;
  308. EXPECT_EQ(PARAM_INVALID, manager.Start(2));
  309. }
  310. // test GetMaxUsedMemory
  311. TEST_F(UtestModelManagerModelManager, get_max_used_memory_fail) {
  312. ModelManager manager;
  313. uint64_t max_size = 0;
  314. manager.model_map_[2] = nullptr;
  315. EXPECT_EQ(PARAM_INVALID, manager.GetMaxUsedMemory(2, max_size));
  316. }
  317. // test GetInputOutputDescInfo
  318. TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_fail) {
  319. ModelManager manager;
  320. manager.model_map_[2] = nullptr;
  321. vector<InputOutputDescInfo> input_shape;
  322. vector<InputOutputDescInfo> output_shape;
  323. EXPECT_EQ(PARAM_INVALID, manager.GetInputOutputDescInfo(2, input_shape, output_shape));
  324. }
  325. *//*
  326. // test GetInputOutputDescInfo fail
  327. TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail) {
  328. ModelManager manager;
  329. manager.model_map_[2] = nullptr;
  330. vector<InputOutputDescInfo> input_shape;
  331. vector<InputOutputDescInfo> output_shape;
  332. EXPECT_EQ(PARAM_INVALID, manager.GetInputOutputDescInfoForZeroCopy(2, input_shape, output_shape));
  333. }
  334. *//*
  335. // test Stop
  336. TEST_F(UtestModelManagerModelManager, stop_fail) {
  337. ModelManager manager;
  338. manager.model_map_[2] = nullptr;
  339. EXPECT_EQ(PARAM_INVALID, manager.Stop(2));
  340. }
  341. // build input_data
  342. TEST_F(UtestModelManagerModelManager, check_data_len_success) {
  343. shared_ptr<ModelListener> g_label_call_back(new DModelListener());
  344. DavinciModel model(0, g_label_call_back);
  345. ModelManager model_manager;
  346. InputData input_data;
  347. DataBuffer data_buffer;
  348. data_buffer.data = new char[51200];
  349. data_buffer.length = 51200;
  350. input_data.index = 0;
  351. input_data.model_id = 1;
  352. input_data.blobs.push_back(data_buffer);
  353. delete[](char *) data_buffer.data;
  354. }
  355. // test LoadModeldef
  356. TEST_F(UtestModelManagerModelManager, destroy_aicpu_session) {
  357. ModelManager manager;
  358. manager.DestroyAicpuSession(0);
  359. manager.sess_ids_.insert(0);
  360. manager.DestroyAicpuSession(0);
  361. }*/
  362. // test DataInputTensor
  363. TEST_F(UtestModelManagerModelManager, test_data_input_tensor) {
  364. shared_ptr<ModelListener> g_label_call_back(nullptr);
  365. auto model = std::make_shared<DavinciModel>(0, g_label_call_back);
  366. ModelManager mm;
  367. uint32_t model_id = 1;
  368. mm.model_map_[1] = model;
  369. mm.hybrid_model_map_[1] = std::make_shared<hybrid::HybridDavinciModel>();
  370. ge::Tensor input_tensor;
  371. vector<ge::Tensor> inputs;
  372. inputs.emplace_back(input_tensor);
  373. auto ret = mm.DataInputTensor(model_id,inputs);
  374. EXPECT_EQ(PARAM_INVALID, ret); // HybridDavinciModel::impl_ is null.
  375. }
  376. TEST_F(UtestModelManagerModelManager, test_launch_kernel_cust_aicpu) {
  377. ModelManager mm;
  378. // cust_aicpu_so_ is empty.
  379. EXPECT_EQ(mm.LaunchKernelCustAicpuSo("empty_cust_aicpu"), SUCCESS);
  380. // deleteCustOp after Launch will deleted.
  381. uintptr_t resource_id = 1; // for rtCtxGetCurrent stub
  382. std::vector<char> kernel_bin(256);
  383. auto &cust_resource_001 = mm.cust_aicpu_so_[resource_id];
  384. auto tbe_kernel = std::shared_ptr<OpKernelBin>(new OpKernelBin("deleteCustOp", std::move(kernel_bin)));
  385. auto &cust_opkernel_001 = cust_resource_001["deleteCustOp"] = tbe_kernel;
  386. EXPECT_FALSE(mm.cust_aicpu_so_.empty());
  387. EXPECT_EQ(mm.LaunchKernelCustAicpuSo("deleteCustOp"), SUCCESS);
  388. EXPECT_TRUE(mm.cust_aicpu_so_.empty());
  389. }
  390. shared_ptr<ModelListener> listerner(new DModelListener());
  391. TEST_F(UtestModelManagerModelManager, test_load_model_online) {
  392. ModelManager mm;
  393. uint32_t model_id = 1;
  394. ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
  395. GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph);
  396. auto &profiling_manager = ge::ProfilingManager::Instance();
  397. profiling_manager.SetSubscribeInfo(0, model_id, true);
  398. Status ret = mm.LoadModelOnline(model_id, ge_root_model, listerner);
  399. profiling_manager.CleanSubscribeInfo();
  400. }
  401. TEST_F(UtestModelManagerModelManager, command_profiling) {
  402. ModelManager manager;
  403. uint32_t model_id = 1;
  404. Command cmd;
  405. auto model = std::make_shared<DavinciModel>(1, listerner);
  406. model->SetId(model_id);
  407. cmd.cmd_params.push_back("modelId");
  408. cmd.cmd_params.push_back(to_string(model_id));
  409. auto &profiling_manager = ge::ProfilingManager::Instance();
  410. profiling_manager.SetSubscribeInfo(0, model_id, true);
  411. Status ret = manager.HandleProfModelUnsubscribeCommand(cmd);
  412. profiling_manager.CleanSubscribeInfo();
  413. }
  414. } // namespace ge

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