# BLAS libraries for Octave or Matlab, preferrably with GPU support?

I just searched around a bit for BLAS implementations and was amazed by the sheer amount of libraries around. Does someone know of a benchmark or otherwise rating of the various libraries?

1. How easy they are to install.
2. Performance.
3. How easy they are to get to work with Octave or Matlab.

I realize all of these would depend on OS and hardware and version of the softwares. But any input would be welcome at this point.

• It's a bit unclear what you mean, because the default linear algebra functionality of any language like octave/matlab is already provided by a blas library included with the distribution. Are you specifically looking for a GPU-accelerated drop-in replacement BLAS, or have I misunderstood? I believe matlab has the proprietary parallel computing toolbox for gpu linear algebra. – Kirill Jan 25 '17 at 20:19
• Yes something like that. – mathreadler Jan 25 '17 at 20:23
• MATLAB already comes with high performance BLAS libraries, so there's no real point in replacing them. – Brian Borchers Jan 25 '17 at 21:13
• Maybe not worth it in terms of performance, but there is always a point in learning. – mathreadler Jan 25 '17 at 21:34
• Octave comes with internal reference BLAS and OpenBLAS. The problem is the default is the vanilla BLAS. You surely need to switch them for decent performance. – Royi May 24 '19 at 7:51

Among open-source BLAS, as far as I know, OpenBLAS (http://www.openblas.net/) is the best option. The website has a DGEMM benchmark, comparing against MKL (see below) and the reference Fortran BLAS. The library is threaded and written in C and assembly. For GPUs, there's clBLAS (https://github.com/clMathLibraries/clBLAS) that implements BLAS using OpenCL. Unfortunately I don't know of benchmarks for clBLAS.

If closed-source proprietary BLAS implementations are okay, Intel MKL is a good option for use on multi-core CPUs and Xeon-Phi accelerators. It has more than just BLAS - it also includes many LAPACK functions and FFT, for instance. NVIDIA's CuBLAS is an option for CUDA-enabled GPUs. cuBLAS is compared against MKL here http://developer.download.nvidia.com/compute/cuda/6_5/rel/docs/CUDA_6.5_Performance_Report.pdf.

I don't know about ClBLAS, but the others are pretty easy to install on Linux; the documentation is clear enough. As for interfacing with Octave/MATLAB, I don't know because I don't use them, but hopefully someone else can answer about that.

• If you are working on an IBM Power8 platform there is a special version of the ESSL library which also contains basic offloading to CUDA for several BLAS calls. – M.K. aka Grisu Feb 6 '17 at 7:39
• Oh I didn't know that, thanks. Anyway, I assumed we were looking at x86 systems since they're the most common; I don't know much about IBM's platform. – Aditya Kashi Feb 6 '17 at 18:41

MATLAB already comes with Intel MKL for its BLAS implementation. There's no reason to replace that.

As for using GPUs, if you make your array a gpuArray (to do that, just do gpuArray(A)), then you can use MATLAB's matrix multiplication and it will use optimized kernals from MAGMA to perform the computation. You can Google around to reason some people saying this outperforms CUBLAS by like 10%, but the comments are usually old (2013) and blablabla: it's fast enough that it's likely the best option if you're in MATLAB (though if you really want performance, you should look at Julia with CUBLAS, which will have a lower interop overhead and faster user-compiled kernals).

The reason why you won't find a BLAS implementation that "has both" is because the implementations have to be completely different to fully leverage the GPU, and so at that point they might as well be different libraries since the reason to bundle code is usually for some form of code reuse. You can try swapping out backend BLAS implementations in MATLAB to learn, but it likely won't cause a performance change it may give difficulties because it's very undocumented. That's just one problem among many with closed-source software. If you want to be able to modify every detail, swap BLAS libraries and libm implementations, etc., you may want to look into using an open-source software instead, which as above I'd recommend Julia (or you may be able to do this with Octave, though I don't know and will refer to whatever documentation they have).

• It's actually very straight forward to swap BLAS/LAPACK libraries with Octave, since they're dynamically linked. In particular, you can use libnvblas.so (the CUDA toolkit drop in replacement BLAS library) with OpenBLAS as the backup for functions not in libnvblas.so. – Brian Borchers Dec 24 '17 at 4:03
• @BrianBorchers Have you gotten Octave to use github.com/CNugteren/CLBlast? My first attempt at this did not work. – tholu Oct 19 '18 at 12:53
• No, I haven't tried working with this project- cuBLAS works adequately for me on my NVIDIA GPU. – Brian Borchers Oct 19 '18 at 14:47