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.

profiling_manager.cc 19 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 "common/profiling/profiling_manager.h"
  17. #include <nlohmann/json.hpp>
  18. #include "framework/common/debug/ge_log.h"
  19. #include "framework/common/debug/log.h"
  20. #include "framework/common/string_util.h"
  21. #include "graph/ge_context.h"
  22. #include "runtime/base.h"
  23. using Json = nlohmann::json;
  24. namespace {
  25. const char *const kJobID = "jobID";
  26. const char *const kDeviceID = "deviceID";
  27. const char *const kStartCfg = "startCfg";
  28. const char *const kFeatures = "features";
  29. const char *const kConf = "conf";
  30. const char *const kEvents = "events";
  31. const char *const kAiCoreEvents = "ai_core_events";
  32. const char *const kName = "name";
  33. const char *const kTraceID = "traceId";
  34. const size_t kReportMaxLen = 2048;
  35. } // namespace
  36. namespace ge {
  37. ProfilingManager::ProfilingManager() {}
  38. ProfilingManager::~ProfilingManager() {}
  39. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager &ProfilingManager::Instance() {
  40. static ProfilingManager profiling_manager;
  41. return profiling_manager;
  42. }
  43. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::Init(const Options &options) {
  44. #ifdef DAVINCI_SUPPORT_PROFILING
  45. vector<int32_t>().swap(device_id_);
  46. device_id_.push_back(options.device_id);
  47. job_id_ = options.job_id;
  48. Status ret;
  49. if (!recv_profiling_config_.empty()) {
  50. GELOGI("Profiling json config from acl:%s", recv_profiling_config_.c_str());
  51. ret = InitFromAclCfg(recv_profiling_config_);
  52. } else {
  53. ret = InitFromOptions(options);
  54. }
  55. if (ret != SUCCESS) {
  56. GELOGE(ret, "Failed to init profiling.");
  57. return ret;
  58. }
  59. if (is_profiling_) {
  60. // register Framework to profiling
  61. int result = Msprof::Engine::Init(GE_PROFILING_MODULE, &engine_);
  62. if (result != 0) {
  63. GELOGE(FAILED, "Register profiling engine failed.");
  64. return FAILED;
  65. }
  66. // profiling startup first time
  67. GELOGI("Begin to init profiling, device num %zu", device_id_.size());
  68. for (size_t i = 0; i < device_id_.size(); ++i) {
  69. ret = StartProfiling(0, device_id_[i]);
  70. if (ret != SUCCESS) {
  71. GELOGE(ret, "Profiling start failed on device %d.", device_id_[i]);
  72. return FAILED;
  73. }
  74. GELOGI("Profiling init succ on device %d.", device_id_[i]);
  75. }
  76. } else {
  77. GELOGI("The profiling is off, skip the initialization");
  78. }
  79. #endif
  80. return SUCCESS;
  81. }
  82. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::InitFromAclCfg(
  83. const std::string &config) {
  84. #ifdef DAVINCI_SUPPORT_PROFILING
  85. try {
  86. is_profiling_ = false;
  87. profiling_opts_.clear();
  88. op_trace_conf_.clear();
  89. Json start_prof_conf = Json::parse(config);
  90. Json &prof_conf = start_prof_conf[kStartCfg][0];
  91. job_id_ = prof_conf[kJobID];
  92. Json &device_id = prof_conf[kDeviceID];
  93. if (device_id.size() != 0) {
  94. vector<int32_t>().swap(device_id_);
  95. bool is_all = false;
  96. for (size_t i = 0; i < device_id.size(); i++) {
  97. std::string device_id_str = device_id[i].get<std::string>();
  98. if (device_id_str == "all") {
  99. is_all = true;
  100. break;
  101. }
  102. device_id_.push_back(std::stoi(device_id_str));
  103. }
  104. if (is_all == true) {
  105. int32_t count = 0;
  106. rtError_t rt_err = rtGetDeviceCount(&count);
  107. if (rt_err != RT_ERROR_NONE) {
  108. GELOGE(FAILED, "Call rtGetDeviceCount to get device failed.");
  109. }
  110. vector<int32_t>().swap(device_id_);
  111. for (int32_t i = 0; i < count; ++i) {
  112. device_id_.push_back(i);
  113. }
  114. }
  115. }
  116. GELOGI("Profiling json config from acl:%s", config.c_str());
  117. Json &features = prof_conf[kFeatures];
  118. for (size_t i = 0; i < features.size(); ++i) {
  119. Json &feature = features[i];
  120. if ((feature.find(kName) == feature.end()) || feature[kName].is_null()) {
  121. continue;
  122. }
  123. const std::string &name = feature[kName];
  124. if (name == "op_trace") {
  125. GELOGI("Op trace config from acl");
  126. Json &conf = feature[kConf];
  127. Json &events = conf[0][kEvents];
  128. const std::string &ai_core_events = events[0][kAiCoreEvents];
  129. GELOGI("Op trace config from acl ai_core_events:%s", ai_core_events.c_str());
  130. is_op_trace_ = true;
  131. // op trace get conf
  132. ProfMgrConf prof_mgr_conf;
  133. int result = ProfMgrGetConf(ai_core_events, &prof_mgr_conf);
  134. if (result != 0) {
  135. GELOGE(FAILED, "ProfMgrGetConf failed.");
  136. return FAILED;
  137. }
  138. op_trace_conf_ = prof_mgr_conf.conf;
  139. op_trace_iter_num_ = static_cast<int32_t>(op_trace_conf_.size());
  140. GELOGI("Op trace profiling iter num %d,", op_trace_iter_num_);
  141. } else if (name == "task_trace") {
  142. is_op_trace_ = false;
  143. GELOGI("Task trace config from acl");
  144. } else if (name == "system_trace") {
  145. is_op_trace_ = false;
  146. Json &conf = feature[kConf];
  147. std::stringstream system_trace_conf;
  148. system_trace_conf << conf;
  149. system_trace_conf_ = system_trace_conf.str();
  150. GELOGI("System trace config from acl");
  151. }
  152. profiling_opts_.push_back(name);
  153. }
  154. is_profiling_ = true;
  155. } catch (...) {
  156. GELOGE(FAILED, "Json conf is not invalid !");
  157. return ge::PARAM_INVALID;
  158. }
  159. #endif
  160. return ge::SUCCESS;
  161. }
  162. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::InitFromOptions(const Options &options) {
  163. #ifdef DAVINCI_SUPPORT_PROFILING
  164. // enable profiling support two ways: env and front end
  165. const char *profiling_mode = std::getenv("PROFILING_MODE");
  166. const char *prof_options = std::getenv("PROFILING_OPTIONS");
  167. if ((profiling_mode == nullptr) || (strcmp("true", profiling_mode) != 0) || (prof_options == nullptr)) {
  168. is_profiling_ = false;
  169. } else {
  170. std::string prof_options_str = std::string(prof_options);
  171. profiling_opts_ = StringUtils::Split(prof_options_str, ':');
  172. is_profiling_ = true;
  173. GELOGI("The profiling in env is %s, %s", profiling_mode, prof_options);
  174. }
  175. if (!is_profiling_) {
  176. const std::string enable_profiling = "1";
  177. if (options.profiling_mode != enable_profiling || options.profiling_options.empty()) {
  178. is_profiling_ = false;
  179. return SUCCESS;
  180. } else {
  181. profiling_opts_ = StringUtils::Split(options.profiling_options, ':');
  182. is_profiling_ = true;
  183. GELOGI("The profiling in options is %s, %s", options.profiling_mode.c_str(), options.profiling_options.c_str());
  184. }
  185. }
  186. // features:'training_trace', 'task_trace' or 'op_trace' etc
  187. if (!profiling_opts_.empty()) {
  188. if (profiling_opts_[0] == "op_trace") {
  189. is_op_trace_ = true;
  190. // op trace get conf
  191. ProfMgrConf prof_mgr_conf;
  192. int result = ProfMgrGetConf("", &prof_mgr_conf);
  193. if (result != 0) {
  194. GELOGE(FAILED, "ProfMgrGetConf failed.");
  195. return FAILED;
  196. }
  197. op_trace_conf_ = prof_mgr_conf.conf;
  198. op_trace_iter_num_ = static_cast<int32_t>(op_trace_conf_.size());
  199. GELOGI("op trace profiling iter num %d,", op_trace_iter_num_);
  200. } else {
  201. is_op_trace_ = false;
  202. op_trace_iter_num_ = 1;
  203. }
  204. }
  205. #endif
  206. return ge::SUCCESS;
  207. }
  208. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::StartProfiling(int32_t iter_num,
  209. int32_t device_id) {
  210. #ifdef DAVINCI_SUPPORT_PROFILING
  211. if (!profiling_opts_.empty()) {
  212. GELOGI("Start profiling index is %d", iter_num);
  213. // current one docker only use one device
  214. Json p_device;
  215. try {
  216. // profiling need physical_device_id
  217. p_device[kDeviceID] = std::to_string(device_id);
  218. p_device[kJobID] = job_id_;
  219. p_device[kTraceID] = std::to_string(GetContext().TraceId());
  220. Json features;
  221. if (is_op_trace_) {
  222. Json f;
  223. f[kName] = "op_trace";
  224. Json conf;
  225. if (op_trace_conf_.size() <= static_cast<size_t>(iter_num)) {
  226. GELOGE(FAILED, "Op trace iter num is invalid!");
  227. return FAILED;
  228. }
  229. Json events;
  230. events[0] = nlohmann::json::parse(op_trace_conf_[iter_num]);
  231. conf[0][kEvents] = events;
  232. f[kConf] = conf;
  233. features[0] = f;
  234. if (iter_num == 0) {
  235. is_load_ = true;
  236. }
  237. } else {
  238. for (std::vector<std::string>::size_type i = 0; i < profiling_opts_.size(); i++) {
  239. Json f;
  240. if (profiling_opts_[i] == "system_trace") {
  241. f[kConf] = nlohmann::json::parse(system_trace_conf_);
  242. }
  243. f[kName] = profiling_opts_[i];
  244. features[i] = f;
  245. }
  246. is_load_ = true;
  247. }
  248. p_device[kFeatures] = features;
  249. // only one device, but sProfMgrStartUp API require for device list
  250. Json devices;
  251. devices[0] = p_device;
  252. Json start_cfg;
  253. start_cfg[kStartCfg] = devices;
  254. // convert json to string
  255. std::stringstream ss;
  256. ss << start_cfg;
  257. send_profiling_config_ = ss.str();
  258. GELOGI("Profiling config %s\n", send_profiling_config_.c_str());
  259. } catch (...) {
  260. GELOGE(FAILED, "Op trace json conf is not invalid !");
  261. return FAILED;
  262. }
  263. // runtime startup for profiling
  264. GE_CHK_RT_RET(rtProfilerStart());
  265. // call profiling startup API
  266. ProfMgrCfg prof_cfg = {send_profiling_config_};
  267. void *prof_handle = ProfMgrStartUp(&prof_cfg);
  268. if (prof_handle == nullptr) {
  269. GELOGW("ProfMgrStartUp failed.");
  270. return FAILED;
  271. }
  272. prof_handle_vec_.push_back(prof_handle);
  273. }
  274. #endif
  275. return SUCCESS;
  276. }
  277. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::StopProfiling() {
  278. #ifdef DAVINCI_SUPPORT_PROFILING
  279. Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter();
  280. if (reporter != nullptr) {
  281. int ret = reporter->Flush();
  282. GELOGI("Report data end, ret is %d", ret);
  283. }
  284. rtError_t rt_ret = rtProfilerStop();
  285. if (rt_ret != RT_ERROR_NONE) {
  286. GELOGI("Call rtProfilerStop ret:%d", rt_ret);
  287. }
  288. for (size_t i = 0; i < prof_handle_vec_.size(); ++i) {
  289. int result = ProfMgrStop(prof_handle_vec_[i]);
  290. if (result != 0) {
  291. GELOGW("ProfMgr stop return fail:%d.", result);
  292. return;
  293. }
  294. }
  295. vector<void *>().swap(prof_handle_vec_);
  296. is_load_ = false;
  297. recv_profiling_config_ = "";
  298. GELOGI("Stop Profiling success.");
  299. #endif
  300. }
  301. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingTaskDescInfo(
  302. const std::vector<TaskDescInfo> &task_desc_info, const int32_t &device_id) {
  303. #ifdef DAVINCI_SUPPORT_PROFILING
  304. Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter();
  305. if (reporter == nullptr) {
  306. GELOGI("Profiling report is nullptr!");
  307. return;
  308. }
  309. std::string data;
  310. for (const auto &task : task_desc_info) {
  311. std::string op_name = task.op_name;
  312. uint32_t block_dim = task.block_dim;
  313. uint32_t task_id = task.task_id;
  314. uint32_t stream_id = task.stream_id;
  315. data = op_name.append(" ").append(std::to_string(block_dim)
  316. .append(" ")
  317. .append(std::to_string(task_id))
  318. .append(" ")
  319. .append(std::to_string(stream_id))
  320. .append("\n"));
  321. Msprof::Engine::ReporterData reporter_data{};
  322. reporter_data.deviceId = device_id;
  323. reporter_data.data = (unsigned char *)data.c_str();
  324. reporter_data.dataLen = data.size();
  325. int ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "task_desc_info", sizeof("task_desc_info"));
  326. if (ret != EOK) {
  327. GELOGE(ret, "Report data tag of task_desc_info memcpy error!");
  328. return;
  329. }
  330. ret = reporter->Report(&reporter_data);
  331. if (ret != SUCCESS) {
  332. GELOGE(ret, "Reporter data of task_desc_info fail!");
  333. return;
  334. }
  335. }
  336. data.clear();
  337. #endif
  338. }
  339. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingGraphDescInfo(
  340. const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, const int32_t &device_id) {
  341. #ifdef DAVINCI_SUPPORT_PROFILING
  342. Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter();
  343. GE_IF_BOOL_EXEC(reporter == nullptr, GELOGI("Profiling report is nullptr!"); return;);
  344. std::string data;
  345. for (const auto &graph : compute_graph_desc_info) {
  346. data.append("op_name:").append(graph.op_name).append(" op_type:").append(graph.op_type);
  347. for (size_t i = 0; i < graph.input_format.size(); ++i) {
  348. data.append(" input_id:")
  349. .append(std::to_string(i))
  350. .append(" input_format:")
  351. .append(std::to_string(graph.input_format.at(i)))
  352. .append(" input_data_type:")
  353. .append(std::to_string(graph.input_data_type.at(i)))
  354. .append(" input_shape:\"");
  355. size_t input_shape_len = graph.input_shape.at(i).size();
  356. if (input_shape_len == 0) {
  357. data.append("");
  358. } else if (input_shape_len == 1) {
  359. data.append(std::to_string(graph.input_shape.at(i).at(0)));
  360. } else {
  361. for (size_t j = 0; j < input_shape_len - 1; ++j) {
  362. data.append(std::to_string(graph.input_shape.at(i).at(j))).append(",");
  363. }
  364. data.append(std::to_string(graph.input_shape.at(i).at(input_shape_len - 1)));
  365. }
  366. data.append("\"");
  367. }
  368. for (size_t i = 0; i < graph.output_format.size(); ++i) {
  369. data.append(" output_id:")
  370. .append(std::to_string(i))
  371. .append(" output_format:")
  372. .append(std::to_string(graph.output_format.at(i)))
  373. .append(" output_data_type:")
  374. .append(std::to_string(graph.output_data_type.at(i)))
  375. .append(" output_shape:\"");
  376. size_t output_shape_len = graph.output_shape.at(i).size();
  377. if (output_shape_len == 0) {
  378. data.append("");
  379. } else if (output_shape_len == 1) {
  380. data.append(std::to_string(graph.output_shape.at(i).at(0)));
  381. } else {
  382. for (size_t j = 0; j < output_shape_len - 1; ++j) {
  383. data.append(std::to_string(graph.output_shape.at(i).at(j))).append(",");
  384. }
  385. data.append(std::to_string(graph.output_shape.at(i).at(output_shape_len - 1)));
  386. }
  387. data.append("\"");
  388. }
  389. data.append("\n");
  390. Msprof::Engine::ReporterData reporter_data{};
  391. Report(device_id, data, *reporter, reporter_data);
  392. data.clear();
  393. }
  394. #endif
  395. }
  396. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::Report(
  397. const int32_t &device_id, const string &data, Msprof::Engine::Reporter &reporter,
  398. Msprof::Engine::ReporterData &reporter_data) {
  399. #ifdef DAVINCI_SUPPORT_PROFILING
  400. size_t index = data.size() / kReportMaxLen;
  401. if (index >= 1) {
  402. reporter_data.deviceId = device_id;
  403. int ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info"));
  404. GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag of graph_desc_info memcpy error!"); return;);
  405. for (size_t i = 0; i < index; ++i) {
  406. reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * i;
  407. reporter_data.dataLen = kReportMaxLen;
  408. ret = reporter.Report(&reporter_data);
  409. GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "Reporter data of graph_desc_info fail!"); return;);
  410. }
  411. reporter_data.dataLen = data.size() - kReportMaxLen * index;
  412. if (reporter_data.dataLen != 0) {
  413. reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * index;
  414. ret = reporter.Report(&reporter_data);
  415. GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "Reporter data of graph_desc_info fail!"); return;);
  416. }
  417. } else {
  418. reporter_data.deviceId = device_id;
  419. reporter_data.data = (unsigned char *)data.c_str();
  420. reporter_data.dataLen = data.size();
  421. int ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info"));
  422. GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag of graph_desc_info memcpy error!"); return;);
  423. ret = reporter.Report(&reporter_data);
  424. GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "Reporter data of graph_desc_info fail!"); return;);
  425. }
  426. #endif
  427. }
  428. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::PluginUnInit(const std::string &module) const {
  429. #ifdef DAVINCI_SUPPORT_PROFILING
  430. int ret = Msprof::Engine::UnInit(module);
  431. if (ret != SUCCESS) {
  432. GELOGE(ret, "profiling plugin uninit failed, ret:%d", ret);
  433. }
  434. #endif
  435. }
  436. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportProfilingData(
  437. const std::vector<TaskDescInfo> &task_desc_info, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info) {
  438. #ifdef DAVINCI_SUPPORT_PROFILING
  439. int32_t device_id = 0;
  440. rtError_t rt_ret = rtGetDevice(&device_id);
  441. if (rt_ret != RT_ERROR_NONE) {
  442. GELOGE(rt_ret, "runtime get device_id failed, current device_id:%d", device_id);
  443. return;
  444. }
  445. GELOGI("current device_id:%d", device_id);
  446. auto ret = std::find(device_id_.begin(), device_id_.end(), device_id);
  447. if (ret == device_id_.end()) {
  448. GELOGE(FAILED, "get valid device_id failed, profiling report failed.");
  449. return;
  450. }
  451. GELOGI("start ProfilingTaskDescInfo.");
  452. ProfilingTaskDescInfo(task_desc_info, device_id);
  453. GELOGI("start ProfilingGraphDescInfo.");
  454. ProfilingGraphDescInfo(compute_graph_desc_info, device_id);
  455. GELOGI("Report profiling data for GE end.");
  456. #endif
  457. }
  458. FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::SetProfilingConfig(
  459. const std::string &profiling_cfg) {
  460. recv_profiling_config_ = profiling_cfg;
  461. }
  462. /**
  463. * @brief Profiling PluginImpl
  464. */
  465. // PluginImpl static variable init
  466. Msprof::Engine::Reporter *PluginImpl::reporter_ = nullptr;
  467. PluginImpl::PluginImpl(const std::string &module) : module_(module) { GELOGI("Create PluginImpl\n"); }
  468. int PluginImpl::Init(const Msprof::Engine::Reporter *reporter) {
  469. GELOGI("PluginImpl init");
  470. reporter_ = const_cast<Msprof::Engine::Reporter *>(reporter);
  471. return 0;
  472. }
  473. int PluginImpl::UnInit() {
  474. GELOGI("PluginImpl Uninit");
  475. reporter_ = nullptr;
  476. return 0;
  477. }
  478. Msprof::Engine::PluginIntf *ProfilingEngineImpl::CreatePlugin() {
  479. GELOGI(" Create Plugin");
  480. return new (std::nothrow) PluginImpl(GE_PROFILING_MODULE);
  481. }
  482. int ProfilingEngineImpl::ReleasePlugin(Msprof::Engine::PluginIntf *plugin) {
  483. if (plugin != nullptr) {
  484. delete plugin;
  485. plugin = nullptr;
  486. }
  487. return 0;
  488. }
  489. } // namespace ge

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