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.

inner_session.cc 20 kB

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
4 years ago
4 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
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 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
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
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /**
  2. * Copyright 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 "session/inner_session.h"
  17. #include <map>
  18. #include <memory>
  19. #include <vector>
  20. #include "analyzer/analyzer.h"
  21. #include "adx_datadump_server.h"
  22. #include "common/dump/dump_properties.h"
  23. #include "common/dump/dump_manager.h"
  24. #include "common/util.h"
  25. #include "framework/common/debug/ge_log.h"
  26. #include "graph/ge_context.h"
  27. #include "graph/ge_global_options.h"
  28. #include "graph/ge_local_context.h"
  29. #include "graph/common/local_context.h"
  30. #include "graph/load/model_manager/model_manager.h"
  31. #include "graph/manager/graph_var_manager.h"
  32. #include "graph/utils/tensor_adapter.h"
  33. #include "runtime/mem.h"
  34. namespace ge {
  35. namespace {
  36. const int32_t kDumpStatus = 0;
  37. Status CheckReuseMemoryOption(const std::map<string, string> &options) {
  38. auto iter = options.find(OPTION_EXEC_DISABLE_REUSED_MEMORY);
  39. if (iter != options.end()) {
  40. if (iter->second == "0") {
  41. GELOGD("%s=0, reuse memory is open", OPTION_EXEC_DISABLE_REUSED_MEMORY);
  42. } else if (iter->second == "1") {
  43. GELOGD("%s=1, reuse memory is close", OPTION_EXEC_DISABLE_REUSED_MEMORY);
  44. } else {
  45. GELOGE(PARAM_INVALID, "[CheckReuse][MemoryOption]option %s=%s is invalid",
  46. OPTION_EXEC_DISABLE_REUSED_MEMORY, iter->second.c_str());
  47. REPORT_INNER_ERROR("E19999", "CheckReuseMemoryOption failed because option %s=%s is invalid.",
  48. OPTION_EXEC_DISABLE_REUSED_MEMORY, iter->second.c_str());
  49. return FAILED;
  50. }
  51. }
  52. return SUCCESS;
  53. }
  54. }
  55. static std::mutex mutex_; // BuildGraph and RunGraph use
  56. bool InnerSession::is_dump_server_inited_ = false;
  57. InnerSession::InnerSession(uint64_t session_id, const std::map<string, string> &options)
  58. : init_flag_(false), session_id_(session_id), options_(options) {}
  59. Status InnerSession::Initialize() {
  60. if (init_flag_) {
  61. GELOGW("[InnerSession:%lu] session already initialize.", session_id_);
  62. return SUCCESS;
  63. }
  64. // If the global options and the session options are duplicated, the session options is preferred.
  65. auto all_options = options_;
  66. all_options.insert(GetMutableGlobalOptions().begin(), GetMutableGlobalOptions().end());
  67. Status ret = CheckReuseMemoryOption(all_options);
  68. if (ret != SUCCESS) {
  69. GELOGE(ret, "[CheckReuse][MemoryOption] failed, [InnerSession:%lu].", session_id_);
  70. REPORT_CALL_ERROR("E19999", "CheckReuseMemoryOption failed, InnerSession=%lu.", session_id_);
  71. return ret;
  72. }
  73. UpdateThreadContext(std::map<std::string, std::string>{});
  74. // session device id set here
  75. std::string str_session_device_id;
  76. if (GetContext().GetOption("ge.session_device_id", str_session_device_id) == SUCCESS) {
  77. GELOGI("Option session device id has set, value is %s.", str_session_device_id.c_str());
  78. uint32_t session_device_id = 0;
  79. try {
  80. session_device_id = static_cast<uint32_t>(std::stoi(str_session_device_id.c_str()));
  81. // session device id has priority
  82. GetContext().SetCtxDeviceId(session_device_id);
  83. } catch (std::invalid_argument &) {
  84. GELOGW("session device id %s transform to int failed.", str_session_device_id.c_str());
  85. } catch (std::out_of_range &) {
  86. GELOGW("session device id %s transform to int failed.", str_session_device_id.c_str());
  87. }
  88. }
  89. GE_CHK_RT_RET(rtSetDevice(GetContext().DeviceId()));
  90. DumpProperties dump_properties;
  91. dump_properties.InitByOptions();
  92. GE_CHK_STATUS_RET(AddDumpProperties(dump_properties), "[Add][DumpProperties] failed.");
  93. ret = graph_manager_.Initialize(options_);
  94. if (ret != SUCCESS) {
  95. GELOGE(ret, "[Init][GraphManager] failed, InnerSession:%lu.", session_id_);
  96. REPORT_CALL_ERROR("E19999", "GraphManager initialize failed, InnerSession:%lu.", session_id_);
  97. GE_CHK_STATUS(RemoveDumpProperties(), "[Remove][DumpProperties] failed.");
  98. return ret;
  99. }
  100. ret = VarManager::Instance(session_id_)->SetMemoryMallocSize(all_options);
  101. if (ret != SUCCESS) {
  102. GELOGE(ret, "[Set][MemoryMallocSize] failed.");
  103. REPORT_CALL_ERROR("E19999", "VarManager SetMemoryMallocSize failed, InnerSession:%lu.", session_id_);
  104. (void)graph_manager_.Finalize();
  105. GE_CHK_STATUS(RemoveDumpProperties(), "[Remove][DumpProperties] failed.");
  106. GE_CHK_RT(rtDeviceReset(static_cast<int32_t>(GetContext().DeviceId())));
  107. return ret;
  108. }
  109. int32_t version = static_cast<int32_t>(SessionVersion::ClOUD_VERSION);
  110. const int DEFAULT_DEVICE_ID = 0;
  111. const int DEFAULT_JOB_ID = 0;
  112. ret = VarManager::Instance(session_id_)->Init(version, session_id_, DEFAULT_DEVICE_ID, DEFAULT_JOB_ID);
  113. if (ret != SUCCESS) {
  114. GELOGE(ret, "[Init][VarManager] failed.");
  115. REPORT_CALL_ERROR("E19999", "VarManager init failed, InnerSession:%lu.", session_id_);
  116. GE_CHK_STATUS(RemoveDumpProperties(), "[Remove][DumpProperties] failed.");
  117. }
  118. init_flag_ = true;
  119. return SUCCESS;
  120. }
  121. Status InnerSession::Finalize() {
  122. std::lock_guard<std::mutex> lock(resource_mutex_);
  123. if (!init_flag_) {
  124. GELOGW("[InnerSession:%lu] session does not initialize.", session_id_);
  125. return SUCCESS;
  126. }
  127. UpdateThreadContext(std::map<std::string, std::string>{});
  128. Status ret = graph_manager_.Finalize();
  129. if (ret != SUCCESS) {
  130. // Subsequent code execution is required, so no return is required
  131. GELOGE(ret, "[Finalize][GraphManager] failed, InnerSession:%lu.", session_id_);
  132. REPORT_CALL_ERROR("E19999", "GraphManager Finalize failed, InnerSession:%lu.", session_id_);
  133. }
  134. ModelManager::GetInstance()->DestroyAicpuSession(session_id_);
  135. init_flag_ = false;
  136. // release var memory
  137. GELOGI("VarManager free var memory.");
  138. (void)VarManager::Instance(session_id_)->FreeVarMemory();
  139. // release analyzer saved info(Session Level)
  140. Analyzer::GetInstance()->DestroySessionJsonObject(session_id_);
  141. GE_CHK_RT(rtDeviceReset(static_cast<int32_t>(GetContext().DeviceId())));
  142. GE_CHK_STATUS_RET(RemoveDumpProperties(), "[Remove][DumpProperties] failed.");
  143. return ret;
  144. }
  145. Status InnerSession::GetVariable(const std::string &name, Tensor &val) {
  146. UpdateThreadContext(std::map<std::string, std::string>{});
  147. return graph_manager_.GetVariable(name, val);
  148. }
  149. Status InnerSession::AddGraph(uint32_t graph_id, const Graph &graph) {
  150. std::map<std::string, std::string> options;
  151. return AddGraph(graph_id, graph, options);
  152. }
  153. Status InnerSession::AddGraph(uint32_t graph_id, const Graph &graph,
  154. const std::map<std::string, std::string> &options) {
  155. std::lock_guard<std::mutex> lock(resource_mutex_);
  156. if (!init_flag_) {
  157. GELOGE(GE_SESS_INIT_FAILED, "[Add][Graph] failed because GraphManager not init, InnerSession:%lu, graph_id:%u.",
  158. session_id_, graph_id);
  159. REPORT_INNER_ERROR("E19999", "AddGraph failed because GraphManager not init, InnerSession:%lu, graph_id:%u.",
  160. session_id_, graph_id);
  161. return GE_SESS_INIT_FAILED;
  162. }
  163. UpdateThreadContext(options);
  164. Status ret = graph_manager_.AddGraph(graph_id, graph, options, domi::GetContext());
  165. if (ret != SUCCESS) {
  166. GELOGE(ret, "[Add][Graph] failed, InnerSession:%lu graphid: %u.", session_id_, graph_id);
  167. REPORT_CALL_ERROR("E19999", "GraphManager AddGraph failed, InnerSession:%lu graphid: %u.", session_id_, graph_id);
  168. return ret;
  169. }
  170. GELOGI("[InnerSession:%lu] add graph success, graph_id=%u.", session_id_, graph_id);
  171. return SUCCESS;
  172. }
  173. Status InnerSession::AddGraphWithCopy(uint32_t graph_id, const Graph &graph,
  174. const std::map<std::string, std::string> &options) {
  175. std::lock_guard<std::mutex> lock(resource_mutex_);
  176. if (!init_flag_) {
  177. GELOGE(GE_SESS_INIT_FAILED, "[Add][Graph] failed because GraphManager not init, InnerSession:%lu, graph_id:%u.",
  178. session_id_, graph_id);
  179. REPORT_INNER_ERROR("E19999",
  180. "AddGraphWithCopy failed because GraphManager not init, InnerSession:%lu, graph_id:%u.",
  181. session_id_, graph_id);
  182. return GE_SESS_INIT_FAILED;
  183. }
  184. UpdateThreadContext(options);
  185. Status ret = graph_manager_.AddGraphWithCopy(graph_id, graph, options, domi::GetContext());
  186. if (ret != SUCCESS) {
  187. GELOGE(ret, "[Add][Graph] failed, InnerSession:%lu graphid: %u.", session_id_, graph_id);
  188. REPORT_CALL_ERROR("E19999",
  189. "GraphManager AddGraphWithCopy failed, InnerSession:%lu graphid: %u.", session_id_, graph_id);
  190. return ret;
  191. }
  192. GELOGI("[InnerSession:%lu] add graph success, graph_id=%u.", session_id_, graph_id);
  193. return SUCCESS;
  194. }
  195. Status InnerSession::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs) {
  196. GELOGI("[InnerSession:%lu] run graph on session, graph_id=%u.", session_id_, graph_id);
  197. if (mutex_.try_lock()) {
  198. std::lock_guard<std::mutex> lock(mutex_, std::adopt_lock);
  199. if (!init_flag_) {
  200. GELOGE(GE_SESS_INIT_FAILED, "[Run][Graph]failed because GraphManager not Init, InnerSession:%lu, graph_id:%u.",
  201. session_id_, graph_id);
  202. REPORT_INNER_ERROR("E19999", "RunGraph failed because GraphManager not Init, InnerSession:%lu, graph_id:%u.",
  203. session_id_, graph_id);
  204. return GE_SESS_INIT_FAILED;
  205. }
  206. UpdateThreadContext(graph_id);
  207. vector<GeTensor> geInputs;
  208. for (auto &item : inputs) {
  209. geInputs.push_back(TensorAdapter::AsGeTensor(item));
  210. }
  211. vector<GeTensor> geOutputs;
  212. Status ret = graph_manager_.RunGraph(graph_id, geInputs, geOutputs, session_id_);
  213. domi::GetContext().out_nodes_map.clear();
  214. domi::GetContext().user_out_nodes.clear();
  215. if (ret != SUCCESS) {
  216. GELOGE(ret, "[Run][Graph]failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id);
  217. REPORT_CALL_ERROR("E19999",
  218. "GraphManager RunGraph failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id);
  219. return ret;
  220. }
  221. outputs.clear();
  222. for (auto &item : geOutputs) {
  223. outputs.push_back(TensorAdapter::AsTensor(item));
  224. }
  225. GELOGI("[InnerSession:%lu] run graph success, graph_id=%u.", session_id_, graph_id);
  226. return SUCCESS;
  227. } else {
  228. GELOGE(GE_SESS_ALREADY_RUNNING, "[Run][Graph]failed, InnerSession:%lu, graph_id=%u.", session_id_, graph_id);
  229. REPORT_INNER_ERROR("E19999",
  230. "RunGraph failed because mutex try_lock false, InnerSession:%lu, graph_id=%u.",
  231. session_id_, graph_id);
  232. return GE_SESS_ALREADY_RUNNING;
  233. }
  234. }
  235. Status InnerSession::RemoveGraph(uint32_t graph_id) {
  236. std::lock_guard<std::mutex> lock(resource_mutex_);
  237. if (!init_flag_) {
  238. GELOGE(GE_SESS_INIT_FAILED,
  239. "[Remove][Graph] failed because GraphManager not init, InnerSession:%lu, graph_id=%u.",
  240. session_id_, graph_id);
  241. REPORT_INNER_ERROR("E19999",
  242. "RemoveGraph failed, because GraphManager not init, InnerSession:%lu, graph_id=%u.",
  243. session_id_, graph_id);
  244. return GE_SESS_INIT_FAILED;
  245. }
  246. UpdateThreadContext(graph_id);
  247. Status ret = graph_manager_.RemoveGraph(graph_id);
  248. if (ret != SUCCESS) {
  249. GELOGE(ret, "[Remove][Graph] failed, InnerSession:%lu, graph_id=%u.", session_id_, graph_id);
  250. REPORT_CALL_ERROR("E19999",
  251. "GraphManager RemoveGraph failed, InnerSession:%lu, graph_id=%u.", session_id_, graph_id);
  252. return ret;
  253. }
  254. GELOGI("[InnerSession:%lu] remove graph success, graph_id=%u.", session_id_, graph_id);
  255. return SUCCESS;
  256. }
  257. Status InnerSession::RegisterCallBackFunc(
  258. const std::string &key,
  259. const std::function<Status(uint32_t, const std::map<std::string, ge::Tensor> &)> &callback) {
  260. std::lock_guard<std::mutex> lock(resource_mutex_);
  261. if (!init_flag_) {
  262. GELOGE(GE_SESS_INIT_FAILED,
  263. "[Register][CallBackFunc] failed because GraphManager not initialize, InnerSession:%lu.", session_id_);
  264. REPORT_INNER_ERROR("E19999",
  265. "RegisterCallBackFunc failed because GraphManager not init, InnerSession:%lu.", session_id_);
  266. return GE_SESS_INIT_FAILED;
  267. }
  268. UpdateThreadContext(std::map<std::string, std::string>{});
  269. Status ret = graph_manager_.RegisterCallBackFunc(key, callback);
  270. if (ret != SUCCESS) {
  271. GELOGE(ret, "[Register][CallBackFunc] failed, InnerSession:%lu register %s.", session_id_, key.c_str());
  272. REPORT_CALL_ERROR("E19999",
  273. "GraphManager RegisterCallBackFunc failed, InnerSession:%lu register %s.",
  274. session_id_, key.c_str());
  275. return ret;
  276. }
  277. GELOGI("[InnerSession:%lu] register %s callback function success.", session_id_, key.c_str());
  278. return SUCCESS;
  279. }
  280. Status InnerSession::RegisterCallBackFunc(
  281. const std::string &key,
  282. const std::function<Status(uint32_t, const std::map<AscendString, ge::Tensor> &)> &callback) {
  283. std::lock_guard<std::mutex> lock(resource_mutex_);
  284. if (!init_flag_) {
  285. GELOGE(GE_SESS_INIT_FAILED,
  286. "[Register][CallBackFunc]failed because GraphManager not initialize, InnerSession:%lu.", session_id_);
  287. REPORT_INNER_ERROR("E19999",
  288. "RegisterCallBackFunc failed because GraphManager not initialize, InnerSession:%lu.",
  289. session_id_);
  290. return GE_SESS_INIT_FAILED;
  291. }
  292. UpdateThreadContext(std::map<std::string, std::string>{});
  293. Status ret = graph_manager_.RegisterCallBackFunc(key, callback);
  294. if (ret != SUCCESS) {
  295. GELOGE(ret, "[Register][CallBackFunc] failed, InnerSession:%lu register %s.", session_id_, key.c_str());
  296. REPORT_CALL_ERROR("E19999",
  297. "GraphManager RegisterCallBackFunc failed, InnerSession:%lu register %s.",
  298. session_id_, key.c_str());
  299. return ret;
  300. }
  301. GELOGI("[InnerSession:%lu] register %s callback function success.", session_id_, key.c_str());
  302. return SUCCESS;
  303. }
  304. Status InnerSession::BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs) {
  305. UpdateThreadContext(graph_id);
  306. GELOGI("[InnerSession:%lu] build graph on session, graph_id=%u.", session_id_, graph_id);
  307. std::vector<ge::GeTensor> ge_inputs;
  308. for (auto const &input : inputs) {
  309. std::vector<int64_t> input_dims;
  310. std::transform(input.dims.begin(), input.dims.end(), std::back_inserter(input_dims),
  311. [](int64_t x) -> int64_t { return x; });
  312. GeShape input_shape(input_dims);
  313. GeTensorDesc input_tensor_desc;
  314. input_tensor_desc.SetShape(input_shape);
  315. input_tensor_desc.SetDataType(static_cast<ge::DataType>(input.data_type));
  316. ge_inputs.emplace_back(input_tensor_desc);
  317. }
  318. GeRootModelPtr ge_root_model = nullptr;
  319. Status ret = graph_manager_.BuildGraph(graph_id, ge_inputs, ge_root_model, session_id_, true);
  320. if (ret != SUCCESS) {
  321. GELOGE(ret, "[Build][Graph] failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id);
  322. REPORT_CALL_ERROR("E19999",
  323. "GraphManager BuildGraph failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id);
  324. return ret;
  325. }
  326. GELOGI("[InnerSession:%lu] build graph success, graph_id=%u.", session_id_, graph_id);
  327. return ret;
  328. }
  329. Status InnerSession::RunGraphAsync(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs,
  330. RunAsyncCallback callback) {
  331. UpdateThreadContext(graph_id);
  332. GELOGI("[InnerSession:%lu] run graph on session, graph_id=%u.", session_id_, graph_id);
  333. Status ret = graph_manager_.RunGraphAsync(graph_id, inputs, session_id_, callback);
  334. if (ret != SUCCESS) {
  335. GELOGE(ret, "[Run][GraphAsync]failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id);
  336. REPORT_CALL_ERROR("E19999",
  337. "GraphManager RunGraphAsync failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id);
  338. return ret;
  339. }
  340. GELOGI("[InnerSession:%lu] run graph success, graph_id=%u.", session_id_, graph_id);
  341. return ret;
  342. }
  343. const GraphManager &InnerSession::getGraphManagerObj() const { return graph_manager_; }
  344. void InnerSession::UpdateThreadContext(const std::map<std::string, std::string> &options) {
  345. GetThreadLocalContext().SetGlobalOption(GetMutableGlobalOptions());
  346. GetThreadLocalContext().SetSessionOption(options_);
  347. GetThreadLocalContext().SetGraphOption(options);
  348. GetContext().SetSessionId(session_id_);
  349. SetRtSocVersion();
  350. }
  351. void InnerSession::UpdateThreadContext(uint32_t graph_id) {
  352. auto options = graph_manager_.GetGraphOptions(graph_id);
  353. if (options == nullptr) {
  354. GELOGW("graph level options is null.");
  355. UpdateThreadContext(std::map<std::string, std::string>{});
  356. } else {
  357. UpdateThreadContext(*options);
  358. }
  359. }
  360. bool InnerSession::IsGraphNeedRebuild(uint32_t graph_id) {
  361. UpdateThreadContext(graph_id);
  362. return graph_manager_.IsGraphNeedRebuild(graph_id);
  363. }
  364. Status InnerSession::GetAllVariables(std::map<std::string, GeTensorDesc> &all_variables) {
  365. return VarManager::Instance(session_id_)->GetAllVariables(all_variables);
  366. }
  367. Status InnerSession::GenCheckPointGraph(const std::map<std::string, GeTensorDesc> &all_variables, Graph &graph) {
  368. return graph_manager_.GenCheckPointGraph(all_variables, graph);
  369. }
  370. Status InnerSession::SaveVariables(const Graph &graph, const std::vector<std::string> &var_names,
  371. const std::vector<Tensor> &outputs, std::vector<Tensor> &var_values) {
  372. return graph_manager_.SaveVariables(graph, var_names, outputs, var_values);
  373. }
  374. Status InnerSession::AddDumpProperties(const DumpProperties &dump_properties) {
  375. if (!is_dump_server_inited_) {
  376. if (dump_properties.IsDumpOpen() || dump_properties.IsOpDebugOpen()) {
  377. GE_IF_BOOL_EXEC(AdxDataDumpServerInit() != kDumpStatus,
  378. GELOGE(PARAM_INVALID, "[Init][AdxDataDumpServer] failed, session_id:%lu.", session_id_);
  379. return PARAM_INVALID)
  380. GELOGI("Init adx data dump server success");
  381. is_dump_server_inited_ = true;
  382. }
  383. }
  384. DumpManager::GetInstance().AddDumpProperties(session_id_, dump_properties);
  385. return SUCCESS;
  386. }
  387. Status InnerSession::RemoveDumpProperties() {
  388. DumpManager::GetInstance().RemoveDumpProperties(session_id_);
  389. if (is_dump_server_inited_ && DumpManager::GetInstance().GetDumpPropertiesMap().empty()) {
  390. GE_IF_BOOL_EXEC(AdxDataDumpServerUnInit() != kDumpStatus,
  391. GELOGE(PARAM_INVALID, "[UnInit][AdxDataDumpServer] failed, session_id:%lu.", session_id_);
  392. REPORT_INNER_ERROR("E19999", "RemoveDumpProperties failed because AdxDataDumpServerUnInit failed,"
  393. "session_id:%lu", session_id_);
  394. return PARAM_INVALID)
  395. GELOGI("UnInit adx data dump server success");
  396. is_dump_server_inited_ = false;
  397. }
  398. return SUCCESS;
  399. }
  400. void InnerSession::SetRtSocVersion() {
  401. const auto &global_options = GetMutableGlobalOptions();
  402. auto it = global_options.find(ge::SOC_VERSION);
  403. if (it != global_options.end()) {
  404. const char *soc_version = it->second.c_str();
  405. rtError_t rt_ret = rtSetSocVersion(soc_version);
  406. if (rt_ret != RT_ERROR_NONE) {
  407. GELOGW("Set soc version %s failed. ret:0x%X", soc_version, rt_ret);
  408. }
  409. GELOGI("Set soc version %s success.", soc_version);
  410. }
  411. }
  412. } // namespace ge

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