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.

kernel.h 16 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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 __CCE_RUNTIME_KERNEL_H__
  17. #define __CCE_RUNTIME_KERNEL_H__
  18. #include "base.h"
  19. #include "stream.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * @ingroup rt_kernel
  25. * @brief shared memory data control
  26. */
  27. typedef struct tagRtSmData {
  28. uint64_t L2_mirror_addr; // preload or swap source address
  29. uint32_t L2_data_section_size; // every data size
  30. uint8_t L2_preload; // 1 - preload from mirrorAddr, 0 - no preload
  31. uint8_t modified; // 1 - data will be modified by kernel, 0 - no modified
  32. uint8_t priority; // data priority
  33. int8_t prev_L2_page_offset_base; // remap source section offset
  34. uint8_t L2_page_offset_base; // remap destination section offset
  35. uint8_t L2_load_to_ddr; // 1 - need load out, 0 - no need
  36. uint8_t reserved[2]; // reserved
  37. } rtSmData_t;
  38. /**
  39. * @ingroup rt_kernel
  40. * @brief shared memory description
  41. */
  42. typedef struct tagRtSmCtrl {
  43. rtSmData_t data[8]; // data description
  44. uint64_t size; // max page Num
  45. uint8_t remap[64]; /* just using for static remap mode, default:0xFF
  46. array index: virtual l2 page id, array value: physic l2 page id */
  47. uint8_t l2_in_main; // 0-DDR, 1-L2, default:0xFF
  48. uint8_t reserved[3];
  49. } rtSmDesc_t;
  50. typedef rtSmDesc_t rtL2Ctrl_t;
  51. /**
  52. * @ingroup rt_kernel
  53. * @brief device binary type
  54. */
  55. typedef struct tagRtDevBinary {
  56. uint32_t magic; // magic number
  57. uint32_t version; // version of binary
  58. const void *data; // binary data
  59. uint64_t length; // binary length
  60. } rtDevBinary_t;
  61. /**
  62. * @ingroup rt_kernel
  63. * @brief function mode type
  64. */
  65. #define ONLINE_PROF_MAX_PMU_NUM (8)
  66. typedef struct ProfilefDataInfo {
  67. const void *stubFunc;
  68. uint32_t blockDim;
  69. const void *args;
  70. uint32_t argsSize;
  71. rtSmDesc_t *smDesc;
  72. rtStream_t stream;
  73. uint64_t totalcycle;
  74. uint64_t ovcycle;
  75. uint64_t pmu_cnt[ONLINE_PROF_MAX_PMU_NUM];
  76. } rtProfDataInfo_t;
  77. /**
  78. * @ingroup rt_kernel
  79. * @brief function mode type
  80. */
  81. typedef enum {
  82. FUNC_MODE_NORMAL = 0,
  83. FUNC_MODE_PCTRACE_USERPROFILE_RECORDLOOP,
  84. FUNC_MODE_PCTRACE_USERPROFILE_SKIPLOOP,
  85. FUNC_MODE_PCTRACE_CYCLECNT_RECORDLOOP,
  86. FUNC_MODE_PCTRACE_CYCLECNT_SKIPLOOP,
  87. FUNC_MODE_BUTT
  88. } rtFuncModeType_t;
  89. /**
  90. * @ingroup rt_kernel
  91. * @brief kernel info
  92. */
  93. typedef struct rtKernelInfo {
  94. uint64_t task_offset; // kernel offset in module
  95. /* flowtable */
  96. void *arg; // launch kernel arg
  97. uint32_t arg_size;
  98. /* module */
  99. void *module_addr; // module::baseaddr_
  100. uint32_t module_size;
  101. } * rtKernelInfo_t;
  102. /**
  103. * @ingroup rt_KernelConfigDump
  104. * @brief device dump type
  105. */
  106. typedef enum tagRtDumpKind {
  107. RT_DATA_DUMP_KIND_INVALID = -1,
  108. RT_DATA_DUMP_KIND_DUMP = 0,
  109. RT_DATA_DUMP_KIND_RESERVED
  110. } rtDumpKind_t;
  111. /**
  112. * @ingroup rt_kernel
  113. * @brief report callback
  114. */
  115. typedef rtError_t (*rtKernelReportCallback)(rtStream_t stream, rtKernelInfo_t kernelInfo);
  116. /**
  117. * @ingroup rt_kernel
  118. * @brief stream report callback
  119. */
  120. typedef void (*rtCallback_t)(void *fnData);
  121. /**
  122. * @ingroup rt_kernel
  123. * @brief magic number of plain binary for aicore
  124. */
  125. #define RT_DEV_BINARY_MAGIC_PLAIN 0xabceed50
  126. /**
  127. * @ingroup rt_kernel
  128. * @brief magic number of plain binary for aicpu
  129. */
  130. #define RT_DEV_BINARY_MAGIC_PLAIN_AICPU 0xabceed51
  131. /**
  132. * @ingroup rt_kernel
  133. * @brief magic number of plain binary for aivector
  134. */
  135. #define RT_DEV_BINARY_MAGIC_PLAIN_AIVEC 0xabceed52
  136. /**
  137. * @ingroup rt_kernel
  138. * @brief magic number of elf binary for aicore
  139. */
  140. #define RT_DEV_BINARY_MAGIC_ELF 0x43554245
  141. /**
  142. * @ingroup rt_kernel
  143. * @brief magic number of elf binary for aicpu
  144. */
  145. #define RT_DEV_BINARY_MAGIC_ELF_AICPU 0x41415243
  146. /**
  147. * @ingroup rt_kernel
  148. * @brief magic number of elf binary for aivector
  149. */
  150. #define RT_DEV_BINARY_MAGIC_ELF_AIVEC 0x41415246
  151. /**
  152. * @ingroup rt_kernel_flags
  153. * @brief kernel op bit flags
  154. */
  155. #define RT_KERNEL_DEFAULT (0x00)
  156. #define RT_KERNEL_CONVERT (0x01)
  157. #define RT_KERNEL_DUMPFLAG (0x02)
  158. /**
  159. * @ingroup rt_kernel
  160. * @brief register device binary
  161. * @param [in] bin device binary description
  162. * @param [out] handle device binary handle
  163. * @return RT_ERROR_NONE for ok
  164. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  165. */
  166. RTS_API rtError_t rtDevBinaryRegister(const rtDevBinary_t *bin, void **handle);
  167. /**
  168. * @ingroup rt_kernel
  169. * @brief register fast memeory device binary
  170. * @param [in] handle device binary handle
  171. * @return RT_ERROR_NONE for ok
  172. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  173. */
  174. RTS_API rtError_t rtBinaryRegisterToFastMemory(void *handle);
  175. /**
  176. * @ingroup rt_kernel
  177. * @brief unregister device binary
  178. * @param [in] handle device binary handle
  179. * @return RT_ERROR_NONE for ok
  180. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  181. */
  182. RTS_API rtError_t rtDevBinaryUnRegister(void *handle);
  183. /**
  184. * @ingroup rt_kernel
  185. * @brief register device binary metadata
  186. * @param [in] handle device binary description
  187. * @param [in] metadata device binary metadata
  188. * @return RT_ERROR_NONE for ok
  189. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  190. */
  191. RTS_API rtError_t rtMetadataRegister(void *handle, const char *metadata);
  192. /**
  193. * @ingroup rt_kernel
  194. * @brief register device binary dependency
  195. * @param [in] mHandle master device binary description
  196. * @param [in] sHandle slave device binary description
  197. * @return RT_ERROR_NONE for ok
  198. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  199. */
  200. RTS_API rtError_t rtDependencyRegister(void *mHandle, void *sHandle);
  201. /**
  202. * @ingroup rt_kernel
  203. * @brief register device function
  204. * @param [in] binHandle device binary handle
  205. * @param [in] stubFunc stub function
  206. * @param [in] stubName stub function name
  207. * @param [in] devFunc device function description. symbol name or address
  208. * offset, depending binary type.
  209. * @return RT_ERROR_NONE for ok
  210. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  211. */
  212. RTS_API rtError_t rtFunctionRegister(void *binHandle, const void *stubFunc, const char *stubName, const void *devFunc,
  213. uint32_t funcMode);
  214. /**
  215. * @ingroup rt_kernel
  216. * @brief find stub function by name
  217. * @param [in] stubName stub function name
  218. * @param [out] stubFunc stub function
  219. * @return RT_ERROR_NONE for ok
  220. */
  221. RTS_API rtError_t rtGetFunctionByName(const char *stubName, void **stubFunc);
  222. /**
  223. * @ingroup rt_kernel
  224. * @brief find addr by stub func
  225. * @param [in] stubFunc stub function
  226. * @param [out] addr
  227. * @return RT_ERROR_NONE for ok
  228. */
  229. RTS_API rtError_t rtGetAddrByFun(const void *stubFunc, void **addr);
  230. /**
  231. * @ingroup rt_kernel
  232. * @brief query registered or not by stubName
  233. * @param [in] stubName stub function name
  234. * @return RT_ERROR_NONE for ok
  235. */
  236. RTS_API rtError_t rtQueryFunctionRegistered(const char *stubName);
  237. /**
  238. * @ingroup rt_kernel
  239. * @brief config data dump
  240. * @param [in] dumpSizePerBlock dump size
  241. * @param [in] blockDim block dimentions
  242. * @param [in] dumpBaseAddr dump base address
  243. * @return RT_ERROR_NONE for ok, errno for failed
  244. */
  245. RTS_API rtError_t rtKernelConfigDump(uint32_t kind, uint32_t dumpSizePerBlock, uint32_t blockDim, void **dumpBaseAddr,
  246. rtStream_t stream_);
  247. /**
  248. * @ingroup rt_kernel
  249. * @brief launch kernel to device
  250. * @param [in] stubFunc stub function
  251. * @param [in] blockDim block dimentions
  252. * @param [in] args argments address for kernel function
  253. * @param [in] argsSize argements size
  254. * @param [in] smDesc shared memory description
  255. * @param [in] stream associated stream
  256. * @return RT_ERROR_NONE for ok, errno for failed
  257. */
  258. RTS_API rtError_t rtKernelLaunch(const void *stubFunc, uint32_t blockDim, void *args, uint32_t argsSize,
  259. rtSmDesc_t *smDesc, rtStream_t stream);
  260. /**
  261. * @ingroup rt_kernel
  262. * @brief launch kernel to device
  263. * @param [in] stubFunc stub function
  264. * @param [in] blockDim block dimentions
  265. * @param [in] args argments address for kernel function
  266. * @param [in] argsSize argements size
  267. * @param [in] smDesc shared memory description
  268. * @param [in] stream associated stream
  269. * @param [in] flag dump flag
  270. * @return RT_ERROR_NONE for ok, errno for failed
  271. */
  272. RTS_API rtError_t rtKernelLaunchWithFlag(const void *stubFunc, uint32_t blockDim, void *args, uint32_t argsSize,
  273. rtSmDesc_t *smDesc, rtStream_t stream, uint32_t flags);
  274. /**
  275. * @ingroup rt_kernel
  276. * @brief launch kernel to device
  277. * @param [in] args argments address for kernel function
  278. * @param [in] argsSize argements size
  279. * @param [in] flags launch flags
  280. * @param [in] stream associated stream
  281. * @return RT_ERROR_NONE for ok, errno for failed
  282. */
  283. RTS_API rtError_t rtKernelLaunchEx(void *args, uint32_t argsSize, uint32_t flags, rtStream_t stream);
  284. /**
  285. * @ingroup rt_kernel
  286. * @brief launch cpu kernel to device
  287. * @param [in] soName so name
  288. * @param [in] kernelName kernel name
  289. * @param [in] blockDim block dimentions
  290. * @param [in] args argments address for kernel function
  291. * @param [in] argsSize argments size
  292. * @param [in] smDesc shared memory description
  293. * @param [in] stream associated stream
  294. * @retval RT_ERROR_NONE for ok, errno for failed
  295. */
  296. RTS_API rtError_t rtCpuKernelLaunch(const void *soName, const void *kernelName, uint32_t blockDim, const void *args,
  297. uint32_t argsSize, rtSmDesc_t *smDesc, rtStream_t stream);
  298. /**
  299. * @ingroup rt_kernel
  300. * @brief launch cpu kernel to device with dump identifier
  301. * @param [in] soName so name
  302. * @param [in] kernelName kernel name
  303. * @param [in] blockDim block dimentions
  304. * @param [in] args argments address for kernel function
  305. * @param [in] argsSize argments size
  306. * @param [in] smDesc shared memory description
  307. * @param [in] stream associated stream
  308. * @param [in] flag dump flag or others function flag
  309. * @retval RT_ERROR_NONE for ok, errno for failed
  310. */
  311. RTS_API rtError_t rtCpuKernelLaunchWithFlag(const void *soName, const void *kernelName, uint32_t blockDim,
  312. const void *args, uint32_t argsSize, rtSmDesc_t *smDesc, rtStream_t stream,
  313. uint32_t flags);
  314. /**
  315. * @ingroup rt_kernel
  316. * @brief load dump info to aicpu
  317. * @param [in] dumpInfo dump info
  318. * @param [in] length length of dump info
  319. * @return RT_ERROR_NONE for ok, errno for failed
  320. */
  321. RTS_API rtError_t rtDatadumpInfoLoad(const void *dumpInfo, uint32_t length);
  322. #ifndef __CLANG_CCE_RUNTIME_H__
  323. #define __CLANG_CCE_RUNTIME_H__
  324. /**
  325. * @ingroup rt_kernel
  326. * @brief configure call argment for next rtLaunch in current thread
  327. * @param [in] numBlocks block dimentions
  328. * @param [in] smDesc shared memory description
  329. * @param [in] stream associated stream
  330. * @return RT_ERROR_NONE for ok
  331. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  332. */
  333. #ifdef __cplusplus
  334. RTS_API rtError_t rtConfigureCall(uint32_t numBlocks, rtSmDesc_t *smDesc = nullptr, rtStream_t stream = nullptr);
  335. #else
  336. RTS_API rtError_t rtConfigureCall(uint32_t numBlocks, rtSmDesc_t *smDesc, rtStream_t stream);
  337. #endif
  338. #endif // __CLANG_CCE_RUNTIME_H__
  339. /**
  340. * @ingroup rt_kernel
  341. * @brief setup argment for next rtLaunch in current thread
  342. * @param [in] arg argment address for kernel function
  343. * @param [in] size argment size
  344. * @param [in] offset argment table offset
  345. * @return RT_ERROR_NONE for ok
  346. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  347. */
  348. RTS_API rtError_t rtSetupArgument(const void *arg, uint32_t size, uint32_t offset);
  349. /**
  350. * @ingroup rt_kernel
  351. * @brief launch kernel to device with previous setting kernel argment
  352. * and call argment
  353. * @param [in] stubFunc stub function
  354. * @return RT_ERROR_NONE for ok
  355. * @note:if this interface is changed, pls notify the compiler changing at the same time.
  356. */
  357. RTS_API rtError_t rtLaunch(const void *stubFunc);
  358. /**
  359. * @ingroup rt_kernel
  360. * @brief implicitly transfered data to device.
  361. * lifecycle end after next kernel task finish
  362. * @param [in] ptr host memory
  363. * @param [in] size host memory size
  364. * @param [in] flag reserved. set to 0
  365. * @param [out] arg returned arg. used for next kernel's arg.
  366. * @return RT_ERROR_NONE for ok
  367. */
  368. RTS_API rtError_t rtKernelConfigTransArg(const void *ptr, uint64_t size, uint32_t flag, void **arg);
  369. /**
  370. * @ingroup rt_kernel
  371. * @brief start fusion kernels.
  372. * @param [in] stream stream for fusion kernels
  373. * @return RT_ERROR_NONE for ok, errno for failed
  374. */
  375. RTS_API rtError_t rtKernelFusionStart(rtStream_t stream);
  376. /**
  377. * @ingroup rt_kernel
  378. * @brief end fusion kernels.
  379. * @param [in] stream stream for fusion kernels
  380. * @return RT_ERROR_NONE for ok, errno for failed
  381. */
  382. RTS_API rtError_t rtKernelFusionEnd(rtStream_t stream);
  383. /**
  384. * @ingroup rt_kernel
  385. * @brief set kernelinfo callback
  386. * @param [in] callback
  387. * @return RT_ERROR_NONE for ok, errno for failed
  388. */
  389. RTS_API rtError_t rtSetKernelReportCallback(rtKernelReportCallback callBack);
  390. /**
  391. * @ingroup rt_kernel
  392. * @brief subscribe stream callback report.
  393. * @param [in] threadId thread id for stream
  394. * @param [in] stream stream for subscribe
  395. * @return RT_ERROR_NONE for ok, errno for failed
  396. */
  397. RTS_API rtError_t rtSubscribeReport(uint64_t threadId, rtStream_t stream);
  398. /**
  399. * @ingroup rt_kernel
  400. * @brief add callback launch task in stream.
  401. * @param [in] callBackFunc app callback function
  402. * @param [in] fnData user data
  403. * @param [in] stream subscribed stream
  404. * @return RT_ERROR_NONE for ok, errno for failed
  405. */
  406. RTS_API rtError_t rtCallbackLaunch(rtCallback_t callBackFunc, void *fnData, rtStream_t stream, bool isBlock);
  407. /**
  408. * @ingroup rt_kernel
  409. * @brief process callback report.
  410. * @param [in] timeout if timeout=-1, while(1); else timeout
  411. * @return RT_ERROR_NONE for ok, errno for failed
  412. */
  413. RTS_API rtError_t rtProcessReport(int32_t timeout);
  414. /**
  415. * @ingroup rt_kernel
  416. * @brief unsubscribe callback report.
  417. * @param [in] threadId thread id for stream
  418. * @param [in] stream stream for subscribe
  419. * @return RT_ERROR_NONE for ok, errno for failed
  420. */
  421. RTS_API rtError_t rtUnSubscribeReport(uint64_t threadId, rtStream_t stream);
  422. /**
  423. * @ingroup profiling_base
  424. * @brief start online prof.
  425. */
  426. RTS_API rtError_t rtStartOnlineProf(rtStream_t stream, uint32_t sampleNum);
  427. /**
  428. * @ingroup profiling_base
  429. * @brief stop online prof.
  430. */
  431. RTS_API rtError_t rtStopOnlineProf(rtStream_t stream);
  432. /**
  433. * @ingroup profiling_base
  434. * @brief get online prof.
  435. */
  436. RTS_API rtError_t rtGetOnlineProfData(rtStream_t stream, rtProfDataInfo_t *pProfData, uint32_t profDataNum);
  437. #ifdef __cplusplus
  438. }
  439. #endif
  440. #endif // __CCE_RUNTIME_KERNEL_H__

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