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.

dev.h 13 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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 CCE_RUNTIME_DEVICE_H
  17. #define CCE_RUNTIME_DEVICE_H
  18. #include "base.h"
  19. #if defined(__cplusplus)
  20. extern "C" {
  21. #endif
  22. #define RT_CAPABILITY_SUPPORT (0x1U)
  23. #define RT_CAPABILITY_NOT_SUPPORT (0x0U)
  24. #define MEMORY_INFO_TS_4G_LIMITED (0x0U) // for compatibility
  25. typedef struct tagRTDeviceInfo {
  26. uint8_t env_type; // 0: FPGA 1: EMU 2: ESL
  27. uint32_t ctrl_cpu_ip;
  28. uint32_t ctrl_cpu_id;
  29. uint32_t ctrl_cpu_core_num;
  30. uint32_t ctrl_cpu_endian_little;
  31. uint32_t ts_cpu_core_num;
  32. uint32_t ai_cpu_core_num;
  33. uint32_t ai_core_num;
  34. uint32_t ai_core_freq;
  35. uint32_t ai_cpu_core_id;
  36. uint32_t ai_core_id;
  37. uint32_t aicpu_occupy_bitmap;
  38. uint32_t hardware_version;
  39. uint32_t ts_num;
  40. } rtDeviceInfo_t;
  41. typedef enum tagRtRunMode {
  42. RT_RUN_MODE_OFFLINE = 0,
  43. RT_RUN_MODE_ONLINE,
  44. RT_RUN_MODE_AICPU_SCHED,
  45. RT_RUN_MODE_RESERVED
  46. } rtRunMode;
  47. typedef enum tagRtAicpuDeployType {
  48. AICPU_DEPLOY_CROSS_OS = 0x0,
  49. AICPU_DEPLOY_CROSS_PROCESS,
  50. AICPU_DEPLOY_CROSS_THREAD,
  51. AICPU_DEPLOY_RESERVED
  52. } rtAicpuDeployType_t;
  53. typedef enum tagRtFeatureType {
  54. FEATURE_TYPE_MEMCPY = 0,
  55. FEATURE_TYPE_MEMORY,
  56. FEATURE_TYPE_RSV
  57. } rtFeatureType_t;
  58. typedef enum tagRtDeviceFeatureType {
  59. FEATURE_TYPE_SCHE,
  60. FEATURE_TYPE_BLOCKING_OPERATOR,
  61. FEATURE_TYPE_FFTS_MODE,
  62. FEATURE_TYPE_END,
  63. } rtDeviceFeatureType_t;
  64. typedef enum tagMemcpyInfo {
  65. MEMCPY_INFO_SUPPORT_ZEROCOPY = 0,
  66. MEMCPY_INFO_RSV
  67. } rtMemcpyInfo_t;
  68. typedef enum tagMemoryInfo {
  69. MEMORY_INFO_TS_LIMITED = 0,
  70. MEMORY_INFO_RSV
  71. } rtMemoryInfo_t;
  72. typedef enum tagRtDeviceModuleType {
  73. RT_MODULE_TYPE_SYSTEM = 0, /**< system info*/
  74. RT_MODULE_TYPE_AICPU, /** < aicpu info*/
  75. RT_MODULE_TYPE_CCPU, /**< ccpu_info*/
  76. RT_MODULE_TYPE_DCPU, /**< dcpu info*/
  77. RT_MODULE_TYPE_AICORE, /**< AI CORE info*/
  78. RT_MODULE_TYPE_TSCPU, /**< tscpu info*/
  79. RT_MODULE_TYPE_PCIE, /**< PCIE info*/
  80. RT_MODULE_TYPE_VECTOR_CORE, /**< VECTOR CORE info*/
  81. } rtDeviceModuleType_t;
  82. // used for rtGetDevMsg callback function
  83. typedef void (*rtGetMsgCallback)(const char_t *msg, uint32_t len);
  84. typedef enum tagGetDevMsgType {
  85. RT_GET_DEV_ERROR_MSG = 0,
  86. RT_GET_DEV_RUNNING_STREAM_SNAPSHOT_MSG,
  87. RT_GET_DEV_MSG_RESERVE
  88. } rtGetDevMsgType_t;
  89. /**
  90. * @ingroup dvrt_dev
  91. * @brief get total device number.
  92. * @param [in|out] count the device number
  93. * @return RT_ERROR_NONE for ok
  94. * @return RT_ERROR_INVALID_VALUE for error input
  95. */
  96. RTS_API rtError_t rtGetDeviceCount(int32_t *count);
  97. /**
  98. * @ingroup dvrt_dev
  99. * @brief get device ids
  100. * @param [in|out] get details of device ids
  101. * @return RT_ERROR_NONE for ok
  102. * @return RT_ERROR_DRV_ERR for error
  103. */
  104. RTS_API rtError_t rtGetDeviceIDs(uint32_t *devices, uint32_t len);
  105. /**
  106. * @ingroup dvrt_dev
  107. * @brief get device infomation.
  108. * @param [in] device the device id
  109. * @param [in] moduleType module type
  110. typedef enum {
  111. MODULE_TYPE_SYSTEM = 0, system info
  112. MODULE_TYPE_AICPU, aicpu info
  113. MODULE_TYPE_CCPU, ccpu_info
  114. MODULE_TYPE_DCPU, dcpu info
  115. MODULE_TYPE_AICORE, AI CORE info
  116. MODULE_TYPE_TSCPU, tscpu info
  117. MODULE_TYPE_PCIE, PCIE info
  118. } DEV_MODULE_TYPE;
  119. * @param [in] infoType info type
  120. typedef enum {
  121. INFO_TYPE_ENV = 0,
  122. INFO_TYPE_VERSION,
  123. INFO_TYPE_MASTERID,
  124. INFO_TYPE_CORE_NUM,
  125. INFO_TYPE_OS_SCHED,
  126. INFO_TYPE_IN_USED,
  127. INFO_TYPE_ERROR_MAP,
  128. INFO_TYPE_OCCUPY,
  129. INFO_TYPE_ID,
  130. INFO_TYPE_IP,
  131. INFO_TYPE_ENDIAN,
  132. } DEV_INFO_TYPE;
  133. * @param [out] value the device info
  134. * @return RT_ERROR_NONE for ok
  135. * @return RT_ERROR_DRV_ERR for error
  136. */
  137. RTS_API rtError_t rtGetDeviceInfo(uint32_t deviceId, int32_t moduleType, int32_t infoType, int64_t *value);
  138. /**
  139. * @ingroup dvrt_dev
  140. * @brief set target device for current thread
  141. * @param [int] device the device id
  142. * @return RT_ERROR_NONE for ok
  143. * @return RT_ERROR_INVALID_VALUE for error input
  144. */
  145. RTS_API rtError_t rtSetDevice(int32_t device);
  146. /**
  147. * @ingroup dvrt_dev
  148. * @brief set target device for current thread
  149. * @param [int] device the device id
  150. * @param [int] deviceMode the device mode
  151. * @return RT_ERROR_NONE for ok
  152. * @return RT_ERROR_INVALID_VALUE for error input
  153. */
  154. RTS_API rtError_t rtSetDeviceV2(int32_t device, rtDeviceMode deviceMode);
  155. /**
  156. * @ingroup dvrt_dev
  157. * @brief get deviceMode
  158. * @param [out] deviceMode the device mode
  159. * @return RT_ERROR_NONE for ok
  160. * @return RT_ERROR_INVALID_VALUE for error input
  161. */
  162. RTS_API rtError_t rtGetDeviceMode(rtDeviceMode *deviceMode);
  163. /**
  164. * @ingroup dvrt_dev
  165. * @brief set target die for current thread
  166. * @param [int] die the die id
  167. * @return RT_ERROR_NONE for ok
  168. * @return RT_ERROR_INVALID_VALUE for error input
  169. */
  170. RTS_API rtError_t rtSetDie(int32_t die);
  171. /**
  172. * @ingroup dvrt_dev
  173. * @brief get target die of current thread
  174. * @param [in|out] die the die id
  175. * @return RT_ERROR_NONE for ok
  176. * @return RT_ERROR_INVALID_VALUE for error input
  177. */
  178. RTS_API rtError_t rtGetDie(int32_t *die);
  179. /**
  180. * @ingroup dvrt_dev
  181. * @brief set target device for current thread
  182. * @param [int] device the device id
  183. * @return RT_ERROR_NONE for ok
  184. * @return RT_ERROR_INVALID_VALUE for error input
  185. */
  186. RTS_API rtError_t rtSetDeviceEx(int32_t device);
  187. /**
  188. * @ingroup dvrt_dev
  189. * @brief get Index by phyId.
  190. * @param [in] phyId the physical device id
  191. * @param [out] devIndex the logic device id
  192. * @return RT_ERROR_NONE for ok
  193. * @return RT_ERROR_INVALID_VALUE for error input
  194. */
  195. RTS_API rtError_t rtGetDeviceIndexByPhyId(uint32_t phyId, uint32_t *devIndex);
  196. /**
  197. * @ingroup dvrt_dev
  198. * @brief get phyId by Index.
  199. * @param [in] devIndex the logic device id
  200. * @param [out] phyId the physical device id
  201. * @return RT_ERROR_NONE for ok
  202. * @return RT_ERROR_INVALID_VALUE for error input
  203. */
  204. RTS_API rtError_t rtGetDevicePhyIdByIndex(uint32_t devIndex, uint32_t *phyId);
  205. /**
  206. * @ingroup dvrt_dev
  207. * @brief enable direction:devIdDes---->phyIdSrc.
  208. * @param [in] devIdDes the logical device id
  209. * @param [in] phyIdSrc the physical device id
  210. * @return RT_ERROR_NONE for ok
  211. * @return RT_ERROR_INVALID_VALUE for error input
  212. */
  213. RTS_API rtError_t rtEnableP2P(uint32_t devIdDes, uint32_t phyIdSrc, uint32_t flag);
  214. /**
  215. * @ingroup dvrt_dev
  216. * @brief disable direction:devIdDes---->phyIdSrc.
  217. * @param [in] devIdDes the logical device id
  218. * @param [in] phyIdSrc the physical device id
  219. * @return RT_ERROR_NONE for ok
  220. * @return RT_ERROR_INVALID_VALUE for error input
  221. */
  222. RTS_API rtError_t rtDisableP2P(uint32_t devIdDes, uint32_t phyIdSrc);
  223. /**
  224. * @ingroup dvrt_dev
  225. * @brief get cability of P2P omemry copy betwen device and peeredevic.
  226. * @param [in] device the logical device id
  227. * @param [in] peerDevice the physical device id
  228. * @param [outv] *canAccessPeer 1:enable 0:disable
  229. * @return RT_ERROR_NONE for ok
  230. * @return RT_ERROR_INVALID_VALUE for error input
  231. */
  232. RTS_API rtError_t rtDeviceCanAccessPeer(int32_t *canAccessPeer, uint32_t device, uint32_t peerDevice);
  233. /**
  234. * @ingroup dvrt_dev
  235. * @brief get status
  236. * @param [in] devIdDes the logical device id
  237. * @param [in] phyIdSrc the physical device id
  238. * @param [in|out] status status value
  239. * @return RT_ERROR_NONE for ok
  240. * @return RT_ERROR_INVALID_VALUE for error input
  241. */
  242. RTS_API rtError_t rtGetP2PStatus(uint32_t devIdDes, uint32_t phyIdSrc, uint32_t *status);
  243. /**
  244. * @ingroup dvrt_dev
  245. * @brief get value of current thread
  246. * @param [in|out] pid value of pid
  247. * @return RT_ERROR_NONE for ok
  248. */
  249. RTS_API rtError_t rtDeviceGetBareTgid(uint32_t *pid);
  250. /**
  251. * @ingroup dvrt_dev
  252. * @brief get target device of current thread
  253. * @param [in|out] device the device id
  254. * @return RT_ERROR_NONE for ok
  255. * @return RT_ERROR_INVALID_VALUE for error input
  256. */
  257. RTS_API rtError_t rtGetDevice(int32_t *device);
  258. /**
  259. * @ingroup dvrt_dev
  260. * @brief reset all opened device
  261. * @return RT_ERROR_NONE for ok
  262. * @return RT_ERROR_INVALID_VALUE for error input
  263. */
  264. RTS_API rtError_t rtDeviceReset(int32_t device);
  265. /**
  266. * @ingroup dvrt_dev
  267. * @brief reset opened device
  268. * @return RT_ERROR_NONE for ok
  269. * @return RT_ERROR_INVALID_VALUE for error input
  270. */
  271. RTS_API rtError_t rtDeviceResetEx(int32_t device);
  272. /**
  273. * @ingroup dvrt_dev
  274. * @brief get total device infomation.
  275. * @param [in] device the device id
  276. * @param [in] type limit type RT_LIMIT_TYPE_LOW_POWER_TIMEOUT=0
  277. * @param [in] value limit value
  278. * @param [out] info the device info
  279. * @return RT_ERROR_NONE for ok
  280. * @return RT_ERROR_INVALID_VALUE for error input
  281. */
  282. RTS_API rtError_t rtDeviceSetLimit(int32_t device, rtLimitType_t type, uint32_t value);
  283. /**
  284. * @ingroup dvrt_dev
  285. * @brief Wait for compute device to finish
  286. * @return RT_ERROR_NONE for ok
  287. * @return RT_ERROR_INVALID_VALUE for error input
  288. */
  289. RTS_API rtError_t rtDeviceSynchronize(void);
  290. /**
  291. * @ingroup dvrt_dev
  292. * @brief get priority range of current device
  293. * @param [in|out] leastPriority least priority
  294. * @param [in|out] greatestPriority greatest priority
  295. * @return RT_ERROR_NONE for ok
  296. * @return RT_ERROR_INVALID_VALUE for error input
  297. */
  298. RTS_API rtError_t rtDeviceGetStreamPriorityRange(int32_t *leastPriority, int32_t *greatestPriority);
  299. /**
  300. * @ingroup dvrt_dev
  301. * @brief Set exception handling callback function
  302. * @param [in] callback rtExceptiontype
  303. * @return RT_ERROR_NONE for ok
  304. * @return RT_ERROR_INVALID_VALUE for error input
  305. */
  306. RTS_API rtError_t rtSetExceptCallback(rtErrorCallback callback);
  307. /**
  308. * @ingroup dvrt_dev
  309. * @brief Setting Scheduling Type of Graph
  310. * @param [in] tsId the ts id
  311. * @return RT_ERROR_NONE for ok
  312. * @return RT_ERROR_INVALID_VALUE for error input
  313. */
  314. RTS_API rtError_t rtSetTSDevice(uint32_t tsId);
  315. /**
  316. * @ingroup dvrt_dev
  317. * @brief init aicpu executor
  318. * @param [out] runtime run mode
  319. * @return RT_ERROR_NONE for ok
  320. * @return RT_ERROR_DRV_ERR for can not get run mode
  321. */
  322. RTS_API rtError_t rtGetRunMode(rtRunMode *mode);
  323. /**
  324. * @ingroup dvrt_dev
  325. * @brief get aicpu deploy
  326. * @param [out] aicpu deploy
  327. * @return RT_ERROR_NONE for ok
  328. * @return RT_ERROR_DRV_ERR for can not get aicpu deploy
  329. */
  330. RTS_API rtError_t rtGetAicpuDeploy(rtAicpuDeployType_t *deployType);
  331. /**
  332. * @ingroup dvrt_dev
  333. * @brief set chipType
  334. * @return RT_ERROR_NONE for ok
  335. */
  336. RTS_API rtError_t rtSetSocVersion(const char_t *version);
  337. /**
  338. * @ingroup dvrt_dev
  339. * @brief get chipType
  340. * @return RT_ERROR_NONE for ok
  341. */
  342. RTS_API rtError_t rtGetSocVersion(char_t *version, const uint32_t maxLen);
  343. /**
  344. * @ingroup dvrt_dev
  345. * @brief get status
  346. * @param [in] devId the logical device id
  347. * @param [in] otherDevId the other logical device id
  348. * @param [in] infoType info type
  349. * @param [in|out] value pair info
  350. * @return RT_ERROR_NONE for ok
  351. */
  352. RTS_API rtError_t rtGetPairDevicesInfo(uint32_t devId, uint32_t otherDevId, int32_t infoType, int64_t *value);
  353. /**
  354. * @ingroup dvrt_dev
  355. * @brief get capability infomation.
  356. * @param [in] featureType feature type
  357. typedef enum tagRtFeatureType {
  358. FEATURE_TYPE_MEMCPY = 0,
  359. FEATURE_TYPE_RSV,
  360. } rtFeatureType_t;
  361. * @param [in] featureInfo info type
  362. typedef enum tagMemcpyInfo {
  363. MEMCPY_INFO_SUPPORT_ZEROCOPY = 0,
  364. MEMCPY_INFO _RSV,
  365. } rtMemcpyInfo_t;
  366. * @param [out] value the capability info RT_CAPABILITY_SUPPORT or RT_CAPABILITY_NOT_SUPPORT
  367. * @return RT_ERROR_NONE for ok
  368. */
  369. RTS_API rtError_t rtGetRtCapability(rtFeatureType_t featureType, int32_t featureInfo, int64_t *value);
  370. /**
  371. * @ingroup dvrt_dev
  372. * @brief set target device for current thread
  373. * @param [int] device the device id
  374. * @return RT_ERROR_NONE for ok
  375. * @return RT_ERROR_INVALID_VALUE for error input
  376. */
  377. RTS_API rtError_t rtSetDeviceWithoutTsd(int32_t device);
  378. /**
  379. * @ingroup dvrt_dev
  380. * @brief reset all opened device
  381. * @return RT_ERROR_NONE for ok
  382. * @return RT_ERROR_INVALID_VALUE for error input
  383. */
  384. RTS_API rtError_t rtDeviceResetWithoutTsd(int32_t device);
  385. /**
  386. * @ingroup dvrt_dev
  387. * @brief get device message
  388. * @param [in] rtGetDevMsgType_t getMsgType:msg type
  389. * @param [in] GetMsgCallback callback:acl callback function
  390. * @return RT_ERROR_NONE for ok
  391. * @return RT_ERROR_INVALID_VALUE for error input
  392. */
  393. RTS_API rtError_t rtGetDevMsg(rtGetDevMsgType_t getMsgType, rtGetMsgCallback callback);
  394. #if defined(__cplusplus)
  395. }
  396. #endif
  397. #endif // CCE_RUNTIME_DEVICE_H

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