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.4 kB

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

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