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

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

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