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_cblas.h 20 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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_OPS_ACL_CBLAS_H_
  17. #define INC_EXTERNAL_ACL_OPS_ACL_CBLAS_H_
  18. #include "acl/acl.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef enum aclTransType {
  23. ACL_TRANS_N,
  24. ACL_TRANS_T,
  25. ACL_TRANS_NZ,
  26. ACL_TRANS_NZ_T
  27. } aclTransType;
  28. typedef enum aclComputeType {
  29. ACL_COMPUTE_HIGH_PRECISION,
  30. ACL_COMPUTE_LOW_PRECISION
  31. } aclComputeType;
  32. /**
  33. * @ingroup AscendCL
  34. * @brief perform the matrix-vector multiplication
  35. *
  36. * @param transA [IN] transpose type of matrix A
  37. * @param m [IN] number of rows of matrix A
  38. * @param n [IN] number of columns of matrix A
  39. * @param alpha [IN] pointer to scalar used for multiplication.
  40. * of same type as dataTypeC
  41. * @param a [IN] pointer to matrix A
  42. * @param lda [IN] leading dimension used to store the matrix A
  43. * @param dataTypeA [IN] datatype of matrix A
  44. * @param x [IN] pointer to vector x
  45. * @param incx [IN] stride between consecutive elements of vector x
  46. * @param dataTypeX [IN] datatype of vector x
  47. * @param beta [IN] pointer to scalar used for multiplication.
  48. * of same type as dataTypeC If beta == 0,
  49. * then y does not have to be a valid input
  50. * @param y [IN|OUT] pointer to vector y
  51. * @param incy [IN] stride between consecutive elements of vector y
  52. * @param dataTypeY [IN] datatype of vector y
  53. * @param type [IN] computation type
  54. * @param stream [IN] stream
  55. *
  56. * @retval ACL_SUCCESS The function is successfully executed.
  57. * @retval OtherValues Failure
  58. */
  59. ACL_FUNC_VISIBILITY aclError aclblasGemvEx(aclTransType transA, int m, int n,
  60. const void *alpha, const void *a, int lda, aclDataType dataTypeA,
  61. const void *x, int incx, aclDataType dataTypeX,
  62. const void *beta, void *y, int incy, aclDataType dataTypeY,
  63. aclComputeType type, aclrtStream stream);
  64. /**
  65. * @ingroup AscendCL
  66. * @brief create a handle for performing the matrix-vector multiplication
  67. *
  68. * @param transA [IN] transpose type of matrix A
  69. * @param m [IN] number of rows of matrix A
  70. * @param n [IN] number of columns of matrix A
  71. * @param dataTypeA [IN] datatype of matrix A
  72. * @param dataTypeX [IN] datatype of vector x
  73. * @param dataTypeY [IN] datatype of vector y
  74. * @param type [IN] computation type
  75. * @param handle [OUT] pointer to the pointer to the handle
  76. *
  77. * @retval ACL_SUCCESS The function is successfully executed.
  78. * @retval OtherValues Failure
  79. */
  80. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForGemvEx(aclTransType transA,
  81. int m,
  82. int n,
  83. aclDataType dataTypeA,
  84. aclDataType dataTypeX,
  85. aclDataType dataTypeY,
  86. aclComputeType type,
  87. aclopHandle **handle);
  88. /**
  89. * @ingroup AscendCL
  90. * @brief perform the matrix-vector multiplication
  91. *
  92. * @param transA [IN] transpose type of matrix A
  93. * @param m [IN] number of rows of matrix A
  94. * @param n [IN] number of columns of matrix A
  95. * @param alpha [IN] pointer to scalar used for multiplication
  96. * @param a [IN] pointer to matrix A
  97. * @param lda [IN] leading dimension used to store the matrix A
  98. * @param x [IN] pointer to vector x
  99. * @param incx [IN] stride between consecutive elements of vector x
  100. * @param beta [IN] pointer to scalar used for multiplication.
  101. * If beta value == 0,
  102. * then y does not have to be a valid input
  103. * @param y [IN|OUT] pointer to vector y
  104. * @param incy [IN] stride between consecutive elements of vector y
  105. * @param type [IN] computation type
  106. * @param stream [IN] stream
  107. * @retval ACL_SUCCESS The function is successfully executed.
  108. * @retval OtherValues Failure
  109. */
  110. ACL_FUNC_VISIBILITY aclError aclblasHgemv(aclTransType transA,
  111. int m,
  112. int n,
  113. const aclFloat16 *alpha,
  114. const aclFloat16 *a,
  115. int lda,
  116. const aclFloat16 *x,
  117. int incx,
  118. const aclFloat16 *beta,
  119. aclFloat16 *y,
  120. int incy,
  121. aclComputeType type,
  122. aclrtStream stream);
  123. /**
  124. * @ingroup AscendCL
  125. * @brief create a handle for performing the matrix-vector multiplication
  126. *
  127. * @param transA [IN] transpose type of matrix A
  128. * @param m [IN] number of rows of matrix A
  129. * @param n [IN] number of columns of matrix A
  130. * @param type [IN] computation type
  131. * @param handle [OUT] pointer to the pointer to the handle
  132. *
  133. * @retval ACL_SUCCESS The function is successfully executed.
  134. * @retval OtherValues Failure
  135. */
  136. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForHgemv(aclTransType transA,
  137. int m,
  138. int n,
  139. aclComputeType type,
  140. aclopHandle **handle);
  141. /**
  142. * @ingroup AscendCL
  143. * @brief perform the matrix-vector multiplication
  144. *
  145. * @param transA [IN] transpose type of matrix A
  146. * @param m [IN] number of rows of matrix A
  147. * @param n [IN] number of columns of matrix A
  148. * @param alpha [IN] pointer to scalar used for multiplication
  149. * @param a [IN] pointer to matrix A
  150. * @param lda [IN] leading dimension used to store the matrix A
  151. * @param x [IN] pointer to vector x
  152. * @param incx [IN] stride between consecutive elements of vector x
  153. * @param beta [IN] pointer to scalar used for multiplication.
  154. * If beta value == 0,
  155. * then y does not have to be a valid input
  156. * @param y [IN|OUT] pointer to vector y
  157. * @param incy [IN] stride between consecutive elements of vector y
  158. * @param type [IN] computation type
  159. * @param stream [IN] stream
  160. *
  161. * @retval ACL_SUCCESS The function is successfully executed.
  162. * @retval OtherValues Failure
  163. */
  164. ACL_FUNC_VISIBILITY aclError aclblasS8gemv(aclTransType transA,
  165. int m,
  166. int n,
  167. const int32_t *alpha,
  168. const int8_t *a,
  169. int lda,
  170. const int8_t *x,
  171. int incx,
  172. const int32_t *beta,
  173. int32_t *y,
  174. int incy,
  175. aclComputeType type,
  176. aclrtStream stream);
  177. /**
  178. * @ingroup AscendCL
  179. * @brief create a handle for performing the matrix-vector multiplication
  180. *
  181. * @param transA [IN] transpose type of matrix A
  182. * @param m [IN] number of rows of matrix A
  183. * @param n [IN] number of columns of matrix A
  184. * @param handle [OUT] pointer to the pointer to the handle
  185. * @param type [IN] computation type
  186. *
  187. * @retval ACL_SUCCESS The function is successfully executed.
  188. * @retval OtherValues Failure
  189. */
  190. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForS8gemv(aclTransType transA,
  191. int m,
  192. int n,
  193. aclComputeType type,
  194. aclopHandle **handle);
  195. /**
  196. * @ingroup AscendCL
  197. * @brief perform the matrix-matrix multiplication
  198. *
  199. * @param transA [IN] transpose type of matrix A
  200. * @param transB [IN] transpose type of matrix B
  201. * @param transC [IN] transpose type of matrix C
  202. * @param m [IN] number of rows of matrix A and matrix C
  203. * @param n [IN] number of columns of matrix B and matrix C
  204. * @param k [IN] number of columns of matrix A and rows of matrix B
  205. * @param alpha [IN] pointer to scalar used for multiplication. of same type as dataTypeC
  206. * @param matrixA [IN] pointer to matrix A
  207. * @param lda [IN] leading dimension array used to store matrix A
  208. * @param dataTypeA [IN] datatype of matrix A
  209. * @param matrixB [IN] pointer to matrix B
  210. * @param ldb [IN] leading dimension array used to store matrix B
  211. * @param dataTypeB [IN] datatype of matrix B
  212. * @param beta [IN] pointer to scalar used for multiplication.
  213. * of same type as dataTypeC If beta == 0,
  214. * then matrixC does not have to be a valid input
  215. * @param matrixC [IN|OUT] pointer to matrix C
  216. * @param ldc [IN] leading dimension array used to store matrix C
  217. * @param dataTypeC [IN] datatype of matrix C
  218. * @param type [IN] computation type
  219. * @param stream [IN] stream
  220. *
  221. * @retval ACL_SUCCESS The function is successfully executed.
  222. * @retval OtherValues Failure
  223. */
  224. ACL_FUNC_VISIBILITY aclError aclblasGemmEx(aclTransType transA,
  225. aclTransType transB,
  226. aclTransType transC,
  227. int m,
  228. int n,
  229. int k,
  230. const void *alpha,
  231. const void *matrixA,
  232. int lda,
  233. aclDataType dataTypeA,
  234. const void *matrixB,
  235. int ldb,
  236. aclDataType dataTypeB,
  237. const void *beta,
  238. void *matrixC,
  239. int ldc,
  240. aclDataType dataTypeC,
  241. aclComputeType type,
  242. aclrtStream stream);
  243. /**
  244. * @ingroup AscendCL
  245. * @brief create a handle for performing the matrix-matrix multiplication
  246. *
  247. * @param transA [IN] transpose type of matrix A
  248. * @param transB [IN] transpose type of matrix B
  249. * @param transC [IN] transpose type of matrix C
  250. * @param m [IN] number of rows of matrix A and matrix C
  251. * @param n [IN] number of columns of matrix B and matrix C
  252. * @param k [IN] number of columns of matrix A and rows of matrix B
  253. * @param dataTypeA [IN] datatype of matrix A
  254. * @param dataTypeB [IN] datatype of matrix B
  255. * @param dataTypeC [IN] datatype of matrix C
  256. * @param type [IN] computation type
  257. * @param handle [OUT] pointer to the pointer to the handle
  258. * @param type [IN] computation type
  259. *
  260. * @retval ACL_SUCCESS The function is successfully executed.
  261. * @retval OtherValues Failure
  262. */
  263. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForGemmEx(aclTransType transA,
  264. aclTransType transB,
  265. aclTransType transC,
  266. int m,
  267. int n,
  268. int k,
  269. aclDataType dataTypeA,
  270. aclDataType dataTypeB,
  271. aclDataType dataTypeC,
  272. aclComputeType type,
  273. aclopHandle **handle);
  274. /**
  275. * @ingroup AscendCL
  276. * @brief perform the matrix-matrix multiplication
  277. *
  278. * @param transA [IN] transpose type of matrix A
  279. * @param transB [IN] transpose type of matrix B
  280. * @param transC [IN] transpose type of matrix C
  281. * @param m [IN] number of rows of matrix A and matrix C
  282. * @param n [IN] number of columns of matrix B and matrix C
  283. * @param k [IN] number of columns of matrix A and rows of matrix B
  284. * @param alpha [IN] pointer to scalar used for multiplication
  285. * @param matrixA [IN] pointer to matrix A
  286. * @param lda [IN] leading dimension used to store the matrix A
  287. * @param matrixB [IN] pointer to matrix B
  288. * @param ldb [IN] leading dimension used to store the matrix B
  289. * @param beta [IN] pointer to scalar used for multiplication.
  290. * If beta value == 0,
  291. * then matrixC does not have to be a valid input
  292. * @param matrixC [IN|OUT] pointer to matrix C
  293. * @param ldc [IN] leading dimension used to store the matrix C
  294. * @param type [IN] computation type
  295. * @param stream [IN] stream
  296. *
  297. * @retval ACL_SUCCESS The function is successfully executed.
  298. * @retval OtherValues Failure
  299. */
  300. ACL_FUNC_VISIBILITY aclError aclblasHgemm(aclTransType transA,
  301. aclTransType transB,
  302. aclTransType transC,
  303. int m,
  304. int n,
  305. int k,
  306. const aclFloat16 *alpha,
  307. const aclFloat16 *matrixA,
  308. int lda,
  309. const aclFloat16 *matrixB,
  310. int ldb,
  311. const aclFloat16 *beta,
  312. aclFloat16 *matrixC,
  313. int ldc,
  314. aclComputeType type,
  315. aclrtStream stream);
  316. /**
  317. * @ingroup AscendCL
  318. * @brief create a handle for performing the matrix-matrix multiplication
  319. *
  320. * @param transA [IN] transpose type of matrix A
  321. * @param transB [IN] transpose type of matrix B
  322. * @param transC [IN] transpose type of matrix C
  323. * @param m [IN] number of rows of matrix A and matrix C
  324. * @param n [IN] number of columns of matrix B and matrix C
  325. * @param k [IN] number of columns of matrix A and rows of matrix B
  326. * @param type [IN] computation type
  327. * @param handle [OUT] pointer to the pointer to the handle
  328. *
  329. * @retval ACL_SUCCESS The function is successfully executed.
  330. * @retval OtherValues Failure
  331. */
  332. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForHgemm(aclTransType transA,
  333. aclTransType transB,
  334. aclTransType transC,
  335. int m,
  336. int n,
  337. int k,
  338. aclComputeType type,
  339. aclopHandle **handle);
  340. /**
  341. * @ingroup AscendCL
  342. * @brief perform the matrix-matrix multiplication
  343. *
  344. * @param transA [IN] transpose type of matrix A
  345. * @param transB [IN] transpose type of matrix B
  346. * @param transC [IN] transpose type of matrix C
  347. * @param m [IN] number of rows of matrix A and matrix C
  348. * @param n [IN] number of columns of matrix B and matrix C
  349. * @param k [IN] number of columns of matrix A and rows of matrix B
  350. * @param alpha [IN] pointer to scalar used for multiplication
  351. * @param matrixA [IN] pointer to matrix A
  352. * @param lda [IN] leading dimension used to store the matrix A
  353. * @param matrixB [IN] pointer to matrix B
  354. * @param ldb [IN] leading dimension used to store the matrix B
  355. * @param beta [IN] pointer to scalar used for multiplication.
  356. * If beta value == 0,
  357. * then matrixC does not have to be a valid input
  358. * @param matrixC [IN|OUT] pointer to matrix C
  359. * @param ldc [IN] leading dimension used to store the matrix C
  360. * @param type [IN] computation type
  361. * @param stream [IN] stream
  362. *
  363. * @retval ACL_SUCCESS The function is successfully executed.
  364. * @retval OtherValues Failure
  365. */
  366. ACL_FUNC_VISIBILITY aclError aclblasS8gemm(aclTransType transA,
  367. aclTransType transB,
  368. aclTransType transC,
  369. int m,
  370. int n,
  371. int k,
  372. const int32_t *alpha,
  373. const int8_t *matrixA,
  374. int lda,
  375. const int8_t *matrixB,
  376. int ldb,
  377. const int32_t *beta,
  378. int32_t *matrixC,
  379. int ldc,
  380. aclComputeType type,
  381. aclrtStream stream);
  382. /**
  383. * @ingroup AscendCL
  384. * @brief create a handle for performing the matrix-matrix multiplication
  385. *
  386. * @param transA [IN] transpose type of matrix A
  387. * @param transB [IN] transpose type of matrix B
  388. * @param transC [IN] transpose type of matrix C
  389. * @param m [IN] number of rows of matrix A and matrix C
  390. * @param n [IN] number of columns of matrix B and matrix C
  391. * @param k [IN] number of columns of matrix A and rows of matrix B
  392. * @param type [IN] computation type
  393. * @param handle [OUT] pointer to the pointer to the handle
  394. *
  395. * @retval ACL_SUCCESS The function is successfully executed.
  396. * @retval OtherValues Failure
  397. */
  398. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForS8gemm(aclTransType transA,
  399. aclTransType transB,
  400. aclTransType transC,
  401. int m,
  402. int n,
  403. int k,
  404. aclComputeType type,
  405. aclopHandle **handle);
  406. #ifdef __cplusplus
  407. }
  408. #endif
  409. #endif // INC_EXTERNAL_ACL_OPS_ACL_CBLAS_H_

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