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

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 { ACL_TRANS_N, ACL_TRANS_T, ACL_TRANS_NZ, ACL_TRANS_NZ_T } aclTransType;
  23. typedef enum aclComputeType { ACL_COMPUTE_HIGH_PRECISION, ACL_COMPUTE_LOW_PRECISION } aclComputeType;
  24. /**
  25. * @ingroup AscendCL
  26. * @brief perform the matrix-vector multiplication
  27. *
  28. * @param transA [IN] transpose type of matrix A
  29. * @param m [IN] number of rows of matrix A
  30. * @param n [IN] number of columns of matrix A
  31. * @param alpha [IN] pointer to scalar used for multiplication.
  32. * of same type as dataTypeC
  33. * @param a [IN] pointer to matrix A
  34. * @param lda [IN] leading dimension used to store the matrix A
  35. * @param dataTypeA [IN] datatype of matrix A
  36. * @param x [IN] pointer to vector x
  37. * @param incx [IN] stride between consecutive elements of vector x
  38. * @param dataTypeX [IN] datatype of vector x
  39. * @param beta [IN] pointer to scalar used for multiplication.
  40. * of same type as dataTypeC If beta == 0,
  41. * then y does not have to be a valid input
  42. * @param y [IN|OUT] pointer to vector y
  43. * @param incy [IN] stride between consecutive elements of vector y
  44. * @param dataTypeY [IN] datatype of vector y
  45. * @param type [IN] computation type
  46. * @param stream [IN] stream
  47. *
  48. * @retval ACL_SUCCESS The function is successfully executed.
  49. * @retval OtherValues Failure
  50. */
  51. ACL_FUNC_VISIBILITY aclError aclblasGemvEx(aclTransType transA, int m, int n, const void *alpha, const void *a, int lda,
  52. aclDataType dataTypeA, const void *x, int incx, aclDataType dataTypeX,
  53. const void *beta, void *y, int incy, aclDataType dataTypeY,
  54. aclComputeType type, aclrtStream stream);
  55. /**
  56. * @ingroup AscendCL
  57. * @brief create a handle for performing the matrix-vector multiplication
  58. *
  59. * @param transA [IN] transpose type of matrix A
  60. * @param m [IN] number of rows of matrix A
  61. * @param n [IN] number of columns of matrix A
  62. * @param dataTypeA [IN] datatype of matrix A
  63. * @param dataTypeX [IN] datatype of vector x
  64. * @param dataTypeY [IN] datatype of vector y
  65. * @param type [IN] computation type
  66. * @param handle [OUT] pointer to the pointer to the handle
  67. *
  68. * @retval ACL_SUCCESS The function is successfully executed.
  69. * @retval OtherValues Failure
  70. */
  71. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForGemvEx(aclTransType transA, int m, int n, aclDataType dataTypeA,
  72. aclDataType dataTypeX, aclDataType dataTypeY,
  73. aclComputeType type, aclopHandle **handle);
  74. /**
  75. * @ingroup AscendCL
  76. * @brief perform the matrix-vector multiplication
  77. *
  78. * @param transA [IN] transpose type of matrix A
  79. * @param m [IN] number of rows of matrix A
  80. * @param n [IN] number of columns of matrix A
  81. * @param alpha [IN] pointer to scalar used for multiplication
  82. * @param a [IN] pointer to matrix A
  83. * @param lda [IN] leading dimension used to store the matrix A
  84. * @param x [IN] pointer to vector x
  85. * @param incx [IN] stride between consecutive elements of vector x
  86. * @param beta [IN] pointer to scalar used for multiplication.
  87. * If beta value == 0,
  88. * then y does not have to be a valid input
  89. * @param y [IN|OUT] pointer to vector y
  90. * @param incy [IN] stride between consecutive elements of vector y
  91. * @param type [IN] computation type
  92. * @param stream [IN] stream
  93. * @retval ACL_SUCCESS The function is successfully executed.
  94. * @retval OtherValues Failure
  95. */
  96. ACL_FUNC_VISIBILITY aclError aclblasHgemv(aclTransType transA, int m, int n, const aclFloat16 *alpha,
  97. const aclFloat16 *a, int lda, const aclFloat16 *x, int incx,
  98. const aclFloat16 *beta, aclFloat16 *y, int incy, aclComputeType type,
  99. aclrtStream stream);
  100. /**
  101. * @ingroup AscendCL
  102. * @brief create a handle for performing the matrix-vector multiplication
  103. *
  104. * @param transA [IN] transpose type of matrix A
  105. * @param m [IN] number of rows of matrix A
  106. * @param n [IN] number of columns of matrix A
  107. * @param type [IN] computation type
  108. * @param handle [OUT] pointer to the pointer to the handle
  109. *
  110. * @retval ACL_SUCCESS The function is successfully executed.
  111. * @retval OtherValues Failure
  112. */
  113. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForHgemv(aclTransType transA, int m, int n, aclComputeType type,
  114. aclopHandle **handle);
  115. /**
  116. * @ingroup AscendCL
  117. * @brief perform the matrix-vector multiplication
  118. *
  119. * @param transA [IN] transpose type of matrix A
  120. * @param m [IN] number of rows of matrix A
  121. * @param n [IN] number of columns of matrix A
  122. * @param alpha [IN] pointer to scalar used for multiplication
  123. * @param a [IN] pointer to matrix A
  124. * @param lda [IN] leading dimension used to store the matrix A
  125. * @param x [IN] pointer to vector x
  126. * @param incx [IN] stride between consecutive elements of vector x
  127. * @param beta [IN] pointer to scalar used for multiplication.
  128. * If beta value == 0,
  129. * then y does not have to be a valid input
  130. * @param y [IN|OUT] pointer to vector y
  131. * @param incy [IN] stride between consecutive elements of vector y
  132. * @param type [IN] computation type
  133. * @param stream [IN] stream
  134. *
  135. * @retval ACL_SUCCESS The function is successfully executed.
  136. * @retval OtherValues Failure
  137. */
  138. ACL_FUNC_VISIBILITY aclError aclblasS8gemv(aclTransType transA, int m, int n, const int32_t *alpha, const int8_t *a,
  139. int lda, const int8_t *x, int incx, const int32_t *beta, int32_t *y,
  140. int incy, aclComputeType type, aclrtStream stream);
  141. /**
  142. * @ingroup AscendCL
  143. * @brief create a handle for performing 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 handle [OUT] pointer to the pointer to the handle
  149. * @param type [IN] computation type
  150. *
  151. * @retval ACL_SUCCESS The function is successfully executed.
  152. * @retval OtherValues Failure
  153. */
  154. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForS8gemv(aclTransType transA, int m, int n, aclComputeType type,
  155. aclopHandle **handle);
  156. /**
  157. * @ingroup AscendCL
  158. * @brief perform the matrix-matrix multiplication
  159. *
  160. * @param transA [IN] transpose type of matrix A
  161. * @param transB [IN] transpose type of matrix B
  162. * @param transC [IN] transpose type of matrix C
  163. * @param m [IN] number of rows of matrix A and matrix C
  164. * @param n [IN] number of columns of matrix B and matrix C
  165. * @param k [IN] number of columns of matrix A and rows of matrix B
  166. * @param alpha [IN] pointer to scalar used for multiplication. of same type as dataTypeC
  167. * @param matrixA [IN] pointer to matrix A
  168. * @param lda [IN] leading dimension array used to store matrix A
  169. * @param dataTypeA [IN] datatype of matrix A
  170. * @param matrixB [IN] pointer to matrix B
  171. * @param ldb [IN] leading dimension array used to store matrix B
  172. * @param dataTypeB [IN] datatype of matrix B
  173. * @param beta [IN] pointer to scalar used for multiplication.
  174. * of same type as dataTypeC If beta == 0,
  175. * then matrixC does not have to be a valid input
  176. * @param matrixC [IN|OUT] pointer to matrix C
  177. * @param ldc [IN] leading dimension array used to store matrix C
  178. * @param dataTypeC [IN] datatype of matrix C
  179. * @param type [IN] computation type
  180. * @param stream [IN] stream
  181. *
  182. * @retval ACL_SUCCESS The function is successfully executed.
  183. * @retval OtherValues Failure
  184. */
  185. ACL_FUNC_VISIBILITY aclError aclblasGemmEx(aclTransType transA, aclTransType transB, aclTransType transC, int m, int n,
  186. int k, const void *alpha, const void *matrixA, int lda,
  187. aclDataType dataTypeA, const void *matrixB, int ldb, aclDataType dataTypeB,
  188. const void *beta, void *matrixC, int ldc, aclDataType dataTypeC,
  189. aclComputeType type, aclrtStream stream);
  190. /**
  191. * @ingroup AscendCL
  192. * @brief create a handle for performing the matrix-matrix multiplication
  193. *
  194. * @param transA [IN] transpose type of matrix A
  195. * @param transB [IN] transpose type of matrix B
  196. * @param transC [IN] transpose type of matrix C
  197. * @param m [IN] number of rows of matrix A and matrix C
  198. * @param n [IN] number of columns of matrix B and matrix C
  199. * @param k [IN] number of columns of matrix A and rows of matrix B
  200. * @param dataTypeA [IN] datatype of matrix A
  201. * @param dataTypeB [IN] datatype of matrix B
  202. * @param dataTypeC [IN] datatype of matrix C
  203. * @param type [IN] computation type
  204. * @param handle [OUT] pointer to the pointer to the handle
  205. * @param type [IN] computation type
  206. *
  207. * @retval ACL_SUCCESS The function is successfully executed.
  208. * @retval OtherValues Failure
  209. */
  210. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForGemmEx(aclTransType transA, aclTransType transB, aclTransType transC,
  211. int m, int n, int k, aclDataType dataTypeA,
  212. aclDataType dataTypeB, aclDataType dataTypeC,
  213. aclComputeType type, aclopHandle **handle);
  214. /**
  215. * @ingroup AscendCL
  216. * @brief perform the matrix-matrix multiplication
  217. *
  218. * @param transA [IN] transpose type of matrix A
  219. * @param transB [IN] transpose type of matrix B
  220. * @param transC [IN] transpose type of matrix C
  221. * @param m [IN] number of rows of matrix A and matrix C
  222. * @param n [IN] number of columns of matrix B and matrix C
  223. * @param k [IN] number of columns of matrix A and rows of matrix B
  224. * @param alpha [IN] pointer to scalar used for multiplication
  225. * @param matrixA [IN] pointer to matrix A
  226. * @param lda [IN] leading dimension used to store the matrix A
  227. * @param matrixB [IN] pointer to matrix B
  228. * @param ldb [IN] leading dimension used to store the matrix B
  229. * @param beta [IN] pointer to scalar used for multiplication.
  230. * If beta value == 0,
  231. * then matrixC does not have to be a valid input
  232. * @param matrixC [IN|OUT] pointer to matrix C
  233. * @param ldc [IN] leading dimension used to store the matrix C
  234. * @param type [IN] computation type
  235. * @param stream [IN] stream
  236. *
  237. * @retval ACL_SUCCESS The function is successfully executed.
  238. * @retval OtherValues Failure
  239. */
  240. ACL_FUNC_VISIBILITY aclError aclblasHgemm(aclTransType transA, aclTransType transB, aclTransType transC, int m, int n,
  241. int k, const aclFloat16 *alpha, const aclFloat16 *matrixA, int lda,
  242. const aclFloat16 *matrixB, int ldb, const aclFloat16 *beta,
  243. aclFloat16 *matrixC, int ldc, aclComputeType type, aclrtStream stream);
  244. /**
  245. * @ingroup AscendCL
  246. * @brief create a handle for performing the matrix-matrix multiplication
  247. *
  248. * @param transA [IN] transpose type of matrix A
  249. * @param transB [IN] transpose type of matrix B
  250. * @param transC [IN] transpose type of matrix C
  251. * @param m [IN] number of rows of matrix A and matrix C
  252. * @param n [IN] number of columns of matrix B and matrix C
  253. * @param k [IN] number of columns of matrix A and rows of matrix B
  254. * @param type [IN] computation type
  255. * @param handle [OUT] pointer to the pointer to the handle
  256. *
  257. * @retval ACL_SUCCESS The function is successfully executed.
  258. * @retval OtherValues Failure
  259. */
  260. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForHgemm(aclTransType transA, aclTransType transB, aclTransType transC,
  261. int m, int n, int k, aclComputeType type,
  262. aclopHandle **handle);
  263. /**
  264. * @ingroup AscendCL
  265. * @brief perform the matrix-matrix multiplication
  266. *
  267. * @param transA [IN] transpose type of matrix A
  268. * @param transB [IN] transpose type of matrix B
  269. * @param transC [IN] transpose type of matrix C
  270. * @param m [IN] number of rows of matrix A and matrix C
  271. * @param n [IN] number of columns of matrix B and matrix C
  272. * @param k [IN] number of columns of matrix A and rows of matrix B
  273. * @param alpha [IN] pointer to scalar used for multiplication
  274. * @param matrixA [IN] pointer to matrix A
  275. * @param lda [IN] leading dimension used to store the matrix A
  276. * @param matrixB [IN] pointer to matrix B
  277. * @param ldb [IN] leading dimension used to store the matrix B
  278. * @param beta [IN] pointer to scalar used for multiplication.
  279. * If beta value == 0,
  280. * then matrixC does not have to be a valid input
  281. * @param matrixC [IN|OUT] pointer to matrix C
  282. * @param ldc [IN] leading dimension used to store the matrix C
  283. * @param type [IN] computation type
  284. * @param stream [IN] stream
  285. *
  286. * @retval ACL_SUCCESS The function is successfully executed.
  287. * @retval OtherValues Failure
  288. */
  289. ACL_FUNC_VISIBILITY aclError aclblasS8gemm(aclTransType transA, aclTransType transB, aclTransType transC, int m, int n,
  290. int k, const int32_t *alpha, const int8_t *matrixA, int lda,
  291. const int8_t *matrixB, int ldb, const int32_t *beta, int32_t *matrixC,
  292. int ldc, aclComputeType type, aclrtStream stream);
  293. /**
  294. * @ingroup AscendCL
  295. * @brief create a handle for performing the matrix-matrix multiplication
  296. *
  297. * @param transA [IN] transpose type of matrix A
  298. * @param transB [IN] transpose type of matrix B
  299. * @param transC [IN] transpose type of matrix C
  300. * @param m [IN] number of rows of matrix A and matrix C
  301. * @param n [IN] number of columns of matrix B and matrix C
  302. * @param k [IN] number of columns of matrix A and rows of matrix B
  303. * @param type [IN] computation type
  304. * @param handle [OUT] pointer to the pointer to the handle
  305. *
  306. * @retval ACL_SUCCESS The function is successfully executed.
  307. * @retval OtherValues Failure
  308. */
  309. ACL_FUNC_VISIBILITY aclError aclblasCreateHandleForS8gemm(aclTransType transA, aclTransType transB, aclTransType transC,
  310. int m, int n, int k, aclComputeType type,
  311. aclopHandle **handle);
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif // INC_EXTERNAL_ACL_OPS_ACL_CBLAS_H_

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