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.

event_manager.cc 2.8 kB

5 years ago
5 years ago
4 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "graph/manager/model_manager/event_manager.h"
  17. #define RETURN_IF_COND_NOT_MET(condition, ...) \
  18. do { \
  19. if (!(condition)) { \
  20. GELOGE(FAILED, __VA_ARGS__); \
  21. return; \
  22. } \
  23. } while (0);
  24. namespace ge {
  25. Status EventManager::Init(size_t event_num) {
  26. if (this->inited_) {
  27. return SUCCESS;
  28. }
  29. rtEvent_t event = nullptr;
  30. current_idx_ = 0;
  31. for (size_t i = 0; i < event_num; ++i) {
  32. GE_CHK_RT_RET(rtEventCreate(&event));
  33. this->event_list_.push_back(event);
  34. }
  35. this->inited_ = true;
  36. return SUCCESS;
  37. }
  38. void EventManager::Release() noexcept {
  39. for (size_t i = 0; i < this->event_list_.size(); ++i) {
  40. rtError_t rt_ret = rtEventDestroy(this->event_list_[i]);
  41. RETURN_IF_COND_NOT_MET(rt_ret == RT_ERROR_NONE, "[Destroy][Event] failed, idx is %zu, ret is 0x%x.", i, rt_ret);
  42. }
  43. this->event_list_.clear();
  44. this->inited_ = false;
  45. }
  46. Status EventManager::EventRecord(size_t event_idx, rtStream_t stream) {
  47. GE_CHK_BOOL_RET_STATUS_NOLOG(this->inited_, INTERNAL_ERROR);
  48. GE_CHK_BOOL_RET_STATUS_NOLOG(event_idx < this->event_list_.size(), PARAM_INVALID);
  49. GE_CHK_RT_RET(rtEventRecord(this->event_list_[event_idx], stream));
  50. current_idx_ = static_cast<uint32_t>(event_idx);
  51. return SUCCESS;
  52. }
  53. Status EventManager::EventElapsedTime(size_t start_event_idx, size_t stop_event_idx, float &time) {
  54. GE_CHK_BOOL_RET_STATUS_NOLOG(this->inited_, INTERNAL_ERROR);
  55. GE_CHK_BOOL_RET_STATUS_NOLOG(start_event_idx < this->event_list_.size() &&
  56. stop_event_idx < this->event_list_.size() && start_event_idx <= stop_event_idx,
  57. PARAM_INVALID);
  58. GE_CHK_RT_RET(rtEventElapsedTime(&time, this->event_list_[start_event_idx], this->event_list_[stop_event_idx]));
  59. return SUCCESS;
  60. }
  61. Status EventManager::GetEvent(uint32_t index, rtEvent_t &event) {
  62. GE_CHK_BOOL_RET_STATUS_NOLOG(index < this->event_list_.size(), PARAM_INVALID);
  63. event = this->event_list_[index];
  64. return SUCCESS;
  65. }
  66. } // namespace ge

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