Setup

knitr::opts_chunk$set(echo = TRUE)
require(pryr)
## Loading required package: pryr
require(gpuR)
## Loading required package: gpuR
## Number of platforms: 1
## - platform: Intel(R) Corporation: OpenCL 2.0 
##   - gpu index: 0
##     - Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
## checked all devices
## completed initialization
## gpuR 1.2.1
## 
## Attaching package: 'gpuR'
## The following objects are masked from 'package:base':
## 
##     colnames, svd

gpuR does not copy in memory

x = matrix(rnorm(16), 4, 4)
address(x)
## [1] "0xabcc8e0"
x[1,1] <- 0
address(x)
## [1] "0xabe8d30"
x = gpuMatrix(rnorm(16), 4, 4)
x@address
## <pointer: 0x0000000006e37880>
x[1,1] <- 0
x@address
## <pointer: 0x0000000006e37880>

Checking the speed-up: Code

result <- data.frame()

for (exponent in seq(2,24,2)){
  A = matrix(rnorm(2^exponent), nrow=sqrt(2^exponent))
  B = matrix(rnorm(2^exponent), nrow=sqrt(2^exponent))
  
  now <- Sys.time()
  gpuA = gpuMatrix(A, type="double")
  gpuB = gpuMatrix(B, type="double")
  gpuC = gpuA %*% gpuB
  gpu <- Sys.time()-now
  
  now <- Sys.time()
  C = A%*%B
  classic <- Sys.time()-now
  
  now <- Sys.time()
  vclA = vclMatrix(A, type="double")
  vclB = vclMatrix(B, type="double")
  vclC = vclA %*% vclB
  vcl <- Sys.time()-now
  
 result <- rbind(result,c(nrow(A), classic, gpu, vcl)) 
}
colnames(result) <- c("nrow", "time_classic", "time_gpu", "time_vcl")

Results

nrow time_classic time_gpu time_vcl
2 0.0000000 1.5431540 0.0470049
4 0.0000000 0.0410039 0.0410039
8 0.0000000 0.0410051 0.0460038
16 0.0000000 0.0430040 0.0410051
32 0.0000000 0.6520650 0.0430040
64 0.0000000 0.0410039 0.0410042
128 0.0009999 0.0430040 0.0420041
256 0.0100009 0.0500052 0.0440040
512 0.1130111 0.0920091 0.0530059
1024 0.8010812 0.5460539 0.1150110
2048 6.4346428 3.8013802 0.2900290
4096 53.6563652 32.1852179 1.0051000