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_profiling.cc 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "framework/common/profiling/ge_profiling.h"
  17. #include "runtime/base.h"
  18. #include "common/profiling/profiling_manager.h"
  19. #include "framework/common/debug/ge_log.h"
  20. #include "framework/common/debug/log.h"
  21. #include "framework/common/ge_inner_error_codes.h"
  22. #include "common/model/ge_model.h"
  23. namespace {
  24. const uint64_t kModelId = ge::INVALID_MODEL_ID;
  25. const uint16_t kStepStart = 0;
  26. const uint16_t kStepEnd = 1;
  27. } // namespace
  28. ge::Status ProfSetStepInfo(uint64_t index_id, uint16_t tag_id, rtStream_t stream) {
  29. static bool is_first_run = true;
  30. int32_t device_id = 0;
  31. rtError_t rt_ret = rtGetDevice(&device_id);
  32. if (rt_ret != RT_ERROR_NONE) {
  33. GELOGE(rt_ret, "[Get][LogicDeviceId]Failed, ret 0x%X", rt_ret);
  34. REPORT_CALL_ERROR("E19999", "Get logic device id failed, ret 0x%X", rt_ret);
  35. return ge::FAILED;
  36. }
  37. auto &profiling_manager = ge::ProfilingManager::Instance();
  38. profiling_manager.SetStepInfoIndex(index_id);
  39. if (is_first_run && tag_id == kStepStart) {
  40. GE_CHK_STATUS_RET_NOLOG(profiling_manager.ProfileStepInfo(index_id, kModelId, tag_id, stream, device_id));
  41. is_first_run = false;
  42. return ge::SUCCESS;
  43. }
  44. if (!is_first_run && tag_id == kStepEnd) {
  45. GE_CHK_STATUS_RET_NOLOG(profiling_manager.ProfileStepInfo(index_id, kModelId, tag_id, stream, device_id));
  46. is_first_run = true;
  47. return ge::SUCCESS;
  48. }
  49. GELOGE(ge::FAILED, "Param tag_id:%u invalid when is_first_run is %d", tag_id, is_first_run);
  50. REPORT_INPUT_ERROR("E10001", std::vector<std::string>({"value", "parameter", "reason"}),
  51. std::vector<std::string>({std::to_string(tag_id), "tag_id",
  52. "tag id must be 0 when first run, must be 1 when second run"}));
  53. return ge::FAILED;
  54. }
  55. ge::Status ProfGetDeviceFormGraphId(uint32_t graph_id, uint32_t &device_id) {
  56. return ge::ProfilingManager::Instance().GetDeviceIdFromGraph(graph_id, device_id);
  57. }
  58. void ProfSetGraphIdToDeviceMap(uint32_t graph_id, uint32_t &device_id) {
  59. ge::ProfilingManager::Instance().SetGraphIdToDeviceMap(graph_id, device_id);
  60. }

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