C++ matrix type(s) for use with MKL BLAS

C++ matrix type(s) for use with MKL BLAS

It seems Intel is considering putting its weight behind the boost::numeric::matrix library. I think this is the wrong choice.

To write efficient code with the boost::numeric::matrix library requires good knowledge of C++ templates, which is not something most hpc programmers have, nor should they need to. In many cases it forces the programmer to explicitly state that the lhs is non aliased to avoid temporary construction, and using operator overloading to wrap calls to the mkl blas introduces a layer between client and mkl which requires expert knowledge of how C++ works in order to be sure the resultant behaviour is efficient. While compilers these days may be sufficiently standardised in terms of their implementation of C++ template features, I personally am not confident of this and won't be trusting it for production code any time soon.

Intel should provide its own simple matrix and vector classes, and wrappers on the relevant mkl routines that take care of defaulting parameters to the wrapped call based on the shape of the matrix, e.g. for dgemm we can default the row order parameter and m,n,k,lda,ldb etc, resulting in an interface that is as simple as the fortran:

void my_dgemm(const dmatrix& A, const dmatrix& B, dmatrix& Result, bool transposeA=false, bool transposeB=false, double alpha=1.0, double beta=0.0)

//the dmatrix class could look something like this:
class dmatrix
size_t row_count; size_t col_count;
std::vector data; // could make this a raw double* if we need to MKL_alloc in the constructor for alignment etc.
dmatrix(size_t r, size_t c): row_count, col_count(c) { data.resize(row_count*col_count)}
operator double*() { return &data[0]; }
//...element access, copy, assignment etc - but no operator overloads for blas operations

These classes and wrappers should be relatively simple to create, and if Intel provides them, they can control their implementation and control/guarantee efficiency; also, this way, Intel won't end up spending a bunch of time helping users through misunderstanding of third party matrix implementations.

Anyone want to have a bash at a reference implementation on github?

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.