42.cuBLAS开发指南中文版--cuBLAS中的Level-3函数gemm()

2.7.1. cublas<t>gemm()

在这里插入图片描述

cublasStatus_t cublasSgemm(cublasHandle_t handle,
                           cublasOperation_t transa, cublasOperation_t transb,
                           int m, int n, int k,
                           const float           *alpha,
                           const float           *A, int lda,
                           const float           *B, int ldb,
                           const float           *beta,
                           float           *C, int ldc)
cublasStatus_t cublasDgemm(cublasHandle_t handle,
                           cublasOperation_t transa, cublasOperation_t transb,
                           int m, int n, int k,
                           const double          *alpha,
                           const double          *A, int lda,
                           const double          *B, int ldb,
                           const double          *beta,
                           double          *C, int ldc)
cublasStatus_t cublasCgemm(cublasHandle_t handle,
                           cublasOperation_t transa, cublasOperation_t transb,
                           int m, int n, int k,
                           const cuComplex       *alpha,
                           const cuComplex       *A, int lda,
                           const cuComplex       *B, int ldb,
                           const cuComplex       *beta,
                           cuComplex       *C, int ldc)
cublasStatus_t cublasZgemm(cublasHandle_t handle,
                           cublasOperation_t transa, cublasOperation_t transb,
                           int m, int n, int k,
                           const cuDoubleComplex *alpha,
                           const cuDoubleComplex *A, int lda,
                           const cuDoubleComplex *B, int ldb,
                           const cuDoubleComplex *beta,
                           cuDoubleComplex *C, int ldc)
cublasStatus_t cublasHgemm(cublasHandle_t handle,
                           cublasOperation_t transa, cublasOperation_t transb,
                           int m, int n, int k,
                           const __half *alpha,
                           const __half *A, int lda,
                           const __half *B, int ldb,
                           const __half *beta,
                           __half *C, int ldc)

此函数执行矩阵矩阵乘法

C = α o p ( A ) o p ( B ) + β C C = \alpha op(A)op(B) + \beta C C=αop(A)op(B)+βC

其中 α \alpha α β \beta β 是标量,A 、 B 和 C 是以列优先格式存储的矩阵,维度分别为 op(A) mxk 、 op(B) kxn 和 C mxn 。 另外,对于矩阵 A:

o p ( A ) = { A      如 果 t r a n s a = = C U B L A S _ O P _ N , A T    如 果 t r a n s a = = C U B L A S _ O P _ T , A H    如 果 t r a n s a = = C U B L A S _ O P _ C op(A)= \begin{cases} A\ \ \ \ 如果 transa == CUBLAS\_OP\_N,\\ A^T \ \ 如果 transa == CUBLAS\_OP\_T,\\ A^H \ \ 如果 transa == CUBLAS\_OP\_C \end{cases} op(A)=A    transa==CUBLAS_OP_N,AT  transa==CUBLAS_OP_T,AH  transa==CUBLAS_OP_C

这里op(B)定义的是B矩阵

Param.MemoryIn/outMeaning
handleinputhandle to the cuBLAS library context.
transainputOperation op(A) that is non- or (conj.) transpose.
transbinputOperation op(B) that is non- or (conj.) transpose.
minputNumber of rows of matrix op(A) and C.
ninputNumber of columns of matrix op(B) and C.
kinputNumber of columns of op(A) and rows of op(B).
alphahost or deviceinput<type> scalar used for multiplication.
Adeviceinput<type> array of dimensions lda x k with lda>=max(1,m) if transa == CUBLAS_OP_N and lda x m with lda>=max(1,k) otherwise.
ldainputLeading dimension of two-dimensional array used to store the matrix A.
Bdeviceinput<type> array of dimension ldb x n with ldb>=max(1,k) if transb == CUBLAS_OP_N and ldb x k with ldb>=max(1,n) otherwise.
ldbinputLeading dimension of two-dimensional array used to store matrix B.
betahost or deviceinput<type> scalar used for multiplication. If beta==0, C does not have to be a valid input.
Cdevicein/out<type> array of dimensions ldc x n with ldc>=max(1,m).
ldcinputLeading dimension of a two-dimensional array used to store the matrix C.

该函数可能返回的错误值及其含义如下表所示:

ErrorValueMeaning
CUBLAS_STATUS_SUCCESS操作成功完成
CUBLAS_STATUS_NOT_INITIALIZED库未初始化
CUBLAS_STATUS_INVALID_VALUEIf m, n, k < 0 or if transa, transb != CUBLAS_OP_N, CUBLAS_OP_C, CUBLAS_OP_T or if lda < max(1, m) if transa == CUBLAS_OP_N and lda < max(1, k) otherwise or if ldb < max(1, k) if transb == CUBLAS_OP_N and ldb < max(1, n) otherwise or if ldc < max(1, m) or if alpha, beta == NULL or C == NULL if C needs to be scaled
CUBLAS_STATUS_EXECUTION_FAILED该功能无法在 GPU 上启动

参考资料请参考:

sgemm, dgemm, cgemm, zgemm

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

扫地的小何尚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值