The Matrix class adds a dependency to a blas library and its headers (either cblas.h or mkl_cblas.h + mkl.h + mkl_vsl.h + mkl_vml.h, depending on whether USE_MKL is defined or not).

The blas library name along with the include and library search paths could be retrieved from config.blas.ldflags. The cblas interface (which I assume is identical to mkl_cblas) can be retrieved from theano.tensor.blas_headers.cblas_header_text(), and its value can replace the include <cblas.h> directive from matrix.h.

The compilation commands for all the modules that use nvmatrix could be altered to include these dependencies by adding them in the lists returned by c_lib_dirs and c_libraries in pool.py and base_acts.py, as well as in convnet_compile.py, and by adding -D USE_MKL, if the default blas lib is mkl.

However, what I find to be problematic is that the MKL version shipped with EPD doesn't include the mkl specific header files (as far as I can see), while the code in matrix.cpp makes heavy use of mkl specific calls if the library is available.

One option to solve this problem would be to modify the Matrix class so that it only uses the cblas interface to either MKL or another implementation. That would mean that all the references to mkl-only functions in nvmatrix to be deleted, which I believe might result in poorer performance due to not taking full advantage of the MKL.

Another option would be to distribute the header files, or, at least, some of their content along with theano or pylearn, but I fear there might be copyright issues with this approach.

If you only want matrix.h and matrix.cpp for the definitions of the log and sqrt functions, then perhaps it would be easier to just copy those little pieces of code into nvmatrix.h and nvmatirx.cu, respectively, or just keep the explicit casts.