Why does BLAS have a gemm
function for matrix-matrix multiplication and a separate gemv
function for matrix-vector multiplication? Isn't matrix-vector multiplication just a special case of matrix-matrix multiplication where one matrix only has one row/column?
Background: Matrix-Matrix Multiplication GEMM is defined as the operation C = αAB+βC , with A and B as matrix inputs, α and β as scalar inputs, and C as a pre-existing matrix which is overwritten by the output.
Computes a matrix-vector product using a general matrix. Description. The gemv routines compute a scalar-matrix-vector product and add the result to a scalar-vector product, with a general matrix.
BLAS implementations will take advantage of special floating point hardware such as vector registers or SIMD instructions. It originated as a Fortran library in 1979 and its interface was standardized by the BLAS Technical (BLAST) Forum, whose latest BLAS report can be found on the netlib website.
GEMM is a general procedure ubiquitously used in linear al- gebra, machine learning, statistics, and many other areas and is implemented in the BLAS (Basic Linear Algebra Subpro- grams) library (BLA, 2002). It multiplies two input matrices to produce an output matrix.
Mathematically, matrix-vector multiplication is a special case of matrix-matrix multiplication, but that's not necessarily true of them as realized in a software library.
They support different options. For example, gemv
supports strided access to the vectors on which it is operating, whereas gemm
does not support strided matrix layouts. In the C language bindings, gemm
requires that you specify the storage ordering of all three matrices, whereas that is unnecessary in gemv
for the vector arguments because it would be meaningless.
Besides supporting different options, there are families of optimizations that might be performed on gemm
that are not applicable to gemv
. If you know that you are doing a matrix-vector product, you don't want the library to waste time figuring out that's the case before switching into a code path that is optimized for that case; you'd rather call it directly instead.
When you optimize gemv and gemm different techniques apply:
Let me know if you want more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With