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_executor_unittest.cc 6.0 kB

5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <memory>
  18. #include "common/ge_inner_error_codes.h"
  19. #include "common/types.h"
  20. #include "common/util.h"
  21. #include "runtime/mem.h"
  22. #include "common/util.h"
  23. #include "omg/omg_inner_types.h"
  24. #define private public
  25. #define protected public
  26. #include "executor/ge_executor.h"
  27. #include "common/auth/file_saver.h"
  28. #include "common/debug/log.h"
  29. #include "common/properties_manager.h"
  30. #include "common/types.h"
  31. #include "graph/load/graph_loader.h"
  32. #include "graph/load/new_model_manager/davinci_model.h"
  33. #include "graph/load/new_model_manager/davinci_model_parser.h"
  34. #include "graph/load/new_model_manager/model_manager.h"
  35. #include "graph/load/new_model_manager/task_info/kernel_task_info.h"
  36. #include "graph/load/new_model_manager/task_info/kernel_ex_task_info.h"
  37. #include "ge/common/dump/dump_properties.h"
  38. #include "graph/manager/graph_mem_allocator.h"
  39. #include "graph/utils/graph_utils.h"
  40. #include "proto/ge_ir.pb.h"
  41. #undef private
  42. #undef protected
  43. using namespace std;
  44. namespace ge {
  45. class UtestGeExecutor : public testing::Test {
  46. protected:
  47. static void InitModelDefault(ge::Model &model) {
  48. ge::AttrUtils::SetInt(&model, ATTR_MODEL_MEMORY_SIZE, 0);
  49. ge::AttrUtils::SetInt(&model, ATTR_MODEL_WEIGHT_SIZE, 0);
  50. ge::AttrUtils::SetInt(&model, ATTR_MODEL_STREAM_NUM, 0);
  51. ge::AttrUtils::SetInt(&model, ATTR_MODEL_EVENT_NUM, 0);
  52. ge::AttrUtils::SetStr(&model, ATTR_MODEL_TARGET_TYPE, "MINI"); // domi::MINI
  53. auto compute_graph = std::make_shared<ge::ComputeGraph>("graph");
  54. auto graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
  55. model.SetGraph(graph);
  56. }
  57. void SetUp() {
  58. unsetenv("FMK_SYSMODE");
  59. unsetenv("FMK_DUMP_PATH");
  60. unsetenv("FMK_USE_FUSION");
  61. unsetenv("DAVINCI_TIMESTAT_ENABLE");
  62. }
  63. };
  64. class DModelListener : public ge::ModelListener {
  65. public:
  66. DModelListener() {
  67. };
  68. Status OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t resultCode,
  69. std::vector<ge::OutputTensorInfo> &outputs) {
  70. GELOGI("In Call back. OnComputeDone");
  71. return SUCCESS;
  72. }
  73. };
  74. shared_ptr<ge::ModelListener> g_label_call_back(new DModelListener());
  75. static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") {
  76. auto op_desc = std::make_shared<ge::OpDesc>(name, type);
  77. op_desc->SetStreamId(0);
  78. op_desc->SetId(0);
  79. ge::AttrUtils::SetFloat(op_desc, ge::ATTR_NAME_ALPHA, 0);
  80. ge::AttrUtils::SetFloat(op_desc, ge::ATTR_NAME_BETA, 0);
  81. op_desc->SetWorkspace({});
  82. ;
  83. op_desc->SetWorkspaceBytes({});
  84. op_desc->SetInputOffset({});
  85. op_desc->SetOutputOffset({});
  86. ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_WEIGHT_NAME, {});
  87. ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_MODE, 0);
  88. ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_PAD_MODE, 0);
  89. ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_DATA_MODE, 0);
  90. ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_CEIL_MODE, 0);
  91. ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_NAN_OPT, 0);
  92. ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_WINDOW, {});
  93. ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_PAD, {});
  94. ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_STRIDE, {});
  95. ge::AttrUtils::SetListInt(op_desc, ge::ATTR_NAME_ACTIVE_STREAM_LIST, {1, 1});
  96. ge::AttrUtils::SetInt(op_desc, ge::ATTR_NAME_STREAM_SWITCH_COND, 0);
  97. return op_desc;
  98. }
  99. /*
  100. TEST_F(UtestGeExecutor, fail_UnloadModel_model_manager_stop_unload_error) {
  101. uint32_t model_id = 1;
  102. ge::GeExecutor ge_executor;
  103. ge_executor.isInit_ = true;
  104. ge::Status ret = ge_executor.UnloadModel(model_id);
  105. EXPECT_EQ(ge::PARAM_INVALID, ret);
  106. ge_executor.isInit_ = false;
  107. ret = ge_executor.UnloadModel(model_id);
  108. EXPECT_EQ(ge::GE_EXEC_NOT_INIT, ret);
  109. }
  110. TEST_F(UtestGeExecutor, fail_CommandHandle_model_manager_HandleCommand_error) {
  111. ge::Command cmd;
  112. ge::GeExecutor ge_executor;
  113. ge::Status ret = ge_executor.CommandHandle(cmd);
  114. EXPECT_EQ(ge::PARAM_INVALID, ret);
  115. }
  116. */
  117. TEST_F(UtestGeExecutor, InitFeatureMapAndP2PMem_failed) {
  118. DavinciModel model(0, g_label_call_back);
  119. model.is_feature_map_mem_has_inited_ = true;
  120. EXPECT_EQ(model.InitFeatureMapAndP2PMem(nullptr, 0), PARAM_INVALID);
  121. }
  122. TEST_F(UtestGeExecutor, kernel_InitDumpTask) {
  123. DavinciModel model(0, g_label_call_back);
  124. model.om_name_ = "testom";
  125. model.name_ = "test";
  126. OpDescPtr op_desc = CreateOpDesc("test", "test");
  127. std::map<std::string, std::set<std::string>> model_dump_properties_map;
  128. std::set<std::string> s;
  129. model_dump_properties_map[DUMP_ALL_MODEL] = s;
  130. DumpProperties dp;
  131. dp.model_dump_properties_map_ = model_dump_properties_map;
  132. model.SetDumpProperties(dp);
  133. KernelTaskInfo kernel_task_info;
  134. kernel_task_info.davinci_model_ = &model;
  135. kernel_task_info.op_desc_ = op_desc;
  136. kernel_task_info.InitDumpTask(0);
  137. }
  138. TEST_F(UtestGeExecutor, kernel_ex_InitDumpTask) {
  139. DavinciModel model(0, g_label_call_back);
  140. model.om_name_ = "testom";
  141. model.name_ = "test";
  142. OpDescPtr op_desc = CreateOpDesc("test", "test");
  143. std::map<std::string, std::set<std::string>> model_dump_properties_map;
  144. std::set<std::string> s;
  145. model_dump_properties_map[DUMP_ALL_MODEL] = s;
  146. DumpProperties dp;
  147. dp.model_dump_properties_map_ = model_dump_properties_map;
  148. model.SetDumpProperties(dp);
  149. KernelExTaskInfo kernel_ex_task_info;
  150. kernel_ex_task_info.davinci_model_ = &model;
  151. kernel_ex_task_info.InitDumpTask(nullptr, op_desc);
  152. }
  153. }

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