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

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

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