Learn R Programming

The "gmatrix" Package

This package implements a general framework for utilizing R to harness the power of NVIDIA GPU's. The "gmatrix" and "gvector" classes allow for easy management of the separate device and host memory spaces. Numerous numerical operations are implemented for these objects on the GPU. These operations include matrix multiplication, addition, subtraction, the kronecker product, the outer product, comparison operators, logical operators, trigonometric functions, indexing, sorting, random number generation and many more. The "gmatrix" package has only been tested and compiled for linux machines. It would certainly be nice of someone to get it working in Windows. Until then, Windows is not supported. In addition we assume that the divice is at least of NVIDIA(R) compute capibility 2.0, so this package may not work with older devices.

Installation Instructions

  1. Install the the CUDA Toolkit. The current version of 'gmatix' has been tested for CUDA Toolkit 5.0 and 7.0.
  2. Install R. The current version of 'gmatrix' has been tested under R 3.0.2 and 3.2.2.
  3. Start R and then install the 'gmatrix' package with the following commands. Package compilation may take 5-10 minutes.
install.packages("gmatrix")

Alternatively, if you would like to install the developmental version, the following from the linux command line may be used:

git clone https://github.com/njm18/gmatrix.git
rm ./gmatrix/.git -rf
MAKE="make -j7" #note this make the compile process use 7 threads 
R CMD INSTALL gmatrix

 

Installation Note

By default, when compiling, the build process assumes that

  • The nvcc compiler is in the PATH, and that the the CUDA library files may be located based on the location of nvcc.
  • R is located in the PATH, and that the R libraries may be located using this information.
  • The compute capability of the target device is 2.0.

If these are incorrect assumptions, the user may set these values and install using the following R command as an example.

install.packages("gmatrix" ,  
   configure.args = "
      --with-arch=sm_30
      --with-cuda-home=/opt/cuda
      --with-r-home==/opt/R"
)

Testing the Installation

We recomend that the user test the installation using the following commands:

library(gmatrix)
gtest()

Please report any errors to the package maintainer.

Getting Started

  • Load the library for each sessesion using: library(gmatrix)
  • To list available gpu devices use: listDevices()
  • To set the device use: setDevice()
  • To move object to the device use: g()
  • To move object to the host use: h()
  • Object on the device can be manipulated in much the same way other R objects can.
  • A list of help topics may be optained using: help(package="gmatrix")

Copy Link

Version

Install

install.packages('gmatrix')

Monthly Downloads

24

Version

0.3

License

GPL-3 | file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Nathan Morris

Last Published

December 1st, 2015

Functions in gmatrix (0.3)

as.numeric, as.integer, as.logical, as.vector and as.matrix

Methods to coerce a GPU object to an R object
grunif

The Uniform Distribution
gident

Create an identity matrix on the GPU.
dim

Dimensions of an Object
elementwise functions

Elementwise functions/operators
g.rep

Replicate Elements of a vector or gvector,
gvector

Create a gvector object
gouter

GPU generalized outer product.
setDevice

Get and set the current device.
gmatrix

Create and object of class gmatrix
gmatrix-package

Making GPU power available in R
ifelse

Conditional Element Selection
gnamestrip

Strip a GPU object of it names, or row/colnames.
diag

Matrix Diagonals
indexing

Indexing Methods
gdbinom

The Binomial Distribution
sort

Sorting
which

Which indices are TRUE?
gdgamma

The Gamma Distribution
show

Methods for displaying GPU objects
length

Length of an Object
gdpois

The Poisson Distribution
gmm

Multiply two matrices with the output matrix allready allocated.
gorder

Ordering Permutation
chol

Method to calculate the Choleski decomposition square symmetric posative definite matrix
gset.seed

Set the seed values, and number of states for the GPU.
elementwise binary operators

Binary Operators
ggc

GPU Garbage Collection
skeleton-internal

Internal skeleton objects
gsumby

Sumby
gsvd-class

Class "gsvd"
gqr-class

Class "gqr"
names

Get and set names
colnames

Methods to get and set the 'rownames' and 'colnames' of a matrix.
ncol

Mumber of rows/columns
gvector-class

Class "gvector"
dimnames

Dimnames of an Object
gmatrix-class

Class "gmatrix"
g

Transfer and R object to and from the GPU.
lpgr-class

Class "lpgr"
gRowLogSums

Sum the up the rows in log space.
setTuningPameters

Set tuning parameters
convertType

Convert the type of a GPU object
gmatTimesDiagVec

Multiply a matrix times the 'diag' of a vector quickly.
type

Get or set the type of a GPU object
mean, sum

mean and sum methods
normal

GPU Normal Distribution
gkroneckerProd

Kronecker Product
gBasicHMC

Performing Hamiltonian MCMC
gtest

Testing
checkDevice

Check that the specified integer is the current device.
gdbeta

The Beta Distribution
colMeans

Methods to Form Row and Column Sums and Means
as.gmatrix, as.gvector

Methods for coercing an object to a GPU class
t

Transpose
device

Get and set methods for the device slot of a gvector or gmatrix object
max

Maxima and Minima
gseq

Sequence
crossprod,tcrossprod

Matrix Crossproduct
rsample

Sample and integer for each row of a gmatrix object.
gdup

Duplicate a GPU object
matrix multiplication

Matrix Multiplication