copyFromDevice: Copy data betwen R and GPU

Description Usage Arguments Value Author(s) See Also Examples

Description

These functions perform the (potentially) necessary copying of data between the host and the GPU device. The functions codeToDevice and copyFromDevice are the explicit functions. We can use R's subsetting to copy the elements with ref[] and ref[] = x.

Usage

1
2
3
4
5
copyFromDevice(obj, nels, type)
copyToDevice(obj, to = cudaMalloc(length(obj), elType = elType, strict = strict),
              elType = typeof(obj), strict = !missing(elType) )
cudaMalloc(numEls, sizeof = 4L, elType = NA, 
            strict = !missing(elType) || inherits(elType, "AsIs")) 

Arguments

obj

the R object to be copied to the GPU or the reference to the GPU memory that is to be copied back to R

nels,numEls

the number of elements to be copied or to be allocated

type

the type of the elements being copied

elType

the name of the R/GPU type to be allocated

sizeof

the size of the element in the array/vector on the GPU to be allocated

to

a reference to space on the GPU to store the data being copied from R to the GPU

strict

a logical value that controls whether we treat the value elType as verbatim and use it exactly or whether we can map it to another type. If this is FALSE, "double" is mapped to "float".

Value

cudaMalloc returns a generic pointer to memory on the GPU.

copyToDevice returns an object that knows both the type and the number of elements of the array and so can retrieve this from the GPU.

copyFromDevice returns the R vector corresponding to the data on the GPU.

Author(s)

Duncan Temple Lang

See Also

.cuda

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
if(getNumDevices() > 0) {

 cuGetContext()

 N = 1e5
 x = rnorm(N)

 cx = copyToDevice(x)
 length(cx[])
   # or explicitly with
 vals = copyFromDevice(cx)
 length(vals)

 i = sample(1:N, 100)
   # subsetting on the GPU
 cx[i]
}

duncantl/RCUDA documentation built on May 15, 2019, 5:26 p.m.