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

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