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_call_wrapper.h 4.6 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef GE_GE_CALL_WRAPPER_H_
  17. #define GE_GE_CALL_WRAPPER_H_
  18. #include "framework/common/debug/ge_log.h"
  19. /*lint --emacro((773),GE_TIMESTAMP_START)*/
  20. /*lint -esym(773,GE_TIMESTAMP_START)*/
  21. #define GE_TIMESTAMP_START(stage) uint64_t startUsec_##stage = ge::GetCurrentTimestamp()
  22. #define GE_TIMESTAMP_END(stage, stage_name) \
  23. do { \
  24. uint64_t endUsec_##stage = ge::GetCurrentTimestamp(); \
  25. GELOGI("[GEPERFTRACE] The time cost of %s is [%lu] micro second.", (stage_name), \
  26. (endUsec_##stage - startUsec_##stage)); \
  27. } while (0);
  28. #define GE_TIMESTAMP_EVENT_END(stage, stage_name) \
  29. do { \
  30. uint64_t endUsec_##stage = ge::GetCurrentTimestamp(); \
  31. GEEVENT("[GEPERFTRACE] The time cost of %s is [%lu] micro second.", (stage_name), \
  32. (endUsec_##stage - startUsec_##stage)); \
  33. } while (0);
  34. #define GE_TIMESTAMP_CALLNUM_START(stage) \
  35. uint64_t startUsec_##stage = ge::GetCurrentTimestamp(); \
  36. uint64_t call_num_of##stage = 0; \
  37. uint64_t time_of##stage = 0
  38. #define GE_TIMESTAMP_RESTART(stage) (startUsec_##stage = ge::GetCurrentTimestamp())
  39. #define GE_TIMESTAMP_ADD(stage) \
  40. time_of##stage += ge::GetCurrentTimestamp() - startUsec_##stage; \
  41. call_num_of##stage++
  42. #define GE_TIMESTAMP_CALLNUM_END(stage, stage_name) \
  43. GELOGI("[GEPERFTRACE] The time cost of %s is [%lu] micro second, call num is %lu", (stage_name), time_of##stage, \
  44. call_num_of##stage)
  45. #define GE_TIMESTAMP_CALLNUM_EVENT_END(stage, stage_name) \
  46. GEEVENT("[GEPERFTRACE] The time cost of %s is [%lu] micro second, call num is %lu", (stage_name), time_of##stage, \
  47. call_num_of##stage)
  48. #define RUN_WITH_TIMESTAMP_NAME(var_name, prefix, func, ...) \
  49. do { \
  50. GE_TIMESTAMP_START(var_name); \
  51. auto ret_inner_macro = func(__VA_ARGS__); \
  52. GE_TIMESTAMP_END(var_name, #prefix "::" #func) \
  53. if (ret_inner_macro != ge::SUCCESS) { \
  54. GELOGE(ret_inner_macro, "Failed to process " #prefix "_" #func); \
  55. return ret_inner_macro; \
  56. } \
  57. } while (0)
  58. #define RUN_WITH_PERF_TIMESTAMP_NAME(var_name, prefix, func, ...) \
  59. do { \
  60. GE_TIMESTAMP_START(var_name); \
  61. auto ret_inner_macro = func(__VA_ARGS__); \
  62. GE_TIMESTAMP_EVENT_END(var_name, #prefix "::" #func) \
  63. if (ret_inner_macro != ge::SUCCESS) { \
  64. GELOGE(ret_inner_macro, "Failed to process " #prefix "_" #func); \
  65. return ret_inner_macro; \
  66. } \
  67. } while (0)
  68. #define JOIN_NAME_INNER(a, b) a##b
  69. #define JOIN_NAME(a, b) JOIN_NAME_INNER(a, b)
  70. #define COUNTER_NAME(a) JOIN_NAME(a, __COUNTER__)
  71. #define GE_RUN(prefix, func, ...) \
  72. RUN_WITH_TIMESTAMP_NAME(COUNTER_NAME(ge_timestamp_##prefix), prefix, func, __VA_ARGS__)
  73. #define GE_RUN_PERF(prefix, func, ...) \
  74. RUN_WITH_PERF_TIMESTAMP_NAME(COUNTER_NAME(ge_timestamp_##prefix), prefix, func, __VA_ARGS__)
  75. #endif // GE_GE_CALL_WRAPPER_H_

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