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 34 kB

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