clBuffer: Create and handle OpenCL buffers

Description Usage Arguments Author(s) See Also Examples

View source: R/clBuffer.R

Description

OpenCL buffers are just like numeric or integer vectors that reside on the GPU and can directly be accessed by kernels. Both non-scalar arguments to oclRun and its return type are OpenCL buffers.

Just like vectors in R, OpenCL buffers have a mode, which is (as of now) one of "double" or "numeric" (corresponds to double in OpenCL C), "single" (float) or "integer" (int).

The constructor clBuffer takes a context as created by oclContext, a length and a mode argument.

The conversion function as.clBuffer creates an OpenCL buffer of the same length and mode as the argument and copies the data. Conversely, as.double (= as.numeric) and as.integer read a buffer and coerce the result as vector the appropriate mode.

With is.clBuffer one can check if an object is an OpenCL buffer.

The methods length.clBuffer and print.clBuffer retrieve the length and print the contents, respectively.

Basic access to the data is available via [...]. As of now, only an empty selection is supported (which selects all elements), i.e. you can only select buf[].

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
clBuffer(context, length, mode = c("numeric", "single", "double", "integer"))
as.clBuffer(vector, context)
is.clBuffer(any)
## S3 method for class 'clBuffer'
as.double(x, ...)
## S3 method for class 'clBuffer'
as.integer(x, ...)
## S3 method for class 'clBuffer'
print(x, ...)
## S3 method for class 'clBuffer'
length(x)
## S3 method for class 'clBuffer'
x[indices]
## S3 replacement method for class 'clBuffer'
x[indices] <- value

Arguments

context

OpenCL context as created by oclContext

length

Length of the required buffer

mode

Mode of the buffer, can be one of "numeric", "clFloat", "integer"

vector

Numeric or integer vector or clFloat object

any

Arbitrary object

x

OpenCL buffer object (clBuffer)

indices

Indices to access the buffer, must be omitted (as of now)

value

New values

...

Arguments passed to subsequent methods

Author(s)

Aaron Puchert

See Also

oclContext, oclRun

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(OpenCL)
ctx<-oclContext()

buf<-clBuffer(ctx, 16, "numeric")
# Do not write buf<-..., as this replaces buf with a vector.
buf[]<-sqrt(1:16)
buf

intbuf<-as.clBuffer(1:16, ctx)
print(intbuf)

length(buf)
as.numeric(buf)
buf[]

## clBuffer is the required argument and return type of oclRun.
## See oclRun() examples.

OpenCL documentation built on July 24, 2021, 5:07 p.m.

Related to clBuffer in OpenCL...