Installing cuda toolkit and related R packages

· · Read in about 2 min · (356 words)

The main purpose of this post is to keep all steps of installing cuda toolkit (and R related packages) and in one place. Also I hope this may be useful for someone.

Installing cuda toolkit ( Ubuntu )

First of all we need to install nvidia cuda toolkti. I’am on latest ubuntu 15.04, but found this article well suited for me. But there are few additions:

  1. It is very important to have no nvidia drivers before installation ( first I corrupted my system and have to reinstall it 🙁 ). So I recommend to switch to real terminal (ctrl + alt + f1), remove all nvidia stuff sudo apt-get purge nvidia-* and then follow steps from article above.

  2. This will install cuda toolkit and corresponding nvidia drivers.

sudo dpkg -i cuda-repo-ubuntu1410_7.0-28_amd64.deb
sudo apt-get update
sudo apt-get install cuda
  1. After installation we need to modify our .bashrc file. Add following lines:
export CUDA_HOME=/usr/local/cuda-7.0
export PATH

Note, that I added path to nvcc compiler.

Installing gputools

First simply try:

install.packages('gputools', repos = '')

After that I recieved:

Unsupported gpu architecture ‘compute_10’

Solving this issue I found this link useful. I have gt525m card and have compute capability 2.1. You can verify your GPU capabilities here. So I downloaded gputools source package:

cd ~
tar -zxvf gputools_0.28.tar.gz

and replace following string

NVCC := $(CUDA_HOME)/bin/nvcc -gencode arch=compute_10,code=sm_10 -gencode arch=compute_13,code=sm_13 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30

in gputools/src/Makefile by

NVCC := $(CUDA_HOME)/bin/nvcc -gencode arch=compute_20,code=sm_21

Next try to gzip it back and install from source:

install.packages("~/gputools.tar.gz", repos = NULL, type = "source")

Than I recieved: fatal error: R.h: No such file or directory #include

We have to adjust R header dir location. First of all look for R.h:

locate /R.h

replace string R_INC := $(R_HOME)/include in gputools/src/ string by found path:

R_INC := /usr/share/R/include

In case we recieve error regarding shared we also need to adjust links for libcublas shared library:

sudo ln -s /usr/local/cuda/lib64/ /usr/lib/

thanks to this thread.

Testing performance

here is simple benchmark:

N <- 1e3
m <- matrix(sample(100, size = N*N, replace = T), nrow = N)