Struct ocl::builders::KernelBuilder[][src]

pub struct KernelBuilder<'b> { /* fields omitted */ }

A kernel builder.

Examples

This example is not tested
// Create a kernel:
let kernel = Kernel::builder()
    .program(&program)
    .name("process")
    .queue(queue.clone())
    .global_work_size(&gws_patch_count)
    .arg(&(patch_size as i32))
    .arg(&source_buffer)
    .arg(&destination_buffer)
    .build()?;

Re-use and clone:

This example is not tested
// Create a builder for re-use:
let builder = Kernel::builder()
    .program(&program)
    .name("process")
    .queue(queue.clone())
    .global_work_size([512, 64, 64])
    .arg(&(patch_size as i32))
    .arg(&source_buffer)
    .arg_named("dest", &destination_buffer);

// Create multiple kernels using the same builder:
let kernel_0 = builder.build()?;
let kernel_1 = builder.build()?;

// Clone the builder:
let mut builder_clone = builder.clone();

// Modify a default parameter:
builder_clone.global_work_size([1024, 128, 128]);

// Create another kernel using the cloned builder:
let kernel_2 = builder_clone.build()?;

// Modify one of the arguments using the created kernel directly
// (arguments cannot be modified using the builder):
kernel_2.set_arg("dest", &alternate_destination_buffer)?;

// Arguments can also be referred to by index:
kernel_2.set_arg(1, &alternate_source_buffer)?;

Methods

impl<'b> KernelBuilder<'b>
[src]

Returns a new kernel builder.

Specifies a program object with a successfully built executable.

Specifies a function name in the program declared with the __kernel qualifier (e.g. __kernel void add_values(...).

Sets the default queue to be used by all subsequent enqueue commands unless otherwise changed (with ::set_default_queue) or overridden (by ::cmd().queue(...)...).

The queue must be associated with a device associated with the kernel's program.

Deprecated since 0.18.0

: Use ::global_work_offset instead.

Sets the default global work offset.

Used when enqueuing kernel commands. Superseded if specified while building a queue command with ::cmd.

Deprecated since 0.18.0

: Use ::global_work_size instead.

Sets the default global work size.

Used when enqueuing kernel commands. Superseded if specified while building a queue command with ::cmd.

Deprecated since 0.18.0

: Use ::local_work_size instead.

Sets the default local work size.

Used when enqueuing kernel commands. Superseded if specified while building a queue command with ::cmd.

Sets the default global work offset.

Used when enqueuing kernel commands. Superseded if specified while building a queue command with ::cmd.

Sets the default global work size.

Used when enqueuing kernel commands. Superseded if specified while building a queue command with ::cmd.

Sets the default local work size.

Used when enqueuing kernel commands. Superseded if specified while building a queue command with ::cmd.

Adds a new Buffer, Image, scalar, or vector argument to the kernel.

The argument is added to the bottom of the argument order.

Example

This example is not tested
let kern = ocl_pq.kernel_builder("multiply_by_scalar")
    .arg(&100.0f32)
    .arg(&source_buffer)
    .arg(&result_buffer)
    .build()?;

Deprecated since 0.18

: Use ::arg instead.

Adds a new argument to the kernel specifying the buffer object represented by 'buffer'.

The argument is added to the bottom of the argument order.

Deprecated since 0.18

: Use ::arg instead.

Adds a new argument to the kernel specifying the image object represented by 'image'.

The argument is added to the bottom of the argument order.

Deprecated since 0.18

: Use ::arg_sampler instead.

Adds a new argument to the kernel specifying the sampler object represented by 'sampler'. Argument is added to the bottom of the argument order.

Deprecated since 0.18

: Use ::arg instead.

Adds a new argument specifying the value: scalar.

The argument is added to the bottom of the argument order.

Deprecated since 0.18

: Use ::arg instead.

Adds a new argument specifying the value: vector.

The argument is added to the bottom of the argument order.

Deprecated since 0.18

: Use ::arg_local instead.

Adds a new argument specifying the allocation of a local variable of size length * sizeof(T) bytes (builder_style).

The argument is added to the bottom of the argument order.

Local variables are used to share data between work items in the same workgroup.

Adds a new argument to the kernel specifying the sampler object represented by 'sampler'. Argument is added to the bottom of the argument order.

Adds a new argument specifying the allocation of a local variable of size length * sizeof(T) bytes (builder_style).

The argument is added to the bottom of the argument order.

Local variables are used to share data between work items in the same workgroup.

Adds a new named Buffer, Image, scalar, or vector argument to the kernel.

The argument is added to the bottom of the argument order.

To set a Buffer or Image argument to None (null), you must use a type annotation (e.g. None::<&Buffer<f32>>). Scalar and vector arguments may not be null; use zero (e.g. &0) instead.

Named arguments can be modified later using ::set_arg().

Example

This example is not tested
// Create a kernel with arguments corresponding to those in the kernel.
// One argument will be 'named':
let kern = ocl_pq.kernel_builder("multiply_by_scalar")
    .arg(&COEFF)
    .arg(&source_buffer)
    .arg_named("result", None::<&Buffer<f32>>)
    .build()?;

// Set our named argument. The Option<_> wrapper is, well... optional:
kern.set_arg("result", &result_buffer)?;
// We can also set arguments (named or not) by index:
kern.set_arg(2, &result_buffer)?;

Deprecated since 0.18

: Use ::arg_named instead.

Adds a new named argument specifying the buffer object represented by 'buffer'.

The argument is added to the bottom of the argument order.

Named arguments can be easily modified later using ::set_arg_buf_named().

Deprecated since 0.18

: Use ::arg_named instead.

Adds a new named argument specifying the image object represented by 'image'.

The argument is added to the bottom of the argument order.

Named arguments can be easily modified later using ::set_arg_img_named().

Deprecated since 0.18

: Use ::arg_sampler_named instead.

Adds a new named argument specifying the sampler object represented by 'sampler'.

The argument is added to the bottom of the argument order.

Named arguments can be easily modified later using ::set_arg_smp_named().

Deprecated since 0.18

: Use ::arg_named instead.

Adds a new named argument specifying the value: scalar.

The argument is added to the bottom of the argument order.

Scalar arguments may not be null, use zero (e.g. &0) instead.

Named arguments can be easily modified later using ::set_arg_scl_named().

Deprecated since 0.18

: Use ::arg_named instead.

Adds a new named argument specifying the value: vector.

The argument is added to the bottom of the argument order.

Vector arguments may not be null, use zero (e.g. &0) instead.

Named arguments can be easily modified later using ::set_arg_vec_named().

Adds a new named argument specifying the sampler object represented by 'sampler'.

The argument is added to the bottom of the argument order.

Named arguments can be easily modified later using ::set_arg_smp_named().

Specifies whether or not to store a copy of memory objects (Buffer and Image).

Safety

Disabling memory object argument retention can lead to a misleading error message or a difficult to debug segfault (depending on the platform) if a memory object is dropped before a kernel referring to it is enqueued. Only disable this if you are certain all of the memory objects set as kernel arguments will outlive the Kernel itself.

Disables argument type checking when setting arguments.

Because the performance cost of argument type checking is negligible, disabling is not recommended.

Argument type checking will automatically be disabled if any of the devices in use do not support OpenCL version 1.2 or higher or if argument information is not available on the associated platform.

Builds and returns a new Kernel

Trait Implementations

impl<'b> Debug for KernelBuilder<'b>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'b> !Send for KernelBuilder<'b>

impl<'b> !Sync for KernelBuilder<'b>