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_mdl.h 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /**
  2. * @file acl_mdl.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_MODEL_H_
  11. #define INC_EXTERNAL_ACL_ACL_MODEL_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include "acl_base.h"
  15. #include "acl_rt.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define ACL_MAX_DIM_CNT 128
  20. #define ACL_MAX_TENSOR_NAME_LEN 128
  21. #define ACL_MAX_BATCH_NUM 128
  22. #define ACL_MAX_HW_NUM 128
  23. #define ACL_MAX_SHAPE_COUNT 128
  24. #define ACL_DYNAMIC_TENSOR_NAME "ascend_mbatch_shape_data"
  25. #define ACL_DYNAMIC_AIPP_NAME "ascend_dynamic_aipp_data"
  26. typedef struct aclmdlDataset aclmdlDataset;
  27. typedef struct aclmdlDesc aclmdlDesc;
  28. typedef struct aclmdlAIPP aclmdlAIPP;
  29. typedef struct aclAippExtendInfo aclAippExtendInfo;
  30. typedef enum {
  31. ACL_YUV420SP_U8 = 1,
  32. ACL_XRGB8888_U8,
  33. ACL_RGB888_U8,
  34. ACL_YUV400_U8,
  35. ACL_NC1HWC0DI_FP16,
  36. ACL_NC1HWC0DI_S8,
  37. ACL_ARGB8888_U8,
  38. ACL_YUYV_U8,
  39. ACL_YUV422SP_U8,
  40. ACL_AYUV444_U8,
  41. ACL_RAW10,
  42. ACL_RAW12,
  43. ACL_RAW16,
  44. ACL_RAW24,
  45. ACL_AIPP_RESERVED = 0xffff,
  46. } aclAippInputFormat;
  47. typedef struct aclmdlIODims {
  48. char name[ACL_MAX_TENSOR_NAME_LEN]; /**< tensor name */
  49. size_t dimCount; /**< dim array count */
  50. int64_t dims[ACL_MAX_DIM_CNT]; /**< dim data array */
  51. } aclmdlIODims;
  52. typedef struct aclAippDims {
  53. aclmdlIODims srcDims; /**< input dims before model transform */
  54. size_t srcSize; /**< input size before model transform */
  55. aclmdlIODims aippOutdims; /**< aipp output dims */
  56. size_t aippOutSize; /**< aipp output size */
  57. } aclAippDims;
  58. typedef struct aclmdlBatch {
  59. size_t batchCount; /**< batch array count */
  60. uint64_t batch[ACL_MAX_BATCH_NUM]; /**< batch data array */
  61. } aclmdlBatch;
  62. typedef struct aclmdlHW {
  63. size_t hwCount; /**< height&width array count */
  64. uint64_t hw[ACL_MAX_HW_NUM][2]; /**< height&width data array */
  65. } aclmdlHW;
  66. typedef struct aclAippInfo {
  67. aclAippInputFormat inputFormat;
  68. int32_t srcImageSizeW;
  69. int32_t srcImageSizeH;
  70. int8_t cropSwitch;
  71. int32_t loadStartPosW;
  72. int32_t loadStartPosH;
  73. int32_t cropSizeW;
  74. int32_t cropSizeH;
  75. int8_t resizeSwitch;
  76. int32_t resizeOutputW;
  77. int32_t resizeOutputH;
  78. int8_t paddingSwitch;
  79. int32_t leftPaddingSize;
  80. int32_t rightPaddingSize;
  81. int32_t topPaddingSize;
  82. int32_t bottomPaddingSize;
  83. int8_t cscSwitch;
  84. int8_t rbuvSwapSwitch;
  85. int8_t axSwapSwitch;
  86. int8_t singleLineMode;
  87. int32_t matrixR0C0;
  88. int32_t matrixR0C1;
  89. int32_t matrixR0C2;
  90. int32_t matrixR1C0;
  91. int32_t matrixR1C1;
  92. int32_t matrixR1C2;
  93. int32_t matrixR2C0;
  94. int32_t matrixR2C1;
  95. int32_t matrixR2C2;
  96. int32_t outputBias0;
  97. int32_t outputBias1;
  98. int32_t outputBias2;
  99. int32_t inputBias0;
  100. int32_t inputBias1;
  101. int32_t inputBias2;
  102. int32_t meanChn0;
  103. int32_t meanChn1;
  104. int32_t meanChn2;
  105. int32_t meanChn3;
  106. float minChn0;
  107. float minChn1;
  108. float minChn2;
  109. float minChn3;
  110. float varReciChn0;
  111. float varReciChn1;
  112. float varReciChn2;
  113. float varReciChn3;
  114. aclFormat srcFormat;
  115. aclDataType srcDatatype;
  116. size_t srcDimNum;
  117. size_t shapeCount;
  118. aclAippDims outDims[ACL_MAX_SHAPE_COUNT];
  119. aclAippExtendInfo *aippExtend; /**< reserved parameters, current version needs to be null */
  120. } aclAippInfo;
  121. /**
  122. * @ingroup AscendCL
  123. * @brief Create data of type aclmdlDesc
  124. *
  125. * @retval the aclmdlDesc pointer
  126. */
  127. ACL_FUNC_VISIBILITY aclmdlDesc *aclmdlCreateDesc();
  128. /**
  129. * @ingroup AscendCL
  130. * @brief destroy data of type aclmdlDesc
  131. *
  132. * @param modelDesc [IN] Pointer to almdldlDesc to be destroyed
  133. * @retval ACL_ERROR_NONE The function is successfully executed.
  134. * @retval OtherValues Failure
  135. */
  136. ACL_FUNC_VISIBILITY aclError aclmdlDestroyDesc(aclmdlDesc *modelDesc);
  137. /**
  138. * @ingroup AscendCL
  139. * @brief Get aclmdlDesc data of the model according to the model ID
  140. *
  141. * @param modelDesc [OUT] aclmdlDesc pointer
  142. * @param modelId [IN] model id
  143. * @retval ACL_ERROR_NONE The function is successfully executed.
  144. * @retval OtherValues Failure
  145. */
  146. ACL_FUNC_VISIBILITY aclError aclmdlGetDesc(aclmdlDesc *modelDesc, uint32_t modelId);
  147. /**
  148. * @ingroup AscendCL
  149. * @brief Get the number of the inputs of
  150. * the model according to data of aclmdlDesc
  151. *
  152. * @param modelDesc [IN] aclmdlDesc pointer
  153. * @retval input size with aclmdlDesc
  154. */
  155. ACL_FUNC_VISIBILITY size_t aclmdlGetNumInputs(aclmdlDesc *modelDesc);
  156. /**
  157. * @ingroup AscendCL
  158. * @brief Get the number of the output of
  159. * the model according to data of aclmdlDesc
  160. *
  161. * @param modelDesc [IN] aclmdlDesc pointer
  162. * @retval output size with aclmdlDesc
  163. */
  164. ACL_FUNC_VISIBILITY size_t aclmdlGetNumOutputs(aclmdlDesc *modelDesc);
  165. /**
  166. * @ingroup AscendCL
  167. * @brief Get the size of the specified input according to
  168. * the data of type aclmdlDesc
  169. *
  170. * @param modelDesc [IN] aclmdlDesc pointer
  171. * @param index [IN] the size of the number of inputs to be obtained,
  172. * the index value starts from 0
  173. * @retval Specify the size of the input
  174. */
  175. ACL_FUNC_VISIBILITY size_t aclmdlGetInputSizeByIndex(aclmdlDesc *modelDesc, size_t index);
  176. /**
  177. * @ingroup AscendCL
  178. * @brief Get the size of the specified output according to
  179. * the data of type aclmdlDesc
  180. *
  181. * @param modelDesc [IN] aclmdlDesc pointer
  182. * @param index [IN] the size of the number of outputs to be obtained,
  183. * the index value starts from 0
  184. * @retval Specify the size of the output
  185. */
  186. ACL_FUNC_VISIBILITY size_t aclmdlGetOutputSizeByIndex(aclmdlDesc *modelDesc, size_t index);
  187. /**
  188. * @ingroup AscendCL
  189. * @brief Create data of type aclmdlDataset
  190. *
  191. * @retval the aclmdlDataset pointer
  192. */
  193. ACL_FUNC_VISIBILITY aclmdlDataset *aclmdlCreateDataset();
  194. /**
  195. * @ingroup AscendCL
  196. * @brief destroy data of type aclmdlDataset
  197. *
  198. * @param dataset [IN] Pointer to aclmdlDataset to be destroyed
  199. * @retval ACL_ERROR_NONE The function is successfully executed.
  200. * @retval OtherValues Failure
  201. */
  202. ACL_FUNC_VISIBILITY aclError aclmdlDestroyDataset(const aclmdlDataset *dataset);
  203. /**
  204. * @ingroup AscendCL
  205. * @brief Add aclDataBuffer to aclmdlDataset
  206. *
  207. * @param dataset [IN|OUT] aclmdlDataset address of aclDataBuffer to be added
  208. * @param dataBuffer [IN] aclDataBuffer address to be added
  209. * @retval ACL_ERROR_NONE The function is successfully executed.
  210. * @retval OtherValues Failure
  211. */
  212. ACL_FUNC_VISIBILITY aclError aclmdlAddDatasetBuffer(aclmdlDataset *dataset,
  213. aclDataBuffer *dataBuffer);
  214. /**
  215. * @ingroup AscendCL
  216. * @brief Get the number of aclDataBuffer in aclmdlDataset
  217. *
  218. * @param dataset [IN] aclmdlDataset poiter
  219. * @retval the number of aclDataBuffer
  220. */
  221. ACL_FUNC_VISIBILITY size_t aclmdlGetDatasetNumBuffers(const aclmdlDataset *dataset);
  222. /**
  223. * @ingroup AscendCL
  224. * @brief Get the aclDataBuffer in aclmdlDataset by index
  225. *
  226. * @param dataset [IN] aclmdlDataset poiter
  227. * @param index [IN] the index of aclDataBuffer
  228. * @retval Get successfully, return the address of aclDataBuffer
  229. * @retval Failure return NULL
  230. */
  231. ACL_FUNC_VISIBILITY aclDataBuffer *aclmdlGetDatasetBuffer(const aclmdlDataset *dataset,
  232. size_t index);
  233. /**
  234. * @ingroup AscendCL
  235. * @brief Load offline model data from files
  236. * and manage memory internally by the system
  237. *
  238. * @par Function
  239. * After the system finishes loading the model,
  240. * the model ID returned is used as a mark to identify the model
  241. * during subsequent operations.
  242. * @param modelPath [IN] Storage path for offline model files
  243. * @param modelId [OUT] Model ID generated after
  244. * the system finishes loading the model
  245. * @retval ACL_ERROR_NONE The function is successfully executed.
  246. * @retval OtherValues Failure
  247. */
  248. ACL_FUNC_VISIBILITY aclError aclmdlLoadFromFile(const char *modelPath, uint32_t *modelId);
  249. /**
  250. * @ingroup AscendCL
  251. * @brief Load offline model data from memory and manage the memory of
  252. * model running internally by the system
  253. *
  254. * @par Function
  255. * After the system finishes loading the model,
  256. * the model ID returned is used as a mark to identify the model
  257. * during subsequent operations
  258. * @param model [IN] Model data stored in memory
  259. * @param modelSize [IN] model data size
  260. * @param modelId [OUT] Model ID generated after
  261. * the system finishes loading the model
  262. * @retval ACL_ERROR_NONE The function is successfully executed.
  263. * @retval OtherValues Failure
  264. */
  265. ACL_FUNC_VISIBILITY aclError aclmdlLoadFromMem(const void *model, size_t modelSize,
  266. uint32_t *modelId);
  267. /**
  268. * @ingroup AscendCL
  269. * @brief Load offline model data from a file,
  270. * and the user manages the memory of the model run by itself
  271. *
  272. * @par Function
  273. * After the system finishes loading the model,
  274. * the model ID returned is used as a mark to identify the model
  275. * during subsequent operations.
  276. * @param modelPath [IN] Storage path for offline model files
  277. * @param modelId [OUT] Model ID generated after finishes loading the model
  278. * @param workPtr [IN] A pointer to the working memory
  279. * required by the model on the Device,can be null
  280. * @param workSize [IN] The amount of working memory required by the model
  281. * @param weightPtr [IN] Pointer to model weight memory on Device
  282. * @param weightSize [IN] The amount of weight memory required by the model
  283. * @retval ACL_ERROR_NONE The function is successfully executed.
  284. * @retval OtherValues Failure
  285. */
  286. ACL_FUNC_VISIBILITY aclError aclmdlLoadFromFileWithMem(const char *modelPath,
  287. uint32_t *modelId, void *workPtr, size_t workSize,
  288. void *weightPtr, size_t weightSize);
  289. /**
  290. * @ingroup AscendCL
  291. * @brief Load offline model data from memory,
  292. * and the user can manage the memory of model running
  293. *
  294. * @par Function
  295. * After the system finishes loading the model,
  296. * the model ID returned is used as a mark to identify the model
  297. * during subsequent operations
  298. * @param model [IN] Model data stored in memory
  299. * @param modelSize [IN] model data size
  300. * @param modelId [OUT] Model ID generated after finishes loading the model
  301. * @param workPtr [IN] A pointer to the working memory
  302. * required by the model on the Device,can be null
  303. * @param workSize [IN] work memory size
  304. * @param weightPtr [IN] Pointer to model weight memory on Device,can be null
  305. * @param weightSize [IN] The amount of weight memory required by the model
  306. * @retval ACL_ERROR_NONE The function is successfully executed.
  307. * @retval OtherValues Failure
  308. */
  309. ACL_FUNC_VISIBILITY aclError aclmdlLoadFromMemWithMem(const void *model, size_t modelSize,
  310. uint32_t *modelId, void *workPtr, size_t workSize,
  311. void *weightPtr, size_t weightSize);
  312. /**
  313. * @ingroup AscendCL
  314. * @brief load model from file with async queue
  315. *
  316. * @param modelPath [IN] model path
  317. * @param modelId [OUT] return model id if load success
  318. * @param inputQ [IN] input queue pointer
  319. * @param inputQNum [IN] input queue num
  320. * @param outputQ [IN] output queue pointer
  321. * @param outputQNum [IN] output queue num
  322. * @retval ACL_ERROR_NONE The function is successfully executed.
  323. * @retval OtherValues Failure
  324. */
  325. ACL_FUNC_VISIBILITY aclError aclmdlLoadFromFileWithQ(const char *modelPath, uint32_t *modelId, const uint32_t *inputQ,
  326. size_t inputQNum, const uint32_t *outputQ, size_t outputQNum);
  327. /**
  328. * @ingroup AscendCL
  329. * @brief load model from memory with async queue
  330. *
  331. * @param model [IN] model memory which user manages
  332. * @param modelSize [IN] model size
  333. * @param modelId [OUT] return model id if load success
  334. * @param inputQ [IN] input queue pointer
  335. * @param inputQNum [IN] input queue num
  336. * @param outputQ [IN] output queue pointer
  337. * @param outputQNum [IN] output queue num
  338. * @retval ACL_ERROR_NONE The function is successfully executed.
  339. * @retval OtherValues Failure
  340. */
  341. ACL_FUNC_VISIBILITY aclError aclmdlLoadFromMemWithQ(const void *model, size_t modelSize, uint32_t *modelId,
  342. const uint32_t *inputQ, size_t inputQNum, const uint32_t *outputQ, size_t outputQNum);
  343. /**
  344. * @ingroup AscendCL
  345. * @brief Execute model synchronous inference until the inference result is returned
  346. *
  347. * @param modelId [IN] ID of the model to perform inference
  348. * @param input [IN] Input data for model inference
  349. * @param output [OUT] Output data for model inference
  350. * @retval ACL_ERROR_NONE The function is successfully executed.
  351. * @retval OtherValues Failure
  352. */
  353. ACL_FUNC_VISIBILITY aclError aclmdlExecute(uint32_t modelId, const aclmdlDataset *input,
  354. aclmdlDataset *output);
  355. /**
  356. * @ingroup AscendCL
  357. * @brief Execute model asynchronous inference until the inference result is returned
  358. *
  359. * @param modelId [IN] ID of the model to perform inference
  360. * @param input [IN] Input data for model inference
  361. * @param output [OUT] Output data for model inference
  362. * @param stream [IN] stream
  363. * @retval ACL_ERROR_NONE The function is successfully executed.
  364. * @retval OtherValues Failure
  365. *
  366. * @see aclmdlLoadFromFile | aclmdlLoadFromMem | aclmdlLoadFromFileWithMem |
  367. * aclmdlLoadFromMemWithMem
  368. */
  369. ACL_FUNC_VISIBILITY aclError aclmdlExecuteAsync(uint32_t modelId, const aclmdlDataset *input,
  370. aclmdlDataset *output, aclrtStream stream);
  371. /**
  372. * @ingroup AscendCL
  373. * @brief unload model with model id
  374. *
  375. * @param modelId [IN] model id to be unloaded
  376. * @retval ACL_ERROR_NONE The function is successfully executed.
  377. * @retval OtherValues Failure
  378. */
  379. ACL_FUNC_VISIBILITY aclError aclmdlUnload(uint32_t modelId);
  380. /**
  381. * @ingroup AscendCL
  382. * @brief Get the weight memory size and working memory size
  383. * required for model execution according to the model file
  384. *
  385. * @param fileName [IN] Model path to get memory information
  386. * @param workSize [OUT] The amount of working memory for model executed
  387. * @param weightSize [OUT] The amount of weight memory for model executed
  388. * @retval ACL_ERROR_NONE The function is successfully executed.
  389. * @retval OtherValues Failure
  390. */
  391. ACL_FUNC_VISIBILITY aclError aclmdlQuerySize(const char *fileName, size_t *workSize, size_t *weightSize);
  392. /**
  393. * @ingroup AscendCL
  394. * @brief Obtain the weights required for
  395. * model execution according to the model data in memory
  396. *
  397. * @par Restriction
  398. * The execution and weight memory is Device memory,
  399. * and requires user application and release.
  400. * @param model [IN] model memory which user manages
  401. * @param modelSize [IN] model data size
  402. * @param workSize [OUT] The amount of working memory for model executed
  403. * @param weightSize [OUT] The amount of weight memory for model executed
  404. * @retval ACL_ERROR_NONE The function is successfully executed.
  405. * @retval OtherValues Failure
  406. */
  407. ACL_FUNC_VISIBILITY aclError aclmdlQuerySizeFromMem(const void *model, size_t modelSize, size_t *workSize,
  408. size_t *weightSize);
  409. /**
  410. * @ingroup AscendCL
  411. * @brief In dynamic batch scenarios,
  412. * it is used to set the number of images processed
  413. * at one time during model inference
  414. *
  415. * @param modelId [IN] model id
  416. * @param dataset [IN] data for model inference
  417. * @param index [IN] index of dynamic tensor
  418. * @param batchSize [IN] Number of images processed at a time during model
  419. * @retval ACL_ERROR_NONE The function is successfully executed.
  420. * @retval OtherValues Failure
  421. *
  422. * @see aclmdlLoadFromFile | aclmdlLoadFromMem | aclmdlLoadFromFileWithMem |
  423. * aclmdlLoadFromMemWithMem | aclmdlGetInputIndexByName
  424. */
  425. ACL_FUNC_VISIBILITY aclError aclmdlSetDynamicBatchSize(uint32_t modelId, aclmdlDataset *dataset, size_t index,
  426. uint64_t batchSize);
  427. /**
  428. * @ingroup AscendCL
  429. * @brief Sets the H and W of the specified input of the model
  430. *
  431. * @param modelId [IN] model id
  432. * @param dataset [IN] data for model inference
  433. * @param index [IN] index of dynamic tensor
  434. * @param height [IN] model height
  435. * @param width [IN] model width
  436. * @retval ACL_ERROR_NONE The function is successfully executed.
  437. * @retval OtherValues Failure
  438. *
  439. * @see aclmdlLoadFromFile | aclmdlLoadFromMem | aclmdlLoadFromFileWithMem |
  440. * aclmdlLoadFromMemWithMem | aclmdlGetInputIndexByName
  441. */
  442. ACL_FUNC_VISIBILITY aclError aclmdlSetDynamicHWSize(uint32_t modelId, aclmdlDataset *dataset, size_t index,
  443. uint64_t height, uint64_t width);
  444. /**
  445. * @ingroup AscendCL
  446. * @brief get input dims info
  447. *
  448. * @param modelDesc [IN] model description
  449. * @param index [IN] input tensor index
  450. * @param dims [OUT] dims info
  451. * @retval ACL_ERROR_NONE The function is successfully executed.
  452. * @retval OtherValues Failure
  453. *
  454. * @see aclmdlGetInputDimsV2
  455. */
  456. ACL_FUNC_VISIBILITY aclError aclmdlGetInputDims(const aclmdlDesc *modelDesc, size_t index, aclmdlIODims *dims);
  457. /**
  458. * @ingroup AscendCL
  459. * @brief get input dims info(version 2), especially for static aipp
  460. * it is the same with aclmdlGetInputDims while model without static aipp
  461. *
  462. * @param modelDesc [IN] model description
  463. * @param index [IN] input tensor index
  464. * @param dims [OUT] dims info
  465. *
  466. * @retval ACL_ERROR_NONE The function is successfully executed.
  467. * @retval OtherValues Failure
  468. *
  469. * @see aclmdlGetInputDims
  470. */
  471. ACL_FUNC_VISIBILITY aclError aclmdlGetInputDimsV2(const aclmdlDesc *modelDesc, size_t index, aclmdlIODims *dims);
  472. /**
  473. * @ingroup AscendCL
  474. * @brief get output dims info
  475. *
  476. * @param modelDesc [IN] model description
  477. * @param index [IN] output tensor index
  478. * @param dims [OUT] dims info
  479. * @retval ACL_ERROR_NONE The function is successfully executed.
  480. * @retval OtherValues Failure
  481. */
  482. ACL_FUNC_VISIBILITY aclError aclmdlGetOutputDims(const aclmdlDesc *modelDesc, size_t index, aclmdlIODims *dims);
  483. /**
  484. * @ingroup AscendCL
  485. * @brief get current output dims info
  486. *
  487. * @par Function
  488. * The following use cases are supported:
  489. * @li Get current output shape when model is dynamic and
  490. * dynamic shape info is set
  491. * @li Get max output shape when model is dynamic and
  492. * dynamic shape info is not set
  493. * @li Get actual output shape when model is static
  494. *
  495. * @param modelDesc [IN] model description
  496. * @param index [IN] output tensor index
  497. * @param dims [OUT] dims info
  498. * @retval ACL_ERROR_NONE The function is successfully executed.
  499. * @retval OtherValues Failure
  500. */
  501. ACL_FUNC_VISIBILITY aclError aclmdlGetCurOutputDims(const aclmdlDesc *modelDesc, size_t index, aclmdlIODims *dims);
  502. /**
  503. * @ingroup AscendCL
  504. * @brief get input name by index
  505. *
  506. * @param modelDesc [IN] model description
  507. * @param index [IN] intput tensor index
  508. * @retval input tensor name,the same life cycle with modelDesc
  509. */
  510. ACL_FUNC_VISIBILITY const char *aclmdlGetInputNameByIndex(const aclmdlDesc *modelDesc, size_t index);
  511. /**
  512. * @ingroup AscendCL
  513. * @brief get output name by index
  514. *
  515. * @param modelDesc [IN] model description
  516. * @param index [IN] output tensor index
  517. * @retval output tensor name,the same life cycle with modelDesc
  518. */
  519. ACL_FUNC_VISIBILITY const char *aclmdlGetOutputNameByIndex(const aclmdlDesc *modelDesc, size_t index);
  520. /**
  521. * @ingroup AscendCL
  522. * @brief get input format by index
  523. *
  524. * @param modelDesc [IN] model description
  525. * @param index [IN] intput tensor index
  526. * @retval input tensor format
  527. */
  528. ACL_FUNC_VISIBILITY aclFormat aclmdlGetInputFormat(const aclmdlDesc *modelDesc, size_t index);
  529. /**
  530. * @ingroup AscendCL
  531. * @brief get output format by index
  532. *
  533. * @param modelDesc [IN] model description
  534. * @param index [IN] output tensor index
  535. * @retval output tensor format
  536. */
  537. ACL_FUNC_VISIBILITY aclFormat aclmdlGetOutputFormat(const aclmdlDesc *modelDesc, size_t index);
  538. /**
  539. * @ingroup AscendCL
  540. * @brief get input data type by index
  541. *
  542. * @param modelDesc [IN] model description
  543. * @param index [IN] intput tensor index
  544. * @retval input tensor data type
  545. */
  546. ACL_FUNC_VISIBILITY aclDataType aclmdlGetInputDataType(const aclmdlDesc *modelDesc, size_t index);
  547. /**
  548. * @ingroup AscendCL
  549. * @brief get output data type by index
  550. *
  551. * @param modelDesc [IN] model description
  552. * @param index [IN] output tensor index
  553. * @retval output tensor data type
  554. */
  555. ACL_FUNC_VISIBILITY aclDataType aclmdlGetOutputDataType(const aclmdlDesc *modelDesc, size_t index);
  556. /**
  557. * @ingroup AscendCL
  558. * @brief get input tensor index by name
  559. *
  560. * @param modelDesc [IN] model description
  561. * @param name [IN] intput tensor name
  562. * @param index [OUT] intput tensor index
  563. * @retval ACL_ERROR_NONE The function is successfully executed.
  564. * @retval OtherValues Failure
  565. */
  566. ACL_FUNC_VISIBILITY aclError aclmdlGetInputIndexByName(const aclmdlDesc *modelDesc, const char *name, size_t *index);
  567. /**
  568. * @ingroup AscendCL
  569. * @brief get output tensor index by name
  570. *
  571. * @param modelDesc [IN] model description
  572. * @param name [IN] output tensor name
  573. * @param index [OUT] output tensor index
  574. * @retval ACL_ERROR_NONE The function is successfully executed.
  575. * @retval OtherValues Failure
  576. */
  577. ACL_FUNC_VISIBILITY aclError aclmdlGetOutputIndexByName(const aclmdlDesc *modelDesc, const char *name, size_t *index);
  578. /**
  579. * @ingroup AscendCL
  580. * @brief get dynamic batch info
  581. *
  582. * @param modelDesc [IN] model description
  583. * @param batch [OUT] dynamic batch info
  584. * @retval ACL_ERROR_NONE The function is successfully executed.
  585. * @retval OtherValues Failure
  586. */
  587. ACL_FUNC_VISIBILITY aclError aclmdlGetDynamicBatch(const aclmdlDesc *modelDesc, aclmdlBatch *batch);
  588. /**
  589. * @ingroup AscendCL
  590. * @brief get dynamic height&width info
  591. *
  592. * @param modelDesc [IN] model description
  593. * @param index [IN] input tensor index
  594. * @param hw [OUT] dynamic height&width info
  595. * @retval ACL_ERROR_NONE The function is successfully executed.
  596. * @retval OtherValues Failure
  597. */
  598. ACL_FUNC_VISIBILITY aclError aclmdlGetDynamicHW(const aclmdlDesc *modelDesc, size_t index, aclmdlHW *hw);
  599. /**
  600. * @ingroup AscendCL
  601. * @brief Create data of type aclmdlAIPP
  602. *
  603. * @param batchSize [IN] batchsizes of model
  604. * @retval the aclmdlAIPP pointer
  605. */
  606. ACL_FUNC_VISIBILITY aclmdlAIPP *aclmdlCreateAIPP(uint64_t batchSize);
  607. /**
  608. * @ingroup AscendCL
  609. * @brief destroy data of type aclmdlAIPP
  610. *
  611. * @param aippParmsSet [IN] Pointer for aclmdlAIPP to be destroyed
  612. * @retval ACL_ERROR_NONE The function is successfully executed.
  613. * @retval OtherValues Failure
  614. */
  615. ACL_FUNC_VISIBILITY aclError aclmdlDestroyAIPP(const aclmdlAIPP *aippParmsSet);
  616. /**
  617. * @ingroup AscendCL
  618. * @brief set InputFormat of type aclmdlAIPP
  619. *
  620. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  621. * @param inputFormat [IN] The inputFormat of aipp
  622. * @retval ACL_ERROR_NONE The function is successfully executed.
  623. * @retval OtherValues Failure
  624. *
  625. * @see aclmdlCreateAIPP
  626. */
  627. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPInputFormat(aclmdlAIPP *aippParmsSet, aclAippInputFormat inputFormat);
  628. /**
  629. * @ingroup AscendCL
  630. * @brief set cscParms of type aclmdlAIPP
  631. *
  632. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  633. * @param csc_switch [IN] Csc switch
  634. * @param cscMatrixR0C0 [IN] Csc_matrix_r0_c0
  635. * @param cscMatrixR0C1 [IN] Csc_matrix_r0_c1
  636. * @param cscMatrixR0C2 [IN] Csc_matrix_r0_c2
  637. * @param cscMatrixR1C0 [IN] Csc_matrix_r1_c0
  638. * @param cscMatrixR1C1 [IN] Csc_matrix_r1_c1
  639. * @param cscMatrixR1C2 [IN] Csc_matrix_r1_c2
  640. * @param cscMatrixR2C0 [IN] Csc_matrix_r2_c0
  641. * @param cscMatrixR2C1 [IN] Csc_matrix_r2_c1
  642. * @param cscMatrixR2C2 [IN] Csc_matrix_r2_c2
  643. * @param cscOutputBiasR0 [IN] Output Bias for RGB to YUV, element of row 0, unsigned number
  644. * @param cscOutputBiasR1 [IN] Output Bias for RGB to YUV, element of row 1, unsigned number
  645. * @param cscOutputBiasR2 [IN] Output Bias for RGB to YUV, element of row 2, unsigned number
  646. * @param cscInputBiasR0 [IN] Input Bias for YUV to RGB, element of row 0, unsigned number
  647. * @param cscInputBiasR1 [IN] Input Bias for YUV to RGB, element of row 1, unsigned number
  648. * @param cscInputBiasR2 [IN] Input Bias for YUV to RGB, element of row 2, unsigned number
  649. * @retval ACL_ERROR_NONE The function is successfully executed.
  650. * @retval OtherValues Failure
  651. *
  652. * @see aclmdlCreateAIPP
  653. */
  654. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPCscParams(aclmdlAIPP *aippParmsSet, int8_t csc_switch,
  655. int16_t cscMatrixR0C0, int16_t cscMatrixR0C1, int16_t cscMatrixR0C2,
  656. int16_t cscMatrixR1C0, int16_t cscMatrixR1C1, int16_t cscMatrixR1C2,
  657. int16_t cscMatrixR2C0, int16_t cscMatrixR2C1, int16_t cscMatrixR2C2,
  658. uint8_t cscOutputBiasR0, uint8_t cscOutputBiasR1,
  659. uint8_t cscOutputBiasR2, uint8_t cscInputBiasR0,
  660. uint8_t cscInputBiasR1, uint8_t cscInputBiasR2);
  661. /**
  662. * @ingroup AscendCL
  663. * @brief set rb/ub swap switch of type aclmdlAIPP
  664. *
  665. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  666. * @param rbuvSwapSwitch [IN] rb/ub swap switch
  667. * @retval ACL_ERROR_NONE The function is successfully executed.
  668. * @retval OtherValues Failure
  669. *
  670. * @see aclmdlCreateAIPP
  671. */
  672. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPRbuvSwapSwitch(aclmdlAIPP *aippParmsSet, int8_t rbuvSwapSwitch);
  673. /**
  674. * @ingroup AscendCL
  675. * @brief set RGBA->ARGB, YUVA->AYUV swap switch of type aclmdlAIPP
  676. *
  677. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  678. * @param axSwapSwitch [IN] RGBA->ARGB, YUVA->AYUV swap switch
  679. * @retval ACL_ERROR_NONE The function is successfully executed.
  680. * @retval OtherValues Failure
  681. *
  682. * @see aclmdlCreateAIPP
  683. */
  684. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPAxSwapSwitch(aclmdlAIPP *aippParmsSet, int8_t axSwapSwitch);
  685. /**
  686. * @ingroup AscendCL
  687. * @brief set source image of type aclmdlAIPP
  688. *
  689. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  690. * @param srcImageSizeW [IN] Source image width
  691. * @param srcImageSizeH [IN] Source image height
  692. * @retval ACL_ERROR_NONE The function is successfully executed.
  693. * @retval OtherValues Failure
  694. *
  695. * @see aclmdlCreateAIPP
  696. */
  697. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPSrcImageSize(aclmdlAIPP *aippParmsSet, int32_t srcImageSizeW,
  698. int32_t srcImageSizeH);
  699. /**
  700. * @ingroup AscendCL
  701. * @brief set resize switch of type aclmdlAIPP
  702. *
  703. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  704. * @param scfSwitch [IN] Resize switch
  705. * @param scfInputSizeW [IN] Input width of scf
  706. * @param scfInputSizeH [IN] Input height of scf
  707. * @param scfOutputSizeW [IN] Output width of scf
  708. * @param scfOutputSizeH [IN] Output height of scf
  709. * @param batchIndex [IN] Batch parameter index
  710. * @retval ACL_ERROR_NONE The function is successfully executed.
  711. * @retval OtherValues Failure
  712. *
  713. * @see aclmdlCreateAIPP
  714. */
  715. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPScfParams(aclmdlAIPP *aippParmsSet,
  716. int8_t scfSwitch,
  717. int32_t scfInputSizeW,
  718. int32_t scfInputSizeH,
  719. int32_t scfOutputSizeW,
  720. int32_t scfOutputSizeH,
  721. uint64_t batchIndex);
  722. /**
  723. * @ingroup AscendCL
  724. * @brief set cropParams of type aclmdlAIPP
  725. *
  726. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  727. * @param cropSwitch [IN] Crop switch
  728. * @param cropStartPosW [IN] The start horizontal position of cropping
  729. * @param cropStartPosH [IN] The start vertical position of cropping
  730. * @param cropSizeW [IN] Crop width
  731. * @param cropSizeH [IN] Crop height
  732. * @param batchIndex [IN] Batch parameter index
  733. * @retval ACL_ERROR_NONE The function is successfully executed.
  734. * @retval OtherValues Failure
  735. *
  736. * @see aclmdlCreateAIPP
  737. */
  738. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPCropParams(aclmdlAIPP *aippParmsSet,
  739. int8_t cropSwitch,
  740. int32_t cropStartPosW,
  741. int32_t cropStartPosH,
  742. int32_t cropSizeW,
  743. int32_t cropSizeH,
  744. uint64_t batchIndex);
  745. /**
  746. * @ingroup AscendCL
  747. * @brief set paddingParams of type aclmdlAIPP
  748. *
  749. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  750. * @param paddingSwitch [IN] Padding switch
  751. * @param paddingSizeTop [IN] Top padding size
  752. * @param paddingSizeBottom [IN] Bottom padding size
  753. * @param paddingSizeLeft [IN] Left padding size
  754. * @param paddingSizeRight [IN] Right padding size
  755. * @param batchIndex [IN] Batch parameter index
  756. * @retval ACL_ERROR_NONE The function is successfully executed.
  757. * @retval OtherValues Failure
  758. *
  759. * @see aclmdlCreateAIPP
  760. */
  761. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPPaddingParams(aclmdlAIPP *aippParmsSet, int8_t paddingSwitch,
  762. int32_t paddingSizeTop, int32_t paddingSizeBottom,
  763. int32_t paddingSizeLeft, int32_t paddingSizeRight,
  764. uint64_t batchIndex);
  765. /**
  766. * @ingroup AscendCL
  767. * @brief set DtcPixelMean of type aclmdlAIPP
  768. *
  769. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  770. * @param dtcPixelMeanChn0 [IN] Mean value of channel 0
  771. * @param dtcPixelMeanChn1 [IN] Mean value of channel 1
  772. * @param dtcPixelMeanChn2 [IN] Mean value of channel 2
  773. * @param dtcPixelMeanChn3 [IN] Mean value of channel 3
  774. * @param batchIndex [IN] Batch parameter index
  775. * @retval ACL_ERROR_NONE The function is successfully executed.
  776. * @retval OtherValues Failure
  777. *
  778. * @see aclmdlCreateAIPP
  779. */
  780. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPDtcPixelMean(aclmdlAIPP *aippParmsSet,
  781. int16_t dtcPixelMeanChn0,
  782. int16_t dtcPixelMeanChn1,
  783. int16_t dtcPixelMeanChn2,
  784. int16_t dtcPixelMeanChn3,
  785. uint64_t batchIndex);
  786. /**
  787. * @ingroup AscendCL
  788. * @brief set DtcPixelMin of type aclmdlAIPP
  789. *
  790. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  791. * @param dtcPixelMinChn0 [IN] Min value of channel 0
  792. * @param dtcPixelMinChn1 [IN] Min value of channel 1
  793. * @param dtcPixelMinChn2 [IN] Min value of channel 2
  794. * @param dtcPixelMinChn3 [IN] Min value of channel 3
  795. * @param batchIndex [IN] Batch parameter index
  796. * @retval ACL_ERROR_NONE The function is successfully executed.
  797. * @retval OtherValues Failure
  798. *
  799. * @see aclmdlCreateAIPP
  800. */
  801. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPDtcPixelMin(aclmdlAIPP *aippParmsSet,
  802. float dtcPixelMinChn0,
  803. float dtcPixelMinChn1,
  804. float dtcPixelMinChn2,
  805. float dtcPixelMinChn3,
  806. uint64_t batchIndex);
  807. /**
  808. * @ingroup AscendCL
  809. * @brief set PixelVarReci of type aclmdlAIPP
  810. *
  811. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  812. * @param dtcPixelVarReciChn0 [IN] sfr_dtc_pixel_variance_reci_ch0
  813. * @param dtcPixelVarReciChn1 [IN] sfr_dtc_pixel_variance_reci_ch1
  814. * @param dtcPixelVarReciChn2 [IN] sfr_dtc_pixel_variance_reci_ch2
  815. * @param dtcPixelVarReciChn3 [IN] sfr_dtc_pixel_variance_reci_ch3
  816. * @param batchIndex [IN] Batch parameter index
  817. * @retval ACL_ERROR_NONE The function is successfully executed.
  818. * @retval OtherValues Failure
  819. *
  820. * @see aclmdlCreateAIPP
  821. */
  822. ACL_FUNC_VISIBILITY aclError aclmdlSetAIPPPixelVarReci(aclmdlAIPP *aippParmsSet,
  823. float dtcPixelVarReciChn0,
  824. float dtcPixelVarReciChn1,
  825. float dtcPixelVarReciChn2,
  826. float dtcPixelVarReciChn3,
  827. uint64_t batchIndex);
  828. /**
  829. * @ingroup AscendCL
  830. * @brief set aipp parameters to model
  831. *
  832. * @param modelId [IN] model id
  833. * @param dataset [IN] Pointer of dataSize
  834. * @param index [IN] index of dataBuffer
  835. * @param aippParmsSet [IN] Pointer for aclmdlAIPP
  836. * @retval ACL_ERROR_NONE The function is successfully executed.
  837. * @retval OtherValues Failure
  838. *
  839. * @see aclmdlLoadFromFile | aclmdlLoadFromMem | aclmdlLoadFromFileWithMem |
  840. * aclmdlLoadFromMemWithMem | aclmdlGetInputIndexByName | aclmdlCreateAIPP
  841. */
  842. ACL_FUNC_VISIBILITY aclError aclmdlSetInputAIPP(uint32_t modelId,
  843. aclmdlDataset *dataset,
  844. size_t index,
  845. const aclmdlAIPP *aippParmsSet);
  846. /**
  847. * @ingroup AscendCL
  848. * @brief get static aipp parameters from model
  849. *
  850. * @param modelId [IN] model id
  851. * @param index [IN] index of tensor
  852. * @param aippinfo [OUT] Pointer for static aipp info
  853. * @retval ACL_ERROR_NONE The function is successfully executed.
  854. * @retval ACL_ERROR_MODEL_AIPP_NOT_EXIST The tensor of index is not configured with aipp
  855. * @retval OtherValues Failure
  856. *
  857. * @see aclmdlLoadFromFile | aclmdlLoadFromMem | aclmdlLoadFromFileWithMem |
  858. * aclmdlLoadFromMemWithMem | aclmdlGetInputIndexByName
  859. */
  860. ACL_FUNC_VISIBILITY aclError aclmdlGetFirstAippInfo(uint32_t modelId, size_t index, aclAippInfo *aippinfo);
  861. #ifdef __cplusplus
  862. }
  863. #endif
  864. #endif // INC_EXTERNAL_ACL_ACL_MODEL_H_

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