Book Image

R High Performance Programming

Book Image

R High Performance Programming

Overview of this book

Table of Contents (17 chapters)
R High Performance Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Fast statistical modeling in R with gputools


gputools provides a convenient way to execute statistical functions on a GPU, without CUDA programming. All the heavy lifting, including copying data from RAM to GPU memory and setting the number of cores to use have been encapsulated within the functions (in fact, gputools relies on the well-encapsulated CUBLAS library, which provides linear algebra functions for GPUs). For example, to perform linear modeling on the mtcars dataset on a CPU, we use the lm(): lm(mpg~cyl+disp+hp, data=mtcars) function. To run it on a GPU, we call the gpuLm() function from gputools: gpuLm(mpg~cyl+disp+hp, data=mtcars). The output of gpuLm() follows the same format as lm().

To demonstrate the speedup that we can expect from a GPU, we will calculate Kendall correlations on random datasets having 100 variables. We will use a varying number of observations from 100, 200, … to 500 records in order to observe the speedup in comparison to the CPU version. The code is as...