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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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,
  508. size_t size,
  509. aclrtMemMallocPolicy policy);
  510. /**
  511. * @ingroup AscendCL
  512. * @brief allocate memory on device with cache
  513. *
  514. * @par Function
  515. * alloc for size linear memory on device
  516. * and return a pointer to allocated memory by *devPtr
  517. *
  518. * @par Restriction
  519. * @li The memory requested by the aclrtMallocCached interface needs to be released
  520. * through the aclrtFree interface.
  521. *
  522. * @param devPtr [OUT] pointer to pointer to allocated memory on device
  523. * @param size [IN] alloc memory size
  524. * @param policy [IN] memory alloc policy
  525. *
  526. * @retval ACL_SUCCESS The function is successfully executed.
  527. * @retval OtherValues Failure
  528. *
  529. * @see aclrtFree | aclrtMalloc
  530. */
  531. ACL_FUNC_VISIBILITY aclError aclrtMallocCached(void **devPtr,
  532. size_t size,
  533. aclrtMemMallocPolicy policy);
  534. /**
  535. * @ingroup AscendCL
  536. * @brief flush cache data to ddr
  537. *
  538. * @param devPtr [IN] the pointer that flush data to ddr
  539. * @param size [IN] flush size
  540. *
  541. * @retval ACL_SUCCESS The function is successfully executed.
  542. * @retval OtherValues Failure
  543. */
  544. ACL_FUNC_VISIBILITY aclError aclrtMemFlush(void *devPtr, size_t size);
  545. /**
  546. * @ingroup AscendCL
  547. * @brief invalidate cache data
  548. *
  549. * @param devPtr [IN] pointer to invalidate cache data
  550. * @param size [IN] invalidate size
  551. *
  552. * @retval ACL_SUCCESS The function is successfully executed.
  553. * @retval OtherValues Failure
  554. */
  555. ACL_FUNC_VISIBILITY aclError aclrtMemInvalidate(void *devPtr, size_t size);
  556. /**
  557. * @ingroup AscendCL
  558. * @brief free device memory
  559. *
  560. * @par Function
  561. * can only free memory allocated through the aclrtMalloc interface
  562. *
  563. * @param devPtr [IN] Pointer to memory to be freed
  564. *
  565. * @retval ACL_SUCCESS The function is successfully executed.
  566. * @retval OtherValues Failure
  567. *
  568. * @see aclrtMalloc
  569. */
  570. ACL_FUNC_VISIBILITY aclError aclrtFree(void *devPtr);
  571. /**
  572. * @ingroup AscendCL
  573. * @brief alloc memory on host
  574. *
  575. * @par Restriction
  576. * @li The requested memory cannot be used in the Device
  577. * and needs to be explicitly copied to the Device.
  578. * @li The memory requested by the aclrtMallocHost interface
  579. * needs to be released through the aclrtFreeHost interface.
  580. *
  581. * @param hostPtr [OUT] pointer to pointer to allocated memory on the host
  582. * @param size [IN] alloc memory size
  583. *
  584. * @retval ACL_SUCCESS The function is successfully executed.
  585. * @retval OtherValues Failure
  586. *
  587. * @see aclrtFreeHost
  588. */
  589. ACL_FUNC_VISIBILITY aclError aclrtMallocHost(void **hostPtr, size_t size);
  590. /**
  591. * @ingroup AscendCL
  592. * @brief free host memory
  593. *
  594. * @par Function
  595. * can only free memory allocated through the aclrtMallocHost interface
  596. *
  597. * @param hostPtr [IN] free memory pointer
  598. *
  599. * @retval ACL_SUCCESS The function is successfully executed.
  600. * @retval OtherValues Failure
  601. *
  602. * @see aclrtMallocHost
  603. */
  604. ACL_FUNC_VISIBILITY aclError aclrtFreeHost(void *hostPtr);
  605. /**
  606. * @ingroup AscendCL
  607. * @brief synchronous memory replication between host and device
  608. *
  609. * @param dst [IN] destination address pointer
  610. * @param destMax [IN] Max length of the destination address memory
  611. * @param src [IN] source address pointer
  612. * @param count [IN] the length of byte to copy
  613. * @param kind [IN] memcpy type
  614. *
  615. * @retval ACL_SUCCESS The function is successfully executed.
  616. * @retval OtherValues Failure
  617. */
  618. ACL_FUNC_VISIBILITY aclError aclrtMemcpy(void *dst,
  619. size_t destMax,
  620. const void *src,
  621. size_t count,
  622. aclrtMemcpyKind kind);
  623. /**
  624. * @ingroup AscendCL
  625. * @brief Initialize memory and set contents of memory to specified value
  626. *
  627. * @par Function
  628. * The memory to be initialized is on the Host or device side,
  629. * and the system determines whether
  630. * it is host or device according to the address
  631. *
  632. * @param devPtr [IN] Starting address of memory
  633. * @param maxCount [IN] Max length of destination address memory
  634. * @param value [IN] Set value
  635. * @param count [IN] The length of memory
  636. *
  637. * @retval ACL_SUCCESS The function is successfully executed.
  638. * @retval OtherValues Failure
  639. */
  640. ACL_FUNC_VISIBILITY aclError aclrtMemset(void *devPtr, size_t maxCount, int32_t value, size_t count);
  641. /**
  642. * @ingroup AscendCL
  643. * @brief Asynchronous memory replication between Host and Device
  644. *
  645. * @par Function
  646. * After calling this interface,
  647. * be sure to call the aclrtSynchronizeStream interface to ensure that
  648. * the task of memory replication has been completed
  649. *
  650. * @par Restriction
  651. * @li For on-chip Device-to-Device memory copy,
  652. * both the source and destination addresses must be 64-byte aligned
  653. *
  654. * @param dst [IN] destination address pointer
  655. * @param destMax [IN] Max length of destination address memory
  656. * @param src [IN] source address pointer
  657. * @param count [IN] the number of byte to copy
  658. * @param kind [IN] memcpy type
  659. * @param stream [IN] asynchronized task stream
  660. *
  661. * @retval ACL_SUCCESS The function is successfully executed.
  662. * @retval OtherValues Failure
  663. *
  664. * @see aclrtSynchronizeStream
  665. */
  666. ACL_FUNC_VISIBILITY aclError aclrtMemcpyAsync(void *dst,
  667. size_t destMax,
  668. const void *src,
  669. size_t count,
  670. aclrtMemcpyKind kind,
  671. aclrtStream stream);
  672. /**
  673. * @ingroup AscendCL
  674. * @brief Asynchronous initialize memory
  675. * and set contents of memory to specified value async
  676. *
  677. * @par Function
  678. * The memory to be initialized is on the Host or device side,
  679. * and the system determines whether
  680. * it is host or device according to the address
  681. *
  682. * @param devPtr [IN] destination address pointer
  683. * @param maxCount [IN] Max length of destination address memory
  684. * @param value [IN] set value
  685. * @param count [IN] the number of byte to set
  686. * @param stream [IN] asynchronized task stream
  687. *
  688. * @retval ACL_SUCCESS The function is successfully executed.
  689. * @retval OtherValues Failure
  690. *
  691. * @see aclrtSynchronizeStream
  692. */
  693. ACL_FUNC_VISIBILITY aclError aclrtMemsetAsync(void *devPtr,
  694. size_t maxCount,
  695. int32_t value,
  696. size_t count,
  697. aclrtStream stream);
  698. /**
  699. * @ingroup AscendCL
  700. * @brief create stream instance
  701. *
  702. * @param stream [OUT] the created stream
  703. *
  704. * @retval ACL_SUCCESS The function is successfully executed.
  705. * @retval OtherValues Failure
  706. */
  707. ACL_FUNC_VISIBILITY aclError aclrtCreateStream(aclrtStream *stream);
  708. /**
  709. * @ingroup AscendCL
  710. * @brief destroy stream instance
  711. *
  712. * @par Function
  713. * Can only destroy streams created through the aclrtCreateStream interface
  714. *
  715. * @par Restriction
  716. * Before calling the aclrtDestroyStream interface to destroy
  717. * the specified Stream, you need to call the aclrtSynchronizeStream interface
  718. * to ensure that the tasks in the Stream have been completed.
  719. *
  720. * @param stream [IN] the stream to destroy
  721. *
  722. * @retval ACL_SUCCESS The function is successfully executed.
  723. * @retval OtherValues Failure
  724. *
  725. * @see aclrtCreateStream | aclrtSynchronizeStream
  726. */
  727. ACL_FUNC_VISIBILITY aclError aclrtDestroyStream(aclrtStream stream);
  728. /**
  729. * @ingroup AscendCL
  730. * @brief block the host until all tasks
  731. * in the specified stream have completed
  732. *
  733. * @param stream [IN] the stream to wait
  734. *
  735. * @retval ACL_SUCCESS The function is successfully executed.
  736. * @retval OtherValues Failure
  737. */
  738. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStream(aclrtStream stream);
  739. /**
  740. * @ingroup AscendCL
  741. * @brief Blocks the operation of the specified Stream until
  742. * the specified Event is completed.
  743. * Support for multiple streams waiting for the same event.
  744. *
  745. * @param stream [IN] the wait stream If using thedefault Stream, set NULL
  746. * @param event [IN] the event to wait
  747. *
  748. * @retval ACL_SUCCESS The function is successfully executed.
  749. * @retval OtherValues Failure
  750. */
  751. ACL_FUNC_VISIBILITY aclError aclrtStreamWaitEvent(aclrtStream stream, aclrtEvent event);
  752. /**
  753. * @ingroup AscendCL
  754. * @brief set group
  755. *
  756. * @par Function
  757. * set the task to the corresponding group
  758. *
  759. * @param groupId [IN] group id
  760. *
  761. * @retval ACL_SUCCESS The function is successfully executed.
  762. * @retval OtherValues Failure
  763. *
  764. * @see aclrtGetGroupCount | aclrtGetAllGroupInfo | aclrtGetGroupInfoDetail
  765. */
  766. ACL_FUNC_VISIBILITY aclError aclrtSetGroup(int32_t groupId);
  767. /**
  768. * @ingroup AscendCL
  769. * @brief get the number of group
  770. *
  771. * @par Function
  772. * get the number of group. if the number of group is zero,
  773. * it means that group is not supported or group is not created.
  774. *
  775. * @param count [OUT] the number of group
  776. *
  777. * @retval ACL_SUCCESS The function is successfully executed.
  778. * @retval OtherValues Failure
  779. *
  780. */
  781. ACL_FUNC_VISIBILITY aclError aclrtGetGroupCount(uint32_t *count);
  782. /**
  783. * @ingroup AscendCL
  784. * @brief create group information
  785. *
  786. * @retval null for failed.
  787. * @retval OtherValues success.
  788. *
  789. * @see aclrtDestroyGroupInfo
  790. */
  791. ACL_FUNC_VISIBILITY aclrtGroupInfo *aclrtCreateGroupInfo();
  792. /**
  793. * @ingroup AscendCL
  794. * @brief destroy group information
  795. *
  796. * @param groupInfo [IN] pointer to group information
  797. *
  798. * @retval ACL_SUCCESS The function is successfully executed.
  799. * @retval OtherValues Failure
  800. *
  801. * @see aclrtCreateGroupInfo
  802. */
  803. ACL_FUNC_VISIBILITY aclError aclrtDestroyGroupInfo(aclrtGroupInfo *groupInfo);
  804. /**
  805. * @ingroup AscendCL
  806. * @brief get all group information
  807. *
  808. * @param groupInfo [OUT] pointer to group information
  809. *
  810. * @retval ACL_SUCCESS The function is successfully executed.
  811. * @retval OtherValues Failure
  812. *
  813. * @see aclrtGetGroupCount
  814. */
  815. ACL_FUNC_VISIBILITY aclError aclrtGetAllGroupInfo(aclrtGroupInfo *groupInfo);
  816. /**
  817. * @ingroup AscendCL
  818. * @brief get detail information of group
  819. *
  820. * @param groupInfo [IN] pointer to group information
  821. * @param groupIndex [IN] group index value
  822. * @param attr [IN] group attribute
  823. * @param attrValue [OUT] pointer to attribute value
  824. * @param valueLen [IN] length of attribute value
  825. * @param paramRetSize [OUT] pointer to real length of attribute value
  826. *
  827. * @retval ACL_SUCCESS The function is successfully executed.
  828. * @retval OtherValues Failure
  829. *
  830. * @see aclrtGetGroupCount | aclrtGetAllGroupInfo
  831. */
  832. ACL_FUNC_VISIBILITY aclError aclrtGetGroupInfoDetail(const aclrtGroupInfo *groupInfo,
  833. int32_t groupIndex,
  834. aclrtGroupAttr attr,
  835. void *attrValue,
  836. size_t valueLen,
  837. size_t *paramRetSize);
  838. /**
  839. * @ingroup AscendCL
  840. * @brief checking whether current device and peer device support the p2p feature
  841. *
  842. * @param canAccessPeer [OUT] pointer to save the checking result
  843. * @param deviceId [IN] current device id
  844. * @param peerDeviceId [IN] peer device id
  845. *
  846. * @retval ACL_SUCCESS The function is successfully executed.
  847. * @retval OtherValues Failure
  848. *
  849. * @see aclrtDeviceEnablePeerAccess | aclrtDeviceDisablePeerAccess
  850. */
  851. ACL_FUNC_VISIBILITY aclError aclrtDeviceCanAccessPeer(int32_t *canAccessPeer, int32_t deviceId, int32_t peerDeviceId);
  852. /**
  853. * @ingroup AscendCL
  854. * @brief enable the peer device to support the p2p feature
  855. *
  856. * @param peerDeviceId [IN] the peer device id
  857. * @param flags [IN] reserved field, now it must be zero
  858. *
  859. * @retval ACL_SUCCESS The function is successfully executed.
  860. * @retval OtherValues Failure
  861. *
  862. * @see aclrtDeviceCanAccessPeer | aclrtDeviceDisablePeerAccess
  863. */
  864. ACL_FUNC_VISIBILITY aclError aclrtDeviceEnablePeerAccess(int32_t peerDeviceId, uint32_t flags);
  865. /**
  866. * @ingroup AscendCL
  867. * @brief disable the peer device to support the p2p function
  868. *
  869. * @param peerDeviceId [IN] the peer device id
  870. *
  871. * @retval ACL_SUCCESS The function is successfully executed.
  872. * @retval OtherValues Failure
  873. *
  874. * @see aclrtDeviceCanAccessPeer | aclrtDeviceEnablePeerAccess
  875. */
  876. ACL_FUNC_VISIBILITY aclError aclrtDeviceDisablePeerAccess(int32_t peerDeviceId);
  877. /**
  878. * @ingroup AscendCL
  879. * @brief Obtain the free memory and total memory of specified attribute.
  880. * the specified memory include normal memory and huge memory.
  881. *
  882. * @param attr [IN] the memory attribute of specified device
  883. * @param free [OUT] the free memory of specified device
  884. * @param total [OUT] the total memory of specified device.
  885. *
  886. * @retval ACL_SUCCESS The function is successfully executed.
  887. * @retval OtherValues Failure
  888. */
  889. ACL_FUNC_VISIBILITY aclError aclrtGetMemInfo(aclrtMemAttr attr, size_t *free, size_t *total);
  890. #ifdef __cplusplus
  891. }
  892. #endif
  893. #endif // INC_EXTERNAL_ACL_ACL_RT_H_

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