Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BLAS and CUBLAS

I'm wondering about NVIDIA's cuBLAS Library. Does anybody have experience with it? For example if I write a C program using BLAS will I be able to replace the calls to BLAS with calls to cuBLAS? Or even better implement a mechanism which let's the user choose at runtime?

What about if I use the BLAS Library provided by Boost with C++?

like image 677
Nils Avatar asked Apr 30 '10 08:04

Nils


2 Answers

The answer by janneb is incorrect, cuBLAS is not a drop-in replacement for a CPU BLAS. It assumes data is already on the device, and the function signatures have an extra parameter to keep track of a cuBLAS context.

However, coming in CUDA 6.0 is a new library called NVBLAS which provides exactly this "drop-in" functionality. It intercepts Level3 BLAS calls (GEMM, TRSV, etc) and automatically sends them to the GPU, effectively tiling the PCIE transfer with on-GPU computation.

There is some information here: https://developer.nvidia.com/cublasxt, and CUDA 6.0 is available to CUDA registered developers today.

Full docs will be online once CUDA 6.0 is released to the general public.

like image 95
Jonathan Cohen Avatar answered Sep 17 '22 12:09

Jonathan Cohen


CUBLAS does not wrap around BLAS. CUBLAS also accesses matrices in a column-major ordering, such as some Fortran codes and BLAS.

I am more used to writing code in C, even for CUDA. A code written with CBLAS (which is a C wrap of BLAS) can easily be change into a CUDA code. Be aware that Fortran codes that use BLAS are quite different from C/C++ codes that use CBLAS. Fortran and BLAS normally store matrices or double arrays in column-major ordering, but C/C++ normally handle Row-major ordering. I normally handle this problem writing saving the matrices in a 1D arrays, and use #define to write a macro toa access the element i,j of a matrix as:

/* define macro to access Aij in the row-wise array A[M*N] */
#define indrow(ii,jj,N) (ii-1)*N+jj-1 /* does not depend on rows M  */
/* define macro to access Aij in the col-wise array A[M*N] */
#define indcol(ii,jj,M) (jj-1)*M+ii-1 

CBLAS library has a well organize parameters and conventions (const enum variables) to give to each function the ordering of the matrix. Beware that also the storage of matrices vary, a row-wise banded matrix is not stored the same as a column-wise band matrix.

I don't think there are mechanics to allow the user to choose between using BLAS or CUBLAS, without writing the code twice. CUBLAS also has on most function calls a "handle" variable that does not appear on BLAS. I though of #define to change the name at each function call, but this might not work.

like image 41
lucky85dog Avatar answered Sep 16 '22 12:09

lucky85dog