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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /**
  2. * @file acl_rt.h
  3. *
  4. * Copyright (C) Huawei Technologies Co., Ltd. 2019-2020. All Rights Reserved.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. */
  10. #ifndef INC_EXTERNAL_ACL_ACL_RT_H_
  11. #define INC_EXTERNAL_ACL_ACL_RT_H_
  12. #include <stdint.h>
  13. #include <stddef.h>
  14. #include "acl_base.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef enum aclrtRunMode {
  19. ACL_DEVICE,
  20. ACL_HOST,
  21. } aclrtRunMode;
  22. typedef enum aclrtTsId {
  23. ACL_TS_ID_AICORE = 0,
  24. ACL_TS_ID_AIVECTOR = 1,
  25. ACL_TS_ID_RESERVED = 2,
  26. } aclrtTsId;
  27. typedef enum aclrtEventStatus {
  28. ACL_EVENT_STATUS_COMPLETE = 0,
  29. ACL_EVENT_STATUS_NOT_READY = 1,
  30. ACL_EVENT_STATUS_RESERVED = 2,
  31. } aclrtEventStatus;
  32. typedef enum aclrtCallbackBlockType {
  33. ACL_CALLBACK_NO_BLOCK,
  34. ACL_CALLBACK_BLOCK,
  35. } aclrtCallbackBlockType;
  36. typedef enum aclrtMemcpyKind {
  37. ACL_MEMCPY_HOST_TO_HOST,
  38. ACL_MEMCPY_HOST_TO_DEVICE,
  39. ACL_MEMCPY_DEVICE_TO_HOST,
  40. ACL_MEMCPY_DEVICE_TO_DEVICE,
  41. } aclrtMemcpyKind;
  42. typedef enum aclrtMemMallocPolicy {
  43. ACL_MEM_MALLOC_HUGE_FIRST,
  44. ACL_MEM_MALLOC_HUGE_ONLY,
  45. ACL_MEM_MALLOC_NORMAL_ONLY,
  46. } aclrtMemMallocPolicy;
  47. typedef struct rtExceptionInfo aclrtExceptionInfo;
  48. typedef void (*aclrtCallback)(void *userData);
  49. typedef void (*aclrtExceptionInfoCallback)(aclrtExceptionInfo *exceptionInfo);
  50. /**
  51. * @ingroup AscendCL
  52. * @brief Set a callback function to handle exception information
  53. *
  54. * @param callback [IN] callback function to handle exception information
  55. * @retval ACL_ERROR_NONE The function is successfully executed.
  56. * @retval OtherValues Failure
  57. */
  58. ACL_FUNC_VISIBILITY aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback);
  59. /**
  60. * @ingroup AscendCL
  61. * @brief Get task id from exception information
  62. *
  63. * @param info [IN] pointer of exception information
  64. * @retval The task id from exception information
  65. * @retval 0xFFFFFFFF if info is null
  66. */
  67. ACL_FUNC_VISIBILITY uint32_t aclrtGetTaskIdFromExceptionInfo(const aclrtExceptionInfo *info);
  68. /**
  69. * @ingroup AscendCL
  70. * @brief Get stream id from exception information
  71. *
  72. * @param info [IN] pointer of exception information
  73. * @retval The stream id from exception information
  74. * @retval 0xFFFFFFFF if info is null
  75. */
  76. ACL_FUNC_VISIBILITY uint32_t aclrtGetStreamIdFromExceptionInfo(const aclrtExceptionInfo *info);
  77. /**
  78. * @ingroup AscendCL
  79. * @brief Get thread id from exception information
  80. *
  81. * @param info [IN] pointer of exception information
  82. * @retval The thread id of fail task
  83. * @retval 0xFFFFFFFF if info is null
  84. */
  85. ACL_FUNC_VISIBILITY uint32_t aclrtGetThreadIdFromExceptionInfo(const aclrtExceptionInfo *info);
  86. /**
  87. * @ingroup AscendCL
  88. * @brief The thread that handles the callback function on the Stream
  89. *
  90. * @param threadId [IN] thread ID
  91. * @param stream [IN] stream handle
  92. * @retval ACL_ERROR_NONE The function is successfully executed.
  93. * @retval OtherValues Failure
  94. */
  95. ACL_FUNC_VISIBILITY aclError aclrtSubscribeReport(uint64_t threadId, aclrtStream stream);
  96. /**
  97. * @ingroup AscendCL
  98. * @brief Add a callback function to be executed on the host
  99. * to the task queue of the Stream
  100. *
  101. * @param fn [IN] Specify the callback function to be added
  102. * The function prototype of the callback function is:
  103. * typedef void (*aclrtCallback)(void *userData);
  104. * @param userData [IN] User data to be passed to the callback function
  105. * @param blockType [IN] callback block type
  106. * @param stream [IN] stream handle
  107. * @retval ACL_ERROR_NONE The function is successfully executed.
  108. * @retval OtherValues Failure
  109. */
  110. ACL_FUNC_VISIBILITY aclError aclrtLaunchCallback(aclrtCallback fn, void *userData, aclrtCallbackBlockType blockType,
  111. aclrtStream stream);
  112. /**
  113. * @ingroup AscendCL
  114. * @brief After waiting for a specified time, trigger callback processing
  115. *
  116. * @par Function
  117. * The thread processing callback specified by
  118. * the aclrtSubscribeReport interface
  119. * @param timeout [IN] timeout value
  120. * @retval ACL_ERROR_NONE The function is successfully executed.
  121. * @retval OtherValues Failure
  122. *
  123. * @see aclrtSubscribeReport
  124. */
  125. ACL_FUNC_VISIBILITY aclError aclrtProcessReport(int32_t timeout);
  126. /**
  127. * @ingroup AscendCL
  128. * @brief Cancel thread registration,
  129. * the callback function on the specified Stream
  130. * is no longer processed by the specified thread
  131. *
  132. * @param threadId [IN] thread ID
  133. * @param stream [IN] stream handle
  134. * @retval ACL_ERROR_NONE The function is successfully executed.
  135. * @retval OtherValues Failure
  136. */
  137. ACL_FUNC_VISIBILITY aclError aclrtUnSubscribeReport(uint64_t threadId, aclrtStream stream);
  138. /**
  139. * @ingroup AscendCL
  140. * @brief create context and associates it with the calling thread
  141. *
  142. * @par Function
  143. * The following use cases are supported:
  144. * @li If you don't call the aclrtCreateContext interface
  145. * to explicitly create the context,
  146. * the system will use the default context, which is implicitly created
  147. * when the aclrtSetDevice interface is called.
  148. * @li If multiple contexts are created in a process
  149. * (there is no limit on the number of contexts),
  150. * the current thread can only use one of them at the same time.
  151. * It is recommended to explicitly specify the context of the current thread
  152. * through the aclrtSetCurrentContext interface to increase.
  153. * the maintainability of the program.
  154. * @param context [OUT] point to the created context
  155. * @param deviceId [IN] device to create context on
  156. * @retval ACL_ERROR_NONE The function is successfully executed.
  157. * @retval OtherValues Failure
  158. *
  159. * @see aclrtSetDevice | aclrtSetCurrentContext
  160. */
  161. ACL_FUNC_VISIBILITY aclError aclrtCreateContext(aclrtContext *context, int32_t deviceId);
  162. /**
  163. * @ingroup AscendCL
  164. * @brief destroy context instance
  165. *
  166. * @par Function
  167. * Can only destroy context created through aclrtCreateContext interface
  168. * @param context [IN] the context to destroy
  169. * @retval ACL_ERROR_NONE The function is successfully executed.
  170. * @retval OtherValues Failure
  171. *
  172. * @see aclrtCreateContext
  173. */
  174. ACL_FUNC_VISIBILITY aclError aclrtDestroyContext(aclrtContext context);
  175. /**
  176. * @ingroup AscendCL
  177. * @brief set the context of the thread
  178. *
  179. * @par Function
  180. * The following scenarios are supported:
  181. * @li If the aclrtCreateContext interface is called in a thread to explicitly
  182. * create a Context (for example: ctx1), the thread's Context can be specified
  183. * without calling the aclrtSetCurrentContext interface.
  184. * The system uses ctx1 as the context of thread1 by default.
  185. * @li If the aclrtCreateContext interface is not explicitly created,
  186. * the system uses the default context as the context of the thread.
  187. * At this time, the aclrtDestroyContext interface cannot be used to release
  188. * the default context.
  189. * @li If the aclrtSetCurrentContext interface is called multiple times to
  190. * set the thread's Context, the last one prevails.
  191. *
  192. * @par Restriction
  193. * @li If the cevice corresponding to the context set for the thread
  194. * has been reset, you cannot set the context as the context of the thread,
  195. * otherwise a business exception will result.
  196. * @li It is recommended to use the context created in a thread.
  197. * If the aclrtCreateContext interface is called in thread A to create a context,
  198. * and the context is used in thread B,
  199. * the user must guarantee the execution order of tasks in the same stream
  200. * under the same context in two threads.
  201. * @param context [IN] the current context of the thread
  202. * @retval ACL_ERROR_NONE The function is successfully executed.
  203. * @retval OtherValues Failure
  204. *
  205. * @see aclrtCreateContext | aclrtDestroyContext
  206. */
  207. ACL_FUNC_VISIBILITY aclError aclrtSetCurrentContext(aclrtContext context);
  208. /**
  209. * @ingroup AscendCL
  210. * @brief get the context of the thread
  211. *
  212. * @par Function
  213. * If the user calls the aclrtSetCurrentContext interface
  214. * multiple times to set the context of the current thread,
  215. * then the last set context is obtained
  216. * @param context [OUT] the current context of the thread
  217. * @retval ACL_ERROR_NONE The function is successfully executed.
  218. * @retval OtherValues Failure
  219. *
  220. * @see aclrtSetCurrentContext
  221. */
  222. ACL_FUNC_VISIBILITY aclError aclrtGetCurrentContext(aclrtContext *context);
  223. /**
  224. * @ingroup AscendCL
  225. * @brief Specify the device to use for the operation
  226. * implicitly create the default context and the default stream
  227. *
  228. * @par Function
  229. * The following use cases are supported:
  230. * @li Device can be specified in the process or thread.
  231. * If you call the aclrtSetDevice interface multiple
  232. * times to specify the same device,
  233. * you only need to call the aclrtResetDevice interface to reset the device.
  234. * @li The same device can be specified for operation
  235. * in different processes or threads.
  236. * @li Device is specified in a process,
  237. * and multiple threads in the process can share this device to explicitly
  238. * create a Context (aclrtCreateContext interface).
  239. * @li In multi-device scenarios, you can switch to other devices
  240. * through the aclrtSetDevice interface in the process.
  241. * @param deviceId [IN] the device id
  242. * @retval ACL_ERROR_NONE The function is successfully executed.
  243. * @retval OtherValues Failure
  244. *
  245. * @see aclrtResetDevice |aclrtCreateContext
  246. */
  247. ACL_FUNC_VISIBILITY aclError aclrtSetDevice(int32_t deviceId);
  248. /**
  249. * @ingroup AscendCL
  250. * @brief Reset the current operating Device and free resources on the device,
  251. * including the default context, the default stream,
  252. * and all streams created under the default context,
  253. * and synchronizes the interface.
  254. * If the task under the default context or stream has not been completed,
  255. * the system will wait for the task to complete before releasing it.
  256. *
  257. * @par Restriction
  258. * @li The Context, Stream, and Event that are explicitly created
  259. * on the device to be reset. Before resetting,
  260. * it is recommended to follow the following interface calling sequence,
  261. * otherwise business abnormalities may be caused.
  262. * @li Interface calling sequence:
  263. * call aclrtDestroyEvent interface to release Event or
  264. * call aclrtDestroyStream interface to release explicitly created Stream->
  265. * call aclrtDestroyContext to release explicitly created Context->
  266. * call aclrtResetDevice interface
  267. * @param deviceId [IN] the device id
  268. * @retval ACL_ERROR_NONE The function is successfully executed.
  269. * @retval OtherValues Failure
  270. */
  271. ACL_FUNC_VISIBILITY aclError aclrtResetDevice(int32_t deviceId);
  272. /**
  273. * @ingroup AscendCL
  274. * @brief get target device of current thread
  275. *
  276. * @param deviceId [OUT] the device id
  277. * @retval ACL_ERROR_NONE The function is successfully executed.
  278. * @retval OtherValues Failure
  279. */
  280. ACL_FUNC_VISIBILITY aclError aclrtGetDevice(int32_t *deviceId);
  281. /**
  282. * @ingroup AscendCL
  283. * @brief get target side
  284. *
  285. * @param runMode [OUT] the run mode
  286. * @retval ACL_ERROR_NONE The function is successfully executed.
  287. * @retval OtherValues Failure
  288. */
  289. ACL_FUNC_VISIBILITY aclError aclrtGetRunMode(aclrtRunMode *runMode);
  290. /**
  291. * @ingroup AscendCL
  292. * @brief Wait for compute device to finish
  293. *
  294. * @retval ACL_ERROR_NONE The function is successfully executed.
  295. * @retval OtherValues Failure
  296. */
  297. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeDevice(void);
  298. /**
  299. * @ingroup AscendCL
  300. * @brief Set Scheduling TS
  301. *
  302. * @param tsId [IN] the ts id
  303. * @retval ACL_ERROR_NONE The function is successfully executed.
  304. * @retval OtherValues Failure
  305. */
  306. ACL_FUNC_VISIBILITY aclError aclrtSetTsDevice(aclrtTsId tsId);
  307. /**
  308. * @ingroup AscendCL
  309. * @brief get total device number.
  310. *
  311. * @param count [IN|OUT] the device number
  312. * @retval ACL_ERROR_NONE The function is successfully executed.
  313. * @retval OtherValues Failure
  314. */
  315. ACL_FUNC_VISIBILITY aclError aclrtGetDeviceCount(uint32_t *count);
  316. /**
  317. * @ingroup AscendCL
  318. * @brief create event instance
  319. *
  320. * @param event [OUT] created event
  321. * @retval ACL_ERROR_NONE The function is successfully executed.
  322. * @retval OtherValues Failure
  323. */
  324. ACL_FUNC_VISIBILITY aclError aclrtCreateEvent(aclrtEvent *event);
  325. /**
  326. * @ingroup AscendCL
  327. * @brief destroy event instance
  328. *
  329. * @par Function
  330. * Only events created through the aclrtCreateEvent interface can be
  331. * destroyed, synchronous interfaces. When destroying an event,
  332. * the user must ensure that the tasks involved in the aclrtSynchronizeEvent
  333. * interface or the aclrtStreamWaitEvent interface are completed before
  334. * they are destroyed.
  335. * @param event [IN] event to destroy
  336. * @retval ACL_ERROR_NONE The function is successfully executed.
  337. * @retval OtherValues Failure
  338. *
  339. * @see aclrtCreateEvent | aclrtSynchronizeEvent | aclrtStreamWaitEvent
  340. */
  341. ACL_FUNC_VISIBILITY aclError aclrtDestroyEvent(aclrtEvent event);
  342. /**
  343. * @ingroup AscendCL
  344. * @brief Record an Event in the Stream
  345. *
  346. * @param event [IN] event to record
  347. * @param stream [IN] stream handle
  348. * @retval ACL_ERROR_NONE The function is successfully executed.
  349. * @retval OtherValues Failure
  350. */
  351. ACL_FUNC_VISIBILITY aclError aclrtRecordEvent(aclrtEvent event, aclrtStream stream);
  352. /**
  353. * @ingroup AscendCL
  354. * @brief Reset an event
  355. *
  356. * @par Function
  357. * Users need to make sure to wait for the tasks in the Stream
  358. * to complete before resetting the Event
  359. * @param event [IN] event to reset
  360. * @param stream [IN] stream handle
  361. * @retval ACL_ERROR_NONE The function is successfully executed.
  362. * @retval OtherValues Failure
  363. */
  364. ACL_FUNC_VISIBILITY aclError aclrtResetEvent(aclrtEvent event, aclrtStream stream);
  365. /**
  366. * @ingroup AscendCL
  367. * @brief Queries an event's status
  368. *
  369. * @param event [IN] event to query
  370. * @param status [OUT] event status
  371. * @retval ACL_ERROR_NONE The function is successfully executed.
  372. * @retval OtherValues Failure
  373. */
  374. ACL_FUNC_VISIBILITY aclError aclrtQueryEvent(aclrtEvent event, aclrtEventStatus *status);
  375. /**
  376. * @ingroup AscendCL
  377. * @brief Block Host Running, wait event to be complete
  378. *
  379. * @param event [IN] event to wait
  380. * @retval ACL_ERROR_NONE The function is successfully executed.
  381. * @retval OtherValues Failure
  382. */
  383. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeEvent(aclrtEvent event);
  384. /**
  385. * @ingroup AscendCL
  386. * @brief computes the elapsed time between events.
  387. *
  388. * @param ms [OUT] time between start and end in ms
  389. * @param start [IN] starting event
  390. * @param end [IN] ending event
  391. * @retval ACL_ERROR_NONE The function is successfully executed.
  392. * @retval OtherValues Failure
  393. *
  394. * @see aclrtCreateEvent | aclrtRecordEvent | aclrtSynchronizeStream
  395. */
  396. ACL_FUNC_VISIBILITY aclError aclrtEventElapsedTime(float *ms, aclrtEvent start, aclrtEvent end);
  397. /**
  398. * @ingroup AscendCL
  399. * @brief alloc memory on device
  400. *
  401. * @par Function
  402. * alloc for size linear memory on device
  403. * and return a pointer to allocated memory by *devPtr
  404. *
  405. * @par Restriction
  406. * @li The memory requested by the aclrtMalloc interface needs to be released
  407. * through the aclrtFree interface.
  408. * @li Before calling the media data processing interface,
  409. * if you need to apply memory on the device to store input or output data,
  410. * you need to call acldvppMalloc to apply for memory.
  411. * @param devPtr [IN|OUT] pointer to pointer to allocated memory on device
  412. * @param size [IN] alloc memory size
  413. * @param policy [IN] memory alloc policy
  414. * @retval ACL_ERROR_NONE The function is successfully executed.
  415. * @retval OtherValues Failure
  416. *
  417. * @see aclrtFree | acldvppMalloc
  418. */
  419. ACL_FUNC_VISIBILITY aclError aclrtMalloc(void **devPtr,
  420. size_t size,
  421. aclrtMemMallocPolicy policy);
  422. /**
  423. * @ingroup AscendCL
  424. * @brief free device memory
  425. *
  426. * @par Function
  427. * can only free memory allocated through the aclrtMalloc interface
  428. * @param devPtr [IN] Pointer to memory to be freed
  429. * @retval ACL_ERROR_NONE The function is successfully executed.
  430. * @retval OtherValues Failure
  431. *
  432. * @see aclrtMalloc
  433. */
  434. ACL_FUNC_VISIBILITY aclError aclrtFree(void *devPtr);
  435. /**
  436. * @ingroup AscendCL
  437. * @brief alloc memory on host
  438. *
  439. * @par Restriction
  440. * @li The requested memory cannot be used in the Device
  441. * and needs to be explicitly copied to the Device.
  442. * @li The memory requested by the aclrtMallocHost interface
  443. * needs to be released through the aclrtFreeHost interface.
  444. * @param hostPtr [IN|OUT] pointer to pointer to allocated memory on the host
  445. * @param size [IN] alloc memory size
  446. * @retval ACL_ERROR_NONE The function is successfully executed.
  447. * @retval OtherValues Failure
  448. *
  449. * @see aclrtFreeHost
  450. */
  451. ACL_FUNC_VISIBILITY aclError aclrtMallocHost(void **hostPtr, size_t size);
  452. /**
  453. * @ingroup AscendCL
  454. * @brief free host memory
  455. *
  456. * @par Function
  457. * can only free memory allocated through the aclrtMallocHost interface
  458. * @param hostPtr [IN] free memory pointer
  459. * @retval ACL_ERROR_NONE The function is successfully executed.
  460. * @retval OtherValues Failure
  461. *
  462. * @see aclrtMallocHost
  463. */
  464. ACL_FUNC_VISIBILITY aclError aclrtFreeHost(void *hostPtr);
  465. /**
  466. * @ingroup AscendCL
  467. * @brief synchronous memory replication between host and device
  468. *
  469. * @param dst [IN] destination address pointer
  470. * @param destMax [IN] Max length of the destination address memory
  471. * @param src [IN] source address pointer
  472. * @param count [IN] the length of byte to copy
  473. * @param kind [IN] memcpy type
  474. * @retval ACL_ERROR_NONE The function is successfully executed.
  475. * @retval OtherValues Failure
  476. */
  477. ACL_FUNC_VISIBILITY aclError aclrtMemcpy(void *dst,
  478. size_t destMax,
  479. const void *src,
  480. size_t count,
  481. aclrtMemcpyKind kind);
  482. /**
  483. * @ingroup AscendCL
  484. * @brief Initialize memory and set contents of memory to specified value
  485. *
  486. * @par Function
  487. * The memory to be initialized is on the Host or device side,
  488. * and the system determines whether
  489. * it is host or device according to the address
  490. * @param devPtr [IN] Starting address of memory
  491. * @param maxCount [IN] Max length of destination address memory
  492. * @param value [IN] Set value
  493. * @param count [IN] The length of memory
  494. * @retval ACL_ERROR_NONE The function is successfully executed.
  495. * @retval OtherValues Failure
  496. */
  497. ACL_FUNC_VISIBILITY aclError aclrtMemset(void *devPtr, size_t maxCount, int32_t value, size_t count);
  498. /**
  499. * @ingroup AscendCL
  500. * @brief Asynchronous memory replication between Host and Device
  501. *
  502. * @par Function
  503. * After calling this interface,
  504. * be sure to call the aclrtSynchronizeStream interface to ensure that
  505. * the task of memory replication has been completed
  506. *
  507. * @par Restriction
  508. * @li For on-chip Device-to-Device memory copy,
  509. * both the source and destination addresses must be 64-byte aligned
  510. * @param dst [IN] destination address pointer
  511. * @param destMax [IN] Max length of destination address memory
  512. * @param src [IN] source address pointer
  513. * @param count [IN] the number of byte to copy
  514. * @param kind [IN] memcpy type
  515. * @param stream [IN] asynchronized task stream
  516. * @retval ACL_ERROR_NONE The function is successfully executed.
  517. * @retval OtherValues Failure
  518. *
  519. * @see aclrtSynchronizeStream
  520. */
  521. ACL_FUNC_VISIBILITY aclError aclrtMemcpyAsync(void *dst,
  522. size_t destMax,
  523. const void *src,
  524. size_t count,
  525. aclrtMemcpyKind kind,
  526. aclrtStream stream);
  527. /**
  528. * @ingroup AscendCL
  529. * @brief Asynchronous initialize memory
  530. * and set contents of memory to specified value async
  531. *
  532. * @par Function
  533. * The memory to be initialized is on the Host or device side,
  534. * and the system determines whether
  535. * it is host or device according to the address
  536. * @param devPtr [IN] destination address pointer
  537. * @param maxCount [IN] Max length of destination address memory
  538. * @param value [IN] set value
  539. * @param count [IN] the number of byte to set
  540. * @param stream [IN] asynchronized task stream
  541. * @retval ACL_ERROR_NONE The function is successfully executed.
  542. * @retval OtherValues Failure
  543. *
  544. * @see aclrtSynchronizeStream
  545. */
  546. ACL_FUNC_VISIBILITY aclError aclrtMemsetAsync(void *devPtr,
  547. size_t maxCount,
  548. int32_t value,
  549. size_t count,
  550. aclrtStream stream);
  551. /**
  552. * @ingroup AscendCL
  553. * @brief create stream instance
  554. *
  555. * @param stream [OUT] the created stream
  556. * @retval ACL_ERROR_NONE The function is successfully executed.
  557. * @retval OtherValues Failure
  558. */
  559. ACL_FUNC_VISIBILITY aclError aclrtCreateStream(aclrtStream *stream);
  560. /**
  561. * @ingroup AscendCL
  562. * @brief destroy stream instance
  563. *
  564. * @par Function
  565. * Can only destroy streams created through the aclrtCreateStream interface
  566. *
  567. * @par Restriction
  568. * Before calling the aclrtDestroyStream interface to destroy
  569. * the specified Stream, you need to call the aclrtSynchronizeStream interface
  570. * to ensure that the tasks in the Stream have been completed.
  571. * @param stream [IN] the stream to destroy
  572. * @retval ACL_ERROR_NONE The function is successfully executed.
  573. * @retval OtherValues Failure
  574. *
  575. * @see aclrtCreateStream | aclrtSynchronizeStream
  576. */
  577. ACL_FUNC_VISIBILITY aclError aclrtDestroyStream(aclrtStream stream);
  578. /**
  579. * @ingroup AscendCL
  580. * @brief block the host until all tasks
  581. * in the specified stream have completed
  582. *
  583. * @param stream [IN] the stream to wait
  584. * @retval ACL_ERROR_NONE The function is successfully executed.
  585. * @retval OtherValues Failure
  586. */
  587. ACL_FUNC_VISIBILITY aclError aclrtSynchronizeStream(aclrtStream stream);
  588. /**
  589. * @ingroup AscendCL
  590. * @brief Blocks the operation of the specified Stream until
  591. * the specified Event is completed.
  592. * Support for multiple streams waiting for the same event.
  593. *
  594. * @param stream [IN] the wait stream If using thedefault Stream, set NULL
  595. * @param event [IN] the event to wait
  596. * @retval ACL_ERROR_NONE The function is successfully executed.
  597. * @retval OtherValues Failure
  598. */
  599. ACL_FUNC_VISIBILITY aclError aclrtStreamWaitEvent(aclrtStream stream, aclrtEvent event);
  600. #ifdef __cplusplus
  601. }
  602. #endif
  603. #endif // INC_EXTERNAL_ACL_ACL_RT_H_

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台