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

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

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