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_base.h 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /**
  2. * @file acl_base.h
  3. *
  4. * Copyright (C) Huawei Technologies Co., Ltd. 2019-2020. All Rights Reserved.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. */
  10. #ifndef INC_EXTERNAL_ACL_ACL_BASE_H_
  11. #define INC_EXTERNAL_ACL_ACL_BASE_H_
  12. #include <stdint.h>
  13. #include <stddef.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #ifdef FUNC_VISIBILITY
  18. #define ACL_FUNC_VISIBILITY __attribute__((visibility("default")))
  19. #else
  20. #define ACL_FUNC_VISIBILITY
  21. #endif
  22. typedef void *aclrtStream;
  23. typedef void *aclrtEvent;
  24. typedef void *aclrtContext;
  25. typedef int aclError;
  26. typedef uint16_t aclFloat16;
  27. typedef struct aclDataBuffer aclDataBuffer;
  28. typedef struct aclTensorDesc aclTensorDesc;
  29. const int ACL_ERROR_NONE = 0;
  30. const int ACL_ERROR_INVALID_PARAM = 100000;
  31. const int ACL_ERROR_UNINITIALIZE = 100001;
  32. const int ACL_ERROR_REPEAT_INITIALIZE = 100002;
  33. const int ACL_ERROR_INVALID_FILE = 100003;
  34. const int ACL_ERROR_WRITE_FILE = 100004;
  35. const int ACL_ERROR_INVALID_FILE_SIZE = 100005;
  36. const int ACL_ERROR_PARSE_FILE = 100006;
  37. const int ACL_ERROR_FILE_MISSING_ATTR = 100007;
  38. const int ACL_ERROR_FILE_ATTR_INVALID = 100008;
  39. const int ACL_ERROR_INVALID_DUMP_CONFIG = 100009;
  40. const int ACL_ERROR_INVALID_PROFILING_CONFIG = 100010;
  41. const int ACL_ERROR_INVALID_MODEL_ID = 100011;
  42. const int ACL_ERROR_DESERIALIZE_MODEL = 100012;
  43. const int ACL_ERROR_PARSE_MODEL = 100013;
  44. const int ACL_ERROR_READ_MODEL_FAILURE = 100014;
  45. const int ACL_ERROR_MODEL_SIZE_INVALID = 100015;
  46. const int ACL_ERROR_MODEL_MISSING_ATTR = 100016;
  47. const int ACL_ERROR_MODEL_INPUT_NOT_MATCH = 100017;
  48. const int ACL_ERROR_MODEL_OUTPUT_NOT_MATCH = 100018;
  49. const int ACL_ERROR_MODEL_NOT_DYNAMIC = 100019;
  50. const int ACL_ERROR_OP_TYPE_NOT_MATCH = 100020;
  51. const int ACL_ERROR_OP_INPUT_NOT_MATCH = 100021;
  52. const int ACL_ERROR_OP_OUTPUT_NOT_MATCH = 100022;
  53. const int ACL_ERROR_OP_ATTR_NOT_MATCH = 100023;
  54. const int ACL_ERROR_OP_NOT_FOUND = 100024;
  55. const int ACL_ERROR_OP_LOAD_FAILED = 100025;
  56. const int ACL_ERROR_UNSUPPORTED_DATA_TYPE = 100026;
  57. const int ACL_ERROR_FORMAT_NOT_MATCH = 100027;
  58. const int ACL_ERROR_BIN_SELECTOR_NOT_REGISTERED = 100028;
  59. const int ACL_ERROR_KERNEL_NOT_FOUND = 100029;
  60. const int ACL_ERROR_BIN_SELECTOR_ALREADY_REGISTERED = 100030;
  61. const int ACL_ERROR_KERNEL_ALREADY_REGISTERED = 100031;
  62. const int ACL_ERROR_INVALID_QUEUE_ID = 100032;
  63. const int ACL_ERROR_REPEAT_SUBSCRIBE = 100033;
  64. const int ACL_ERROR_STREAM_NOT_SUBSCRIBE = 100034;
  65. const int ACL_ERROR_THREAD_NOT_SUBSCRIBE = 100035;
  66. const int ACL_ERROR_WAIT_CALLBACK_TIMEOUT = 100036;
  67. const int ACL_ERROR_REPEAT_FINALIZE = 100037;
  68. const int ACL_ERROR_NOT_STATIC_AIPP = 100038;
  69. const int ACL_ERROR_BAD_ALLOC = 200000;
  70. const int ACL_ERROR_API_NOT_SUPPORT = 200001;
  71. const int ACL_ERROR_INVALID_DEVICE = 200002;
  72. const int ACL_ERROR_MEMORY_ADDRESS_UNALIGNED = 200003;
  73. const int ACL_ERROR_RESOURCE_NOT_MATCH = 200004;
  74. const int ACL_ERROR_INVALID_RESOURCE_HANDLE = 200005;
  75. const int ACL_ERROR_FEATURE_UNSUPPORTED = 200006;
  76. const int ACL_ERROR_STORAGE_OVER_LIMIT = 300000;
  77. const int ACL_ERROR_INTERNAL_ERROR = 500000;
  78. const int ACL_ERROR_FAILURE = 500001;
  79. const int ACL_ERROR_GE_FAILURE = 500002;
  80. const int ACL_ERROR_RT_FAILURE = 500003;
  81. const int ACL_ERROR_DRV_FAILURE = 500004;
  82. const int ACL_ERROR_PROFILING_FAILURE = 500005;
  83. typedef enum {
  84. ACL_DT_UNDEFINED = -1,
  85. ACL_FLOAT = 0,
  86. ACL_FLOAT16 = 1,
  87. ACL_INT8 = 2,
  88. ACL_INT32 = 3,
  89. ACL_UINT8 = 4,
  90. ACL_INT16 = 6,
  91. ACL_UINT16 = 7,
  92. ACL_UINT32 = 8,
  93. ACL_INT64 = 9,
  94. ACL_UINT64 = 10,
  95. ACL_DOUBLE = 11,
  96. ACL_BOOL = 12,
  97. } aclDataType;
  98. typedef enum {
  99. ACL_FORMAT_UNDEFINED = -1,
  100. ACL_FORMAT_NCHW = 0,
  101. ACL_FORMAT_NHWC = 1,
  102. ACL_FORMAT_ND = 2,
  103. ACL_FORMAT_NC1HWC0 = 3,
  104. ACL_FORMAT_FRACTAL_Z = 4,
  105. ACL_FORMAT_FRACTAL_NZ = 29,
  106. } aclFormat;
  107. typedef enum {
  108. ACL_DEBUG = 0,
  109. ACL_INFO = 1,
  110. ACL_WARNING = 2,
  111. ACL_ERROR = 3,
  112. } aclLogLevel;
  113. /**
  114. * @ingroup AscendCL
  115. * @brief Converts data of type aclFloat16 to data of type float
  116. *
  117. * @param value [IN] Data to be converted
  118. * @retval Transformed data
  119. */
  120. ACL_FUNC_VISIBILITY float aclFloat16ToFloat(aclFloat16 value);
  121. /**
  122. * @ingroup AscendCL
  123. * @brief Converts data of type float to data of type aclFloat16
  124. *
  125. * @param value [IN] Data to be converted
  126. * @retval Transformed data
  127. */
  128. ACL_FUNC_VISIBILITY aclFloat16 aclFloatToFloat16(float value);
  129. /**
  130. * @ingroup AscendCL
  131. * @brief create data of aclDataBuffer
  132. *
  133. * @param data [IN] pointer to data
  134. * @li Need to be managed by the user,
  135. * call aclrtMalloc interface to apply for memory,
  136. * call aclrtFree interface to release memory
  137. * @param size [IN] size of data in bytes
  138. * @retval pointer to created instance. nullptr if run out of memory
  139. *
  140. * @see aclrtMalloc | aclrtFree
  141. */
  142. ACL_FUNC_VISIBILITY aclDataBuffer *aclCreateDataBuffer(void *data, size_t size);
  143. /**
  144. * @ingroup AscendCL
  145. * @brief destroy data of aclDataBuffer
  146. *
  147. * @par Function
  148. * Only the aclDataBuffer type data is destroyed here.
  149. * The memory of the data passed in when the aclDataDataBuffer interface
  150. * is called to create aclDataBuffer type data must be released by the user
  151. * @param dataBuffer [IN] pointer to the aclDataBuffer
  152. * @retval ACL_ERROR_NONE The function is successfully executed.
  153. * @retval OtherValues Failure
  154. *
  155. * @see aclCreateDataBuffer
  156. */
  157. ACL_FUNC_VISIBILITY aclError aclDestroyDataBuffer(const aclDataBuffer *dataBuffer);
  158. /**
  159. * @ingroup AscendCL
  160. * @brief get data address from aclDataBuffer
  161. *
  162. * @param dataBuffer [IN] pointer to the data of aclDataBuffer
  163. * @retval data address
  164. */
  165. ACL_FUNC_VISIBILITY void *aclGetDataBufferAddr(const aclDataBuffer *dataBuffer);
  166. /**
  167. * @ingroup AscendCL
  168. * @brief get data size of aclDataBuffer
  169. *
  170. * @param dataBuffer [IN] pointer to the data of aclDataBuffer
  171. * @retval data size
  172. */
  173. ACL_FUNC_VISIBILITY uint32_t aclGetDataBufferSize(const aclDataBuffer *dataBuffer);
  174. /**
  175. * @ingroup AscendCL
  176. * @brief get size of aclDataType
  177. *
  178. * @param dataType [IN] aclDataType data the size to get
  179. * @retval size of the aclDataType
  180. */
  181. ACL_FUNC_VISIBILITY size_t aclDataTypeSize(aclDataType dataType);
  182. // interfaces of tensor desc
  183. /**
  184. * @ingroup AscendCL
  185. * @brief create data aclTensorDesc
  186. *
  187. * @param dataType [IN] Data types described by tensor
  188. * @param numDims [IN] the number of dimensions of the shape
  189. * @param dims [IN] the size of the specified dimension
  190. * @param format [IN] tensor format
  191. * @retval aclTensorDesc pointer.
  192. * @retval nullptr if param is invalid or run out of memory
  193. */
  194. ACL_FUNC_VISIBILITY aclTensorDesc *aclCreateTensorDesc(aclDataType dataType,
  195. int numDims,
  196. const int64_t *dims,
  197. aclFormat format);
  198. /**
  199. * @ingroup AscendCL
  200. * @brief destroy data aclTensorDesc
  201. *
  202. * @param desc [IN] pointer to the data of aclTensorDesc to destroy
  203. */
  204. ACL_FUNC_VISIBILITY void aclDestroyTensorDesc(const aclTensorDesc *desc);
  205. /**
  206. * @ingroup AscendCL
  207. * @brief get data type specified by the tensor description
  208. *
  209. * @param desc [IN] pointer to the instance of aclTensorDesc
  210. * @retval data type specified by the tensor description.
  211. * @retval ACL_DT_UNDEFINED if description is null
  212. */
  213. ACL_FUNC_VISIBILITY aclDataType aclGetTensorDescType(const aclTensorDesc *desc);
  214. /**
  215. * @ingroup AscendCL
  216. * @brief get data format specified by the tensor description
  217. *
  218. * @param desc [IN] pointer to the instance of aclTensorDesc
  219. * @retval data format specified by the tensor description.
  220. * @retval ACL_FORMAT_UNDEFINED if description is null
  221. */
  222. ACL_FUNC_VISIBILITY aclFormat aclGetTensorDescFormat(const aclTensorDesc *desc);
  223. /**
  224. * @ingroup AscendCL
  225. * @brief get tensor size specified by the tensor description
  226. *
  227. * @param desc [IN] pointer to the instance of aclTensorDesc
  228. * @retval data size specified by the tensor description.
  229. * @retval 0 if description is null
  230. */
  231. ACL_FUNC_VISIBILITY size_t aclGetTensorDescSize(const aclTensorDesc *desc);
  232. /**
  233. * @ingroup AscendCL
  234. * @brief get element count specified by the tensor description
  235. *
  236. * @param desc [IN] pointer to the instance of aclTensorDesc
  237. * @retval element count specified by the tensor description.
  238. * @retval 0 if description is null
  239. */
  240. ACL_FUNC_VISIBILITY size_t aclGetTensorDescElementCount(const aclTensorDesc *desc);
  241. /**
  242. * @ingroup AscendCL
  243. * @brief get number of dims specified by the tensor description
  244. *
  245. * @param desc [IN] pointer to the instance of aclTensorDesc
  246. * @retval number of dims specified by the tensor description.
  247. * @retval 0 if description is null
  248. */
  249. ACL_FUNC_VISIBILITY size_t aclGetTensorDescNumDims(const aclTensorDesc *desc);
  250. /**
  251. * @ingroup AscendCL
  252. * @brief Get the size of the specified dim in the tensor description
  253. *
  254. * @param desc [IN] pointer to the instance of aclTensorDesc
  255. * @param index [IN] index of dims, start from 0.
  256. * @retval dim specified by the tensor description and index.
  257. * @retval -1 if description or index is invalid
  258. */
  259. ACL_FUNC_VISIBILITY int64_t aclGetTensorDescDim(const aclTensorDesc *desc, size_t index);
  260. /**
  261. * @ingroup AscendCL
  262. * @brief set tensor description name
  263. *
  264. * @param desc [IN] pointer to the instance of aclTensorDesc
  265. * @param name [IN] tensor description name
  266. */
  267. ACL_FUNC_VISIBILITY void aclSetTensorDescName(aclTensorDesc *desc, const char *name);
  268. /**
  269. * @ingroup AscendCL
  270. * @brief get tensor description name
  271. *
  272. * @param desc [IN] pointer to the instance of aclTensorDesc
  273. * @retval tensor description name.
  274. * @retval empty string if description is null
  275. */
  276. ACL_FUNC_VISIBILITY const char *aclGetTensorDescName(aclTensorDesc *desc);
  277. /**
  278. * @ingroup AscendCL
  279. * @brief Convert the format in the source aclTensorDesc according to
  280. * the specified dstFormat to generate a new target aclTensorDesc.
  281. * The format in the source aclTensorDesc remains unchanged.
  282. *
  283. * @param srcDesc [IN] pointer to the source tensor desc
  284. * @param dstFormat [IN] destination format
  285. * @param dstDesc [OUT] pointer to the pointer to the destination tensor desc
  286. * @retval ACL_ERROR_NONE The function is successfully executed.
  287. * @retval OtherValues Failure
  288. */
  289. ACL_FUNC_VISIBILITY aclError aclTransTensorDescFormat(const aclTensorDesc *srcDesc, aclFormat dstFormat,
  290. aclTensorDesc **dstDesc);
  291. /**
  292. * @ingroup AscendCL
  293. * @brief Set the storage format specified by the tensor description
  294. *
  295. * @param desc [IN|OUT] pointer to the instance of aclTensorDesc
  296. * @param format [IN] the storage format
  297. * @retval ACL_ERROR_NONE The function is successfully executed.
  298. * @retval OtherValues Failure
  299. */
  300. ACL_FUNC_VISIBILITY aclError aclSetTensorStorageFormat(aclTensorDesc *desc, aclFormat format);
  301. /**
  302. * @ingroup AscendCL
  303. * @brief Set the storage shape specified by the tensor description
  304. *
  305. * @param desc [IN|OUT] pointer to the instance of aclTensorDesc
  306. * @param numDims [IN] the number of dimensions of the shape
  307. * @param dims [IN] the size of the specified dimension
  308. * @retval ACL_ERROR_NONE The function is successfully executed.
  309. * @retval OtherValues Failure
  310. */
  311. ACL_FUNC_VISIBILITY aclError aclSetTensorStorageShape(aclTensorDesc *desc, int numDims, const int64_t *dims);
  312. /**
  313. * @ingroup AscendCL
  314. * @brief an interface for users to output APP logs
  315. *
  316. * @param logLevel [IN] the level of current log
  317. * @param func [IN] the function where the log is located
  318. * @param file [IN] the file where the log is located
  319. * @param line [IN] Number of source lines where the log is located
  320. * @param fmt [IN] the format of current log
  321. * @param ... [IN] the value of current log
  322. */
  323. ACL_FUNC_VISIBILITY void aclAppLog(aclLogLevel logLevel, const char *func, const char *file, uint32_t line,
  324. const char *fmt, ...);
  325. #define ACL_APP_LOG(level, fmt, ...) \
  326. aclAppLog(level, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  327. #ifdef __cplusplus
  328. }
  329. #endif
  330. #endif // INC_EXTERNAL_ACL_ACL_BASE_H_

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台