R Language

GPU-accelerated computing

Remarks#

GPU computing requires a ‘platform’ which can connect to and utilize the hardware. The two primary low-level languages that accomplish this are CUDA and OpenCL. The former requires installation of the proprietary NVIDIA CUDA Toolkit and is only applicable on NVIDIA GPUs. The latter is both company (e.g. NVIDIA, AMD, Intel) and hardware independent (CPU or GPU) but requires the installation of an SDK (software development kit). In order to use a GPU via R you will need to install one of these pieces of software first.

Once either the CUDA Toolkit or a OpenCL SDK is installed, you can install an appropriate R package. Almost all the R GPU packages are dependent upon CUDA and limited to NVIDIA GPUs. These include:

  1. gputools
  2. cudaBayesreg
  3. HiPLARM
  4. gmatrix

There are currently only two OpenCL enabled packages

  1. OpenCL - interface from R to OpenCL
  2. gpuR - general purpose library

Warning - installation can be difficult for different operating systems with different environmental variables and GPU platforms.

gpuR gpuMatrix objects

library(gpuR)

# gpuMatrix objects
X <- gpuMatrix(rnorm(100), 10, 10)
Y <- gpuMatrix(rnorm(100), 10, 10)

# transfer data to GPU when operation called
# automatically copied back to CPU
Z <- X %*% Y

gpuR vclMatrix objects

library(gpuR)

# vclMatrix objects
X <- vclMatrix(rnorm(100), 10, 10)
Y <- vclMatrix(rnorm(100), 10, 10)

# data always on GPU
# no data transfer
Z <- X %*% Y

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow