3 ms·
The Fortran matmul intrinsic doesn't use an optimal algorithm?
by leereeves 3y ago
The Fortran matmul intrinsic doesn't use an optimal algorithm?
- duped 3y agoEven theoretically this is only possible if the dimensions and sparseness are known at compile time, which can be pretty heavy assumptions.
- jcranmer 3y agoThe implementation of every BLAS implementation I'm aware of basically looks like this: if (dims in range A) gemm_implA else if (dims in range B) gemm_implB else if (dims in range C) gemm_implC // several more implementations... The immediate call function is invariably a switch over several implementations, and by the time you reach that call, you have actual knowledge of dimensions.
- duped 3y agoThe branch there can be expensive for small matrices.
- kergonath 3y agoThe compiler is responsible for the implementation of the matmul intrinsic. Most of them have a “decent for small matrices and easy to inline” version by default and an option to convert it to call to BLAS under certain conditions (like larger matrices). Then, the performance is that of your BLAS library. The assumption (quite good in my experience) is that people use the intrinsic naturally because it is easy and natural, but turn to BLAS calls when performance becomes important. Which is not the case for the vast majority of matrix multiplication, even in high performance computing. There is no universal optimal algorithm.
- deleted 3y ago[deleted]