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.

acl_rt.h 35 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. /**
  2. * Copyright 2019-2022 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 INC_EXTERNAL_ACL_ACL_RT_H_
  17. #define INC_EXTERNAL_ACL_ACL_RT_H_
  18. #include <stdint.h>
  19. #include <stddef.h>
  20. #include "acl_base.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define ACL_EVENT_TIME_LINE 0x00000008u
  25. typedef enum aclrtRunMode {
  26. ACL_DEVICE,
  27. ACL_HOST,
  28. } aclrtRunMode;
  29. typedef enum aclrtTsId {
  30. ACL_TS_ID_AICORE = 0,
  31. ACL_TS_ID_AIVECTOR = 1,
  32. ACL_TS_ID_RESERVED = 2,
  33. } aclrtTsId;
  34. typedef enum aclrtEventStatus {
  35. ACL_EVENT_STATUS_COMPLETE = 0,
  36. ACL_EVENT_STATUS_NOT_READY = 1,
  37. ACL_EVENT_STATUS_RESERVED = 2,
  38. } aclrtEventStatus;
  39. typedef enum aclrtEventRecordedStatus {
  40. ACL_EVENT_RECORDED_STATUS_NOT_READY = 0,
  41. ACL_EVENT_RECORDED_STATUS_COMPLETE = 1,
  42. } aclrtEventRecordedStatus;
  43. typedef enum aclrtEventWaitStatus {
  44. ACL_EVENT_WAIT_STATUS_COMPLETE = 0,
  45. ACL_EVENT_WAIT_STATUS_NOT_READY = 1,
  46. ACL_EVENT_WAIT_STATUS_RESERVED = 0xffff,
  47. } aclrtEventWaitStatus;
  48. typedef enum aclrtCallbackBlockType {
  49. ACL_CALLBACK_NO_BLOCK,
  50. ACL_CALLBACK_BLOCK,
  51. } aclrtCallbackBlockType;
  52. typedef enum aclrtMemcpyKind {
  53. ACL_MEMCPY_HOST_TO_HOST,
  54. ACL_MEMCPY_HOST_TO_DEVICE,
  55. ACL_MEMCPY_DEVICE_TO_HOST,
  56. ACL_MEMCPY_DEVICE_TO_DEVICE,
  57. } aclrtMemcpyKind;
  58. typedef enum aclrtMemMallocPolicy {
  59. ACL_MEM_MALLOC_HUGE_FIRST,
  60. ACL_MEM_MALLOC_HUGE_ONLY,
  61. ACL_MEM_MALLOC_NORMAL_ONLY,
  62. ACL_MEM_MALLOC_HUGE_FIRST_P2P,
  63. ACL_MEM_MALLOC_HUGE_ONLY_P2P,
  64. ACL_MEM_MALLOC_NORMAL_ONLY_P2P,
  65. } aclrtMemMallocPolicy;
  66. typedef enum aclrtMemAttr {
  67. ACL_DDR_MEM,
  68. ACL_HBM_MEM,
  69. ACL_DDR_MEM_HUGE,
  70. ACL_DDR_MEM_NORMAL,
  71. ACL_HBM_MEM_HUGE,
  72. ACL_HBM_MEM_NORMAL,
  73. ACL_DDR_MEM_P2P_HUGE,
  74. ACL_DDR_MEM_P2P_NORMAL,
  75. ACL_HBM_MEM_P2P_HUGE,
  76. ACL_HBM_MEM_P2P_NORMAL,
  77. } aclrtMemAttr;
  78. typedef enum aclrtGroupAttr {
  79. ACL_GROUP_AICORE_INT,
  80. ACL_GROUP_AIV_INT,
  81. ACL_GROUP_AIC_INT,
  82. ACL_GROUP_SDMANUM_INT,
  83. ACL_GROUP_ASQNUM_INT,
  84. ACL_GROUP_GROUPID_INT
  85. } aclrtGroupAttr;
  86. typedef enum aclrtFloatOverflowMode {
  87. ACL_RT_OVERFLOW_MODE_SATURATION = 0,
  88. ACL_RT_OVERFLOW_MODE_INFNAN,
  89. ACL_RT_OVERFLOW_MODE_UNDEF,
  90. } aclrtFloatOverflowMode;
  91. typedef struct tagRtGroupInfo aclrtGroupInfo;
  92. typedef struct rtExceptionInfo aclrtExceptionInfo;
  93. typedef void (*aclrtCallback)(void *userData);
  94. typedef void (*aclrtExceptionInfoCallback)(aclrtExceptionInfo *exceptionInfo);
  95. /**
  96. * @ingroup AscendCL
  97. * @brief Set a callback function to handle exception information
  98. *
  99. * @param callback [IN] callback function to handle exception information
  100. *
  101. * @retval ACL_SUCCESS The function is successfully executed.
  102. * @retval OtherValues Failure
  103. */
  104. ACL_FUNC_VISIBILITY aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback);
  105. /**
  106. * @ingroup AscendCL
  107. * @brief Get task id from exception information
  108. *
  109. * @param info [IN] pointer of exception information
  110. *
  111. * @retval The task id from exception information
  112. * @retval 0xFFFFFFFF if info is null
  113. */
  114. ACL_FUNC_VISIBILITY uint32_t aclrtGetTaskIdFromExceptionInfo(const aclrtExceptionInfo *info);
  115. /**
  116. * @ingroup AscendCL
  117. * @brief Get stream id from exception information
  118. *
  119. * @param info [IN] pointer of exception information
  120. *
  121. * @retval The stream id from exception information
  122. * @retval 0xFFFFFFFF if info is null
  123. */
  124. ACL_FUNC_VISIBILITY uint32_t aclrtGetStreamIdFromExceptionInfo(const aclrtExceptionInfo *info);
  125. /**
  126. * @ingroup AscendCL
  127. * @brief Get thread id from exception information
  128. *
  129. * @param info [IN] pointer of exception information
  130. *
  131. * @retval The thread id of fail task
  132. * @retval 0xFFFFFFFF if info is null
  133. */
  134. ACL_FUNC_VISIBILITY uint32_t aclrtGetThreadIdFromExceptionInfo(const aclrtExceptionInfo *info);
  135. /**
  136. * @ingroup AscendCL
  137. * @brief Get device id from exception information
  138. *
  139. * @param info [IN] pointer of exception information
  140. *
  141. * @retval The thread id of fail task
  142. * @retval 0xFFFFFFFF if info is null
  143. */
  144. ACL_FUNC_VISIBILITY uint32_t aclrtGetDeviceIdFromExceptionInfo(const aclrtExceptionInfo *info);
  145. /**
  146. * @ingroup AscendCL
  147. * @brief Get error code from exception information
  148. *
  149. * @param info [IN] pointer of exception information
  150. *
  151. * @retval The error code from exception information
  152. * @retval 0xFFFFFFFF if info is null
  153. */
  154. ACL_FUNC_VISIBILITY uint32_t aclrtGetErrorCodeFromExceptionInfo(const aclrtExceptionInfo *info);
  155. /**
  156. * @ingroup AscendCL
  157. * @brief The thread that handles the callback function on the Stream
  158. *
  159. * @param threadId [IN] thread ID
  160. * @param stream [IN] stream handle
  161. *
  162. * @retval ACL_SUCCESS The function is successfully executed.
  163. * @retval OtherValues Failure
  164. */
  165. ACL_FUNC_VISIBILITY aclError aclrtSubscribeReport(uint64_t threadId, aclrtStream stream);
  166. /**
  167. * @ingroup AscendCL
  168. * @brief Add a callback function to be executed on the host
  169. * to the task queue of the Stream
  170. *
  171. * @param fn [IN] Specify the callback function to be added
  172. * The function prototype of the callback function is:
  173. * typedef void (*aclrtCallback)(void *userData);
  174. * @param userData [IN] User data to be passed to the callback function
  175. * @param blockType [IN] callback block type
  176. * @param stream [IN] stream handle
  177. *
  178. * @retval ACL_SUCCESS The function is successfully executed.
  179. * @retval OtherValues Failure
  180. */
  181. ACL_FUNC_VISIBILITY aclError aclrtLaunchCallback(aclrtCallback fn, void *userData, aclrtCallbackBlockType blockType,
  182. aclrtStream stream);
  183. /**
  184. * @ingroup AscendCL
  185. * @brief After waiting for a specified time, trigger callback processing
  186. *
  187. * @par Function
  188. * The thread processing callback specified by
  189. * the aclrtSubscribeReport interface
  190. *
  191. * @param timeout [IN] timeout value
  192. *
  193. * @retval ACL_SUCCESS The function is successfully executed.
  194. * @retval OtherValues Failure
  195. *
  196. * @see aclrtSubscribeReport
  197. */
  198. ACL_FUNC_VISIBILITY aclError aclrtProcessReport(int32_t timeout);
  199. /**
  200. * @ingroup AscendCL
  201. * @brief Cancel thread registration,
  202. * the callback function on the specified Stream
  203. * is no longer processed by the specified thread
  204. *
  205. * @param threadId [IN] thread ID
  206. * @param stream [IN] stream handle
  207. *
  208. * @retval ACL_SUCCESS The function is successfully executed.
  209. * @retval OtherValues Failure
  210. */
  211. ACL_FUNC_VISIBILITY aclError aclrtUnSubscribeReport(uint64_t threadId, aclrtStream stream);
  212. /**
  213. * @ingroup AscendCL
  214. * @brief create context and associates it with the calling thread
  215. *
  216. * @par Function
  217. * The following use cases are supported:
  218. * @li If you don't call the aclrtCreateContext interface
  219. * to explicitly create the context,
  220. * the system will use the default context, which is implicitly created
  221. * when the aclrtSetDevice interface is called.
  222. * @li If multiple contexts are created in a process
  223. * (there is no limit on the number of contexts),
  224. * the current thread can only use one of them at the same time.
  225. * It is recommended to explicitly specify the context of the current thread
  226. * through the aclrtSetCurrentContext interface to increase.
  227. * the maintainability of the program.
  228. *
  229. * @param context [OUT] point to the created context
  230. * @param deviceId [IN] device to create context on
  231. *
  232. * @retval ACL_SUCCESS The function is successfully executed.
  233. * @retval OtherValues Failure
  234. *
  235. * @see aclrtSetDevice | aclrtSetCurrentContext
  236. */
  237. ACL_FUNC_VISIBILITY aclError aclrtCreateContext(aclrtContext *context, int32_t deviceId);
  238. /**
  239. * @ingroup AscendCL
  240. * @brief destroy context instance
  241. *
  242. * @par Function
  243. * Can only destroy context created through aclrtCreateContext interface
  244. *
  245. * @param context [IN] the context to destroy
  246. *
  247. * @retval ACL_SUCCESS The function is successfully executed.
  248. * @retval OtherValues Failure
  249. *
  250. * @see aclrtCreateContext
  251. */
  252. ACL_FUNC_VISIBILITY aclError aclrtDestroyContext(aclrtContext context);
  253. /**
  254. * @ingroup AscendCL
  255. * @brief set the context of the thread
  256. *
  257. * @par Function
  258. * The following scenarios are supported:
  259. * @li If the aclrtCreateContext interface is called in a thread to explicitly
  260. * create a Context (for example: ctx1), the thread's Context can be specified
  261. * without calling the aclrtSetCurrentContext interface.
  262. * The system uses ctx1 as the context of thread1 by default.
  263. * @li If the aclrtCreateContext interface is not explicitly created,
  264. * the system uses the default context as the context of the thread.
  265. * At this time, the aclrtDestroyContext interface cannot be used to release
  266. * the default context.
  267. * @li If the aclrtSetCurrentContext interface is called multiple times to
  268. * set the thread's Context, the last one prevails.
  269. *
  270. * @par Restriction
  271. * @li If the cevice corresponding to the context set for the thread
  272. * has been reset, you cannot set the context as the context of the thread,
  273. * otherwise a business exception will result.
  274. * @li It is recommended to use the context created in a thread.
  275. * If the aclrtCreateContext interface is called in thread A to create a context,
  276. * and the context is used in thread B,
  277. * the user must guarantee the execution order of tasks in the same stream
  278. * under the same context in two threads.
  279. *
  280. * @param context [IN] the current context of the thread
  281. *
  282. * @retval ACL_SUCCESS The function is successfully executed.
  283. * @retval OtherValues Failure
  284. *
  285. * @see aclrtCreateContext | aclrtDestroyContext
  286. */
  287. ACL_FUNC_VISIBILITY aclError aclrtSetCurrentContext(aclrtContext context);
  288. /**
  289. * @ingroup AscendCL
  290. * @brief get the context of the thread
  291. *
  292. * @par Function
  293. * If the user calls the aclrtSetCurrentContext interface
  294. * multiple times to set the context of the current thread,
  295. * then the last set context is obtained
  296. *
  297. * @param context [OUT] the current context of the thread
  298. *
  299. * @retval ACL_SUCCESS The function is successfully executed.
  300. * @retval OtherValues Failure
  301. *
  302. * @see aclrtSetCurrentContext
  303. */
  304. ACL_FUNC_VISIBILITY aclError aclrtGetCurrentContext(aclrtContext *context);
  305. /**
  306. * @ingroup AscendCL
  307. * @brief Specify the device to use for the operation
  308. * implicitly create the default context and the default stream
  309. *
  310. * @par Function
  311. * The following use cases are supported:
  312. * @li Device can be specified in the process or thread.
  313. * If you call the aclrtSetDevice interface multiple
  314. * times to specify the same device,
  315. * you only need to call the aclrtResetDevice interface to reset the device.
  316. * @li The same device can be specified for operation
  317. * in different processes or threads.
  318. * @li Device is specified in a process,
  319. * and multiple threads in the process can share this device to explicitly
  320. * create a Context (aclrtCreateContext interface).
  321. * @li In multi-device scenarios, you can switch to other devices
  322. * through the aclrtSetDevice interface in the process.
  323. *
  324. * @param deviceId [IN] the device id
  325. *
  326. * @retval ACL_SUCCESS The function is successfully executed.
  327. * @retval OtherValues Failure
  328. *
  329. * @see aclrtResetDevice |aclrtCreateContext
  330. */
  331. ACL_FUNC_VISIBILITY aclError aclrtSetDevice(int32_t deviceId);
  332. /**
  333. * @ingroup AscendCL
  334. * @brief Reset the current operating Device and free resources on the device,
  335. * including the default context, the default stream,
  336. * and all streams created under the default context,
  337. * and synchronizes the interface.
  338. * If the task under the default context or stream has not been completed,
  339. * the system will wait for the task to complete before releasing it.
  340. *
  341. * @par Restriction
  342. * @li The Context, Stream, and Event that are explicitly created
  343. * on the device to be reset. Before resetting,
  344. * it is recommended to follow the following interface calling sequence,
  345. * otherwise business abnormalities may be caused.
  346. * @li Interface calling sequence:
  347. * call aclrtDestroyEvent interface to release Event or
  348. * call aclrtDestroyStream interface to release explicitly created Stream->
  349. * call aclrtDestroyContext to release explicitly created Context->
  350. * call aclrtResetDevice interface
  351. *
  352. * @param deviceId [IN] the device id
  353. *
  354. * @retval ACL_SUCCESS The function is successfully executed.
  355. * @retval OtherValues Failure
  356. */
  357. ACL_FUNC_VISIBILITY aclError aclrtResetDevice(int32_t deviceId);
  358. /**
  359. * @ingroup AscendCL
  360. * @brief get target device of current thread
  361. *
  362. * @param deviceId [OUT] the device id
  363. *
  364. * @retval ACL_SUCCESS The function is successfully executed.
  365. * @retval OtherValues Failure
  366. */
  367. ACL_FUNC_VISIBILITY aclError aclrtGetDevice(int32_t *deviceId);
  368. /**
  369. * @ingroup AscendCL
  370. * @brief get target side
  371. *
  372. * @param runMode [OUT] the run mode
  373. *
  374. * @retval ACL_SUCCESS The function is successfully executed.
  375. * @retval OtherValues Failure
  376. */
  377. ACL_FUNC_VISIBILITY aclError aclrtGetRunMode(aclrtRunMode *runMode);
  378. /**
  379. * @ingroup AscendCL
  380. * @brief Wait for compute device to finish
  381. *
  382. * @retval ACL_SUCCESS The function is successfully executed.
  383. * @retval OtherValues Failure
  384. */
  385. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeDevice(void);
  386. /**
  387. * @ingroup AscendCL
  388. * @brief Set Scheduling TS
  389. *
  390. * @param tsId [IN] the ts id
  391. *
  392. * @retval ACL_SUCCESS The function is successfully executed.
  393. * @retval OtherValues Failure
  394. */
  395. ACL_FUNC_VISIBILITY aclError aclrtSetTsDevice(aclrtTsId tsId);
  396. /**
  397. * @ingroup AscendCL
  398. * @brief get total device number.
  399. *
  400. * @param count [OUT] the device number
  401. *
  402. * @retval ACL_SUCCESS The function is successfully executed.
  403. * @retval OtherValues Failure
  404. */
  405. ACL_FUNC_VISIBILITY aclError aclrtGetDeviceCount(uint32_t *count);
  406. /**
  407. * @ingroup AscendCL
  408. * @brief create event instance
  409. *
  410. * @param event [OUT] created event
  411. *
  412. * @retval ACL_SUCCESS The function is successfully executed.
  413. * @retval OtherValues Failure
  414. */
  415. ACL_FUNC_VISIBILITY aclError aclrtCreateEvent(aclrtEvent *event);
  416. /**
  417. * @ingroup AscendCL
  418. * @brief create event instance with flag
  419. *
  420. * @param event [OUT] created event
  421. * @param flag [IN] event flag
  422. *
  423. * @retval ACL_SUCCESS The function is successfully executed.
  424. * @retval OtherValues Failure
  425. */
  426. ACL_FUNC_VISIBILITY aclError aclrtCreateEventWithFlag(aclrtEvent *event, uint32_t flag);
  427. /**
  428. * @ingroup AscendCL
  429. * @brief destroy event instance
  430. *
  431. * @par Function
  432. * Only events created through the aclrtCreateEvent interface can be
  433. * destroyed, synchronous interfaces. When destroying an event,
  434. * the user must ensure that the tasks involved in the aclrtSynchronizeEvent
  435. * interface or the aclrtStreamWaitEvent interface are completed before
  436. * they are destroyed.
  437. *
  438. * @param event [IN] event to destroy
  439. *
  440. * @retval ACL_SUCCESS The function is successfully executed.
  441. * @retval OtherValues Failure
  442. *
  443. * @see aclrtCreateEvent | aclrtSynchronizeEvent | aclrtStreamWaitEvent
  444. */
  445. ACL_FUNC_VISIBILITY aclError aclrtDestroyEvent(aclrtEvent event);
  446. /**
  447. * @ingroup AscendCL
  448. * @brief Record an Event in the Stream
  449. *
  450. * @param event [IN] event to record
  451. * @param stream [IN] stream handle
  452. *
  453. * @retval ACL_SUCCESS The function is successfully executed.
  454. * @retval OtherValues Failure
  455. */
  456. ACL_FUNC_VISIBILITY aclError aclrtRecordEvent(aclrtEvent event, aclrtStream stream);
  457. /**
  458. * @ingroup AscendCL
  459. * @brief Reset an event
  460. *
  461. * @par Function
  462. * Users need to make sure to wait for the tasks in the Stream
  463. * to complete before resetting the Event
  464. *
  465. * @param event [IN] event to reset
  466. * @param stream [IN] stream handle
  467. *
  468. * @retval ACL_SUCCESS The function is successfully executed.
  469. * @retval OtherValues Failure
  470. */
  471. ACL_FUNC_VISIBILITY aclError aclrtResetEvent(aclrtEvent event, aclrtStream stream);
  472. /**
  473. * @ingroup AscendCL
  474. * @brief Queries an event's status
  475. *
  476. * @param event [IN] event to query
  477. * @param status [OUT] event status
  478. *
  479. * @retval ACL_SUCCESS The function is successfully executed.
  480. * @retval OtherValues Failure
  481. */
  482. ACL_DEPRECATED_MESSAGE("aclrtQueryEvent is deprecated, use aclrtQueryEventStatus instead")
  483. ACL_FUNC_VISIBILITY aclError aclrtQueryEvent(aclrtEvent event, aclrtEventStatus *status);
  484. /**
  485. * @ingroup AscendCL
  486. * @brief Queries an event's status
  487. *
  488. * @param event [IN] event to query
  489. * @param status [OUT] event recorded status
  490. *
  491. * @retval ACL_SUCCESS The function is successfully executed.
  492. * @retval OtherValues Failure
  493. */
  494. ACL_FUNC_VISIBILITY aclError aclrtQueryEventStatus(aclrtEvent event, aclrtEventRecordedStatus *status);
  495. /**
  496. * @ingroup AscendCL
  497. * @brief Queries an event's wait-status
  498. *
  499. * @param event [IN] event to query
  500. * @param status [OUT] event wait-status
  501. *
  502. * @retval ACL_SUCCESS The function is successfully executed.
  503. * @retval OtherValues Failure
  504. */
  505. ACL_FUNC_VISIBILITY aclError aclrtQueryEventWaitStatus(aclrtEvent event, aclrtEventWaitStatus *status);
  506. /**
  507. * @ingroup AscendCL
  508. * @brief Block Host Running, wait event to be complete
  509. *
  510. * @param event [IN] event to wait
  511. *
  512. * @retval ACL_SUCCESS The function is successfully executed.
  513. * @retval OtherValues Failure
  514. */
  515. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeEvent(aclrtEvent event);
  516. /**
  517. * @ingroup AscendCL
  518. * @brief computes the elapsed time between events.
  519. *
  520. * @param ms [OUT] time between start and end in ms
  521. * @param start [IN] starting event
  522. * @param end [IN] ending event
  523. *
  524. * @retval ACL_SUCCESS The function is successfully executed.
  525. * @retval OtherValues Failure
  526. *
  527. * @see aclrtCreateEvent | aclrtRecordEvent | aclrtSynchronizeStream
  528. */
  529. ACL_FUNC_VISIBILITY aclError aclrtEventElapsedTime(float *ms, aclrtEvent startEvent, aclrtEvent endEvent);
  530. /**
  531. * @ingroup AscendCL
  532. * @brief alloc memory on device
  533. *
  534. * @par Function
  535. * alloc for size linear memory on device
  536. * and return a pointer to allocated memory by *devPtr
  537. *
  538. * @par Restriction
  539. * @li The memory requested by the aclrtMalloc interface needs to be released
  540. * through the aclrtFree interface.
  541. * @li Before calling the media data processing interface,
  542. * if you need to apply memory on the device to store input or output data,
  543. * you need to call acldvppMalloc to apply for memory.
  544. *
  545. * @param devPtr [OUT] pointer to pointer to allocated memory on device
  546. * @param size [IN] alloc memory size
  547. * @param policy [IN] memory alloc policy
  548. *
  549. * @retval ACL_SUCCESS The function is successfully executed.
  550. * @retval OtherValues Failure
  551. *
  552. * @see aclrtFree | acldvppMalloc | aclrtMallocCached
  553. */
  554. ACL_FUNC_VISIBILITY aclError aclrtMalloc(void **devPtr, size_t size, aclrtMemMallocPolicy policy);
  555. /**
  556. * @ingroup AscendCL
  557. * @brief allocate memory on device with cache
  558. *
  559. * @par Function
  560. * alloc for size linear memory on device
  561. * and return a pointer to allocated memory by *devPtr
  562. *
  563. * @par Restriction
  564. * @li The memory requested by the aclrtMallocCached interface needs to be released
  565. * through the aclrtFree interface.
  566. *
  567. * @param devPtr [OUT] pointer to pointer to allocated memory on device
  568. * @param size [IN] alloc memory size
  569. * @param policy [IN] memory alloc policy
  570. *
  571. * @retval ACL_SUCCESS The function is successfully executed.
  572. * @retval OtherValues Failure
  573. *
  574. * @see aclrtFree | aclrtMalloc
  575. */
  576. ACL_FUNC_VISIBILITY aclError aclrtMallocCached(void **devPtr, size_t size, aclrtMemMallocPolicy policy);
  577. /**
  578. * @ingroup AscendCL
  579. * @brief flush cache data to ddr
  580. *
  581. * @param devPtr [IN] the pointer that flush data to ddr
  582. * @param size [IN] flush size
  583. *
  584. * @retval ACL_SUCCESS The function is successfully executed.
  585. * @retval OtherValues Failure
  586. */
  587. ACL_FUNC_VISIBILITY aclError aclrtMemFlush(void *devPtr, size_t size);
  588. /**
  589. * @ingroup AscendCL
  590. * @brief invalidate cache data
  591. *
  592. * @param devPtr [IN] pointer to invalidate cache data
  593. * @param size [IN] invalidate size
  594. *
  595. * @retval ACL_SUCCESS The function is successfully executed.
  596. * @retval OtherValues Failure
  597. */
  598. ACL_FUNC_VISIBILITY aclError aclrtMemInvalidate(void *devPtr, size_t size);
  599. /**
  600. * @ingroup AscendCL
  601. * @brief free device memory
  602. *
  603. * @par Function
  604. * can only free memory allocated through the aclrtMalloc interface
  605. *
  606. * @param devPtr [IN] Pointer to memory to be freed
  607. *
  608. * @retval ACL_SUCCESS The function is successfully executed.
  609. * @retval OtherValues Failure
  610. *
  611. * @see aclrtMalloc
  612. */
  613. ACL_FUNC_VISIBILITY aclError aclrtFree(void *devPtr);
  614. /**
  615. * @ingroup AscendCL
  616. * @brief alloc memory on host
  617. *
  618. * @par Restriction
  619. * @li The requested memory cannot be used in the Device
  620. * and needs to be explicitly copied to the Device.
  621. * @li The memory requested by the aclrtMallocHost interface
  622. * needs to be released through the aclrtFreeHost interface.
  623. *
  624. * @param hostPtr [OUT] pointer to pointer to allocated memory on the host
  625. * @param size [IN] alloc memory size
  626. *
  627. * @retval ACL_SUCCESS The function is successfully executed.
  628. * @retval OtherValues Failure
  629. *
  630. * @see aclrtFreeHost
  631. */
  632. ACL_FUNC_VISIBILITY aclError aclrtMallocHost(void **hostPtr, size_t size);
  633. /**
  634. * @ingroup AscendCL
  635. * @brief free host memory
  636. *
  637. * @par Function
  638. * can only free memory allocated through the aclrtMallocHost interface
  639. *
  640. * @param hostPtr [IN] free memory pointer
  641. *
  642. * @retval ACL_SUCCESS The function is successfully executed.
  643. * @retval OtherValues Failure
  644. *
  645. * @see aclrtMallocHost
  646. */
  647. ACL_FUNC_VISIBILITY aclError aclrtFreeHost(void *hostPtr);
  648. /**
  649. * @ingroup AscendCL
  650. * @brief synchronous memory replication between host and device
  651. *
  652. * @param dst [IN] destination address pointer
  653. * @param destMax [IN] Max length of the destination address memory
  654. * @param src [IN] source address pointer
  655. * @param count [IN] the length of byte to copy
  656. * @param kind [IN] memcpy type
  657. *
  658. * @retval ACL_SUCCESS The function is successfully executed.
  659. * @retval OtherValues Failure
  660. */
  661. ACL_FUNC_VISIBILITY aclError aclrtMemcpy(void *dst, size_t destMax, const void *src, size_t count,
  662. aclrtMemcpyKind kind);
  663. /**
  664. * @ingroup AscendCL
  665. * @brief Initialize memory and set contents of memory to specified value
  666. *
  667. * @par Function
  668. * The memory to be initialized is on the Host or device side,
  669. * and the system determines whether
  670. * it is host or device according to the address
  671. *
  672. * @param devPtr [IN] Starting address of memory
  673. * @param maxCount [IN] Max length of destination address memory
  674. * @param value [IN] Set value
  675. * @param count [IN] The length of memory
  676. *
  677. * @retval ACL_SUCCESS The function is successfully executed.
  678. * @retval OtherValues Failure
  679. */
  680. ACL_FUNC_VISIBILITY aclError aclrtMemset(void *devPtr, size_t maxCount, int32_t value, size_t count);
  681. /**
  682. * @ingroup AscendCL
  683. * @brief Asynchronous memory replication between Host and Device
  684. *
  685. * @par Function
  686. * After calling this interface,
  687. * be sure to call the aclrtSynchronizeStream interface to ensure that
  688. * the task of memory replication has been completed
  689. *
  690. * @par Restriction
  691. * @li For on-chip Device-to-Device memory copy,
  692. * both the source and destination addresses must be 64-byte aligned
  693. *
  694. * @param dst [IN] destination address pointer
  695. * @param destMax [IN] Max length of destination address memory
  696. * @param src [IN] source address pointer
  697. * @param count [IN] the number of byte to copy
  698. * @param kind [IN] memcpy type
  699. * @param stream [IN] asynchronized task stream
  700. *
  701. * @retval ACL_SUCCESS The function is successfully executed.
  702. * @retval OtherValues Failure
  703. *
  704. * @see aclrtSynchronizeStream
  705. */
  706. ACL_FUNC_VISIBILITY aclError aclrtMemcpyAsync(void *dst, size_t destMax, const void *src, size_t count,
  707. aclrtMemcpyKind kind, aclrtStream stream);
  708. /**
  709. * @ingroup AscendCL
  710. * @brief synchronous memory replication of two-dimensional matrix between host and device
  711. *
  712. * @param dst [IN] destination address pointer
  713. * @param dpitch [IN] pitch of destination memory
  714. * @param src [IN] source address pointer
  715. * @param spitch [IN] pitch of source memory
  716. * @param width [IN] width of matrix transfer
  717. * @param height [IN] height of matrix transfer
  718. * @param kind [IN] memcpy type
  719. *
  720. * @retval ACL_SUCCESS The function is successfully executed.
  721. * @retval OtherValues Failure
  722. */
  723. ACL_FUNC_VISIBILITY aclError aclrtMemcpy2d(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width,
  724. size_t height, aclrtMemcpyKind kind);
  725. /**
  726. * @ingroup AscendCL
  727. * @brief asynchronous memory replication of two-dimensional matrix between host and device
  728. *
  729. * @param dst [IN] destination address pointer
  730. * @param dpitch [IN] pitch of destination memory
  731. * @param src [IN] source address pointer
  732. * @param spitch [IN] pitch of source memory
  733. * @param width [IN] width of matrix transfer
  734. * @param height [IN] height of matrix transfer
  735. * @param kind [IN] memcpy type
  736. * @param stream [IN] asynchronized task stream
  737. *
  738. * @retval ACL_SUCCESS The function is successfully executed.
  739. * @retval OtherValues Failure
  740. */
  741. ACL_FUNC_VISIBILITY aclError aclrtMemcpy2dAsync(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width,
  742. size_t height, aclrtMemcpyKind kind, aclrtStream stream);
  743. /**
  744. * @ingroup AscendCL
  745. * @brief Asynchronous initialize memory
  746. * and set contents of memory to specified value async
  747. *
  748. * @par Function
  749. * The memory to be initialized is on the Host or device side,
  750. * and the system determines whether
  751. * it is host or device according to the address
  752. *
  753. * @param devPtr [IN] destination address pointer
  754. * @param maxCount [IN] Max length of destination address memory
  755. * @param value [IN] set value
  756. * @param count [IN] the number of byte to set
  757. * @param stream [IN] asynchronized task stream
  758. *
  759. * @retval ACL_SUCCESS The function is successfully executed.
  760. * @retval OtherValues Failure
  761. *
  762. * @see aclrtSynchronizeStream
  763. */
  764. ACL_FUNC_VISIBILITY aclError aclrtMemsetAsync(void *devPtr, size_t maxCount, int32_t value, size_t count,
  765. aclrtStream stream);
  766. /**
  767. * @ingroup AscendCL
  768. * @brief create stream instance
  769. *
  770. * @param stream [OUT] the created stream
  771. *
  772. * @retval ACL_SUCCESS The function is successfully executed.
  773. * @retval OtherValues Failure
  774. */
  775. ACL_FUNC_VISIBILITY aclError aclrtCreateStream(aclrtStream *stream);
  776. /**
  777. * @ingroup AscendCL
  778. * @brief destroy stream instance
  779. *
  780. * @par Function
  781. * Can only destroy streams created through the aclrtCreateStream interface
  782. *
  783. * @par Restriction
  784. * Before calling the aclrtDestroyStream interface to destroy
  785. * the specified Stream, you need to call the aclrtSynchronizeStream interface
  786. * to ensure that the tasks in the Stream have been completed.
  787. *
  788. * @param stream [IN] the stream to destroy
  789. *
  790. * @retval ACL_SUCCESS The function is successfully executed.
  791. * @retval OtherValues Failure
  792. *
  793. * @see aclrtCreateStream | aclrtSynchronizeStream
  794. */
  795. ACL_FUNC_VISIBILITY aclError aclrtDestroyStream(aclrtStream stream);
  796. /**
  797. * @ingroup AscendCL
  798. * @brief block the host until all tasks
  799. * in the specified stream have completed
  800. *
  801. * @param stream [IN] the stream to wait
  802. *
  803. * @retval ACL_SUCCESS The function is successfully executed.
  804. * @retval OtherValues Failure
  805. */
  806. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStream(aclrtStream stream);
  807. /**
  808. * @ingroup AscendCL
  809. * @brief block the host until all tasks
  810. * in the specified stream have completed
  811. *
  812. * @param stream [IN] the stream to wait
  813. * @param timeout [IN] timeout value,the unit is milliseconds
  814. * -1 means waiting indefinitely, 0 means check whether synchronization is complete immediately
  815. *
  816. * @retval ACL_SUCCESS The function is successfully executed.
  817. * @retval OtherValues Failure
  818. */
  819. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStreamWithTimeout(aclrtStream stream, int32_t timeout);
  820. /**
  821. * @ingroup AscendCL
  822. * @brief Blocks the operation of the specified Stream until
  823. * the specified Event is completed.
  824. * Support for multiple streams waiting for the same event.
  825. *
  826. * @param stream [IN] the wait stream If using thedefault Stream, set NULL
  827. * @param event [IN] the event to wait
  828. *
  829. * @retval ACL_SUCCESS The function is successfully executed.
  830. * @retval OtherValues Failure
  831. */
  832. ACL_FUNC_VISIBILITY aclError aclrtStreamWaitEvent(aclrtStream stream, aclrtEvent event);
  833. /**
  834. * @ingroup AscendCL
  835. * @brief set group
  836. *
  837. * @par Function
  838. * set the task to the corresponding group
  839. *
  840. * @param groupId [IN] group id
  841. *
  842. * @retval ACL_SUCCESS The function is successfully executed.
  843. * @retval OtherValues Failure
  844. *
  845. * @see aclrtGetGroupCount | aclrtGetAllGroupInfo | aclrtGetGroupInfoDetail
  846. */
  847. ACL_FUNC_VISIBILITY aclError aclrtSetGroup(int32_t groupId);
  848. /**
  849. * @ingroup AscendCL
  850. * @brief get the number of group
  851. *
  852. * @par Function
  853. * get the number of group. if the number of group is zero,
  854. * it means that group is not supported or group is not created.
  855. *
  856. * @param count [OUT] the number of group
  857. *
  858. * @retval ACL_SUCCESS The function is successfully executed.
  859. * @retval OtherValues Failure
  860. *
  861. */
  862. ACL_FUNC_VISIBILITY aclError aclrtGetGroupCount(uint32_t *count);
  863. /**
  864. * @ingroup AscendCL
  865. * @brief create group information
  866. *
  867. * @retval null for failed.
  868. * @retval OtherValues success.
  869. *
  870. * @see aclrtDestroyGroupInfo
  871. */
  872. ACL_FUNC_VISIBILITY aclrtGroupInfo *aclrtCreateGroupInfo();
  873. /**
  874. * @ingroup AscendCL
  875. * @brief destroy group information
  876. *
  877. * @param groupInfo [IN] pointer to group information
  878. *
  879. * @retval ACL_SUCCESS The function is successfully executed.
  880. * @retval OtherValues Failure
  881. *
  882. * @see aclrtCreateGroupInfo
  883. */
  884. ACL_FUNC_VISIBILITY aclError aclrtDestroyGroupInfo(aclrtGroupInfo *groupInfo);
  885. /**
  886. * @ingroup AscendCL
  887. * @brief get all group information
  888. *
  889. * @param groupInfo [OUT] pointer to group information
  890. *
  891. * @retval ACL_SUCCESS The function is successfully executed.
  892. * @retval OtherValues Failure
  893. *
  894. * @see aclrtGetGroupCount
  895. */
  896. ACL_FUNC_VISIBILITY aclError aclrtGetAllGroupInfo(aclrtGroupInfo *groupInfo);
  897. /**
  898. * @ingroup AscendCL
  899. * @brief get detail information of group
  900. *
  901. * @param groupInfo [IN] pointer to group information
  902. * @param groupIndex [IN] group index value
  903. * @param attr [IN] group attribute
  904. * @param attrValue [OUT] pointer to attribute value
  905. * @param valueLen [IN] length of attribute value
  906. * @param paramRetSize [OUT] pointer to real length of attribute value
  907. *
  908. * @retval ACL_SUCCESS The function is successfully executed.
  909. * @retval OtherValues Failure
  910. *
  911. * @see aclrtGetGroupCount | aclrtGetAllGroupInfo
  912. */
  913. ACL_FUNC_VISIBILITY aclError aclrtGetGroupInfoDetail(const aclrtGroupInfo *groupInfo, int32_t groupIndex,
  914. aclrtGroupAttr attr, void *attrValue, size_t valueLen,
  915. size_t *paramRetSize);
  916. /**
  917. * @ingroup AscendCL
  918. * @brief checking whether current device and peer device support the p2p feature
  919. *
  920. * @param canAccessPeer [OUT] pointer to save the checking result
  921. * @param deviceId [IN] current device id
  922. * @param peerDeviceId [IN] peer device id
  923. *
  924. * @retval ACL_SUCCESS The function is successfully executed.
  925. * @retval OtherValues Failure
  926. *
  927. * @see aclrtDeviceEnablePeerAccess | aclrtDeviceDisablePeerAccess
  928. */
  929. ACL_FUNC_VISIBILITY aclError aclrtDeviceCanAccessPeer(int32_t *canAccessPeer, int32_t deviceId, int32_t peerDeviceId);
  930. /**
  931. * @ingroup AscendCL
  932. * @brief enable the peer device to support the p2p feature
  933. *
  934. * @param peerDeviceId [IN] the peer device id
  935. * @param flags [IN] reserved field, now it must be zero
  936. *
  937. * @retval ACL_SUCCESS The function is successfully executed.
  938. * @retval OtherValues Failure
  939. *
  940. * @see aclrtDeviceCanAccessPeer | aclrtDeviceDisablePeerAccess
  941. */
  942. ACL_FUNC_VISIBILITY aclError aclrtDeviceEnablePeerAccess(int32_t peerDeviceId, uint32_t flags);
  943. /**
  944. * @ingroup AscendCL
  945. * @brief disable the peer device to support the p2p function
  946. *
  947. * @param peerDeviceId [IN] the peer device id
  948. *
  949. * @retval ACL_SUCCESS The function is successfully executed.
  950. * @retval OtherValues Failure
  951. *
  952. * @see aclrtDeviceCanAccessPeer | aclrtDeviceEnablePeerAccess
  953. */
  954. ACL_FUNC_VISIBILITY aclError aclrtDeviceDisablePeerAccess(int32_t peerDeviceId);
  955. /**
  956. * @ingroup AscendCL
  957. * @brief Obtain the free memory and total memory of specified attribute.
  958. * the specified memory include normal memory and huge memory.
  959. *
  960. * @param attr [IN] the memory attribute of specified device
  961. * @param free [OUT] the free memory of specified device
  962. * @param total [OUT] the total memory of specified device.
  963. *
  964. * @retval ACL_SUCCESS The function is successfully executed.
  965. * @retval OtherValues Failure
  966. */
  967. ACL_FUNC_VISIBILITY aclError aclrtGetMemInfo(aclrtMemAttr attr, size_t *free, size_t *total);
  968. /**
  969. * @ingroup AscendCL
  970. * @brief Set the timeout interval for waitting of op
  971. *
  972. * @param timeout [IN] op wait timeout
  973. *
  974. * @retval ACL_SUCCESS The function is successfully executed.
  975. * @retval OtherValues Failure
  976. */
  977. ACL_FUNC_VISIBILITY aclError aclrtSetOpWaitTimeout(uint32_t timeout);
  978. /**
  979. * @ingroup AscendCL
  980. * @brief enable or disable overflow switch on some stream
  981. * @param stream [IN] set overflow switch on this stream
  982. * @param flag [IN] 0 : disable 1 : enable
  983. *
  984. * @retval ACL_SUCCESS The function is successfully executed.
  985. * @retval OtherValues Failure
  986. */
  987. ACL_FUNC_VISIBILITY aclError aclrtSetStreamOverflowSwitch(aclrtStream stream, uint32_t flag);
  988. /**
  989. * @ingroup AscendCL
  990. * @brief get overflow switch on some stream
  991. * @param stream [IN] get overflow switch on this stream
  992. * @param flag [OUT] current overflow switch, 0 : disable others : enable
  993. *
  994. * @retval ACL_SUCCESS The function is successfully executed.
  995. * @retval OtherValues Failure
  996. */
  997. ACL_FUNC_VISIBILITY aclError aclrtGetStreamOverflowSwitch(aclrtStream stream, uint32_t *flag);
  998. /**
  999. * @ingroup AscendCL
  1000. * @brief set saturation mode
  1001. * @param mode [IN] target saturation mode
  1002. *
  1003. * @retval ACL_SUCCESS The function is successfully executed.
  1004. * @retval OtherValues Failure
  1005. */
  1006. ACL_FUNC_VISIBILITY aclError aclrtSetDeviceSatMode(aclrtFloatOverflowMode mode);
  1007. /**
  1008. * @ingroup AscendCL
  1009. * @brief get saturation mode
  1010. * @param mode [OUT] get saturation mode
  1011. *
  1012. * @retval ACL_SUCCESS The function is successfully executed.
  1013. * @retval OtherValues Failure
  1014. */
  1015. ACL_FUNC_VISIBILITY aclError aclrtGetDeviceSatMode(aclrtFloatOverflowMode *mode);
  1016. #ifdef __cplusplus
  1017. }
  1018. #endif
  1019. #endif // INC_EXTERNAL_ACL_ACL_RT_H_

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