There are three levels of BLAS operations,
- Level 1
- Vector operations, e.g. y = /alpha x + y 向量操作
- Level 2
- Matrix-vector operations, e.g. y = /alpha A x + /beta y 矩阵与向量操作
- Level 3
- Matrix-matrix operations, e.g. C = /alpha A B + C 矩阵与矩阵的操作
Each routine has a name which specifies the operation, the type of matrices involved and their precisions. Some of the most common operations and their names are given below,
- DOT
- scalar product, x^T y
- AXPY
- vector sum, /alpha x + y
- MV
- matrix-vector product, A x
- SV
- matrix-vector solve, inv(A) x
- MM
- matrix-matrix product, A B
- SM
- matrix-matrix solve, inv(A) B
The type of matrices are,
- GE
- general
- GB
- general band
- SY
- symmetric
- SB
- symmetric band
- SP
- symmetric packed
- HE
- hermitian
- HB
- hermitian band
- HP
- hermitian packed
- TR
- triangular
- TB
- triangular band
- TP
- triangular packed
Each operation is defined for four precisions,
- S
- single real
- D
- double real
- C
- single complex
- Z
- double complex
Thus, for example, the name SGEMM stands for "single-precision general matrix-matrix multiply" and ZGEMM stands for "double-precision complex matrix-matrix multiply".
因此,例如,命名为SGEMM的函数意思为“单精度普通矩阵乘法”,ZGEMM为“双精度复数矩阵乘法”。
关于blas的具体介绍请参考:http://www.netlib.org/blas/
下面是一些具体的函数说明:
参考:http://blog.csdn.net/g_spider/article/details/6054990
cblas使用:
extern "C" { #include <common.h> #include <cblas.h> } int main(void) { const enum CBLAS_ORDER Order=CblasRowMajor; const enum CBLAS_TRANSPOSE TransA=CblasTrans; const enum CBLAS_TRANSPOSE TransB=CblasNoTrans; const int M=1;//A的行数,C的行数 const int N=2;//B的列数,C的列数 const int K=3;//A的列数,B的行数 const double alpha=1; const double beta=0; const int lda=M;//A的列 const int ldb=N;//B的列 const int ldc=N;//C的列 double A[]={ 1,2,3}; double B[]={ 5,4,3,2,1,0}; double C[2]; cblas_dgemm(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); for(int i=0;i<1;i++) { for(int j=0;j<2;j++) { cout<<C[i*2+j]<<" "; } cout<<endl; } return 0; }
当使用转置时,M,N,K分别对应转置之后A,B,C的行、列,lda,ldb,ldc对应转置之前A,B,C的列