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.

rt_mem_queue.h 13 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*
  2. * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
  3. * Description: mbuf and queue interface
  4. */
  5. #ifndef CCE_RUNTIME_RT_MEM_QUEUE_H
  6. #define CCE_RUNTIME_RT_MEM_QUEUE_H
  7. #include "base.h"
  8. #if defined(__cplusplus)
  9. extern "C" {
  10. #endif
  11. #define RT_MQ_MAX_NAME_LEN 128 // same as driver's
  12. #define RT_MQ_DEPTH_MIN 2U
  13. #define RT_MQ_MODE_PUSH 1
  14. #define RT_MQ_MODE_PULL 2
  15. #define RT_MQ_MODE_DEFAULT RT_MQ_MODE_PUSH
  16. typedef struct tagMemQueueAttr {
  17. char name[RT_MQ_MAX_NAME_LEN];
  18. uint32_t depth;
  19. uint32_t workMode;
  20. uint32_t flowCtrlDropTime;
  21. bool flowCtrlFlag;
  22. bool overWriteFlag;
  23. } rtMemQueueAttr_t;
  24. typedef struct tagMemQueueShareAttr {
  25. uint32_t manage : 1;
  26. uint32_t read : 1;
  27. uint32_t write : 1;
  28. uint32_t rsv : 29;
  29. } rtMemQueueShareAttr_t;
  30. typedef struct tagMemQueueBuffInfo {
  31. void *addr;
  32. size_t len;
  33. } rtMemQueueBuffInfo;
  34. typedef struct tagMemQueueBuff {
  35. void *contextAddr;
  36. size_t contextLen;
  37. rtMemQueueBuffInfo *buffInfo;
  38. uint32_t buffCount;
  39. } rtMemQueueBuff_t;
  40. typedef enum tagMemQueueQueryCmd {
  41. RT_MQ_QUERY_QUE_ATTR_OF_CUR_PROC = 0, // input is qid(4bytes), output is rtMemQueueShareAttr_t
  42. RT_MQ_QUERY_QUES_OF_CUR_PROC = 1,
  43. RT_MQ_QUERY_CMD_MAX = 2
  44. } rtMemQueueQueryCmd_t;
  45. #define RT_MQ_EVENT_QS_MSG 27 // same as driver's
  46. #define RT_MQ_SCHED_PRIORITY_LEVEL0 0 // same as driver's
  47. #define RT_MQ_SCHED_PRIORITY_LEVEL1 1
  48. #define RT_MQ_SCHED_PRIORITY_LEVEL2 2
  49. #define RT_MQ_SCHED_PRIORITY_LEVEL3 3
  50. #define RT_MQ_SCHED_PRIORITY_LEVEL4 4
  51. #define RT_MQ_SCHED_PRIORITY_LEVEL5 5
  52. #define RT_MQ_SCHED_PRIORITY_LEVEL6 6
  53. #define RT_MQ_SCHED_PRIORITY_LEVEL7 7
  54. /* Events can be released between different systems. This parameter specifies the destination type of events
  55. to be released. The destination type is defined based on the CPU type of the destination system. */
  56. #define RT_MQ_DST_ENGINE_ACPU_DEVICE 0 // device AICPU, same as driver's
  57. #define RT_MQ_DST_ENGINE_ACPU_HOST 1 // Host AICPU
  58. #define RT_MQ_DST_ENGINE_CCPU_DEVICE 2 // device CtrlCPU
  59. #define RT_MQ_DST_ENGINE_CCPU_HOST 3 // Host CtrlCPU
  60. #define RT_MQ_DST_ENGINE_DCPU_DEVICE 4 // device DataCPU
  61. #define RT_MQ_DST_ENGINE_TS_CPU 5 // device TS CPU
  62. #define RT_MQ_DST_ENGINE_DVPP_CPU 6 // device DVPP CPU
  63. #define RT_MQ_SCHED_EVENT_QS_MSG 25 // same as driver's EVENT_QS_MSG
  64. /* When the destination engine is AICPU, select a policy.
  65. ONLY: The command is executed only on the local AICPU.
  66. FIRST: The local AICPU is preferentially executed. If the local AICPU is busy, the remote AICPU can be used. */
  67. #define RT_SCHEDULE_POLICY_ONLY 0 // same as driver's schedule_policy
  68. #define RT_SCHEDULE_POLICY_FIRST 1 // same as driver's schedule_policy
  69. typedef struct tagEschedEventSummary {
  70. int32_t pid; // dst PID
  71. uint32_t grpId;
  72. int32_t eventId; // only RT_MQ_SCHED_EVENT_QS_MSG is supported
  73. uint32_t subeventId;
  74. uint32_t msgLen;
  75. char *msg;
  76. uint32_t dstEngine; // dst system cpu type
  77. int32_t policy; // RT_SCHEDULE_POLICY_ONLY or RT_SCHEDULE_POLICY_FIRST
  78. } rtEschedEventSummary_t;
  79. typedef struct tagEschedEventReply {
  80. char *buf;
  81. uint32_t bufLen;
  82. uint32_t replyLen; // output, ack msg len, same with msgLen in halEschedAckEvent
  83. } rtEschedEventReply_t;
  84. #define RT_DEV_PROCESS_CP1 0
  85. #define RT_DEV_PROCESS_CP2 1
  86. #define RT_DEV_PROCESS_DEV_ONLY 2
  87. #define RT_DEV_PROCESS_QS 3
  88. #define RT_DEV_PROCESS_SIGN_LENGTH 49
  89. typedef struct tagBindHostpidInfo {
  90. int32_t hostPid;
  91. uint32_t vfid;
  92. uint32_t chipId;
  93. int32_t mode; // online:0, offline:1
  94. int32_t cpType; // type of custom-process, see RT_DEV_PROCESS_XXX
  95. uint32_t len; // lenth of sign
  96. char sign[RT_DEV_PROCESS_SIGN_LENGTH]; // sign of hostpid
  97. } rtBindHostpidInfo_t;
  98. #define RT_MEM_BUFF_MAX_CFG_NUM 64
  99. typedef struct {
  100. uint32_t cfgId; // cfg id, start from 0
  101. uint32_t totalSize; // one zone total size
  102. uint32_t blkSize; // blk size, 2^n (0, 2M]
  103. uint32_t maxBufSize; // max size can alloc from zone
  104. uint32_t pageType; // page type, small page / huge page
  105. int32_t elasticEnable; // elastic enable
  106. int32_t elasticRate;
  107. int32_t elasticRateMax;
  108. int32_t elasticHighLevel;
  109. int32_t elasticLowLevel;
  110. } rtMemZoneCfg_t;
  111. typedef struct {
  112. rtMemZoneCfg_t cfg[RT_MEM_BUFF_MAX_CFG_NUM];
  113. }rtMemBuffCfg_t;
  114. typedef void *rtMbufPtr_t;
  115. /**
  116. * @ingroup rt_mem_queue
  117. * @brief init queue schedule
  118. * @param [in] device the logical device id
  119. * @return RT_ERROR_NONE for ok
  120. */
  121. RTS_API rtError_t rtMemQueueInitQS(int32_t device);
  122. /**
  123. * @ingroup rt_mem_queue
  124. * @brief create mbuf queue
  125. * @param [in] device the logical device id
  126. * @param [in] rtMemQueueAttr attribute of queue
  127. * @param [out] qid queue id
  128. * @return RT_ERROR_NONE for ok
  129. */
  130. RTS_API rtError_t rtMemQueueCreate(int32_t device, const rtMemQueueAttr_t *queueAttr, uint32_t *qid);
  131. /**
  132. * @ingroup rt_mem_queue
  133. * @brief destroy mbuf queue
  134. * @param [in] device the logical device id
  135. * @param [in] qid queue id
  136. * @return RT_ERROR_NONE for ok
  137. */
  138. RTS_API rtError_t rtMemQueueDestroy(int32_t device, uint32_t qid);
  139. /**
  140. * @ingroup rt_mem_queue
  141. * @brief destroy mbuf queue init
  142. * @param [in] device the logical device id
  143. * @return RT_ERROR_NONE for ok
  144. */
  145. RTS_API rtError_t rtMemQueueInit(int32_t device);
  146. /**
  147. * @ingroup rt_mem_queue
  148. * @brief enqueu mbuf
  149. * @param [in] device the logical device id
  150. * @param [in] qid queue id
  151. * @param [in] mbuf enqueue mbuf
  152. * @return RT_ERROR_NONE for ok
  153. */
  154. RTS_API rtError_t rtMemQueueEnQueue(int32_t device, uint32_t qid, void *mbuf);
  155. /**
  156. * @ingroup rt_mem_queue
  157. * @brief enqueu mbuf
  158. * @param [in] device the logical device id
  159. * @param [in] qid queue id
  160. * @param [out] mbuf dequeue mbuf
  161. * @return RT_ERROR_NONE for ok
  162. */
  163. RTS_API rtError_t rtMemQueueDeQueue(int32_t device, uint32_t qid, void **mbuf);
  164. /**
  165. * @ingroup rt_mem_queue
  166. * @brief enqueu peek
  167. * @param [in] device the logical device id
  168. * @param [in] qid queue id
  169. * @param [out] bufLen length of mbuf in queue
  170. * @param [in] timeout peek timeout (ms), -1: wait all the time until peeking success
  171. * @return RT_ERROR_NONE for ok
  172. */
  173. RTS_API rtError_t rtMemQueuePeek(int32_t device, uint32_t qid, size_t *bufLen, int32_t timeout);
  174. /**
  175. * @ingroup rt_mem_queue
  176. * @brief enqueu buff
  177. * @param [in] device the logical device id
  178. * @param [in] qid queue id
  179. * @param [in] inBuf enqueue buff
  180. * @param [in] timeout enqueue timeout (ms), -1: wait all the time until enqueue success
  181. * @return RT_ERROR_NONE for ok
  182. */
  183. RTS_API rtError_t rtMemQueueEnQueueBuff(int32_t device, uint32_t qid, rtMemQueueBuff_t *inBuf, int32_t timeout);
  184. /**
  185. * @ingroup rt_mem_queue
  186. * @brief enqueu buff
  187. * @param [in] device the logical device id
  188. * @param [in] qid queue id
  189. * @param [out] outBuf dequeue buff
  190. * @param [in] timeout dequeue timeout (ms), -1: wait all the time until dequeue success
  191. * @return RT_ERROR_NONE for ok
  192. */
  193. RTS_API rtError_t rtMemQueueDeQueueBuff(int32_t device, uint32_t qid, rtMemQueueBuff_t *outBuf, int32_t timeout);
  194. /**
  195. * @ingroup rt_mem_queue
  196. * @brief query queue status
  197. * @param [in] device: the logical device id
  198. * @param [in] cmd: query cmd
  199. * @param [in] inBuff: input buff
  200. * @param [in] inLen: the length of input
  201. * @param [in|out] outBuff: output buff
  202. * @param [in|out] outLen: the length of output
  203. * @return RT_ERROR_NONE for ok
  204. */
  205. RTS_API rtError_t rtMemQueueQuery(int32_t device, rtMemQueueQueryCmd_t cmd, const void *inBuff, uint32_t inLen,
  206. void *outBuff, uint32_t *outLen);
  207. /**
  208. * @ingroup rt_mem_queue
  209. * @brief grant queue
  210. * @param [in] device: logic devid
  211. * @param [in] qid: queue id
  212. * @param [in] pid: pid
  213. * @param [in] attr: queue share attr
  214. * @return RT_ERROR_NONE for ok
  215. */
  216. RTS_API rtError_t rtMemQueueGrant(int32_t device, uint32_t qid, int32_t pid, rtMemQueueShareAttr_t *attr);
  217. /**
  218. * @ingroup rt_mem_queue
  219. * @brief attach queue
  220. * @param [in] device: logic devid
  221. * @param [in] qid: queue id
  222. * @param [in] timeOut: timeOut
  223. * @return RT_ERROR_NONE for ok
  224. */
  225. RTS_API rtError_t rtMemQueueAttach(int32_t device, uint32_t qid, int32_t timeOut);
  226. /**
  227. * @ingroup rt_mem_queue
  228. * @brief Commit the event to a specific process
  229. * @param [in] device: logic devid
  230. * @param [in] event: event summary info
  231. * @param [out] ack: event reply info
  232. * @return RT_ERROR_NONE for ok
  233. */
  234. RTS_API rtError_t rtEschedSubmitEventSync(int32_t device, rtEschedEventSummary_t *event,
  235. rtEschedEventReply_t *ack);
  236. /**
  237. * @ingroup rt_mem_queue
  238. * @brief query device proccess id
  239. * @param [in] info: see struct rtBindHostpidInfo_t
  240. * @param [out] devPid: device proccess id
  241. * @return RT_ERROR_NONE for ok
  242. */
  243. RTS_API rtError_t rtQueryDevPid(rtBindHostpidInfo_t *info, int32_t *devPid);
  244. /**
  245. * @ingroup rt_mem_queue
  246. * @brief device buff init
  247. * @param [in] cfg, init cfg
  248. * @return RT_ERROR_NONE for ok
  249. */
  250. RTS_API rtError_t rtMbufInit(rtMemBuffCfg_t *cfg);
  251. /**
  252. * @ingroup rt_mem_queue
  253. * @brief alloc buff
  254. * @param [out] buff: buff addr alloced
  255. * @param [in] size: The amount of memory space requested
  256. * @return RT_ERROR_NONE for ok
  257. */
  258. RTS_API rtError_t rtMbufAlloc(rtMbufPtr_t *mbuf, uint64_t size);
  259. /**
  260. * @ingroup rt_mem_queue
  261. * @brief free buff
  262. * @param [in] buff: buff addr to be freed
  263. * @return RT_ERROR_NONE for ok
  264. */
  265. RTS_API rtError_t rtMbufFree(rtMbufPtr_t mbuf);
  266. /**
  267. * @ingroup rt_mem_queue
  268. * @brief get Data addr of Mbuf
  269. * @param [in] mbuf: Mbuf addr
  270. * @param [out] buf: Mbuf data addr
  271. * @return RT_ERROR_NONE for ok
  272. */
  273. RTS_API rtError_t rtMbufGetBuffAddr(rtMbufPtr_t mbuf, void **buf);
  274. /**
  275. * @ingroup rt_mem_queue
  276. * @brief get total Buffer size of Mbuf
  277. * @param [in] mbuf: Mbuf addr
  278. * @param [out] totalSize: total buffer size of Mbuf
  279. * @return RT_ERROR_NONE for ok
  280. */
  281. RTS_API rtError_t rtMbufGetBuffSize(rtMbufPtr_t mbuf, uint64_t *totalSize);
  282. /**
  283. * @ingroup rt_mem_queue
  284. * @brief Get the address and length of its user_data from the specified Mbuf
  285. * @param [in] mbuf: Mbuf addr
  286. * @param [out] priv: address of its user_data
  287. * @param [out] size: length of its user_data
  288. * @return RT_ERROR_NONE for ok
  289. */
  290. RTS_API rtError_t rtMbufGetPrivInfo (rtMbufPtr_t mbuf, void **priv, uint64_t *size);
  291. // mem group
  292. typedef struct {
  293. uint64_t maxMemSize; // max buf size in grp, in KB. = 0 means no limit
  294. } rtMemGrpConfig_t;
  295. typedef struct {
  296. uint32_t admin : 1; // admin permission, can add other proc to grp
  297. uint32_t read : 1; // read only permission
  298. uint32_t write : 1; // read and write permission
  299. uint32_t alloc : 1; // alloc permission (have read and write permission)
  300. uint32_t rsv : 28;
  301. } rtMemGrpShareAttr_t;
  302. #define RT_MEM_GRP_QUERY_GROUPS_OF_PROCESS 1 // query process all grp
  303. typedef struct {
  304. int32_t pid;
  305. } rtMemGrpQueryByProc_t; // cmd: GRP_QUERY_GROUPS_OF_PROCESS
  306. typedef union {
  307. rtMemGrpQueryByProc_t grpQueryByProc; // cmd: GRP_QUERY_GROUPS_OF_PROCESS
  308. } rtMemGrpQueryInput_t;
  309. #define RT_MEM_GRP_NAME_LEN 32 // it must be same as driver define BUFF_GRP_NAME_LEN
  310. typedef struct {
  311. char groupName[RT_MEM_GRP_NAME_LEN]; // group name
  312. rtMemGrpShareAttr_t attr; // process in group attribute
  313. } rtMemGrpOfProc_t; // cmd: GRP_QUERY_GROUPS_OF_PROCESS
  314. typedef struct {
  315. rtMemGrpOfProc_t *groupsOfProc; // cmd: GRP_QUERY_GROUPS_OF_PROCESS
  316. size_t maxNum; // max number of result
  317. size_t resultNum; // if the number of results exceeds 'maxNum', only 'maxNum' results are filled in buffer
  318. } rtMemGrpQueryOutput_t;
  319. /**
  320. * @ingroup rt_mem_queue
  321. * @brief create mem group
  322. * @attention null
  323. * @param [in] name, group name
  324. * @param [in] cfg, group cfg
  325. * @return 0 for success, others for fail
  326. */
  327. RTS_API rtError_t rtMemGrpCreate(const char *name, const rtMemGrpConfig_t *cfg);
  328. /**
  329. * @ingroup rt_mem_queue
  330. * @brief add process to group
  331. * @param [in] name, group name
  332. * @param [in] pid, process id
  333. * @param [in] attr, process permission in group
  334. * @return 0 for success, others for fail
  335. */
  336. RTS_API rtError_t rtMemGrpAddProc(const char *name, int32_t pid, const rtMemGrpShareAttr_t *attr);
  337. /**
  338. * @ingroup rt_mem_queue
  339. * @brief attach proccess to check permission in group
  340. * @param [in] name, group name
  341. * @param [in] timeout, time out ms
  342. * @return 0 for success, others for fail
  343. */
  344. RTS_API rtError_t rtMemGrpAttach(const char *name, int32_t timeout);
  345. /**
  346. * @ingroup rt_mem_queue
  347. * @brief buff group query
  348. * @param [in] cmd, cmd type
  349. * @param [in] input, query input
  350. * @param [in|out] output, query output
  351. * @return 0 for success, others for fail
  352. */
  353. RTS_API rtError_t rtMemGrpQuery(int32_t cmd, const rtMemGrpQueryInput_t *input, rtMemGrpQueryOutput_t *output);
  354. #if defined(__cplusplus)
  355. }
  356. #endif
  357. #endif // CCE_RUNTIME_RT_MEM_QUEUE_H

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