Question

Is it possible to run armadillos calculations using GPU? Is there any way to use the GPU blas libraries (for example cuBLAS) with armadillo? Just a note, I am totally new to GPU programming.

Was it helpful?

Solution 2

No, it is not.

You cannot take code for the cpu and assume it runs on the gpu as both have completely different memory models, hardware, programming styles etc pp.

OTHER TIPS

The current accepted answer is outdated. Comming with CUDA 6 (at the moment Release Candidate status), there is a true drop-in replacement called NVBLAS which takes care about GPU interaction and also works in combination with armadillo. You can use NVBLAS by linking your program agains libnvblas.so

However, not all BLAS methods may be available, so you have to specify a fallback-BLAS library (like openblas).

For more details, see https://developer.nvidia.com/cublasxt

I finally find a quick way on Ubuntu 20.04 with Cmake and CUDA.

Install CUDA

This seems very difficult according to the official guidance, but on Ubuntu 20 using apt works fine.

sudo apt install nvidia-cuda-toolkit

After this, do not forget to set the environmental variable NVBLAS_CONFIG_FILE according to documentation. The default contents on the website will do except for changing the CPU BLAS library. For me, the libopenblas.a does not work and should be set as libopenblas.so.0.

Use Cmake to Compile Armadillo

The manual installation seems to be complex for me, so I just make some adjustments to the cmake install method.

cmake . -Dopenblas_LIBRARY=<PATH TO NVBLAS LIB>/libnvblas.so

Write Code Using Armadillo

The cmake project is just no different and no additional compiling flag is needed since they are all set when compiling the Armadillo library.

If anything went wrong, the log file (by default nvblas.log) will provide some information. It may be something like it can not open the CPU BLAS library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top