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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 struct rtExceptionInfo {
  107. uint32_t taskid;
  108. uint32_t streamid;
  109. uint32_t tid;
  110. } rtExceptionInfo;
  111. typedef void (*rtErrorCallback)(rtExceptionType);
  112. typedef void (*rtTaskFailCallback)(rtExceptionInfo *exceptionInfo);
  113. /**
  114. * @ingroup dvrt_base
  115. * @brief stream handle.
  116. */
  117. typedef void *rtStream_t;
  118. /**
  119. * @ingroup dvrt_base
  120. * @brief runtime event handle.
  121. */
  122. typedef void *rtEvent_t;
  123. /**
  124. * @ingroup dvrt_base
  125. * @brief label handle.
  126. */
  127. typedef void *rtLabel_t;
  128. /**
  129. * @ingroup profiling_base
  130. * @brief runtime handle.
  131. */
  132. RTS_API rtError_t rtSetProfDirEx(const char *profDir, const char *address, const char *jobCtx);
  133. /**
  134. * @ingroup profiling_base
  135. * @brief init profiler object.
  136. */
  137. RTS_API rtError_t rtProfilerInit(const char *profdir, const char *address, const char *job_ctx);
  138. /**
  139. * @ingroup profiling_base
  140. * @brief start rts profiler.
  141. */
  142. RTS_API rtError_t rtProfilerStart(void);
  143. /**
  144. * @ingroup profiling_base
  145. * @brief stop rts profiler.
  146. */
  147. RTS_API rtError_t rtProfilerStop(void);
  148. /**
  149. * @ingroup profiling_base
  150. * @brief ts send keypoint profiler log.
  151. */
  152. RTS_API rtError_t rtProfilerTrace(uint64_t id, bool notify, uint32_t flags, rtStream_t stream);
  153. /**
  154. * @ingroup dvrt_base
  155. * @brief Returns the last error from a runtime call.
  156. */
  157. RTS_API rtError_t rtGetLastError();
  158. /**
  159. * @ingroup dvrt_base
  160. * @brief Returns the last error from a runtime call.
  161. */
  162. RTS_API rtError_t rtPeekAtLastError();
  163. /**
  164. * @ingroup dvrt_base
  165. * @brief set polling receive mode for task report
  166. * @param [out] NA
  167. * @return RT_ERROR_NONE for ok
  168. */
  169. RTS_API rtError_t rtSetPollingMode();
  170. /**
  171. * @ingroup dvrt_base
  172. * @brief register callback for error code
  173. * @param [out] NA
  174. * @return RT_ERROR_NONE for ok
  175. */
  176. RTS_API rtError_t rtSetExceptCallback(rtErrorCallback callback);
  177. /**
  178. * @ingroup dvrt_base
  179. * @brief register callback for task fail
  180. * @param [out] NA
  181. * @return RT_ERROR_NONE for ok
  182. */
  183. RTS_API rtError_t rtSetTaskFailCallback(rtTaskFailCallback callback);
  184. /**
  185. * @ingroup dvrt_base
  186. * @brief notify handle.
  187. */
  188. typedef void *rtNotify_t;
  189. /**
  190. * @ingroup dvrt_base
  191. * @brief create label instance
  192. * @param [out] label created label
  193. * @return RT_ERROR_NONE for ok
  194. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  195. */
  196. RTS_API rtError_t rtLabelCreate(rtLabel_t *label);
  197. /**
  198. * @ingroup dvrt_base
  199. * @brief set label and stream instance
  200. * @param [in] label set label
  201. * @param [in] stream set stream
  202. * @return RT_ERROR_NONE for ok
  203. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  204. */
  205. RTS_API rtError_t rtLabelSet(rtLabel_t label, rtStream_t stream);
  206. /**
  207. * @ingroup dvrt_base
  208. * @brief destroy label instance
  209. * @param [in] label label to destroy
  210. * @return RT_ERROR_NONE for ok
  211. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  212. */
  213. RTS_API rtError_t rtLabelDestroy(rtLabel_t label);
  214. /**
  215. * @ingroup dvrt_base
  216. * @brief label switch instance
  217. * @param [in] ptr address to get value compared
  218. * @param [in] condition
  219. * @param [in] value to compare
  220. * @param [in] true_label goto label
  221. * @param [in] stream to submit label_switch task
  222. * @return RT_ERROR_NONE for ok
  223. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  224. */
  225. RTS_API rtError_t rtLabelSwitch(void *ptr, rtCondition_t condition, uint32_t value, rtLabel_t trueLabel,
  226. rtStream_t stream);
  227. /**
  228. * @ingroup dvrt_base
  229. * @brief goto label instance
  230. * @param [in] label goto label
  231. * @param [in] stream to submit label_goto task
  232. * @return RT_ERROR_NONE for ok
  233. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  234. */
  235. RTS_API rtError_t rtLabelGoto(rtLabel_t label, rtStream_t stream);
  236. /**
  237. * @ingroup dvrt_base
  238. * @brief name label instance
  239. * @param [in] label instance
  240. * @param [in] name label name
  241. * @return RT_ERROR_NONE for ok
  242. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  243. */
  244. RTS_API rtError_t rtNameLabel(rtLabel_t label, const char *name);
  245. /**
  246. * @ingroup dvrt_base
  247. * @brief label switch by index
  248. * @param [in] ptr index value ptr
  249. * @param [in] max index max value
  250. * @param [in] labelInfoPtr label content info ptr
  251. * @param [in] stream set stream
  252. * @return RT_ERROR_NONE for ok
  253. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  254. */
  255. RTS_API rtError_t rtLabelSwitchByIndex(void *ptr, uint32_t max, void *labelInfoPtr, rtStream_t stream);
  256. /**
  257. * @ingroup dvrt_base
  258. * @brief stream goto label
  259. * @param [in] label goto label
  260. * @param [in] stream stream to submit label_goto task
  261. * @return RT_ERROR_NONE for ok
  262. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  263. */
  264. RTS_API rtError_t rtLabelGotoEx(rtLabel_t label, rtStream_t stream);
  265. /**
  266. * @ingroup dvrt_base
  267. * @brief labels to dev info
  268. * @param [in] label model label list
  269. * @param [in] labelNumber label number
  270. * @param [in] dst device ptr
  271. * @param [in] dstMax dst size
  272. * @return RT_ERROR_NONE for ok
  273. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  274. */
  275. RTS_API rtError_t rtLabelListCpy(rtLabel_t *label, uint32_t labelNumber, void *dst, uint32_t dstMax);
  276. /**
  277. * @ingroup dvrt_base
  278. * @brief labels to dev info
  279. * @param [out] label created label handle
  280. * @param [in] stream label bind stream
  281. * @return RT_ERROR_NONE for ok
  282. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input handle
  283. */
  284. RTS_API rtError_t rtLabelCreateEx(rtLabel_t *label, rtStream_t stream);
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288. #endif // __CCE_RUNTIME_BASE_H__

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