前言
前面介绍了BLAS Level 1中向量-向量操作,以及BLAS Level 2中矩阵-向量的操作,就剩下这一篇的BLAS Level 3中的矩阵-矩阵的操作了。对稀疏矩阵的操作以后等要用再看看。对基本的矩阵和向量运算的函数有所了解以后,就进行常用参数分析,以及实现了。
所有函数概览
函数名称 | 缺失部分 | 描述 |
---|---|---|
cblas_?gemm | s,d,c,z | 一般矩阵的矩阵-矩阵乘法 |
cblas_?hemm | c,z | 某个输入矩阵是Hermitian,然后计算矩阵-矩阵乘法 |
cblas_?herk | c,z | Hermitian的k阶更新 |
cblas_?herk2 | c,z | Hermitian的2k阶更新 |
cblas_?symm | s,d,c,z | 某个输入矩阵是对称的,然后计算矩阵-矩阵乘法 |
cblas_?syrk | s,d,c,z | 对称矩阵的k阶更新 |
cblas_?syr2k | s,d,c,z | 对称矩阵的2k阶更新 |
cblas_?trmm | s,d,c,z | 某个输入矩阵是三角的,就是你矩阵-矩阵的乘法 |
cblas_?trsm | s,d,c,z | 解三角矩阵方程 |
矩阵运算
cblas_?gemm
-
作用 : 一般矩阵的矩阵-矩阵乘法
-
定义函数
void cblas_sgemm (const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const MKL_INT m, const MKL_INT n, const MKL_INT k, const float alpha, const float *a, const MKL_INT lda, const float *b, const MKL_INT ldb, const float beta, float *c, const MKL_INT ldc); void cblas_dgemm (const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const MKL_INT m, const MKL_INT n, const MKL_INT k, const double alpha, const double *a, const MKL_INT lda, const double *b, const MKL_INT ldb, const double beta, double *c, const MKL_INT ldc); void cblas_cgemm (const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const MKL_INT m, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc); void cblas_zgemm (const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const MKL_INT m, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc);
-
运算
C:=α∗op(A)∗op(B)+β∗C
C:=\\alpha*op(A)*op(B)+\\beta*C
其中op(x)
op(x)可以是op(x)=x
op(x)=x或者op(x)=xT
op(x)=x^T或者op(x)=XH
op(x)=X^Hα
\\alpha和β
\\beta是标量A,B,C
A,B,C是矩阵:op(A)
op(A)是一个m∗k
m*k的矩阵,op(B)
op(B)是k∗n
k*n的矩阵,C是一个m∗n
m*n的矩阵 -
输入参数
Layout
: 指定矩阵是行优先(CblasRowMajor
)还是列优先(CblasColMajor
)transa
: 指定对矩阵的操作op(A)
op(A),如果transa=CblasNoTrans
那么op(A)=A
op(A)=A;如果transa=CblasTrans
那么op(A)=AT
op(A)=A^T;如果transa=CblasConjTrans
那么op(A)=AH
op(A)=A^Htransb
: 同上m
: 矩阵op(A)
op(A)和C
C的行数n
: 矩阵op(B)op(B)和C的列数k
: 矩阵op(A)
op(A)和op(B)
op(B)的列数alpha
: 标量a
:
transa=CblasNoTrans | transa=CblasTrans或者transa=CblasConjTrans |
---|---|
Layout=CblasColMajor | 矩阵大小
lda∗k |
Layout=CblasRowMajor | 矩阵大小
lda∗m |
lda
: 引导维度
transa=CblasNoTrans | transa=CblasTrans或者transa=CblasConjTrans |
---|---|
Layout=CblasColMajor |
lda max(1,m) |
Layout=CblasRowMajor |
lda max(1,k) |
b
:
transa=CblasNoTrans | transa=CblasTrans或者transa=CblasConjTrans |
---|---|
Layout=CblasColMajor | 矩阵大小
ldb∗n |
Layout=CblasRowMajor | 矩阵大小
ldb∗k |
ldb
:
transa=CblasNoTrans | transa=CblasTrans或者transa=CblasConjTrans |
---|---|
Layout=CblasColMajor |
ldb max(1,k) |
Layout=CblasRowMajor |
ldb max(1,n) |
beta
: 标量
c
: 当Layout=CblasColMajor
时候,数组大小为
lda∗n
lda*n;当Layout=CblasRowMajor
时候,数组大小为
lda∗m
lda*m
ldc
:当Layout=CblasColMajor
的时候,ldc
必须至少为
max(1,m)
max(1,m);当Layout=CblasRowMajor
的时候,ldc
必须至少为
max(1,n)
max(1,n)
- 输出参数: 将计算得到的矩阵写入到
c
cblas_?hemm
-
作用 : 当一个输入矩阵为Hermitian时,计算矩阵-矩阵的乘法
-
定义函数
void cblas_chemm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc); void cblas_zhemm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc);
-
运算
C:=α∗A∗B+β∗CC:=α∗B∗A+β∗C
C:=\\alpha*A*B+\\beta*C\\\\
C:=\\alpha*B*A+\\beta *C
其中,α,β
\\alpha,\\beta是标量,A
A是Hermitian矩阵,B,CB,C是m∗n
m*n的矩阵
cblas_?herk
-
作用: Hermitian的k阶更新
-
定义函数:
void cblas_cherk (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const float alpha, const void *a, const MKL_INT lda, const float beta, void *c, const MKL_INT ldc); void cblas_zherk (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const double alpha, const void *a, const MKL_INT lda, const double beta, void *c, const MKL_INT ldc);
-
运算
C:=α∗A∗AH+β∗CC:=α∗AH∗A+β∗C
C:=\\alpha*A*A^H+\\beta*C\\\\
C:=\\alpha*A^H*A+\\beta*C
其中,α,β
\\alpha,\\beta是标量,C
C是n∗nn*n的Hermitian矩阵,第一个式子的A
A是n∗kn*k矩阵,第二个式子的A
A是k∗nk*n的矩阵
cblas_?herk2
-
作用: Hermitian矩阵的2阶更新
-
定义函数
void cblas_cher2k (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const float beta, void *c, const MKL_INT ldc); void cblas_zher2k (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const double beta, void *c, const MKL_INT ldc);
-
运算
C:=α∗A∗BH+conjg(α)∗B∗AH+β∗CC:=α∗AH∗B+conjg(α)∗BH∗A+β∗C
C:=\\alpha*A*B^H+conjg(\\alpha)*B*A^H+\\beta*C\\\\
C:=\\alpha*A^H*B+conjg(\\alpha)*B^H*A+\\beta*C
其中,α,β
\\alpha,\\beta是标量,C
C是n∗nn*n是Hermitian矩阵,第一个式子中A,B
A,B是n∗k
n*k矩阵,第二个式子中是k∗n
k*n的矩阵
cblas_?symm
-
作用: 某个输入是对称矩阵时候,计算矩阵-矩阵的乘法
-
定义函数
void cblas_ssymm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const MKL_INT m, const MKL_INT n, const float alpha, const float *a, const MKL_INT lda, const float *b, const MKL_INT ldb, const float beta, float *c, const MKL_INT ldc); void cblas_dsymm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const MKL_INT m, const MKL_INT n, const double alpha, const double *a, const MKL_INT lda, const double *b, const MKL_INT ldb, const double beta, double *c, const MKL_INT ldc); void cblas_csymm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc); void cblas_zsymm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc);
-
运算
C:=α∗A∗b+β∗CC:=α∗B∗A+β∗C
C:=\\alpha*A*b+\\beta*C\\\\
C:=\\alpha*B*A+\\beta*C
其中α,β
\\alpha,\\beta是标量,A
A是对称阵,B,CB,C是m∗n
m*n的矩阵
cblas_?syrk
-
作用: 对称矩阵的k阶更新
-
定义函数
void cblas_ssyrk (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const float alpha, const float *a, const MKL_INT lda, const float beta, float *c, const MKL_INT ldc); void cblas_dsyrk (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const double alpha, const double *a, const MKL_INT lda, const double beta, double *c, const MKL_INT ldc); void cblas_csyrk (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *beta, void *c, const MKL_INT ldc); void cblas_zsyrk (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *beta, void *c, const MKL_INT ldc)
-
运算
C:=α∗A∗A′+β∗CC:=α∗A′∗A+β∗C
C:=\\alpha*A*A’+\\beta*C\\\\
C:=\\alpha*A\’*A+\\beta*C
其中,α,β
\\alpha,\\beta是标量,C
C是n∗nn*n的对称阵,第一个式子中A
A是n∗nn*n的矩阵,第二个式子中A
A是k∗nk*n的矩阵
cblas_?syr2k
-
作用: 对称阵的二阶更新
-
定义函数
void cblas_ssyr2k (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const float alpha, const float *a, const MKL_INT lda, const float *b, const MKL_INT ldb, const float beta, float *c, const MKL_INT ldc); void cblas_dsyr2k (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const double alpha, const double *a, const MKL_INT lda, const double *b, const MKL_INT ldb, const double beta, double *c, const MKL_INT ldc); void cblas_csyr2k (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc); void cblas_zsyr2k (const CBLAS_LAYOUT Layout, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE trans, const MKL_INT n, const MKL_INT k, const void *alpha, const void *a, const MKL_INT lda, const void *b, const MKL_INT ldb, const void *beta, void *c, const MKL_INT ldc);
-
运算
C:=α∗A∗B′+α∗B∗A′+β∗CC:=α∗A′∗B+α∗B′∗A+β∗C
C := \\alpha*A*B\’ + \\alpha*B*A\’ + \\beta*C\\\\
C := \\alpha*A\’*B + \\alpha*B\’*A + \\beta*C
其中,α,β
\\alpha,\\beta是标量,C
C是n∗nn*n的对称阵,第一个式子中A,B
A,B是n∗k
n*k的矩阵,第二个式子中A,B
A,B是k∗n
k*n的矩阵
cblas_?trmm
-
作用: 某个输入矩阵为三角阵的时候,计算矩阵-矩阵的乘法
-
定义函数
void cblas_strmm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const float alpha, const float *a, const MKL_INT lda, float *b, const MKL_INT ldb); void cblas_dtrmm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const double alpha, const double *a, const MKL_INT lda, double *b, const MKL_INT ldb); void cblas_ctrmm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, void *b, const MKL_INT ldb); void cblas_ztrmm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, void *b, const MKL_INT ldb);
-
运算
B:=α∗op(A)∗BB:=α∗B∗op(A)
B := \\alpha*op(A)*B\\\\
B := \\alpha*B*op(A)
其中,α
\\alpha是标量,B
B是m∗nm*n的矩阵,op(A)=A
op(A)=A或者op(A)=A′
op(A)=A\’或者op(A)=conjg(A′)
op(A)=conjg(A\’)
cblas_?trsm
-
作用: 解三角矩阵方程
-
定义函数
void cblas_strsm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const float alpha, const float *a, const MKL_INT lda, float *b, const MKL_INT ldb); void cblas_dtrsm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const double alpha, const double *a, const MKL_INT lda, double *b, const MKL_INT ldb); void cblas_ctrsm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, void *b, const MKL_INT ldb); void cblas_ztrsm (const CBLAS_LAYOUT Layout, const CBLAS_SIDE side, const CBLAS_UPLO uplo, const CBLAS_TRANSPOSE transa, const CBLAS_DIAG diag, const MKL_INT m, const MKL_INT n, const void *alpha, const void *a, const MKL_INT lda, void *b, const MKL_INT ldb);
-
运算
op(A)∗X=α∗BX∗op(A)=alpha∗B
op(A)*X = \\alpha*B\\\\
X*op(A) = alpha*B
其中,α
\\alpha是一个标量,X和B
X和B是一个m∗n
m*n的矩阵,A
A是单位或者非单位,上三角或者下三角矩阵,op(A)=Aop(A)=A或者op(A)=A′
op(A)=A\’或者op(A)=conjg(A′)
op(A)=conjg(A’)。把等式的解矩阵X
X冲写入到BB矩阵中。
后续
研究BLAS Level 1 2 3中各种矩阵相关概念。随后是代码实现
暂无评论内容