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

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

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