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

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