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

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

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