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

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