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_op.h 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /**
  2. * @file acl_op.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_OP_H_
  11. #define INC_EXTERNAL_ACL_ACL_OP_H_
  12. #include "acl_base.h"
  13. #include "acl_rt.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef struct aclopHandle aclopHandle;
  18. typedef struct aclopAttr aclopAttr;
  19. typedef struct aclopKernelDesc aclopKernelDesc;
  20. typedef void (*aclDataDeallocator)(void *data, size_t length);
  21. static const int ACL_COMPILE_FLAG_BIN_SELECTOR = 1;
  22. typedef enum aclEngineType {
  23. ACL_ENGINE_SYS,
  24. ACL_ENGINE_AICORE,
  25. ACL_ENGINE_VECTOR,
  26. } aclopEngineType;
  27. /**
  28. * @ingroup AscendCL
  29. * @brief Set base directory that contains single op models
  30. *
  31. * @par Restriction
  32. * The aclopSetModelDir interface can be called only once in a process.
  33. * @param modelDir [IN] path of the directory
  34. *
  35. * @retval ACL_SUCCESS The function is successfully executed.
  36. * @retval OtherValues Failure
  37. */
  38. ACL_FUNC_VISIBILITY aclError aclopSetModelDir(const char *modelDir);
  39. /**
  40. * @ingroup AscendCL
  41. * @brief load single op models from memory
  42. *
  43. * @par Restriction
  44. * The aclopLoad interface can be called more than one times in a process.
  45. * @param model [IN] address of single op models
  46. * @param modelSize [IN] size of single op models
  47. *
  48. * @retval ACL_SUCCESS The function is successfully executed.
  49. * @retval OtherValues Failure
  50. */
  51. ACL_FUNC_VISIBILITY aclError aclopLoad(const void *model, size_t modelSize);
  52. /**
  53. * @ingroup AscendCL
  54. * @brief create data of type aclopAttr
  55. *
  56. * @retval pointer to created instance.
  57. * @retval nullptr if run out of memory
  58. */
  59. ACL_FUNC_VISIBILITY aclopAttr *aclopCreateAttr();
  60. /**
  61. * @ingroup AscendCL
  62. * @brief destroy data of typ aclopAttr
  63. *
  64. * @param attr [IN] pointer to the instance of aclopAttr
  65. */
  66. ACL_FUNC_VISIBILITY void aclopDestroyAttr(const aclopAttr *attr);
  67. /**
  68. * @ingroup AscendCL
  69. * @brief set an attribute. the type of the attribute is bool
  70. *
  71. * @param attr [OUT] pointer to the instance of aclopAttr
  72. * @param attrName [IN] attribute name
  73. * @param attrValue [IN] attribute value
  74. * false if attrValue is 0, true otherwise.
  75. *
  76. * @retval ACL_SUCCESS The function is successfully executed.
  77. * @retval OtherValues Failure
  78. */
  79. ACL_FUNC_VISIBILITY aclError aclopSetAttrBool(aclopAttr *attr, const char *attrName, uint8_t attrValue);
  80. /**
  81. * @ingroup AscendCL
  82. * @brief set an attribute. the type of the attribute is int64_t
  83. *
  84. * @param attr [OUT] pointer to the instance of aclopAttr
  85. * @param attrName [IN] attribute name
  86. * @param attrValue [IN] attribute value
  87. *
  88. * @retval ACL_SUCCESS The function is successfully executed.
  89. * @retval OtherValues Failure
  90. */
  91. ACL_FUNC_VISIBILITY aclError aclopSetAttrInt(aclopAttr *attr, const char *attrName, int64_t attrValue);
  92. /**
  93. * @ingroup AscendCL
  94. * @brief set an attribute. the type of the attribute is float
  95. *
  96. * @param attr [OUT] pointer to the instance of aclopAttr
  97. * @param attrName [IN] attribute name
  98. * @param attrValue [IN] attribute value
  99. *
  100. * @retval ACL_SUCCESS The function is successfully executed.
  101. * @retval OtherValues Failure
  102. */
  103. ACL_FUNC_VISIBILITY aclError aclopSetAttrFloat(aclopAttr *attr, const char *attrName, float attrValue);
  104. /**
  105. * @ingroup AscendCL
  106. * @brief set an attribute. the type of the attribute is string
  107. *
  108. * @param attr [OUT] pointer to the instance of aclopAttr
  109. * @param attrName [IN] attribute name
  110. * @param attrValue [IN] attribute value
  111. *
  112. * @retval ACL_SUCCESS The function is successfully executed.
  113. * @retval OtherValues Failure
  114. */
  115. ACL_FUNC_VISIBILITY aclError aclopSetAttrString(aclopAttr *attr, const char *attrName, const char *attrValue);
  116. /**
  117. * @ingroup AscendCL
  118. * @brief set an attribute. the type of the attribute is aclDataType
  119. *
  120. * @param attr [OUT] pointer to the instance of aclopAttr
  121. * @param attrName [IN] attribute name
  122. * @param attrValue [IN] attribute value
  123. *
  124. * @retval ACL_SUCCESS The function is successfully executed.
  125. * @retval OtherValues Failure
  126. */
  127. ACL_FUNC_VISIBILITY aclError aclopSetAttrDataType(aclopAttr *attr, const char *attrName, aclDataType attrValue);
  128. /**
  129. * @ingroup AscendCL
  130. * @brief set an attribute. the type of the attribute is list of aclDataType
  131. *
  132. * @param attr [OUT] pointer to the instance of aclopAttr
  133. * @param attrName [IN] attribute name
  134. * @param numValues [IN] number of values. false if attrValue is 0, true otherwise.
  135. * @param values [IN] pointer to values
  136. *
  137. * @retval ACL_SUCCESS The function is successfully executed.
  138. * @retval OtherValues Failure
  139. */
  140. ACL_FUNC_VISIBILITY aclError aclopSetAttrListDataType(aclopAttr *attr, const char *attrName, int numValues,
  141. const aclDataType values[]);
  142. /**
  143. * @ingroup AscendCL
  144. * @brief set an attribute. the type of the attribute is list of bools
  145. *
  146. * @param attr [OUT] pointer to the instance of aclopAttr
  147. * @param attrName [IN] attribute name
  148. * @param numValues [IN] number of values. false if attrValue is 0, true otherwise.
  149. * @param values [IN] pointer to values
  150. *
  151. * @retval ACL_SUCCESS The function is successfully executed.
  152. * @retval OtherValues Failure
  153. */
  154. ACL_FUNC_VISIBILITY aclError aclopSetAttrListBool(aclopAttr *attr, const char *attrName, int numValues,
  155. const uint8_t *values);
  156. /**
  157. * @ingroup AscendCL
  158. * @brief set an attribute. the type of the attribute is list of ints
  159. *
  160. * @param attr [OUT] pointer to the instance of aclopAttr
  161. * @param attrName [IN] attribute name
  162. * @param numValues [IN] number of values
  163. * @param values [IN] pointer to values
  164. *
  165. * @retval ACL_SUCCESS The function is successfully executed.
  166. * @retval OtherValues Failure
  167. */
  168. ACL_FUNC_VISIBILITY aclError aclopSetAttrListInt(aclopAttr *attr, const char *attrName, int numValues,
  169. const int64_t *values);
  170. /**
  171. * @ingroup AscendCL
  172. * @brief set an attribute. the type of the attribute is list of floats
  173. *
  174. * @param attr [OUT] pointer to the instance of aclopAttr
  175. * @param attrName [IN] attribute name
  176. * @param numValues [IN] number of values
  177. * @param values [IN] pointer to values
  178. *
  179. * @retval ACL_SUCCESS The function is successfully executed.
  180. * @retval OtherValues Failure
  181. */
  182. ACL_FUNC_VISIBILITY aclError aclopSetAttrListFloat(aclopAttr *attr, const char *attrName, int numValues,
  183. const float *values);
  184. /**
  185. * @ingroup AscendCL
  186. * @brief set an attribute. the type of the attribute is list of strings
  187. *
  188. * @param attr [OUT] pointer to the instance of aclopAttr
  189. * @param attrName [IN] attribute name
  190. * @param numValues [IN] number of values
  191. * @param values [IN] pointer to values
  192. *
  193. * @retval ACL_SUCCESS The function is successfully executed.
  194. * @retval OtherValues Failure
  195. */
  196. ACL_FUNC_VISIBILITY aclError aclopSetAttrListString(aclopAttr *attr, const char *attrName, int numValues,
  197. const char **values);
  198. /**
  199. * @ingroup AscendCL
  200. * @brief set an attribute. the type of the attribute is list of list of ints
  201. *
  202. * @param attr [OUT] pointer to the instance of aclopAttr
  203. * @param attrName [IN] attribute name
  204. * @param numLists [IN] number of lists
  205. * @param numValues [IN] pointer to number of values of each list
  206. * @param values [IN] pointer to values
  207. *
  208. * @retval ACL_SUCCESS The function is successfully executed.
  209. * @retval OtherValues Failure
  210. */
  211. ACL_FUNC_VISIBILITY aclError aclopSetAttrListListInt(aclopAttr *attr,
  212. const char *attrName,
  213. int numLists,
  214. const int *numValues,
  215. const int64_t *const values[]);
  216. /**
  217. * @ingroup AscendCL
  218. * @brief Load and execute the specified operator asynchronously
  219. *
  220. * @par Restriction
  221. * @li The input and output organization of each operator is different,
  222. * and the application needs to organize the operator strictly
  223. * according to the operator input and output parameters when calling.
  224. * @li When the user calls aclopExecute,
  225. * the ACL finds the corresponding task according to the optype,
  226. * the description of the input tesnsor,
  227. * the description of the output tesnsor, and attr, and issues the execution.
  228. *
  229. * @param opType [IN] type of op
  230. * @param numInputs [IN] number of inputs
  231. * @param inputDesc [IN] pointer to array of input tensor descriptions
  232. * @param inputs [IN] pointer to array of input buffers
  233. * @param numOutputs [IN] number of outputs
  234. * @param outputDesc [IN] pointer to array of output tensor descriptions
  235. * @param outputs [OUT] pointer to array of output buffers
  236. * @param attr [IN] pointer to instance of aclopAttr.
  237. * may pass nullptr if the op has no attribute
  238. * @param stream [IN] stream
  239. *
  240. * @retval ACL_SUCCESS The function is successfully executed.
  241. * @retval OtherValues Failure
  242. */
  243. // ACL_DEPRECATED_MESSAGE("aclopExecute is deprecated, use aclopExecuteV2 instead")
  244. ACL_FUNC_VISIBILITY aclError aclopExecute(const char *opType,
  245. int numInputs,
  246. const aclTensorDesc *const inputDesc[],
  247. const aclDataBuffer *const inputs[],
  248. int numOutputs,
  249. const aclTensorDesc *const outputDesc[],
  250. aclDataBuffer *const outputs[],
  251. const aclopAttr *attr,
  252. aclrtStream stream);
  253. /**
  254. * @ingroup AscendCL
  255. * @brief Load and execute the specified operator
  256. * The difference with aclopExecute is that aclopExecuteV2 will refresh outputDesc
  257. *
  258. * @par Restriction
  259. * @li The input and output organization of each operator is different,
  260. * and the application needs to organize the operator strictly
  261. * according to the operator input and output parameters when calling.
  262. * @li When the user calls aclopExecuteV2,
  263. * the ACL finds the corresponding task according to the optype,
  264. * the description of the input tesnsor,
  265. * the description of the output tesnsor, and attr, and issues the execution.
  266. *
  267. * @param opType [IN] type of op
  268. * @param numInputs [IN] number of inputs
  269. * @param inputDesc [IN] pointer to array of input tensor descriptions
  270. * @param inputs [IN] pointer to array of input buffers
  271. * @param numOutputs [IN] number of outputs
  272. * @param outputDesc [IN|OUT] pointer to array of output tensor descriptions
  273. * @param outputs [OUT] pointer to array of output buffers
  274. * @param attr [IN] pointer to instance of aclopAttr.
  275. * may pass nullptr if the op has no attribute
  276. * @param stream [IN] stream
  277. *
  278. * @retval ACL_SUCCESS The function is successfully executed.
  279. * @retval OtherValues Failure
  280. */
  281. ACL_FUNC_VISIBILITY aclError aclopExecuteV2(const char *opType,
  282. int numInputs,
  283. aclTensorDesc *inputDesc[],
  284. aclDataBuffer *inputs[],
  285. int numOutputs,
  286. aclTensorDesc *outputDesc[],
  287. aclDataBuffer *outputs[],
  288. aclopAttr *attr,
  289. aclrtStream stream);
  290. /**
  291. * @ingroup AscendCL
  292. * @brief create a instance of aclopHandle.
  293. *
  294. * @param opType [IN] type of op
  295. * @param numInputs [IN] number of inputs
  296. * @param inputDesc [IN] pointer to array of input tensor descriptions
  297. * @param numOutputs [IN] number of outputs
  298. * @param outputDesc [IN] pointer to array of output tensor descriptions
  299. * @param opAttr [IN] pointer to instance of aclopAttr.
  300. * may pass nullptr if the op has no attribute
  301. * @param handle [OUT] pointer to the pointer to the handle
  302. *
  303. * @retval ACL_SUCCESS The function is successfully executed.
  304. * @retval OtherValues Failure
  305. */
  306. ACL_FUNC_VISIBILITY aclError aclopCreateHandle(const char *opType,
  307. int numInputs,
  308. const aclTensorDesc *const inputDesc[],
  309. int numOutputs,
  310. const aclTensorDesc *const outputDesc[],
  311. const aclopAttr *opAttr,
  312. aclopHandle **handle);
  313. /**
  314. * @ingroup AscendCL
  315. * @brief destroy aclopHandle instance
  316. *
  317. * @param handle [IN] pointer to the instance of aclopHandle
  318. */
  319. ACL_FUNC_VISIBILITY void aclopDestroyHandle(aclopHandle *handle);
  320. /**
  321. * @ingroup AscendCL
  322. * @brief execute an op with the handle.
  323. * can save op model matching cost compared with aclopExecute
  324. *
  325. * @param handle [IN] pointer to the instance of aclopHandle.
  326. * The aclopCreateHandle interface has been called
  327. * in advance to create aclopHandle type data.
  328. * @param numInputs [IN] number of inputs
  329. * @param inputs [IN] pointer to array of input buffers.
  330. * The aclCreateDataBuffer interface has been called
  331. * in advance to create aclDataBuffer type data.
  332. * @param numOutputs [IN] number of outputs
  333. * @param outputs [OUT] pointer to array of output buffers
  334. * @param stream [IN] stream
  335. *
  336. * @retval ACL_SUCCESS The function is successfully executed.
  337. * @retval OtherValues Failure
  338. *
  339. * @see aclopCreateHandle | aclCreateDataBuffer
  340. */
  341. ACL_FUNC_VISIBILITY aclError aclopExecWithHandle(aclopHandle *handle,
  342. int numInputs,
  343. const aclDataBuffer *const inputs[],
  344. int numOutputs,
  345. aclDataBuffer *const outputs[],
  346. aclrtStream stream);
  347. /**
  348. * @ingroup AscendCL
  349. * @brief cast data type
  350. *
  351. * @param srcDesc [IN] source tensor desc
  352. * @param srcBuffer [IN] source tensor buffer
  353. * @param dstDesc [IN] destination tensor desc
  354. * @param dstBuffer [OUT] destination tensor buffer
  355. * @param truncate [IN] do not truncate if value is 0, truncate otherwise
  356. * @param stream [IN] stream
  357. *
  358. * @retval ACL_SUCCESS The function is successfully executed.
  359. * @retval OtherValues Failure
  360. */
  361. ACL_FUNC_VISIBILITY aclError aclopCast(const aclTensorDesc *srcDesc,
  362. const aclDataBuffer *srcBuffer,
  363. const aclTensorDesc *dstDesc,
  364. aclDataBuffer *dstBuffer,
  365. uint8_t truncate,
  366. aclrtStream stream);
  367. /**
  368. * @ingroup AscendCL
  369. * @brief create a handle for casting datatype
  370. *
  371. * @param srcDesc [IN] source tensor desc
  372. * @param dstDesc [IN] destination tensor desc
  373. * @param truncate [IN] do not truncate if value is 0, truncate otherwise
  374. * @param handle [OUT] pointer to the pointer to the handle
  375. *
  376. * @retval ACL_SUCCESS The function is successfully executed.
  377. * @retval OtherValues Failure
  378. */
  379. ACL_FUNC_VISIBILITY aclError aclopCreateHandleForCast(aclTensorDesc *srcDesc,
  380. aclTensorDesc *dstDesc,
  381. uint8_t truncate,
  382. aclopHandle **handle);
  383. /**
  384. * @ingroup AscendCL
  385. * @brief create kernel
  386. *
  387. * @param opType [IN] op type
  388. * @param kernelId [IN] kernel id
  389. * @param kernelName [IN] kernel name
  390. * @param binData [IN] kernel bin data
  391. * @param binSize [IN] kernel bin size
  392. * @param enginetype [IN] enigne type
  393. * @param deallocator [IN] callback function for deallocating bin data,
  394. * null if bin data to be deallocated by caller
  395. *
  396. * @retval ACL_SUCCESS The function is successfully executed.
  397. * @retval OtherValues Failure
  398. *
  399. * @see aclopCompile
  400. */
  401. ACL_FUNC_VISIBILITY aclError aclopCreateKernel(const char *opType,
  402. const char *kernelId,
  403. const char *kernelName,
  404. void *binData,
  405. int binSize,
  406. aclopEngineType enginetype,
  407. aclDataDeallocator deallocator);
  408. /**
  409. * @ingroup AscendCL
  410. * @brief create kernel
  411. *
  412. * @param numInputs [IN] number of inputs
  413. * @param inputDesc [IN] pointer to array of input tensor descriptions
  414. * @param numOutputs [IN] number of outputs
  415. * @param outputDesc [IN] pointer to array of output tensor descriptions
  416. * @param opAttr [IN] pointer to instance of aclopAttr
  417. * @param aclopKernelDesc [IN] pointer to instance of aclopKernelDesc
  418. *
  419. * @retval ACL_SUCCESS The function is successfully executed.
  420. * @retval OtherValues Failure
  421. */
  422. typedef aclError (*aclopCompileFunc)(int numInputs,
  423. const aclTensorDesc *const inputDesc[],
  424. int numOutputs,
  425. const aclTensorDesc *const outputDesc[],
  426. const aclopAttr *opAttr,
  427. aclopKernelDesc *aclopKernelDesc);
  428. /**
  429. * @ingroup AscendCL
  430. * @brief register compile function
  431. *
  432. * @param opType [IN] op type
  433. * @param func [IN] compile function
  434. *
  435. * @retval ACL_SUCCESS The function is successfully executed.
  436. * @retval OtherValues Failure
  437. *
  438. * @see aclopUnregisterCompileFunc
  439. */
  440. ACL_FUNC_VISIBILITY aclError aclopRegisterCompileFunc(const char *opType, aclopCompileFunc func);
  441. /**
  442. * @ingroup AscendCL
  443. * @brief unregister compile function
  444. *
  445. * @param opType [IN] op type
  446. *
  447. * @retval ACL_SUCCESS The function is successfully executed.
  448. * @retval OtherValues Failure
  449. */
  450. ACL_FUNC_VISIBILITY aclError aclopUnregisterCompileFunc(const char *opType);
  451. /**
  452. * @ingroup AscendCL
  453. * @brief set kernel args
  454. *
  455. * @param kernelDesc [IN] pointer to instance of aclopKernelDesc
  456. * @param kernelId [IN] kernel id
  457. * @param blockDim [IN] block dim
  458. * @param args [IN] args
  459. * @param argSize [IN] size in bytes of args
  460. *
  461. * @retval ACL_SUCCESS The function is successfully executed.
  462. * @retval OtherValues Failure
  463. */
  464. ACL_FUNC_VISIBILITY aclError aclopSetKernelArgs(aclopKernelDesc *kernelDesc,
  465. const char *kernelId,
  466. uint32_t blockDim,
  467. const void *args,
  468. uint32_t argSize);
  469. /**
  470. * @ingroup AscendCL
  471. * @brief set workspace sizes
  472. *
  473. * @param kernelDesc [IN] pointer to instance of aclopKernelDesc
  474. * @param numWorkspaces [IN] number of workspaces
  475. * @param workspaceSizes [IN] pointer to array of sizes of workspaces
  476. *
  477. * @retval ACL_SUCCESS The function is successfully executed.
  478. * @retval OtherValues Failure
  479. */
  480. ACL_FUNC_VISIBILITY aclError aclopSetKernelWorkspaceSizes(aclopKernelDesc *kernelDesc, int numWorkspaces,
  481. size_t *workspaceSizes);
  482. /**
  483. * @ingroup AscendCL
  484. * @brief compile op with dynamic shape
  485. *
  486. * @param opType [IN] op type
  487. * @param numInputs [IN] number of inputs
  488. * @param inputDesc [IN] pointer to array of input tensor descriptions
  489. * @param numOutputs [IN] number of outputs
  490. * @param outputDesc [IN] pointer to array of output tensor descriptions
  491. * @param attr [IN] pointer to instance of aclopAttr.
  492. * may pass nullptr if the op has no attribute
  493. *
  494. * @retval ACL_SUCCESS The function is successfully executed.
  495. * @retval OtherValues Failure
  496. */
  497. ACL_FUNC_VISIBILITY aclError aclopUpdateParams(const char *opType,
  498. int numInputs,
  499. const aclTensorDesc *const inputDesc[],
  500. int numOutputs,
  501. const aclTensorDesc *const outputDesc[],
  502. const aclopAttr *attr);
  503. /**
  504. * @ingroup AscendCL
  505. * @brief inferShape the specified operator synchronously
  506. *
  507. * @param opType [IN] type of op
  508. * @param numInputs [IN] number of inputs
  509. * @param inputDesc [IN] pointer to array of input tensor descriptions
  510. * @param inputs [IN] pointer to array of input buffers
  511. * @param numOutputs [IN] number of outputs
  512. * @param outputDesc [OUT] pointer to array of output tensor descriptions
  513. * @param attr [IN] pointer to instance of aclopAttr.
  514. * may pass nullptr if the op has no attribute
  515. *
  516. * @retval ACL_SUCCESS The function is successfully executed.
  517. * @retval OtherValues Failure
  518. */
  519. ACL_FUNC_VISIBILITY aclError aclopInferShape(const char *opType,
  520. int numInputs,
  521. aclTensorDesc *inputDesc[],
  522. aclDataBuffer *inputs[],
  523. int numOutputs,
  524. aclTensorDesc *outputDesc[],
  525. aclopAttr *attr);
  526. #ifdef __cplusplus
  527. }
  528. #endif
  529. #endif // INC_EXTERNAL_ACL_ACL_OP_H_