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

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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, const char *attrName, int numLists,
  192. const int *numValues, const int64_t *const values[]);
  193. /**
  194. * @ingroup AscendCL
  195. * @brief Load and execute the specified operator asynchronously
  196. *
  197. * @par Restriction
  198. * @li The input and output organization of each operator is different,
  199. * and the application needs to organize the operator strictly
  200. * according to the operator input and output parameters when calling.
  201. * @li When the user calls aclopExecute,
  202. * the ACL finds the corresponding task according to the optype,
  203. * the description of the input tesnsor,
  204. * the description of the output tesnsor, and attr, and issues the execution.
  205. *
  206. * @param opType [IN] type of op
  207. * @param numInputs [IN] number of inputs
  208. * @param inputDesc [IN] pointer to array of input tensor descriptions
  209. * @param inputs [IN] pointer to array of input buffers
  210. * @param numOutputs [IN] number of outputs
  211. * @param outputDesc [IN] pointer to array of output tensor descriptions
  212. * @param outputs [OUT] pointer to array of output buffers
  213. * @param attr [IN] pointer to instance of aclopAttr.
  214. * may pass nullptr if the op has no attribute
  215. * @param stream [IN] stream
  216. *
  217. * @retval ACL_SUCCESS The function is successfully executed.
  218. * @retval OtherValues Failure
  219. */
  220. ACL_DEPRECATED_MESSAGE("aclopExecute is deprecated, use aclopExecuteV2 instead")
  221. ACL_FUNC_VISIBILITY aclError aclopExecute(const char *opType, int numInputs, const aclTensorDesc *const inputDesc[],
  222. const aclDataBuffer *const inputs[], int numOutputs,
  223. const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[],
  224. const aclopAttr *attr, aclrtStream stream);
  225. /**
  226. * @ingroup AscendCL
  227. * @brief Load and execute the specified operator
  228. * The difference with aclopExecute is that aclopExecuteV2 will refresh outputDesc
  229. *
  230. * @par Restriction
  231. * @li The input and output organization of each operator is different,
  232. * and the application needs to organize the operator strictly
  233. * according to the operator input and output parameters when calling.
  234. * @li When the user calls aclopExecuteV2,
  235. * the ACL finds the corresponding task according to the optype,
  236. * the description of the input tesnsor,
  237. * the description of the output tesnsor, and attr, and issues the execution.
  238. *
  239. * @param opType [IN] type of op
  240. * @param numInputs [IN] number of inputs
  241. * @param inputDesc [IN] pointer to array of input tensor descriptions
  242. * @param inputs [IN] pointer to array of input buffers
  243. * @param numOutputs [IN] number of outputs
  244. * @param outputDesc [IN|OUT] pointer to array of output tensor descriptions
  245. * @param outputs [OUT] pointer to array of output buffers
  246. * @param attr [IN] pointer to instance of aclopAttr.
  247. * may pass nullptr if the op has no attribute
  248. * @param stream [IN] stream
  249. *
  250. * @retval ACL_SUCCESS The function is successfully executed.
  251. * @retval OtherValues Failure
  252. */
  253. ACL_FUNC_VISIBILITY aclError aclopExecuteV2(const char *opType, int numInputs, aclTensorDesc *inputDesc[],
  254. aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[],
  255. aclDataBuffer *outputs[], aclopAttr *attr, aclrtStream stream);
  256. /**
  257. * @ingroup AscendCL
  258. * @brief create a instance of aclopHandle.
  259. *
  260. * @param opType [IN] type of op
  261. * @param numInputs [IN] number of inputs
  262. * @param inputDesc [IN] pointer to array of input tensor descriptions
  263. * @param numOutputs [IN] number of outputs
  264. * @param outputDesc [IN] pointer to array of output tensor descriptions
  265. * @param opAttr [IN] pointer to instance of aclopAttr.
  266. * may pass nullptr if the op has no attribute
  267. * @param handle [OUT] pointer to the pointer to the handle
  268. *
  269. * @retval ACL_SUCCESS The function is successfully executed.
  270. * @retval OtherValues Failure
  271. */
  272. ACL_FUNC_VISIBILITY aclError aclopCreateHandle(const char *opType, int numInputs,
  273. const aclTensorDesc *const inputDesc[], int numOutputs,
  274. const aclTensorDesc *const outputDesc[], const aclopAttr *opAttr,
  275. aclopHandle **handle);
  276. /**
  277. * @ingroup AscendCL
  278. * @brief destroy aclopHandle instance
  279. *
  280. * @param handle [IN] pointer to the instance of aclopHandle
  281. */
  282. ACL_FUNC_VISIBILITY void aclopDestroyHandle(aclopHandle *handle);
  283. /**
  284. * @ingroup AscendCL
  285. * @brief execute an op with the handle.
  286. * can save op model matching cost compared with aclopExecute
  287. *
  288. * @param handle [IN] pointer to the instance of aclopHandle.
  289. * The aclopCreateHandle interface has been called
  290. * in advance to create aclopHandle type data.
  291. * @param numInputs [IN] number of inputs
  292. * @param inputs [IN] pointer to array of input buffers.
  293. * The aclCreateDataBuffer interface has been called
  294. * in advance to create aclDataBuffer type data.
  295. * @param numOutputs [IN] number of outputs
  296. * @param outputs [OUT] pointer to array of output buffers
  297. * @param stream [IN] stream
  298. *
  299. * @retval ACL_SUCCESS The function is successfully executed.
  300. * @retval OtherValues Failure
  301. *
  302. * @see aclopCreateHandle | aclCreateDataBuffer
  303. */
  304. ACL_FUNC_VISIBILITY aclError aclopExecWithHandle(aclopHandle *handle, int numInputs,
  305. const aclDataBuffer *const inputs[], int numOutputs,
  306. aclDataBuffer *const outputs[], aclrtStream stream);
  307. /**
  308. * @ingroup AscendCL
  309. * @brief cast data type
  310. *
  311. * @param srcDesc [IN] source tensor desc
  312. * @param srcBuffer [IN] source tensor buffer
  313. * @param dstDesc [IN] destination tensor desc
  314. * @param dstBuffer [OUT] destination tensor buffer
  315. * @param truncate [IN] do not truncate if value is 0, truncate otherwise
  316. * @param stream [IN] stream
  317. *
  318. * @retval ACL_SUCCESS The function is successfully executed.
  319. * @retval OtherValues Failure
  320. */
  321. ACL_FUNC_VISIBILITY aclError aclopCast(const aclTensorDesc *srcDesc, const aclDataBuffer *srcBuffer,
  322. const aclTensorDesc *dstDesc, aclDataBuffer *dstBuffer, uint8_t truncate,
  323. aclrtStream stream);
  324. /**
  325. * @ingroup AscendCL
  326. * @brief create a handle for casting datatype
  327. *
  328. * @param srcDesc [IN] source tensor desc
  329. * @param dstDesc [IN] destination tensor desc
  330. * @param truncate [IN] do not truncate if value is 0, truncate otherwise
  331. * @param handle [OUT] pointer to the pointer to the handle
  332. *
  333. * @retval ACL_SUCCESS The function is successfully executed.
  334. * @retval OtherValues Failure
  335. */
  336. ACL_FUNC_VISIBILITY aclError aclopCreateHandleForCast(aclTensorDesc *srcDesc, aclTensorDesc *dstDesc, uint8_t truncate,
  337. aclopHandle **handle);
  338. /**
  339. * @ingroup AscendCL
  340. * @brief create kernel
  341. *
  342. * @param opType [IN] op type
  343. * @param kernelId [IN] kernel id
  344. * @param kernelName [IN] kernel name
  345. * @param binData [IN] kernel bin data
  346. * @param binSize [IN] kernel bin size
  347. * @param enginetype [IN] enigne type
  348. * @param deallocator [IN] callback function for deallocating bin data,
  349. * null if bin data to be deallocated by caller
  350. *
  351. * @retval ACL_SUCCESS The function is successfully executed.
  352. * @retval OtherValues Failure
  353. *
  354. * @see aclopCompile
  355. */
  356. ACL_FUNC_VISIBILITY aclError aclopCreateKernel(const char *opType, const char *kernelId, const char *kernelName,
  357. void *binData, int binSize, aclopEngineType enginetype,
  358. aclDataDeallocator deallocator);
  359. /**
  360. * @ingroup AscendCL
  361. * @brief create kernel
  362. *
  363. * @param numInputs [IN] number of inputs
  364. * @param inputDesc [IN] pointer to array of input tensor descriptions
  365. * @param numOutputs [IN] number of outputs
  366. * @param outputDesc [IN] pointer to array of output tensor descriptions
  367. * @param opAttr [IN] pointer to instance of aclopAttr
  368. * @param aclopKernelDesc [IN] pointer to instance of aclopKernelDesc
  369. *
  370. * @retval ACL_SUCCESS The function is successfully executed.
  371. * @retval OtherValues Failure
  372. */
  373. typedef aclError (*aclopCompileFunc)(int numInputs, const aclTensorDesc *const inputDesc[], int numOutputs,
  374. const aclTensorDesc *const outputDesc[], const aclopAttr *opAttr,
  375. aclopKernelDesc *aclopKernelDesc);
  376. /**
  377. * @ingroup AscendCL
  378. * @brief register compile function
  379. *
  380. * @param opType [IN] op type
  381. * @param func [IN] compile function
  382. *
  383. * @retval ACL_SUCCESS The function is successfully executed.
  384. * @retval OtherValues Failure
  385. *
  386. * @see aclopUnregisterCompileFunc
  387. */
  388. ACL_FUNC_VISIBILITY aclError aclopRegisterCompileFunc(const char *opType, aclopCompileFunc func);
  389. /**
  390. * @ingroup AscendCL
  391. * @brief unregister compile function
  392. *
  393. * @param opType [IN] op type
  394. *
  395. * @retval ACL_SUCCESS The function is successfully executed.
  396. * @retval OtherValues Failure
  397. */
  398. ACL_FUNC_VISIBILITY aclError aclopUnregisterCompileFunc(const char *opType);
  399. /**
  400. * @ingroup AscendCL
  401. * @brief set kernel args
  402. *
  403. * @param kernelDesc [IN] pointer to instance of aclopKernelDesc
  404. * @param kernelId [IN] kernel id
  405. * @param blockDim [IN] block dim
  406. * @param args [IN] args
  407. * @param argSize [IN] size in bytes of args
  408. *
  409. * @retval ACL_SUCCESS The function is successfully executed.
  410. * @retval OtherValues Failure
  411. */
  412. ACL_FUNC_VISIBILITY aclError aclopSetKernelArgs(aclopKernelDesc *kernelDesc, const char *kernelId, uint32_t blockDim,
  413. const void *args, uint32_t argSize);
  414. /**
  415. * @ingroup AscendCL
  416. * @brief set workspace sizes
  417. *
  418. * @param kernelDesc [IN] pointer to instance of aclopKernelDesc
  419. * @param numWorkspaces [IN] number of workspaces
  420. * @param workspaceSizes [IN] pointer to array of sizes of workspaces
  421. *
  422. * @retval ACL_SUCCESS The function is successfully executed.
  423. * @retval OtherValues Failure
  424. */
  425. ACL_FUNC_VISIBILITY aclError aclopSetKernelWorkspaceSizes(aclopKernelDesc *kernelDesc, int numWorkspaces,
  426. size_t *workspaceSizes);
  427. /**
  428. * @ingroup AscendCL
  429. * @brief compile op with dynamic shape
  430. *
  431. * @param opType [IN] op type
  432. * @param numInputs [IN] number of inputs
  433. * @param inputDesc [IN] pointer to array of input tensor descriptions
  434. * @param numOutputs [IN] number of outputs
  435. * @param outputDesc [IN] pointer to array of output tensor descriptions
  436. * @param attr [IN] pointer to instance of aclopAttr.
  437. * may pass nullptr if the op has no attribute
  438. *
  439. * @retval ACL_SUCCESS The function is successfully executed.
  440. * @retval OtherValues Failure
  441. */
  442. ACL_FUNC_VISIBILITY aclError aclopUpdateParams(const char *opType, int numInputs,
  443. const aclTensorDesc *const inputDesc[], int numOutputs,
  444. const aclTensorDesc *const outputDesc[], const aclopAttr *attr);
  445. /**
  446. * @ingroup AscendCL
  447. * @brief inferShape the specified operator synchronously
  448. *
  449. * @param opType [IN] type of op
  450. * @param numInputs [IN] number of inputs
  451. * @param inputDesc [IN] pointer to array of input tensor descriptions
  452. * @param inputs [IN] pointer to array of input buffers
  453. * @param numOutputs [IN] number of outputs
  454. * @param outputDesc [OUT] pointer to array of output tensor descriptions
  455. * @param attr [IN] pointer to instance of aclopAttr.
  456. * may pass nullptr if the op has no attribute
  457. *
  458. * @retval ACL_SUCCESS The function is successfully executed.
  459. * @retval OtherValues Failure
  460. */
  461. ACL_FUNC_VISIBILITY aclError aclopInferShape(const char *opType, int numInputs, aclTensorDesc *inputDesc[],
  462. aclDataBuffer *inputs[], int numOutputs, aclTensorDesc *outputDesc[],
  463. aclopAttr *attr);
  464. #ifdef __cplusplus
  465. }
  466. #endif
  467. #endif // INC_EXTERNAL_ACL_ACL_OP_H_

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