Playing R with GPU accelerated in CentOS 7

来源:互联网 发布:嗟乎!是安知古谓廉者哉 编辑:程序博客网 时间:2024/05/20 18:03

Download R packages

Download packages from cran:gputools_1.0.tar.gz

wget https://cran.r-project.org/src/contrib/gputools_1.0.tar.gz

Install R Packages

First goto R and set work directory:

setwd("~")
config.status: creating src/Makefile** libs** arch - /usr/local/cuda/bin/nvcc -c -Xcompiler "-fpic -I/usr/local/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic" -I. -I"/usr/local/cuda-7.5/include" -I"/usr/lib64/R/include" rinterface.cu -o rinterface.ogcc: error: unrecognized command line option ‘-Wp’make: *** [rinterface.o] Error 1ERROR: compilation failed for package ‘gputools’

So, we need to hack the source code:

edit the Makefile, and change CFLAGS to :

CFLAGS = -O2 -g -pipe -Wall -Wp\,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic

Then

tar cvzf gputools_1.0.tar.gz /gputools_1.0.tar.gz

go into R and install the package:

install.packages("~/gputools.tar.gz", repos = NULL, type = "source")

Verify the installation

library(gputools)N <- 1e3m <- matrix(sample(100, size = N*N, replace = T), nrow = N)system.time(dist(m))system.time(gpuDist(m))

Results:

> library(gputools)> N <- 1e3> m <- matrix(sample(100, size = N*N, replace = T), nrow = N)> system.time(dist(m))   user  system elapsed   6.289   0.005   6.293 > system.time(gpuDist(m))   user  system elapsed   0.242   0.713   1.775 

When using gpu, it saves much time.

[Reference]

Nvidia Blogs: accelerate-r-applications-cuda
Installing cuda toolkit and related R packages

0 0
原创粉丝点击