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_common.h 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /**
  2. * @file prof_common.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_COMMON_H_
  12. #define MSPROFILER_PROF_COMMON_H_
  13. #include <stdint.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif // __cplusplus
  17. #define MSPROF_DATA_HEAD_MAGIC_NUM 0x5a5a
  18. enum MsprofDataTag {
  19. MSPROF_ACL_DATA_TAG = 0, // acl data tag, range: 0~19
  20. MSPROF_GE_DATA_TAG_MODEL_LOAD = 20, // ge data tag, range: 20~39
  21. MSPROF_GE_DATA_TAG_FUSION = 21,
  22. MSPROF_GE_DATA_TAG_INFER = 22,
  23. MSPROF_GE_DATA_TAG_TASK = 23,
  24. MSPROF_GE_DATA_TAG_TENSOR = 24,
  25. MSPROF_GE_DATA_TAG_STEP = 25,
  26. MSPROF_GE_DATA_TAG_ID_MAP = 26,
  27. MSPROF_GE_DATA_TAG_HOST_SCH = 27,
  28. MSPROF_RUNTIME_DATA_TAG_API = 40, // runtime data tag, range: 40~59
  29. MSPROF_RUNTIME_DATA_TAG_TRACK = 41,
  30. MSPROF_AICPU_DATA_TAG = 60, // aicpu data tag, range: 60~79
  31. MSPROF_AICPU_MODEL_TAG = 61,
  32. MSPROF_HCCL_DATA_TAG = 80, // hccl data tag, range: 80~99
  33. MSPROF_DP_DATA_TAG = 100, // dp data tag, range: 100~119
  34. MSPROF_MSPROFTX_DATA_TAG = 120, // hccl data tag, range: 120~139
  35. MSPROF_DATA_TAG_MAX = 65536, // data tag value type is uint16_t
  36. };
  37. /**
  38. * @brief struct of mixed data
  39. */
  40. #define MSPROF_MIX_DATA_RESERVE_BYTES 7
  41. #define MSPROF_MIX_DATA_STRING_LEN 120
  42. enum MsprofMixDataType {
  43. MSPROF_MIX_DATA_HASH_ID = 0,
  44. MSPROF_MIX_DATA_STRING,
  45. };
  46. struct MsprofMixData {
  47. uint8_t type; // MsprofMixDataType
  48. uint8_t rsv[MSPROF_MIX_DATA_RESERVE_BYTES];
  49. union {
  50. uint64_t hashId;
  51. char dataStr[MSPROF_MIX_DATA_STRING_LEN];
  52. } data;
  53. };
  54. #define PATH_LEN_MAX 1023
  55. #define PARAM_LEN_MAX 4095
  56. struct MsprofCommandHandleParams {
  57. uint32_t pathLen;
  58. uint32_t storageLimit; // MB
  59. uint32_t profDataLen;
  60. char path[PATH_LEN_MAX + 1];
  61. char profData[PARAM_LEN_MAX + 1];
  62. };
  63. /**
  64. * @brief profiling command info
  65. */
  66. #define MSPROF_MAX_DEV_NUM 64
  67. struct MsprofCommandHandle {
  68. uint64_t profSwitch;
  69. uint64_t profSwitchHi;
  70. uint32_t devNums;
  71. uint32_t devIdList[MSPROF_MAX_DEV_NUM];
  72. uint32_t modelId;
  73. uint32_t type;
  74. struct MsprofCommandHandleParams params;
  75. };
  76. /**
  77. * @brief struct of data reported by acl
  78. */
  79. #define MSPROF_ACL_DATA_RESERVE_BYTES 32
  80. #define MSPROF_ACL_API_NAME_LEN 64
  81. enum MsprofAclApiType {
  82. MSPROF_ACL_API_TYPE_OP = 1,
  83. MSPROF_ACL_API_TYPE_MODEL,
  84. MSPROF_ACL_API_TYPE_RUNTIME,
  85. MSPROF_ACL_API_TYPE_OTHERS,
  86. };
  87. struct MsprofAclProfData {
  88. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  89. uint16_t dataTag = MSPROF_ACL_DATA_TAG;
  90. uint32_t apiType; // enum MsprofAclApiType
  91. uint64_t beginTime;
  92. uint64_t endTime;
  93. uint32_t processId;
  94. uint32_t threadId;
  95. char apiName[MSPROF_ACL_API_NAME_LEN];
  96. uint8_t reserve[MSPROF_ACL_DATA_RESERVE_BYTES];
  97. };
  98. /**
  99. * @brief struct of data reported by GE
  100. */
  101. #define MSPROF_GE_MODELLOAD_DATA_RESERVE_BYTES 104
  102. struct MsprofGeProfModelLoadData {
  103. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  104. uint16_t dataTag = MSPROF_GE_DATA_TAG_MODEL_LOAD;
  105. uint32_t modelId;
  106. MsprofMixData modelName;
  107. uint64_t startTime;
  108. uint64_t endTime;
  109. uint8_t reserve[MSPROF_GE_MODELLOAD_DATA_RESERVE_BYTES];
  110. };
  111. #define MSPROF_GE_FUSION_DATA_RESERVE_BYTES 8
  112. #define MSPROF_GE_FUSION_OP_NUM 8
  113. struct MsprofGeProfFusionData {
  114. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  115. uint16_t dataTag = MSPROF_GE_DATA_TAG_FUSION;
  116. uint32_t modelId;
  117. MsprofMixData fusionName;
  118. uint64_t inputMemSize;
  119. uint64_t outputMemSize;
  120. uint64_t weightMemSize;
  121. uint64_t workspaceMemSize;
  122. uint64_t totalMemSize;
  123. uint64_t fusionOpNum;
  124. uint64_t fusionOp[MSPROF_GE_FUSION_OP_NUM];
  125. uint8_t reserve[MSPROF_GE_FUSION_DATA_RESERVE_BYTES];
  126. };
  127. #define MSPROF_GE_INFER_DATA_RESERVE_BYTES 64
  128. struct MsprofGeProfInferData {
  129. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  130. uint16_t dataTag = MSPROF_GE_DATA_TAG_INFER;
  131. uint32_t modelId;
  132. MsprofMixData modelName;
  133. uint32_t requestId;
  134. uint32_t threadId;
  135. uint64_t inputDataStartTime;
  136. uint64_t inputDataEndTime;
  137. uint64_t inferStartTime;
  138. uint64_t inferEndTime;
  139. uint64_t outputDataStartTime;
  140. uint64_t outputDataEndTime;
  141. uint8_t reserve[MSPROF_GE_INFER_DATA_RESERVE_BYTES];
  142. };
  143. constexpr int32_t MSPROF_GE_TASK_DATA_RESERVE_BYTES = 12;
  144. #define MSPROF_GE_OP_TYPE_LEN 56
  145. enum MsprofGeTaskType {
  146. MSPROF_GE_TASK_TYPE_AI_CORE = 0,
  147. MSPROF_GE_TASK_TYPE_AI_CPU,
  148. MSPROF_GE_TASK_TYPE_AIV,
  149. MSPROF_GE_TASK_TYPE_WRITE_BACK,
  150. MSPROF_GE_TASK_TYPE_MIX_AIC,
  151. MSPROF_GE_TASK_TYPE_MIX_AIV,
  152. MSPROF_GE_TASK_TYPE_FFTS_PLUS,
  153. MSPROF_GE_TASK_TYPE_DSA,
  154. MSPROF_GE_TASK_TYPE_DVPP,
  155. MSPROF_GE_TASK_TYPE_INVALID
  156. };
  157. enum MsprofGeShapeType {
  158. MSPROF_GE_SHAPE_TYPE_STATIC = 0,
  159. MSPROF_GE_SHAPE_TYPE_DYNAMIC,
  160. };
  161. struct MsprofGeOpType {
  162. uint8_t type; // MsprofMixDataType
  163. uint8_t rsv[MSPROF_MIX_DATA_RESERVE_BYTES];
  164. union {
  165. uint64_t hashId;
  166. char dataStr[MSPROF_GE_OP_TYPE_LEN];
  167. } data;
  168. };
  169. struct MsprofGeProfTaskData {
  170. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  171. uint16_t dataTag = MSPROF_GE_DATA_TAG_TASK;
  172. uint32_t taskType; // MsprofGeTaskType
  173. MsprofMixData opName;
  174. MsprofGeOpType opType;
  175. uint64_t curIterNum;
  176. uint64_t timeStamp;
  177. uint32_t shapeType; // MsprofGeShapeType
  178. uint32_t blockDims;
  179. uint32_t modelId;
  180. uint32_t streamId;
  181. uint32_t taskId;
  182. uint32_t threadId;
  183. uint32_t contextId;
  184. uint8_t reserve[MSPROF_GE_TASK_DATA_RESERVE_BYTES];
  185. };
  186. #define MSPROF_GE_TENSOR_DATA_RESERVE_BYTES 8
  187. #define MSPROF_GE_TENSOR_DATA_SHAPE_LEN 8
  188. #define MSPROF_GE_TENSOR_DATA_NUM 5
  189. enum MsprofGeTensorType {
  190. MSPROF_GE_TENSOR_TYPE_INPUT = 0,
  191. MSPROF_GE_TENSOR_TYPE_OUTPUT,
  192. };
  193. struct MsprofGeTensorData {
  194. uint32_t tensorType; // MsprofGeTensorType
  195. uint32_t format;
  196. uint32_t dataType;
  197. uint32_t shape[MSPROF_GE_TENSOR_DATA_SHAPE_LEN];
  198. };
  199. struct MsprofGeProfTensorData {
  200. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  201. uint16_t dataTag = MSPROF_GE_DATA_TAG_TENSOR;
  202. uint32_t modelId;
  203. uint64_t curIterNum;
  204. uint32_t streamId;
  205. uint32_t taskId;
  206. uint32_t tensorNum;
  207. MsprofGeTensorData tensorData[MSPROF_GE_TENSOR_DATA_NUM];
  208. uint8_t reserve[MSPROF_GE_TENSOR_DATA_RESERVE_BYTES];
  209. };
  210. #define MSPROF_GE_STEP_DATA_RESERVE_BYTES 27
  211. enum MsprofGeStepTag {
  212. MSPROF_GE_STEP_TAG_BEGIN = 0,
  213. MSPROF_GE_STEP_TAG_END,
  214. };
  215. struct MsprofGeProfStepData {
  216. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  217. uint16_t dataTag = MSPROF_GE_DATA_TAG_STEP;
  218. uint32_t modelId;
  219. uint32_t streamId;
  220. uint32_t taskId;
  221. uint64_t timeStamp;
  222. uint64_t curIterNum;
  223. uint32_t threadId;
  224. uint8_t tag; // MsprofGeStepTag
  225. uint8_t reserve[MSPROF_GE_STEP_DATA_RESERVE_BYTES];
  226. };
  227. #define MSPROF_GE_ID_MAP_DATA_RESERVE_BYTES 6
  228. struct MsprofGeProfIdMapData {
  229. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  230. uint16_t dataTag = MSPROF_GE_DATA_TAG_ID_MAP;
  231. uint32_t graphId;
  232. uint32_t modelId;
  233. uint32_t sessionId;
  234. uint64_t timeStamp;
  235. uint16_t mode;
  236. uint8_t reserve[MSPROF_GE_ID_MAP_DATA_RESERVE_BYTES];
  237. };
  238. #define MSPROF_GE_HOST_SCH_DATA_RESERVE_BYTES 24
  239. struct MsprofGeProfHostSchData {
  240. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  241. uint16_t dataTag = MSPROF_GE_DATA_TAG_HOST_SCH;
  242. uint32_t threadId; // record in start event
  243. uint64_t element;
  244. uint64_t event;
  245. uint64_t startTime; // record in start event
  246. uint64_t endTime; // record in end event
  247. uint8_t reserve[MSPROF_GE_HOST_SCH_DATA_RESERVE_BYTES];
  248. };
  249. /**
  250. * @brief struct of data reported by RunTime
  251. */
  252. #define MSPROF_RUNTIME_API_DATA_RESERVE_BYTES 106
  253. #define MSPROF_RUNTIME_TASK_ID_NUM 10
  254. #define MSPROF_RUNTIME_API_NAME_LEN 64
  255. struct MsprofRuntimeProfApiData {
  256. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  257. uint16_t dataTag = MSPROF_RUNTIME_DATA_TAG_API;
  258. uint32_t threadId;
  259. uint64_t entryTime;
  260. uint64_t exitTime;
  261. uint64_t dataSize;
  262. uint8_t apiName[MSPROF_RUNTIME_API_NAME_LEN];
  263. uint32_t retCode;
  264. uint32_t streamId;
  265. uint32_t taskNum;
  266. uint32_t taskId[MSPROF_RUNTIME_TASK_ID_NUM];
  267. uint16_t memcpyDirection;
  268. uint8_t reserve[MSPROF_RUNTIME_API_DATA_RESERVE_BYTES];
  269. };
  270. #define MSPROF_RUNTIME_TRACK_DATA_RESERVE_BYTES 10
  271. #define MSPROF_RUNTIME_TRACK_TASK_TYPE_LEN 32
  272. struct MsprofRuntimeProfTrackData {
  273. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  274. uint16_t dataTag = MSPROF_RUNTIME_DATA_TAG_TRACK;
  275. uint32_t threadId;
  276. uint64_t timeStamp;
  277. char taskType[MSPROF_RUNTIME_TRACK_TASK_TYPE_LEN];
  278. uint32_t taskId;
  279. uint16_t streamId;
  280. uint8_t reserve[MSPROF_RUNTIME_TRACK_DATA_RESERVE_BYTES];
  281. };
  282. /**
  283. * @brief struct of data reported by RunTime
  284. */
  285. #define MSPROF_AICPU_DATA_RESERVE_BYTES 9
  286. struct MsprofAicpuProfData {
  287. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  288. uint16_t dataTag = MSPROF_AICPU_DATA_TAG;
  289. uint16_t streamId;
  290. uint16_t taskId;
  291. uint64_t runStartTime;
  292. uint64_t runStartTick;
  293. uint64_t computeStartTime;
  294. uint64_t memcpyStartTime;
  295. uint64_t memcpyEndTime;
  296. uint64_t runEndTime;
  297. uint64_t runEndTick;
  298. uint32_t threadId;
  299. uint32_t deviceId;
  300. uint64_t submitTick;
  301. uint64_t scheduleTick;
  302. uint64_t tickBeforeRun;
  303. uint64_t tickAfterRun;
  304. uint32_t kernelType;
  305. uint32_t dispatchTime;
  306. uint32_t totalTime;
  307. uint16_t fftsThreadId;
  308. uint8_t version;
  309. uint8_t reserve[MSPROF_AICPU_DATA_RESERVE_BYTES];
  310. };
  311. struct MsprofAicpuModelProfData {
  312. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  313. uint16_t dataTag = MSPROF_AICPU_MODEL_TAG;
  314. uint32_t rsv; // Ensure 8-byte alignment
  315. uint64_t timeStamp;
  316. uint64_t indexId;
  317. uint32_t modelId;
  318. uint16_t tagId;
  319. uint16_t rsv1;
  320. uint64_t eventId;
  321. uint8_t reserve[24];
  322. };
  323. /**
  324. * @brief struct of data reported by DP
  325. */
  326. #define MSPROF_DP_DATA_RESERVE_BYTES 16
  327. #define MSPROF_DP_DATA_ACTION_LEN 16
  328. #define MSPROF_DP_DATA_SOURCE_LEN 64
  329. struct MsprofDpProfData {
  330. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  331. uint16_t dataTag = MSPROF_DP_DATA_TAG;
  332. uint32_t rsv; // Ensure 8-byte alignment
  333. uint64_t timeStamp;
  334. char action[MSPROF_DP_DATA_ACTION_LEN];
  335. char source[MSPROF_DP_DATA_SOURCE_LEN];
  336. uint64_t index;
  337. uint64_t size;
  338. uint8_t reserve[MSPROF_DP_DATA_RESERVE_BYTES];
  339. };
  340. /**
  341. * @brief struct of data reported by HCCL
  342. */
  343. #pragma pack(4)
  344. struct MsprofHcclProfNotify {
  345. uint32_t taskID;
  346. uint64_t notifyID;
  347. uint32_t stage;
  348. uint32_t remoteRank;
  349. uint32_t transportType;
  350. uint32_t role; // role {0: dst, 1:src}
  351. double durationEstimated;
  352. };
  353. struct MsprofHcclProfReduce {
  354. uint32_t taskID;
  355. uint64_t src;
  356. uint64_t dst;
  357. uint64_t size;
  358. uint32_t op; // {0: sum, 1: mul, 2: max, 3: min}
  359. uint32_t dataType; // data type {0: INT8, 1: INT16, 2: INT32, 3: FP16, 4:FP32, 5:INT64, 6:UINT64}
  360. uint32_t linkType; // link type {0: 'OnChip', 1: 'HCCS', 2: 'PCIe', 3: 'RoCE'}
  361. uint32_t remoteRank;
  362. uint32_t transportType; // transport type {0: SDMA, 1: RDMA, 2:LOCAL}
  363. uint32_t role; // role {0: dst, 1:src}
  364. double durationEstimated;
  365. };
  366. struct MsprofHcclProfRDMA {
  367. uint32_t taskID;
  368. uint64_t src;
  369. uint64_t dst;
  370. uint64_t size;
  371. uint64_t notifyID;
  372. uint32_t linkType; // link type {0: 'OnChip', 1: 'HCCS', 2: 'PCIe', 3: 'RoCE'}
  373. uint32_t remoteRank;
  374. uint32_t transportType; // transport type {0: RDMA, 1:SDMA, 2:LOCAL}
  375. uint32_t role; // role {0: dst, 1:src}
  376. uint32_t type; // RDMA type {0: RDMASendNotify, 1:RDMASendPayload}
  377. double durationEstimated;
  378. };
  379. struct MsprofHcclProfMemcpy {
  380. uint32_t taskID;
  381. uint64_t src;
  382. uint64_t dst;
  383. uint64_t size;
  384. uint64_t notifyID;
  385. uint32_t linkType; // link type {0: 'OnChip', 1: 'HCCS', 2: 'PCIe', 3: 'RoCE'}
  386. uint32_t remoteRank;
  387. uint32_t transportType; // transport type {0: RDMA, 1:SDMA, 2:LOCAL}
  388. uint32_t role; // role {0: dst, 1:src}
  389. double durationEstimated;
  390. };
  391. struct MsprofHcclProfStageStep {
  392. uint32_t rank;
  393. uint32_t rankSize;
  394. };
  395. struct MsprofHcclProfFlag {
  396. uint64_t cclTag;
  397. uint64_t groupName;
  398. uint32_t localRank;
  399. uint32_t workFlowMode;
  400. };
  401. /**
  402. * @name MsprofHcclProfData
  403. * @brief struct of data reported by hccl
  404. */
  405. struct MsprofHcclProfData {
  406. uint16_t magicNumber = MSPROF_DATA_HEAD_MAGIC_NUM;
  407. uint16_t dataTag = MSPROF_HCCL_DATA_TAG;
  408. uint32_t planeID;
  409. uint32_t deviceID;
  410. uint32_t streamID;
  411. double ts;
  412. char name[16];
  413. union {
  414. MsprofHcclProfNotify notify;
  415. MsprofHcclProfReduce reduce;
  416. MsprofHcclProfStageStep stageStep;
  417. MsprofHcclProfMemcpy forMemcpy;
  418. MsprofHcclProfRDMA RDMA;
  419. MsprofHcclProfFlag flag;
  420. } args;
  421. };
  422. #pragma pack()
  423. /**
  424. * @name MsprofStampInfo
  425. * @brief struct of data reported by msproftx
  426. */
  427. struct MsprofStampInfo {
  428. uint16_t magicNumber;
  429. uint16_t dataTag;
  430. uint32_t processId;
  431. uint32_t threadId;
  432. uint32_t category; // marker category
  433. uint32_t eventType;
  434. int32_t payloadType;
  435. union PayloadValue {
  436. uint64_t ullValue;
  437. int64_t llValue;
  438. double dValue;
  439. uint32_t uiValue[2];
  440. int32_t iValue[2];
  441. float fValue[2];
  442. } payload; // payload info for marker
  443. uint64_t startTime;
  444. uint64_t endTime;
  445. int32_t messageType;
  446. char message[128];
  447. uint8_t reserve0[4];
  448. uint8_t reserve1[72];
  449. };
  450. #ifdef __cplusplus
  451. }
  452. #endif
  453. #endif // MSPROFILER_PROF_COMMON_H_

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