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

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