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.

base.h 8.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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_BASE_H__
  17. #define __CCE_RUNTIME_BASE_H__
  18. #include <stdint.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. // If you need export the function of this library in Win32 dll, use __declspec(dllexport)
  23. #ifndef RTS_API
  24. #ifdef RTS_DLL_EXPORT
  25. #define RTS_API __declspec(dllexport)
  26. #else
  27. #define RTS_API
  28. #endif
  29. #endif
  30. /**
  31. * @ingroup dvrt_base
  32. * @brief runtime error numbers.
  33. */
  34. typedef enum tagRtError {
  35. RT_ERROR_NONE = 0x0, // success
  36. RT_ERROR_INVALID_VALUE = 0x1, // invalid value
  37. RT_ERROR_MEMORY_ALLOCATION = 0x2, // memory allocation fail
  38. RT_ERROR_INVALID_RESOURCE_HANDLE = 0x3, // invalid handle
  39. RT_ERROR_INVALID_DEVICE_POINTER = 0x4, // invalid device point
  40. RT_ERROR_INVALID_MEMCPY_DIRECTION = 0x5, // invalid memory copy dirction
  41. RT_ERROR_INVALID_DEVICE = 0x6, // invalid device
  42. RT_ERROR_NO_DEVICE = 0x7, // no valid device
  43. RT_ERROR_CMD_OCCUPY_FAILURE = 0x8, // command occpuy failure
  44. RT_ERROR_SET_SIGNAL_FAILURE = 0x9, // set signal failure
  45. RT_ERROR_UNSET_SIGNAL_FAILURE = 0xA, // unset signal failure
  46. RT_ERROR_OPEN_FILE_FAILURE = 0xB, // unset signal failure
  47. RT_ERROR_WRITE_FILE_FAILURE = 0xC,
  48. RT_ERROR_MEMORY_ADDRESS_UNALIGNED = 0xD,
  49. RT_ERROR_DRV_ERR = 0xE,
  50. RT_ERROR_LOST_HEARTBEAT = 0xF,
  51. RT_ERROR_REPORT_TIMEOUT = 0x10,
  52. RT_ERROR_NOT_READY = 0x11,
  53. RT_ERROR_DATA_OPERATION_FAIL = 0x12,
  54. RT_ERROR_INVALID_L2_INSTR_SIZE = 0x13,
  55. RT_ERROR_DEVICE_PROC_HANG_OUT = 0x14,
  56. RT_ERROR_DEVICE_POWER_UP_FAIL = 0x15,
  57. RT_ERROR_DEVICE_POWER_DOWN_FAIL = 0x16,
  58. RT_ERROR_FEATURE_NOT_SUPPROT = 0x17,
  59. RT_ERROR_KERNEL_DUPLICATE = 0x18, // register same kernel repeatly
  60. RT_ERROR_MODEL_STREAM_EXE_FAILED = 0x91, // the model stream failed
  61. RT_ERROR_MODEL_LOAD_FAILED = 0x94, // the model stream failed
  62. RT_ERROR_END_OF_SEQUENCE = 0x95, // end of sequence
  63. RT_ERROR_NO_STREAM_CB_REG = 0x96, // no callback register info for stream
  64. RT_ERROR_DATA_DUMP_LOAD_FAILED = 0x97, // data dump load info fail
  65. RT_ERROR_CALLBACK_THREAD_UNSUBSTRIBE = 0x98, // callback thread unsubstribe
  66. RT_ERROR_RESERVED
  67. } rtError_t;
  68. /**
  69. * @ingroup dvrt_base
  70. * @brief runtime exception numbers.
  71. */
  72. typedef enum tagRtExceptionType {
  73. RT_EXCEPTION_NONE = 0,
  74. RT_EXCEPTION_TS_DOWN = 1,
  75. RT_EXCEPTION_TASK_TIMEOUT = 2,
  76. RT_EXCEPTION_TASK_FAILURE = 3,
  77. RT_EXCEPTION_DEV_RUNNING_DOWN = 4
  78. } rtExceptionType;
  79. /**
  80. * @ingroup dvrt_base
  81. * @brief Switch type.
  82. */
  83. typedef enum tagRtCondition {
  84. RT_EQUAL = 0,
  85. RT_NOT_EQUAL,
  86. RT_GREATER,
  87. RT_GREATER_OR_EQUAL,
  88. RT_LESS,
  89. RT_LESS_OR_EQUAL
  90. } rtCondition_t;
  91. /**
  92. * @ingroup dvrt_base
  93. * @brief Data Type of Extensible Switch Task.
  94. */
  95. typedef enum tagRtSwitchDataType {
  96. RT_SWITCH_INT32 = 0,
  97. RT_SWITCH_INT64 = 1,
  98. } rtSwitchDataType_t;
  99. typedef enum tagRtStreamFlagType {
  100. RT_HEAD_STREAM = 0, // first stream
  101. RT_INVALID_FLAG = 0xFFFFFFFF,
  102. } rtStreamFlagType_t;
  103. typedef enum tagRtLimitType {
  104. RT_LIMIT_TYPE_LOW_POWER_TIMEOUT = 0, // timeout for power down , ms
  105. } rtLimitType_t;
  106. typedef void (*rtErrorCallback)(rtExceptionType);
  107. /**
  108. * @ingroup dvrt_base
  109. * @brief stream handle.
  110. */
  111. typedef void *rtStream_t;
  112. /**
  113. * @ingroup dvrt_base
  114. * @brief runtime event handle.
  115. */
  116. typedef void *rtEvent_t;
  117. /**
  118. * @ingroup dvrt_base
  119. * @brief label handle.
  120. */
  121. typedef void *rtLabel_t;
  122. /**
  123. * @ingroup profiling_base
  124. * @brief runtime handle.
  125. */
  126. RTS_API rtError_t rtSetProfDirEx(const char *profDir, const char *address, const char *jobCtx);
  127. /**
  128. * @ingroup profiling_base
  129. * @brief init profiler object.
  130. */
  131. RTS_API rtError_t rtProfilerInit(const char *profdir, const char *address, const char *job_ctx);
  132. /**
  133. * @ingroup profiling_base
  134. * @brief start rts profiler.
  135. */
  136. RTS_API rtError_t rtProfilerStart(void);
  137. /**
  138. * @ingroup profiling_base
  139. * @brief stop rts profiler.
  140. */
  141. RTS_API rtError_t rtProfilerStop(void);
  142. /**
  143. * @ingroup profiling_base
  144. * @brief ts send keypoint profiler log.
  145. */
  146. RTS_API rtError_t rtProfilerTrace(uint64_t id, bool notify, uint32_t flags, rtStream_t stream);
  147. /**
  148. * @ingroup dvrt_base
  149. * @brief Returns the last error from a runtime call.
  150. */
  151. RTS_API rtError_t rtGetLastError();
  152. /**
  153. * @ingroup dvrt_base
  154. * @brief Returns the last error from a runtime call.
  155. */
  156. RTS_API rtError_t rtPeekAtLastError();
  157. /**
  158. * @ingroup dvrt_base
  159. * @brief set polling receive mode for task report
  160. * @param [out] NA
  161. * @return RT_ERROR_NONE for ok
  162. */
  163. RTS_API rtError_t rtSetPollingMode();
  164. /**
  165. * @ingroup dvrt_base
  166. * @brief register callback for error code
  167. * @param [out] NA
  168. * @return RT_ERROR_NONE for ok
  169. */
  170. RTS_API rtError_t rtSetExceptCallback(rtErrorCallback callback);
  171. /**
  172. * @ingroup dvrt_base
  173. * @brief notify handle.
  174. */
  175. typedef void *rtNotify_t;
  176. /**
  177. * @ingroup dvrt_base
  178. * @brief create label instance
  179. * @param [out] label created label
  180. * @return RT_ERROR_NONE for ok
  181. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  182. */
  183. RTS_API rtError_t rtLabelCreate(rtLabel_t *label);
  184. /**
  185. * @ingroup dvrt_base
  186. * @brief set label and stream instance
  187. * @param [in] label set label
  188. * @param [in] stream set stream
  189. * @return RT_ERROR_NONE for ok
  190. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  191. */
  192. RTS_API rtError_t rtLabelSet(rtLabel_t label, rtStream_t stream);
  193. /**
  194. * @ingroup dvrt_base
  195. * @brief destroy label instance
  196. * @param [in] label label to destroy
  197. * @return RT_ERROR_NONE for ok
  198. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  199. */
  200. RTS_API rtError_t rtLabelDestroy(rtLabel_t label);
  201. /**
  202. * @ingroup dvrt_base
  203. * @brief label switch instance
  204. * @param [in] ptr address to get value compared
  205. * @param [in] condition
  206. * @param [in] value to compare
  207. * @param [in] true_label goto label
  208. * @param [in] stream to submit label_switch task
  209. * @return RT_ERROR_NONE for ok
  210. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  211. */
  212. RTS_API rtError_t rtLabelSwitch(void *ptr, rtCondition_t condition, uint32_t value, rtLabel_t trueLabel,
  213. rtStream_t stream);
  214. /**
  215. * @ingroup dvrt_base
  216. * @brief goto label instance
  217. * @param [in] label goto label
  218. * @param [in] stream to submit label_goto task
  219. * @return RT_ERROR_NONE for ok
  220. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  221. */
  222. RTS_API rtError_t rtLabelGoto(rtLabel_t label, rtStream_t stream);
  223. /**
  224. * @ingroup dvrt_base
  225. * @brief name label instance
  226. * @param [in] label instance
  227. * @param [in] name label name
  228. * @return RT_ERROR_NONE for ok
  229. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  230. */
  231. RTS_API rtError_t rtNameLabel(rtLabel_t label, const char *name);
  232. /**
  233. * @ingroup dvrt_base
  234. * @brief label switch by index
  235. * @param [in] ptr index value ptr
  236. * @param [in] max index max value
  237. * @param [in] labelInfoPtr label content info ptr
  238. * @param [in] stream set stream
  239. * @return RT_ERROR_NONE for ok
  240. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  241. */
  242. RTS_API rtError_t rtLabelSwitchByIndex(void *ptr, uint32_t max, void *labelInfoPtr, rtStream_t stream);
  243. /**
  244. * @ingroup dvrt_base
  245. * @brief stream goto label
  246. * @param [in] label goto label
  247. * @param [in] stream stream to submit label_goto task
  248. * @return RT_ERROR_NONE for ok
  249. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  250. */
  251. RTS_API rtError_t rtLabelGotoEx(rtLabel_t label, rtStream_t stream);
  252. /**
  253. * @ingroup dvrt_base
  254. * @brief labels to dev info
  255. * @param [in] label model label list
  256. * @param [in] labelNumber label number
  257. * @param [in] dst device ptr
  258. * @param [in] dstMax dst size
  259. * @return RT_ERROR_NONE for ok
  260. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  261. */
  262. RTS_API rtError_t rtLabelListCpy(rtLabel_t *label, uint32_t labelNumber, void *dst, uint32_t dstMax);
  263. /**
  264. * @ingroup dvrt_base
  265. * @brief labels to dev info
  266. * @param [out] label created label handle
  267. * @param [in] stream label bind stream
  268. * @return RT_ERROR_NONE for ok
  269. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  270. */
  271. RTS_API rtError_t rtLabelCreateEx(rtLabel_t *label, rtStream_t stream);
  272. #ifdef __cplusplus
  273. }
  274. #endif
  275. #endif // __CCE_RUNTIME_BASE_H__

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