oclSimpleKernel: Create and compile OpenCL kernel code.

Description Usage Arguments Details Value Author(s) See Also

View source: R/ocl.R


oclSimpleKernel creates a kernel object by compiling the supplied code. The kernel can them be used in oclRun.


oclSimpleKernel(device, name, code, precision = c("single", "double", "best"))



Device (element of the list returned by oclDevices()) to compile the kernel on.


Name of the kernel function - must match the name used in the supplied code.


character vector containg the code. The code will be concatenated (as-is, no newlines are added!) by the engine.


precision of all floating-point arguments in the kernel. Note that R uses only double-precision floating point representation, so single-precision computation requires temporary conversion of all input and output values and thus has significant overhead. However, not all devices support double-precision computation. If "best" is used then the kernel code is expected to use single-precision but it will be automatically augmented to double-precision (by replacing words "float" with "double" in the code and adding the cl_khr_fp64 pragma) if supported by the device.


oclSimpleKernel creates a new OpenCL context, then creates and builds the program specified by code and finally creates a kernel from the program.

The kernel built by this function is simple in that it can have exactly one vector output and arbitrarily many inputs. The first argument of the kernel must be __global double* for the output and the second argument must be const int for the length of the output vector. All additional arguments are optional. See oclRun for an example of a simple kernel.

Note that building a kernel can take substantial amount of time (depending on the OpenCL implementation) so it is generally a good idea to compile a kernel once and re-use it many times.


Kernel object that can be used by oclRun.


Simon Urbanek

See Also

oclDevices, oclRun

OpenCL documentation built on May 29, 2017, 8:13 p.m.