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

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