BLAS.gemm on views of matrices does not work

I am not sure if this should work:

using LinearAlgebra
BLAS.gemm('N', 'N', @view(zeros(10,10)[:, 1:3:10]), @view(zeros(10,20)[1:3:10,:]))

It fails with ERROR: matrix does not have contiguous columns.
However, so does BLAS.gemm('N', 'N', zeros(10,4), @view(zeros(10,20)[1:3:10,:])) where there is no column that could be non-continous, but maybe that is just an imprecise error message.

I am asking because I want to use BLAS calls for matrix multiplication with StridedArrays to save on memory allocation and achieve maximal performance.

1 Like

The columns are not contiguous in memory here, since you are skipping to every 3rd row in each column, so this memory layout is not supported by BLAS.

(Why are you calling BLAS.gemm directly instead of using mul!?)


I see, after reading the Implementation section of Mutli-dimensional Arrays I thought BLAS may also support arrays where the dimension over which is summed up is strided, but that is wrong.

Thanks for the tip!