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.

ops_kernel_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
4 years ago
4 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
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 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
4 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 "opskernel_manager/ops_kernel_manager.h"
  17. #include <dlfcn.h>
  18. #include <algorithm>
  19. #include <iostream>
  20. #include <utility>
  21. #include <google/protobuf/io/coded_stream.h>
  22. #include <google/protobuf/io/zero_copy_stream_impl.h>
  23. #include <google/protobuf/text_format.h>
  24. #include "init/gelib.h"
  25. #include "framework/common/debug/ge_log.h"
  26. #include "external/ge/ge_api.h"
  27. #include "proto/optimizer_priority.pb.h"
  28. namespace {
  29. const char *const kInitialize = "Initialize";
  30. const char *const kGetOpsKernelInfoStores = "GetOpsKernelInfoStores";
  31. const char *const kGetGraphOptimizerObjs = "GetGraphOptimizerObjs";
  32. const char *const kFinalize = "Finalize";
  33. std::mutex ops_kernel_info_mutex;
  34. } // namespace
  35. namespace ge {
  36. OpsKernelManager::OpsKernelManager()
  37. : plugin_manager_(), op_tiling_manager_(), init_flag_(false), enable_fe_flag_(false), enable_aicpu_flag_(false) {}
  38. OpsKernelManager::~OpsKernelManager() {
  39. graph_optimizers_.clear();
  40. ops_kernel_store_.clear();
  41. ops_kernel_info_.clear();
  42. }
  43. Status OpsKernelManager::Initialize(const map<string, string> &options_const) {
  44. if (init_flag_) {
  45. GELOGW("OpsKernelManager has been initialized.");
  46. return SUCCESS;
  47. }
  48. std::map<string, string> options(options_const);
  49. Status ret = InitPluginOptions(options);
  50. if (ret != SUCCESS) {
  51. GELOGE(ret, "[Init][PluginOptions] parse pluginFlag from ge options failed.");
  52. REPORT_CALL_ERROR("E19999", "InitPluginOptions failed.");
  53. return ret;
  54. }
  55. vector<string> func_check_list = {kInitialize, kGetOpsKernelInfoStores, kGetGraphOptimizerObjs, kFinalize};
  56. string extern_engine_path;
  57. auto iter = options.find(OPTION_EXEC_IS_USEHCOM);
  58. if (iter == options.end()) {
  59. GELOGI("OPTION_EXEC_IS_USEHCOM is not set, default is single P");
  60. options.emplace("ge.exec.isUseHcom", to_string(0));
  61. }
  62. iter = options.find(OPTION_EXEC_IS_USEHVD);
  63. if (iter == options.end()) {
  64. GELOGI("OPTION_EXEC_IS_USEHVD is not set, default is single P");
  65. options.emplace("ge.exec.isUseHvd", to_string(0));
  66. }
  67. GetExternalEnginePath(extern_engine_path, options);
  68. GELOGI("OPTION_EXEC_EXTERN_PLUGIN_PATH=%s.", extern_engine_path.c_str());
  69. op_tiling_manager_.LoadSo();
  70. ret = plugin_manager_.LoadSo(extern_engine_path, func_check_list);
  71. if (ret == SUCCESS) {
  72. initialize_ = options;
  73. Status rst0 = plugin_manager_.InvokeAll<map<string, string> &, Status>(kInitialize, initialize_);
  74. if (rst0 == FAILED) {
  75. GELOGE(GE_OPS_GET_NO_VALID_SO, "[Invoke][OpsKernelInfo]PluginManager InvokeAll failed.");
  76. REPORT_INNER_ERROR("E19999", "PluginManager InvokeAll failed.");
  77. return GE_OPS_GET_NO_VALID_SO;
  78. }
  79. Status rst1 =
  80. plugin_manager_.InvokeAll<map<string, OpsKernelInfoStorePtr> &>(kGetOpsKernelInfoStores, ops_kernel_store_);
  81. if (rst1 != SUCCESS) {
  82. GELOGW("Initialize OpsKernelInfo failed.");
  83. }
  84. Status rst2 =
  85. plugin_manager_.InvokeAll<map<string, GraphOptimizerPtr> &>(kGetGraphOptimizerObjs, graph_optimizers_);
  86. if (rst2 != SUCCESS) {
  87. GELOGW("Initialize GraphOptimizerObjs failed.");
  88. }
  89. ret = CheckPluginPtr();
  90. if (ret != SUCCESS) {
  91. return ret;
  92. }
  93. ret = InitOpKernelInfoStores(options);
  94. if (ret != SUCCESS) {
  95. return ret;
  96. }
  97. InitOpsKernelInfo();
  98. ret = InitGraphOptimzers(options);
  99. if (ret != SUCCESS) {
  100. return ret;
  101. }
  102. ret = InitGraphOptimizerPriority();
  103. if ((ret != SUCCESS)) {
  104. GELOGE(ret, "[Init][GraphOptimizerPriority] failed.");
  105. REPORT_CALL_ERROR("E19999", "InitGraphOptimizerPriority failed.");
  106. return ret;
  107. }
  108. init_flag_ = true;
  109. return SUCCESS;
  110. } else {
  111. GELOGE(ret, "[Check][SoFile] not find any valid so file.");
  112. REPORT_INNER_ERROR("E19999", "OpsKernelManager::Initialize failed for not find any valid so file.");
  113. return ret;
  114. }
  115. }
  116. void OpsKernelManager::GetExternalEnginePath(std::string &extern_engine_path,
  117. const std::map<string, string>& options) {
  118. GELOGI("Enter get external engine so path schedule");
  119. const char *path_env = std::getenv("ASCEND_ENGINE_PATH");
  120. if (path_env != nullptr) {
  121. extern_engine_path = path_env;
  122. GELOGI("OpsKernelManager get external engine so path from env.");
  123. return;
  124. }
  125. std::string path_base = PluginManager::GetPath();
  126. std::string so_path = "plugin/opskernel/";
  127. std::string path = path_base + so_path;
  128. extern_engine_path = (path + "libfe.so" + ":") + (path + "libge_local_engine.so" + ":") +
  129. (path + "librts_engine.so" + ":") + (path + "libaicpu_ascend_engine.so" + ":") +
  130. (path + "libhost_cpu_engine.so" + ":") + (path + "libaicpu_tf_engine.so" + ":");
  131. auto iter = options.find(OPTION_EXEC_HCCL_FLAG);
  132. if (iter == options.end() || iter->second != "0") {
  133. extern_engine_path += (path_base + "libhcom_graph_adaptor.so");
  134. }
  135. }
  136. Status OpsKernelManager::InitPluginOptions(const map<string, string> &options) {
  137. Status ret;
  138. // parse fe
  139. ret = ParsePluginOptions(options, GE_FE_FLAG, enable_fe_flag_);
  140. if (ret != SUCCESS) {
  141. return ret;
  142. }
  143. // parse aiCpu
  144. ret = ParsePluginOptions(options, GE_AICPU_FLAG, enable_aicpu_flag_);
  145. if (ret != SUCCESS) {
  146. return ret;
  147. }
  148. return SUCCESS;
  149. }
  150. Status OpsKernelManager::ParsePluginOptions(const map<string, string> &options, const string &plugin_name,
  151. bool &enable_flag) {
  152. GELOGI("Parse the Plugin Options, plugin_name:%s.", plugin_name.c_str());
  153. auto iter = options.find(plugin_name);
  154. if (iter != options.end()) {
  155. try {
  156. int32_t flag = std::stoi(iter->second.c_str());
  157. if (flag == 0) {
  158. enable_flag = false;
  159. } else if (flag == 1) {
  160. enable_flag = true;
  161. } else {
  162. GELOGE(GE_GRAPH_OPTIONS_INVALID,
  163. "[Parse][PluginOptions]option_key:%s, its value %s is invalid, it must be 0 or 1.",
  164. plugin_name.c_str(), iter->second.c_str());
  165. REPORT_INNER_ERROR("E19999", "ParsePluginOptions failed, option_key:%s, "
  166. "its value %s is invalid, it must be 0 or 1.", plugin_name.c_str(), iter->second.c_str());
  167. return GE_GRAPH_OPTIONS_INVALID;
  168. }
  169. } catch (std::invalid_argument &) {
  170. GELOGE(GE_GRAPH_OPTIONS_INVALID, "[Parse][PluginOptions] failed, option_key:ge.feFlag,"
  171. "its value %s is invalid_argument, it must be 0 or 1.",
  172. iter->second.c_str());
  173. REPORT_INNER_ERROR("E19999", "ParsePluginOptions failed, option_key:ge.feFlag,"
  174. "its value %s is invalid_argument, it must be 0 or 1.",
  175. iter->second.c_str());
  176. return GE_GRAPH_OPTIONS_INVALID;
  177. } catch (std::out_of_range &) {
  178. GELOGE(GE_GRAPH_OPTIONS_INVALID,
  179. "[Parse][PluginOptions]failed, option_key:ge.feFlag, its value %s is out of range, it must be 0 or 1.",
  180. iter->second.c_str());
  181. REPORT_INNER_ERROR("E19999", "ParsePluginOptions failed, option_key:ge.feFlag,"
  182. "its value %s is out of range, it must be 0 or 1.",
  183. iter->second.c_str());
  184. return GE_GRAPH_OPTIONS_INVALID;
  185. } catch (...) {
  186. GELOGE(GE_GRAPH_OPTIONS_INVALID,
  187. "[Parse][PluginOptions]option_key:%s, its value %s is invalid, it must be 0 or 1.",
  188. plugin_name.c_str(), iter->second.c_str());
  189. REPORT_INNER_ERROR("E19999", "ParsePluginOptions failed, option_key:%s, "
  190. "its value %s is invalid, it must be 0 or 1.", plugin_name.c_str(), iter->second.c_str());
  191. return GE_GRAPH_OPTIONS_INVALID;
  192. }
  193. } else {
  194. GELOGI("Not find option_key %s, set to default value false.", plugin_name.c_str());
  195. enable_flag = false;
  196. }
  197. return SUCCESS;
  198. }
  199. Status OpsKernelManager::CheckPluginPtr() const {
  200. for (auto iter = ops_kernel_store_.begin(); iter != ops_kernel_store_.end(); ++iter) {
  201. if (iter->second == nullptr) {
  202. GELOGE(INTERNAL_ERROR, "[Check][PluginPtr] OpsKernelInfoStorePtr key=%s is null", iter->first.c_str());
  203. REPORT_INNER_ERROR("E19999", "CheckPluginPtr OpsKernelInfoStorePtr key=%s is null", iter->first.c_str());
  204. return FAILED;
  205. }
  206. }
  207. for (auto iter1 = graph_optimizers_.begin(); iter1 != graph_optimizers_.end(); ++iter1) {
  208. if (iter1->second == nullptr) {
  209. GELOGE(INTERNAL_ERROR, "[Check][PluginPtr] GraphOptimizerPtr key=%s is null", iter1->first.c_str());
  210. REPORT_INNER_ERROR("E19999", "GraphOptimizerPtr key=%s is null", iter1->first.c_str());
  211. return FAILED;
  212. }
  213. }
  214. return SUCCESS;
  215. }
  216. Status OpsKernelManager::InitOpKernelInfoStores(const map<string, string> &options) {
  217. GELOGI("The number of OpKernelInfoStoreObjs are %lu.", ops_kernel_store_.size());
  218. for (const auto &it : ops_kernel_store_) {
  219. GELOGI("OpKernelInfoStore name: %s.", (it.first).c_str());
  220. Status ret = it.second->Initialize(options);
  221. if (ret != SUCCESS) {
  222. GELOGE(GE_OPS_KERNEL_STORE_INIT_FAILED,
  223. "[Init][OpKernelLib]OpKernelInfoStore: %s initialize failed.", (it.first).c_str());
  224. REPORT_CALL_ERROR("E19999", "OpKernelInfoStore: %s initialize failed.", (it.first).c_str());
  225. return GE_OPS_KERNEL_STORE_INIT_FAILED;
  226. }
  227. }
  228. return SUCCESS;
  229. }
  230. void OpsKernelManager::InitOpsKernelInfo() {
  231. ops_kernel_info_.clear();
  232. for (const auto &it : ops_kernel_store_) {
  233. map<string, OpInfo> op_infos{};
  234. it.second->GetAllOpsKernelInfo(op_infos);
  235. for (const auto &op_info_it : op_infos) {
  236. auto op_info_copy = op_info_it.second;
  237. // flush ops kernel
  238. op_info_copy.opKernelLib = it.first;
  239. ops_kernel_info_[op_info_it.first].emplace_back(op_info_copy);
  240. GELOGD("OpKernelInfoStore name: %s, found op type is %s, engine name is %s, opkernel name is %s",
  241. (it.first).c_str(), op_info_it.first.c_str(), op_info_it.second.engine.c_str(),
  242. op_info_it.second.opKernelLib.c_str());
  243. }
  244. }
  245. std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
  246. if (instance_ptr == nullptr) {
  247. GELOGE(GE_CLI_GE_NOT_INITIALIZED, "[Get][GELib]malloc instance_ptr failed.");
  248. REPORT_INNER_ERROR("E19999", "InitOpsKernelInfo failed for new GELib.");
  249. return;
  250. }
  251. // sort opinfo of ops_kernel_info_
  252. for (auto &it : ops_kernel_info_) {
  253. if (it.second.empty()) {
  254. continue;
  255. }
  256. auto comp_func = [&instance_ptr](const OpInfo &op_a, const OpInfo &op_b) -> bool {
  257. const string &a = op_a.engine;
  258. const string &b = op_b.engine;
  259. // check if a or b is registered
  260. if (!(instance_ptr->DNNEngineManagerObj().IsEngineRegistered(a))) {
  261. return false;
  262. }
  263. if (!(instance_ptr->DNNEngineManagerObj().IsEngineRegistered(b))) {
  264. return true;
  265. }
  266. // compare compute cost of a and b, IsEngineRegistered make sure engine is not nullptr
  267. auto engine_a = instance_ptr->DNNEngineManagerObj().GetEngine(a);
  268. auto engine_b = instance_ptr->DNNEngineManagerObj().GetEngine(b);
  269. DNNEngineAttribute attr_a, attr_b;
  270. engine_a->GetAttributes(attr_a);
  271. engine_b->GetAttributes(attr_b);
  272. return attr_a.compute_cost < attr_b.compute_cost;
  273. };
  274. // Sort the OpInfos based on the compute cost of the engine
  275. std::sort(it.second.begin(), it.second.end(), comp_func);
  276. }
  277. GELOGI("Init opsKernelInfo finished, size is %zu", ops_kernel_info_.size());
  278. }
  279. Status OpsKernelManager::InitGraphOptimzers(const map<string, string> &options) {
  280. GELOGI("Init graph optimizers options count %zu", options.size());
  281. for (const auto &option : options) {
  282. GELOGI("Init graph optimizers option %s: %s", option.first.c_str(), option.second.c_str());
  283. }
  284. GELOGI("The number of GraphOptimzerObjs are %zu.", graph_optimizers_.size());
  285. for (const auto &it : graph_optimizers_) {
  286. GELOGI("GraphOptimzer name: %s.", (it.first).c_str());
  287. GraphOptimizerAttribute attrs;
  288. GE_CHK_STATUS_RET(it.second->GetAttributes(attrs))
  289. std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
  290. if (instance_ptr == nullptr) {
  291. GELOGE(GE_CLI_GE_NOT_INITIALIZED, "[Get][GELib]malloc instance_ptr failed.");
  292. REPORT_INNER_ERROR("E19999", "InitGraphOptimzers failed for new GELib.");
  293. return GE_CLI_GE_NOT_INITIALIZED;
  294. }
  295. if (!instance_ptr->DNNEngineManagerObj().IsEngineRegistered(attrs.engineName)) {
  296. GELOGW("Engine: %s is not registered.", attrs.engineName.c_str());
  297. continue;
  298. }
  299. Status ret = it.second->Initialize(options);
  300. if (ret != SUCCESS) {
  301. GELOGE(GE_OPS_GRAPH_OPTIMIZER_INIT_FAILED,
  302. "[Init][GraphOptimzer]GraphOptimzer: %s initialize failed.", (it.first).c_str());
  303. REPORT_CALL_ERROR("E19999", "InitGraphOptimzers failed. %s initialize failed.", (it.first).c_str());
  304. return GE_OPS_GRAPH_OPTIMIZER_INIT_FAILED;
  305. }
  306. }
  307. return SUCCESS;
  308. }
  309. Status OpsKernelManager::Finalize() {
  310. if (!init_flag_) {
  311. GELOGW("Finalize is not allowed, initialize first is necessary.");
  312. return SUCCESS;
  313. }
  314. GELOGI("free ops kernel resource.");
  315. for (auto iter = ops_kernel_store_.begin(); iter != ops_kernel_store_.end(); ++iter) {
  316. GELOGI("OpsKernelStore finalize, name: %s.", (iter->first).c_str());
  317. Status status = iter->second->Finalize();
  318. if (SUCCESS != status) {
  319. GELOGE(status, "[Check][Status]OpsKernelStore finalize failed, name: %s.", (iter->first).c_str());
  320. REPORT_CALL_ERROR("E19999", "OpsKernelStore finalize failed, name: %s.", (iter->first).c_str());
  321. return status;
  322. }
  323. }
  324. for (auto iter = graph_optimizers_.begin(); iter != graph_optimizers_.end(); ++iter) {
  325. GELOGI("GraphOptimzers finalize, name: %s.", (iter->first).c_str());
  326. Status status = iter->second->Finalize();
  327. if (status != SUCCESS) {
  328. GELOGE(status, "[Check][Status]GraphOptimzers finalize failed, name: %s.", (iter->first).c_str());
  329. REPORT_CALL_ERROR("E19999", "GraphOptimzers finalize failed, name: %s.", (iter->first).c_str());
  330. return status;
  331. }
  332. }
  333. Status ret = FinalizeOpsKernel();
  334. if (ret != SUCCESS) {
  335. GELOGE(ret, "[Free][Ops Kernel Resource] failed.");
  336. REPORT_CALL_ERROR("E19999", "FinalizeOpsKernel failed, Free Ops kernel resource failed.");
  337. return ret;
  338. }
  339. init_flag_ = false;
  340. return SUCCESS;
  341. }
  342. const vector<OpInfo> &OpsKernelManager::GetOpsKernelInfo(const string &op_type) {
  343. std::lock_guard<std::mutex> lock(ops_kernel_info_mutex);
  344. auto find = ops_kernel_info_.find(op_type);
  345. if (find != ops_kernel_info_.end()) {
  346. return find->second;
  347. } else {
  348. InitOpsKernelInfo();
  349. find = ops_kernel_info_.find(op_type);
  350. if (find != ops_kernel_info_.end()) {
  351. return find->second;
  352. }
  353. GELOGW("Failed to get opsKernelInfo object by type: %s.", op_type.c_str());
  354. return empty_op_info_;
  355. }
  356. }
  357. const map<string, vector<OpInfo>> &OpsKernelManager::GetAllOpsKernelInfo() const {
  358. std::lock_guard<std::mutex> lock(ops_kernel_info_mutex);
  359. return ops_kernel_info_;
  360. }
  361. OpsKernelInfoStorePtr OpsKernelManager::GetOpsKernelInfoStore(const std::string &name) const {
  362. auto find = ops_kernel_store_.find(name);
  363. if (find != ops_kernel_store_.end()) {
  364. return find->second;
  365. }
  366. GELOGW("Failed to get opsKernelInfoStore object by name. OpKernelLibName is %s", name.c_str());
  367. return nullptr;
  368. }
  369. const map<string, OpsKernelInfoStorePtr> &OpsKernelManager::GetAllOpsKernelInfoStores() const {
  370. return ops_kernel_store_;
  371. }
  372. const map<string, GraphOptimizerPtr> &OpsKernelManager::GetAllGraphOptimizerObjs() const { return graph_optimizers_; }
  373. const vector<pair<string, GraphOptimizerPtr>> &OpsKernelManager::GetAllGraphOptimizerObjsByPriority() const {
  374. return graph_optimizers_by_priority_;
  375. }
  376. void OpsKernelManager::GetGraphOptimizerByEngine(const std::string &engine_name,
  377. vector<GraphOptimizerPtr> &graph_optimizer) {
  378. for (const auto &it : graph_optimizers_) {
  379. GraphOptimizerAttribute attrs;
  380. if (it.second->GetAttributes(attrs) != SUCCESS) {
  381. GELOGW("Get GraphOptimzer name: %s attributes failed.", (it.first).c_str());
  382. continue;
  383. }
  384. if (attrs.engineName == engine_name) {
  385. GELOGD("GetGraphOptimizerByEngine GraphOptimzer name: %s, engineName: %s", (it.first).c_str(),
  386. attrs.engineName.c_str());
  387. graph_optimizer.push_back(it.second);
  388. }
  389. }
  390. if (graph_optimizer.empty()) {
  391. GELOGI("GetGraphOptimizerByEngine EngineName %s has no graph_optimizer.", engine_name.c_str());
  392. }
  393. }
  394. bool OpsKernelManager::GetEnableFeFlag() const { return enable_fe_flag_; }
  395. bool OpsKernelManager::GetEnableAICPUFlag() const { return enable_aicpu_flag_; }
  396. bool OpsKernelManager::GetEnablePluginFlag() const { return (enable_fe_flag_ || enable_aicpu_flag_); }
  397. Status OpsKernelManager::InitGraphOptimizerPriority() {
  398. string priority_conf_path = "plugin/opskernel/optimizer_priority.pbtxt";
  399. string path = PluginManager::GetPath();
  400. path.append(priority_conf_path);
  401. optimizers::Priority optimizerPriority;
  402. bool ret = ReadProtoFromText(path.c_str(), &optimizerPriority);
  403. if (!ret) {
  404. GELOGW("Read priority file failed. Follow loading sequence.");
  405. return SUCCESS;
  406. }
  407. auto priorities = optimizerPriority.optimizer();
  408. if (priorities.empty()) {
  409. GELOGI("No priority file config. Follow loading sequence.");
  410. return SUCCESS;
  411. }
  412. // sort optimizer map by priority
  413. std::stringstream priority_seq;
  414. for (const auto optimizer_name : priorities) {
  415. auto name_to_optimizer_pair = graph_optimizers_.find(optimizer_name);
  416. if (name_to_optimizer_pair != graph_optimizers_.end()) {
  417. graph_optimizers_by_priority_.emplace_back(*name_to_optimizer_pair);
  418. priority_seq << optimizer_name.c_str() << ' ';
  419. } else {
  420. GELOGW("Unknown optimizer %s show up in priority config file. Please check.", optimizer_name.c_str());
  421. }
  422. }
  423. GELOGI("Graph Optimizers priority initialized. The sequence will follow : %s.", priority_seq.str().c_str());
  424. return SUCCESS;
  425. }
  426. Status OpsKernelManager::FinalizeOpsKernel() {
  427. GELOGI("ge invoke ops kernal finalize.");
  428. Status ret = plugin_manager_.InvokeAll<Status>(kFinalize);
  429. if (ret != SUCCESS) {
  430. GELOGE(ret, "[Finalize][Check][Status] invoke Fe finalize failed.");
  431. REPORT_INNER_ERROR("E19999", "PluginManager InvokeAll failed.");
  432. return ret;
  433. }
  434. return SUCCESS;
  435. }
  436. } // namespace ge

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