Learn R Programming

gmatrix (version 0.3)

g: Transfer and R object to and from the GPU.

Description

The function g transfers the object to the GPU. The function h transfers it back to the host.

Usage

g(x, type = NULL, dup = TRUE) h(x)

Arguments

x
The object to be transfered.
type
The type to convert the object to. There are three different ways to specify this. One may use the "double", "single", "integer" or "logical" notation. Alternatively the short form "d", "s", "i" or "s" notation may be used. Finally the internal integer representation of 0L, 1L, 2L or 3L may be used.
dup
This may be set to 'FALSE' to avoid duplicating x in the event that it is on the GPU allready and the original type is the same as the type argument.

Value

The 'h' function transfers device data back to the host and returns a matrix or vector, while the 'g' function returns an object of class gmatrix or gvector storing the data on the GPU.

Details

These functions may be more convenient than functions such as 'as.gmatrix' or 'as.gvector'. In addition to having a very short name, one does not need to consider whether the object is a vector or matrix.

See Also

as.gmatrix and as.numeric

Examples

Run this code
h_x=1:10
g_x=g(h_x) #Transfer to the device
g_ans=crossprod(g_x) #Do a a calculation
h_ans=h(g_ans) #Transfer back to the host

Run the code above in your browser using DataLab