Data Science / GPU / Machine Learning / R / Technology / tensorflow

R with (external) GPU

Introduction

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.

logo

Setup

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
LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/lib/nvidia-384:
$ env | grep PATH
PATH=/usr/local/cuda-9.0/bin:/usr/lib/nvidia-384/bin:/usr/lib/nvidia-384:...

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 https://www.rstudio.com/products/rstudio/download/#download . For Ubuntu 17.04, I also needed to download some additional packages and then proceed as follows.

$ wget http://ftp.jp.debian.org/debian/pool/main/g/gstreamer0.10/libgstreamer0.10-0_0.10.36-1.5_amd64.deb
$ wget http://ftp.jp.debian.org/debian/pool/main/g/gst-plugins-base0.10/libgstreamer-plugins-base0.10-0_0.10.36-2_amd64.deb

$ 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 https://raw.githubusercontent.com/StefanoPicozzi/MLOps/master/gpu/gpuR.R 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 https://goatoftheplague.com/2016/12/08/installing-r-package-gputools-and-cuda-8-0-on-ubuntu-16-04/ 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 https://raw.githubusercontent.com/StefanoPicozzi/MLOps/master/gpu/gputools.R

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

Resources

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s