Installing cuda toolkit and related R packages

June 3, 2015

(This article was first published on Data Science Notes - R, and kindly contributed to R-bloggers)

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)
##    user  system elapsed 
##   4.864   0.008   4.874
##    user  system elapsed 
##   0.640   0.168   0.809

To leave a comment for the author, please follow the link and comment on their blog: Data Science Notes - R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)