library('clrng')
if (detectGPUs() >= 1) {
setContext(grep("gpu", listContexts()$device_type)[1])
streams <- createStreamsGpu()
as.vector(rexpGpu(7, streams=streams))
# produce float precision random numbers
options(clrng.type='float')
as.matrix(rexpGpu(c(2,3), rate=0.5, streams))} else {
message("No GPU context available")
}
Run the code above in your browser using DataLab