EPSRC

High Performance Linear Algebra in R

HiPLAR (High Performance Linear Algebra in R) is a suite of R packages that use the latest multi-core and GPU libraries to give substantial speed-ups to existing linear algebra functions in R.

Currently, R users are limited to a small number of packages that allow access to current multi-core and accelerator architectures. Those that are available require special objects and classes whilst only targeting specific functions. HiPLAR has the follwowing features:

  • GPU Support
  • Multi-Core CPU Support
  • Compatible with legacy R code
  • Targets major linear algebra functions in R
  • No new data types or operators
  • Auto-tuning functionality
  • Easy Install

HiPLAR's over-arching goal is to provide easy access to the latest computational architectures using the latest linear algebra libraries and to do so in an easy and user friendly manner. With our simple installer the user can achieve large speed-ups in a matter of minutes with little understanding of the complexities of multi-core and GPU computing.

The user can also use the package without GPU support (should they not have one) and run purely with the multi-core CPU libraries. For users that have multi-core CPUs and an NVIDIA GPU we provide an auto-tuning feature that calculates the optimal configuration for the problem and the hardware. Currently, HiPLAR provides two packages to target linear algebra functions in the standard R release and Matrix packages.

HiPLARM

HiPLARM provides GPU and multi-core functionality to the R Matrix package by overwriting the major linear algebra functions in that package.

The Matrix package has become one of the most used and depended on packages in the R ecosystem and with HiPLARM the package can now be used faster and more efficiently while still retaining the main characteristics and structure of the package. With only a single line, loading the HiPLARM library, the user can unlock the power of their multi-core machines or NVIDIA GPUs. Due to HiPLARM's strong dependency on the Matrix package it is completely compatible with legacy Matrix code and can provide large speedups for the user.

Examples

Here we provide some brief examples to highlight the benefits of using HiPLARM. The following are using HiPLARM and Matrix. These examples were performed on a HP desktop with a Tesla C2075 and a 6 core Intel Xeon against a version of optimised BLAS on a single core.

library(Matrix);
n <- 8192;
X <- Hilbert(n);
A <- nearPD(X);
system.time(B <- chol(A$mat));
# user  system elapsed  
# 97.990   0.356  98.591
library(HiPLARM)
system.time(B <- chol(A$mat));
# user  system elapsed 
# 1.012   0.316   1.337

This code sample shows a Cholesky decomposition of a 8192 x 8192 matrix.

library(Matrix)
x <- Matrix(rnorm(n * n), n, n);
system.time(y <- lu(x)); #square LU decomposition
# user  system elapsed 
# 35.358   0.352  35.799
x2 <- round(10 * x[,-3]); 
system.time(expand(lu2 <- lu(x2))); #Non-Square decomposition
# user  system elapsed  
# 35.542   0.684  36.320 	
library(HiPLARM)
x <- Matrix(rnorm(n * n), n, n);
system.time(y <- lu(x)); #square LU decomposition
# user  system elapsed 
# 2.444   0.589   3.045
x2 <- round(10 * x[,-3]);
expand(lu2 <- lu(x2)); #Non-Square decomposition
# user  system elapsed 
# 2.641   0.916   3.566 
# Now use only multi-core CPU
hiplarSet("hiplar_library",1)
x <- Matrix(rnorm(n * n), n, n);
system.time(y <- lu(x)); #square LU decomposition
# user  system elapsed 
# 44.819   0.360   6.099
x2 <- round(10 * x[,-3]);
expand(lu2 <-lu(x2)); #Non-Square decomposition
# user  system elapsed 
# 44.979   0.680   6.613 
# Sets back to "Auto" mode where GPU or CPU is picked automatically
hiplarSet("hiplar_library,"3");

This code sample shows a square and a non square LU decomposition and how to switch to the CPU only mode or to "Auto" mode where the CPU/GPU is chosen automatically depending on the problem size.

These are only short examples of what is possible with HiPLAR. For more detailed benchmarks please see the benchmark section here and for further, more detailed examples, see here.

Back to top

HiPLARb

HiPLARb gives multi-core and GPU support to the standard R release by overwriting the existing linear algebra functions with new functions to take advantage of the latest CPUs and GPU accelerators. Similar to HiPLARM, the user will experience no qualitative difference between standard R and HiPLARb except the loading of the library. We have targeted approximately 26 linear algebra functions for GPU and multi-core CPU support. Should the user not have an NVIDIA GPU they can opt to use only the multi-core CPU functionality. For a full list of available functions please see our HiPLARb functionality page.

Examples

Below are some simple examples of the HiPLARb package. The first is a simple example of eigenvalue/vector calculation. The timings were taken from a HP workstation with an NVIDIA Tesla C2075 GPU and 6 core Intel Xeon.

library(HiPLARb)
p <- 2048
x <- matrix(rnorm(p * p), p, p)
print(system.time(y <- eigen(x))) #eigenvalue/vector calculation
#user  system elapsed 
# 30.346  36.290  12.313

The next example is a simple matrix multiplication. Again the user will see no difference between using HiPLARb and standard R.

A <- matrix(rnorm(4096 * 4096), nrow=4096, ncol=4096)
B <- matrix(rnorm(4096 * 4096), nrow=4096, ncol=4096)
 system.time(C <- A %*% B) # single core matrix multiplication
#   user  system elapsed 
# 10.760   0.032  10.801 
library(HiPLARb)
A <- matrix(rnorm(4096 * 4096), nrow=4096, ncol=4096)
B <- matrix(rnorm(4096 * 4096), nrow=4096, ncol=4096)
system.time(C <- A %*% B) #multiplication with HiPLARb
# user  system elapsed 
#  0.648   0.048   0.696 

HiPLARb is available for download here and we provide an extensive list of examples on our examples page. We are currently putting together an extensive list of benchmarks which will be available very soon.

MAGMA and PLASMA

The HiPLAR packages provide wrappers to the MAGMA and PLASMA libraries for the standard R release and Matrix packages. MAGMA and PLASMA are the latest libraries to come out of the Innovative Computing Laboratory (ICL) which is at the forefront of scientific and high performance computing. The PLASMA library is explictly designed to take advantage of the latest processor architectures which combine multi-core and shared memory architectures amongst other features. The MAGMA library is built on the premise that future computational trends are moving towards hybrid and heterogeneous architectures, that is, combining multi-core CPUs with accelerators such as GPUs. HiPLAR aims to take advantage of these high performance libraries and architectures for all R users.

Back to top