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 5.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #ifndef MSPROFILER_PROF_CALLBACK_H_
  17. #define MSPROFILER_PROF_CALLBACK_H_
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif // __cplusplus
  21. #include "stddef.h"
  22. #include "stdint.h"
  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 (31)
  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. };
  67. /**
  68. * @name MsprofReporterCallbackType
  69. * @brief reporter callback request type
  70. */
  71. enum MsprofReporterCallbackType {
  72. MSPROF_REPORTER_REPORT = 0, // report data
  73. MSPROF_REPORTER_INIT, // init reporter
  74. MSPROF_REPORTER_UNINIT, // uninit reporter
  75. MSPROF_REPORTER_DATA_MAX_LEN, // data max length for calling report callback
  76. MSPROF_REPORTER_HASH // hash data to id
  77. };
  78. /**
  79. * @name MsprofReporterCallback
  80. * @brief callback to start reporter/stop reporter/report date
  81. * @param moduleId [IN] enum MsprofReporterModuleId
  82. * @param type [IN] enum MsprofReporterCallbackType
  83. * @param data [IN] callback data (nullptr on INTI/UNINIT)
  84. * @param len [IN] callback data size (0 on INIT/UNINIT)
  85. * @return enum MsprofErrorCode
  86. */
  87. typedef int32_t (*MsprofReporterCallback)(uint32_t moduleId, uint32_t type, void *data, uint32_t len);
  88. #define MSPROF_OPTIONS_DEF_LEN_MAX (2048)
  89. /**
  90. * @name MsprofGeOptions
  91. * @brief struct of MSPROF_CTRL_INIT_GE_OPTIONS
  92. */
  93. struct MsprofGeOptions {
  94. char jobId[MSPROF_OPTIONS_DEF_LEN_MAX];
  95. char options[MSPROF_OPTIONS_DEF_LEN_MAX];
  96. };
  97. /**
  98. * @name MsprofCtrlCallbackType
  99. * @brief ctrl callback request type
  100. */
  101. enum MsprofCtrlCallbackType {
  102. MSPROF_CTRL_INIT_ACL_ENV = 0, // start profiling with acl env
  103. MSPROF_CTRL_INIT_ACL_JSON, // start profiling with acl.json
  104. MSPROF_CTRL_INIT_GE_OPTIONS, // start profiling with ge env and options
  105. MSPROF_CTRL_FINALIZE, // stop profiling
  106. MSPROF_CTRL_REPORT_FUN_P, // for report callback
  107. MSPROF_CTRL_PROF_SWITCH_ON, // for prof switch on
  108. MSPROF_CTRL_PROF_SWITCH_OFF // for prof switch off
  109. };
  110. #define PROF_COMMANDHANDLE_TYPE_INIT (0)
  111. #define PROF_COMMANDHANDLE_TYPE_START (1)
  112. #define PROF_COMMANDHANDLE_TYPE_STOP (2)
  113. #define PROF_COMMANDHANDLE_TYPE_FINALIZE (3)
  114. #define PROF_COMMANDHANDLE_TYPE_MODEL_SUBSCRIBE (4)
  115. #define PROF_COMMANDHANDLE_TYPE_MODEL_UNSUBSCRIBE (5)
  116. #define MSPROF_MAX_DEV_NUM (64)
  117. struct MsprofCommandHandle {
  118. uint64_t profSwitch;
  119. uint32_t devNums; // length of device id list
  120. uint32_t devIdList[MSPROF_MAX_DEV_NUM];
  121. uint32_t modelId;
  122. };
  123. /**
  124. * @name MsprofCtrlCallback
  125. * @brief callback to start/stop profiling
  126. * @param type [IN] enum MsprofCtrlCallbackType
  127. * @param data [IN] callback data
  128. * @param len [IN] callback data size
  129. * @return enum MsprofErrorCode
  130. */
  131. typedef int32_t (*MsprofCtrlCallback)(uint32_t type, void *data, uint32_t len);
  132. /**
  133. * @name MsprofSetDeviceCallback
  134. * @brief callback to notify set/reset device
  135. * @param devId [IN] device id
  136. * @param isOpenDevice [IN] true: set device, false: reset device
  137. */
  138. typedef void (*MsprofSetDeviceCallback)(uint32_t devId, bool isOpenDevice);
  139. /*
  140. * @name MsprofInit
  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. int32_t MsprofInit(uint32_t dataType, void *data, uint32_t dataLen);
  148. /*
  149. * @name AscendCL
  150. * @brief Finishing Profiling
  151. * @param NULL
  152. * @return 0:SUCCESS, >0:FAILED
  153. */
  154. int32_t MsprofFinalize();
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158. #endif // MSPROFILER_PROF_CALLBACK_H_

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