clLocal: Create and handle local memory arguments for OpenCL kernels

View source: R/clLocal.R

clLocalR Documentation

Create and handle local memory arguments for OpenCL kernels

Description

OpenCL kernels allow the use of local memory which is shared by all work-items of a work-group. In most cases, such memory is allocated inside the kernel at compile time such as __local numeric temp[GROUP_SIZE]. However, in some rare circumstances it may be desirable to allocate the buffer dynamically as an argument to the kernel. In that case the corresponding argument of the kernel is defined with the __local keyword and the caller has to specify the size of the local memory buffer at run-time when calling the kernel.

The clLocal() function creates a specification of the local memory buffer. It is the only object that may be passed to a kernel argument declared with __local. The object is merely a specification that oclRun knows how to interpret, clLocal doesn't actually allocate any memory.

By default, size is interpreted as bytes, but for convenience it can also specify the number of elements of a particular type. In the special case of "numeric" the actual size of one element (and thus the total buffer size) will depend on the context in which this specification is used (single or double precision).

With is.clLocal one can check if an object is a local buffer specification.

The methods length.clLocal and print.clLocal retrieve the length (number of elements) and print the contents, respectively.

Usage

clLocal(length, mode = c("byte", "numeric", "single", "double", "integer"))
is.clLocal(x)
## S3 method for class 'clLocal'
print(x, ...)
## S3 method for class 'clLocal'
length(x)

Arguments

length

numeric, length (number of elements) of the required buffer. The actual size will depend on mode.

mode

string, mode of the buffer (only used to compute the total size in bytes). The default is to treat length as the size in bytes (i.e., "byte" is aways allowed irrespective of the type of the kernel argument).

x

object

...

Ignored

Value

clLocal returns an object of the class "cLocal"

is.clLocal return TRUE for "clLocal" objects and FALSE otherwise.

print method returns x invisibly.

length returns a numeric scalar with the length (number of elements) in the buffer specification.

Note

The internal structure of the clLocal object should be considered private, may change and no user code should access its components. Similarly, clLocal objects are only legal when returned from the clLocal() function, they may not be created by other means or mutated.

Author(s)

Simon Urbanek

See Also

oclRun


s-u/OpenCL documentation built on March 15, 2024, 6:44 a.m.