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.

prof_callback.h 6.2 kB

3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
  3. * Description: handle perf data
  4. * Author: xp
  5. * Create: 2019-10-13
  6. */
  7. #ifndef MSPROFILER_PROF_CALLBACK_H_
  8. #define MSPROFILER_PROF_CALLBACK_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif // __cplusplus
  12. #if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER))
  13. #define MSVP_PROF_API __declspec(dllexport)
  14. #else
  15. #define MSVP_PROF_API __attribute__((visibility("default")))
  16. #endif
  17. #include "stddef.h"
  18. #include "stdint.h"
  19. /**
  20. * @name MsprofErrorCode
  21. * @brief error code
  22. */
  23. enum MsprofErrorCode {
  24. MSPROF_ERROR_NONE = 0,
  25. MSPROF_ERROR_MEM_NOT_ENOUGH,
  26. MSPROF_ERROR_GET_ENV,
  27. MSPROF_ERROR_CONFIG_INVALID,
  28. MSPROF_ERROR_ACL_JSON_OFF,
  29. MSPROF_ERROR,
  30. };
  31. #define MSPROF_ENGINE_MAX_TAG_LEN (63)
  32. /**
  33. * @name ReporterData
  34. * @brief struct of data to report
  35. */
  36. struct ReporterData {
  37. char tag[MSPROF_ENGINE_MAX_TAG_LEN + 1]; // the sub-type of the module, data with different tag will be writen
  38. int deviceId; // the index of device
  39. size_t dataLen; // the length of send data
  40. unsigned char *data; // the data content
  41. };
  42. /**
  43. * @name MsprofHashData
  44. * @brief struct of data to hash
  45. */
  46. struct MsprofHashData {
  47. int deviceId; // the index of device
  48. size_t dataLen; // the length of data
  49. unsigned char *data; // the data content
  50. uint64_t hashId; // the id of hashed data
  51. };
  52. /**
  53. * @name MsprofReporterModuleId
  54. * @brief module id of data to report
  55. */
  56. enum MsprofReporterModuleId {
  57. MSPROF_MODULE_DATA_PREPROCESS = 0, // DATA_PREPROCESS
  58. MSPROF_MODULE_HCCL, // HCCL
  59. MSPROF_MODULE_ACL, // AclModule
  60. MSPROF_MODULE_FRAMEWORK, // Framework
  61. MSPROF_MODULE_RUNTIME, // runtime
  62. MSPROF_MODULE_MSPROF // msprofTx
  63. };
  64. /**
  65. * @name MsprofReporterCallbackType
  66. * @brief reporter callback request type
  67. */
  68. enum MsprofReporterCallbackType {
  69. MSPROF_REPORTER_REPORT = 0, // report data
  70. MSPROF_REPORTER_INIT, // init reporter
  71. MSPROF_REPORTER_UNINIT, // uninit reporter
  72. MSPROF_REPORTER_DATA_MAX_LEN, // data max length for calling report callback
  73. MSPROF_REPORTER_HASH // hash data to id
  74. };
  75. #define MSPROF_OPTIONS_DEF_LEN_MAX (2048)
  76. /**
  77. * @name MsprofGeOptions
  78. * @brief struct of MSPROF_CTRL_INIT_GE_OPTIONS
  79. */
  80. struct MsprofGeOptions {
  81. char jobId[MSPROF_OPTIONS_DEF_LEN_MAX];
  82. char options[MSPROF_OPTIONS_DEF_LEN_MAX];
  83. };
  84. /**
  85. * @name MsprofCtrlCallbackType
  86. * @brief ctrl callback request type
  87. */
  88. enum MsprofCtrlCallbackType {
  89. MSPROF_CTRL_INIT_ACL_ENV = 0, // start profiling with acl env
  90. MSPROF_CTRL_INIT_ACL_JSON, // start pro with acl.json
  91. MSPROF_CTRL_INIT_GE_OPTIONS, // start profiling with ge env and options
  92. MSPROF_CTRL_FINALIZE, // stop profiling
  93. MSPROF_CTRL_INIT_HELPER, // start profiling in helper device
  94. MSPROF_CTRL_INIT_DYNA = 0xFF, // start profiling for dynamic profiling
  95. };
  96. enum MsprofCommandHandleType {
  97. PROF_COMMANDHANDLE_TYPE_INIT = 0,
  98. PROF_COMMANDHANDLE_TYPE_START,
  99. PROF_COMMANDHANDLE_TYPE_STOP,
  100. PROF_COMMANDHANDLE_TYPE_FINALIZE,
  101. PROF_COMMANDHANDLE_TYPE_MODEL_SUBSCRIBE,
  102. PROF_COMMANDHANDLE_TYPE_MODEL_UNSUBSCRIBE
  103. };
  104. /**
  105. * @brief profiling command type
  106. */
  107. enum ProfCtrlType {
  108. PROF_CTRL_INVALID = 0,
  109. PROF_CTRL_SWITCH,
  110. PROF_CTRL_REPORTER,
  111. PROF_CTRL_STEPINFO,
  112. PROF_CTRL_BUTT
  113. };
  114. /**
  115. * @brief Prof Chip ID
  116. */
  117. enum Prof_Chip_ID {
  118. PROF_CHIP_ID0 = 0
  119. };
  120. typedef int32_t (*MsprofCtrlCallback)(uint32_t type, void *data, uint32_t len);
  121. typedef int32_t (*MsprofReporterCallback)(uint32_t moduleId, uint32_t type, void *data, uint32_t len);
  122. /**
  123. * @brief the struct of profiling set setp info
  124. */
  125. typedef struct ProfStepInfoCmd {
  126. uint64_t index_id;
  127. uint16_t tag_id;
  128. void *stream;
  129. } ProfStepInfoCmd_t;
  130. /**
  131. * @name ProfCommandHandle
  132. * @brief callback to start/stop profiling
  133. * @param type [IN] enum call back type
  134. * @param data [IN] callback data
  135. * @param len [IN] callback data size
  136. * @return enum MsprofErrorCode
  137. */
  138. typedef int32_t (*ProfCommandHandle)(uint32_t type, void *data, uint32_t len);
  139. /*
  140. * @name profInit
  141. * @brief Profiling module init
  142. * @param [in] dataType: profiling type: ACL Env/ACL Json/GE Option
  143. * @param [in] data: profiling switch data
  144. * @param [in] dataLen: Length of data
  145. * @return 0:SUCCESS, >0:FAILED
  146. */
  147. MSVP_PROF_API int32_t MsprofInit(uint32_t moduleId, void *data, uint32_t dataLen);
  148. /**
  149. * @name profRegisterCallback
  150. * @brief register callback to profiling
  151. * @param moduleId [IN] module Id
  152. * @param handle [IN] the pointer of callback
  153. */
  154. MSVP_PROF_API int32_t MsprofRegisterCallback(uint32_t moduleId, ProfCommandHandle handle);
  155. /*
  156. * @name profReportData
  157. * @brief start reporter/stop reporter/report date
  158. * @param moduleId [IN] enum profReporterModuleId
  159. * @param type [IN] enum profReporterCallbackType
  160. * @param data [IN] data (nullptr on INTI/UNINIT)
  161. * @param len [IN] data size (0 on INIT/UNINIT)
  162. * @return enum MsprofErrorCod
  163. */
  164. MSVP_PROF_API int32_t MsprofReportData(uint32_t moduleId, uint32_t type, void* data, uint32_t len);
  165. MSVP_PROF_API int32_t MsprofSetDeviceIdByGeModelIdx(const uint32_t geModelIdx, const uint32_t deviceId);
  166. MSVP_PROF_API int32_t MsprofUnsetDeviceIdByGeModelIdx(const uint32_t geModelIdx, const uint32_t deviceId);
  167. /*
  168. * @name profFinalize
  169. * @brief Finishing Profiling
  170. * @param NULL
  171. * @return 0:SUCCESS, >0:FAILED
  172. */
  173. MSVP_PROF_API int32_t MsprofFinalize();
  174. /**
  175. * @name profNotifySetDevice
  176. * @brief notify set/reset device
  177. * @param devId [IN] device id
  178. * @param isOpenDevice [IN] true: set device, false: reset device
  179. */
  180. MSVP_PROF_API int32_t MsprofNotifySetDevice(uint32_t chipId, uint32_t deviceId, bool isOpen);
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif // MSPROFILER_PROF_CALLBACK_H_

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