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

3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER))
  22. #define MSVP_PROF_API __declspec(dllexport)
  23. #else
  24. #define MSVP_PROF_API __attribute__((visibility("default")))
  25. #endif
  26. #include "stddef.h"
  27. #include "stdint.h"
  28. /**
  29. * @name MsprofErrorCode
  30. * @brief error code
  31. */
  32. enum MsprofErrorCode {
  33. MSPROF_ERROR_NONE = 0,
  34. MSPROF_ERROR_MEM_NOT_ENOUGH,
  35. MSPROF_ERROR_GET_ENV,
  36. MSPROF_ERROR_CONFIG_INVALID,
  37. MSPROF_ERROR_ACL_JSON_OFF,
  38. MSPROF_ERROR,
  39. };
  40. #define MSPROF_ENGINE_MAX_TAG_LEN (63)
  41. /**
  42. * @name ReporterData
  43. * @brief struct of data to report
  44. */
  45. struct ReporterData {
  46. char tag[MSPROF_ENGINE_MAX_TAG_LEN + 1]; // the sub-type of the module, data with different tag will be writen
  47. int deviceId; // the index of device
  48. size_t dataLen; // the length of send data
  49. unsigned char *data; // the data content
  50. };
  51. /**
  52. * @name MsprofHashData
  53. * @brief struct of data to hash
  54. */
  55. struct MsprofHashData {
  56. int deviceId; // the index of device
  57. size_t dataLen; // the length of data
  58. unsigned char *data; // the data content
  59. uint64_t hashId; // the id of hashed data
  60. };
  61. /**
  62. * @name MsprofReporterModuleId
  63. * @brief module id of data to report
  64. */
  65. enum MsprofReporterModuleId {
  66. MSPROF_MODULE_DATA_PREPROCESS = 0, // DATA_PREPROCESS
  67. MSPROF_MODULE_HCCL, // HCCL
  68. MSPROF_MODULE_ACL, // AclModule
  69. MSPROF_MODULE_FRAMEWORK, // Framework
  70. MSPROF_MODULE_RUNTIME, // runtime
  71. MSPROF_MODULE_MSPROF // msprofTx
  72. };
  73. /**
  74. * @name MsprofReporterCallbackType
  75. * @brief reporter callback request type
  76. */
  77. enum MsprofReporterCallbackType {
  78. MSPROF_REPORTER_REPORT = 0, // report data
  79. MSPROF_REPORTER_INIT, // init reporter
  80. MSPROF_REPORTER_UNINIT, // uninit reporter
  81. MSPROF_REPORTER_DATA_MAX_LEN, // data max length for calling report callback
  82. MSPROF_REPORTER_HASH // hash data to id
  83. };
  84. /**
  85. * @name MsprofReporterCallback
  86. * @brief callback to start reporter/stop reporter/report date
  87. * @param moduleId [IN] enum MsprofReporterModuleId
  88. * @param type [IN] enum MsprofReporterCallbackType
  89. * @param data [IN] callback data (nullptr on INTI/UNINIT)
  90. * @param len [IN] callback data size (0 on INIT/UNINIT)
  91. * @return enum MsprofErrorCode
  92. */
  93. typedef int32_t (*MsprofReporterCallback)(uint32_t moduleId, uint32_t type, void *data, uint32_t len);
  94. #define MSPROF_OPTIONS_DEF_LEN_MAX (2048)
  95. /**
  96. * @name MsprofGeOptions
  97. * @brief struct of MSPROF_CTRL_INIT_GE_OPTIONS
  98. */
  99. struct MsprofGeOptions {
  100. char jobId[MSPROF_OPTIONS_DEF_LEN_MAX];
  101. char options[MSPROF_OPTIONS_DEF_LEN_MAX];
  102. };
  103. /**
  104. * @name MsprofCtrlCallbackType
  105. * @brief ctrl callback request type
  106. */
  107. enum MsprofCtrlCallbackType {
  108. MSPROF_CTRL_INIT_ACL_ENV = 0, // start profiling with acl env
  109. MSPROF_CTRL_INIT_ACL_JSON, // start profiling with acl.json
  110. MSPROF_CTRL_INIT_GE_OPTIONS, // start profiling with ge env and options
  111. MSPROF_CTRL_FINALIZE, // stop profiling
  112. MSPROF_CTRL_INIT_DYNA = 0xFF, // start profiling for dynamic profiling
  113. };
  114. enum MsprofCommandHandleType {
  115. PROF_COMMANDHANDLE_TYPE_INIT = 0,
  116. PROF_COMMANDHANDLE_TYPE_START,
  117. PROF_COMMANDHANDLE_TYPE_STOP,
  118. PROF_COMMANDHANDLE_TYPE_FINALIZE,
  119. PROF_COMMANDHANDLE_TYPE_MODEL_SUBSCRIBE,
  120. PROF_COMMANDHANDLE_TYPE_MODEL_UNSUBSCRIBE
  121. };
  122. /**
  123. * @name MsprofCtrlCallback
  124. * @brief callback to start/stop profiling
  125. * @param type [IN] enum MsprofCtrlCallbackType
  126. * @param data [IN] callback data
  127. * @param len [IN] callback data size
  128. * @return enum MsprofErrorCode
  129. */
  130. typedef int32_t (*MsprofCtrlCallback)(uint32_t type, void *data, uint32_t len);
  131. /**
  132. * @name MsprofSetDeviceCallback
  133. * @brief callback to notify set/reset device
  134. * @param devId [IN] device id
  135. * @param isOpenDevice [IN] true: set device, false: reset device
  136. */
  137. typedef void (*MsprofSetDeviceCallback)(uint32_t devId, bool isOpenDevice);
  138. /*
  139. * @name MsprofInit
  140. * @brief Profiling module init
  141. * @param [in] dataType: profiling type: ACL Env/ACL Json/GE Option
  142. * @param [in] data: profiling switch data
  143. * @param [in] dataLen: Length of data
  144. * @return 0:SUCCESS, >0:FAILED
  145. */
  146. MSVP_PROF_API int32_t MsprofInit(uint32_t dataType, void *data, uint32_t dataLen);
  147. /*
  148. * @name AscendCL
  149. * @brief Finishing Profiling
  150. * @param NULL
  151. * @return 0:SUCCESS, >0:FAILED
  152. */
  153. MSVP_PROF_API int32_t MsprofFinalize();
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif // MSPROFILER_PROF_CALLBACK_H_

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