This is a quick tutorial of how to install the R package ‘gputools’ version 1.1 using R version 3.3.2 (2016-10-31) and cuda 8.0 on Ubuntu 16.04. Most of these versions are new so I did some search on the internet and I could not find a tutorial about that. However most of this tutorial is based on this page which is for ‘gputools’ version 0.28 and cuda 7.0 on Ubuntu 15.04. At the end I just changed a few lines.
I have tested it on a ASUS ROG G752VM with NVIDIA GeForce GTX 965M graphics card. The instruction assumes you have the necessary CUDA compatible hardware support. In my case I also installed the NVIDIA driver 367.57 first. My computer was new so I did not have any nvidia driver or compatibility issues. However I strongly recommend to look on the internet how to remove the old drivers first, before install the new ones (things like sudo apt-get purge nvidia-cuda*
).
Installing CUDA 8.0
First, to install CUDA 8.0 we can do:
wget https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
Or you can download the CUDA repository package for Ubuntu 16.04 from the CUDA download site and follow the instructions according to your necessities.
Environment Variables
I tried to install the gputools package without adding the variables to the environment and i got an error related to nvcc
. Thus, as part of the CUDA environment, we should add the nvcc
compiler in the .bashrc
file of your home folder.
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
PATH=${CUDA_HOME}/bin:${PATH}
PATH=${CUDA_HOME}/bin/nvcc:${PATH}
export PATH
Installing gputools version 1.1
The fastest way to install gpuplots if you are using R version 3.3.2 is:
install.packages('gputools')
Now my tutorial differs a bit more from the tutorial I mentioned before. I received the message:
rinterface.cu:1:14: fatal error: R.h: No such file or directory #include
So we have to check where R header dir location is. First lets locate the file R.h
:
locate \/R.h
## /usr/share/R/include/R.h
Then next step is to tell to gputools where the R.h
is located. Thus it is necessary to change a line in the source package. First download and extract the source package:
wget http://cran.r-project.org/src/contrib/gputools_1.1.tar.gz
tar -zxvf gputools_1.1.tar.gz
Look into the folder you just extracted then open the file configure
on your favourite Ubuntu editor to replace the string R_INCLUDE="${R_HOME}/include"
for R_INCLUDE="/usr/share/R/include"
(which is the location of my R.h
file).
The two finals steps are compress the modified source code
tar -czvf gputools_1.1_new.tar.gz gputools
and install the modified package
install.packages("~/gputools_1.1_new.tar.gz", repos = NULL, type = "source")
I had lots of warning messages but no error.
Testing performance
Now we can try some simple benchmarks and see how much time the CPU and gpu time will spend. First a small matrix multiplication:
library(gputools)
magnitude <- 10
dimA <- 2*magnitude;dimB <- 3*magnitude;dimC <- 4*magnitude
matA <- matrix(runif(dimA*dimB), dimA, dimB)
matB <- matrix(runif(dimB*dimC), dimB, dimC)
system.time(matA%*%matB);
## user system elapsed
## 0.000 0.000 0.001
system.time(gpuMatMult(matA, matB))
## user system elapsed
## 0.076 0.140 0.215
then using larger matrices:
magnitude <- 1000
dimA <- 2*magnitude;dimB <- 3*magnitude;dimC <- 4*magnitude
matA <- matrix(runif(dimA*dimB), dimA, dimB)
matB <- matrix(runif(dimB*dimC), dimB, dimC)
system.time(matA%*%matB);
## user system elapsed
## 15.552 0.028 15.579
system.time(gpuMatMult(matA, matB))
## user system elapsed
## 0.792 0.124 0.914