Data ScienceGPUMachine LearningR

R with (external) GPU

We are going to mess around with some of the R gpu packages using our eGPU Rig. Look here for how to set up RStudio and then use the gpuR, gputools and keras/tensorflow packages against an eGPU.



0. Prerequisites

Setup your eGPU as described at NUC with eGPU – a Big Little ML Rig.  Smoketest your rig to verify basic CUDA functionality by issuing commands such as.

$ nvidia-smi
$ nvcc -V
$ gcc -v
$ cd ~/MLOps/NVIDIA_CUDA-9.0_Samples/bin/x86_64/linux/release
$ ./deviceQuery
$ ~/MLOps/cudnn_samples_v7/mnistCUDNN
$ ./mnistCUDNN
$ env | grep LD_LIBRARY_PATH
$ env | grep PATH

1. RStudio Desktop

Let’s try out some R GPU libraries, but we are going to need RStudio first. Locate then download your RStudio distribution at . For Ubuntu 17.04, I also needed to download some additional packages and then proceed as follows.

$ wget
$ wget

$ apt-get install -f
$ sudo dpkg -i libgstreamer-plugins-base0.10-0_0.10.36-2_amd64.deb 
$ sudo dpkg -i libgstreamer0.10-0_0.10.36-1.5_amd64.deb 
$ sudo apt install libjpeg62 libedit2

$ sudo gdebi -n rstudio-1.1.383-amd64.deb

2. R gpuR Package

Launch RStudio and install the gpuR package. Copy/paste in the sample sample at and verify it works. Install any other R packages as required, e.g. ggplot2. Looking good?

Screenshot from 2017-10-11 08-36-07

2. R gputools Package

Next we take the gputools R package for a spin. Follow the instructions at to install this package (e.g. to overcome the R.h include file issue).  Install the source modified package as follows:

> install.packages("~/Downloads/gputools_1.1_new.tar.gz", repos = NULL, type = "source")

Once installed try out the sample gputools R script at

3. R Keras Package using Tensorsoft

First we need to setup tensorflow and python as described towards the end of NUC with eGPU – a Big Little ML Rig . Now from RStudio use the Console window to install Keras as follows:

> install.packages('Rcpp')
> install.packages('devtools')
> devtools::install_github("rstudio/reticulate") 
> devtools::install_github("rstudio/keras")
> library("keras")
> install_keras(tensorflow = "gpu")

You are now ready to test drive a few sample scripts:

Screenshot from 2017-10-13 19-17-06

Other gpu R Packages Attempted

  • cudaBayesreg
    • install fails with -lRmath related issue
  • gmatrix
    • install fails with gcc version related issue
  • permGPU
    • install fails with Biobase availability related issue
  • gpuRcuda
    • R CMD INSTALL fails with packaging issue
  • rpud
    • Requires license file



Leave a Reply