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?
Why does BLAS have a gemm function for matrix-matrix multiplication and a separate gemv
Share
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,
gemvsupports strided access to the vectors on which it is operating, whereasgemmdoes not support strided matrix layouts. In the C language bindings,gemmrequires that you specify the storage ordering of all three matrices, whereas that is unnecessary ingemvfor the vector arguments because it would be meaningless.Besides supporting different options, there are families of optimizations that might be performed on
gemmthat are not applicable togemv. 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.