Struct ocl::builders::KernelBuilder

source ·
pub struct KernelBuilder<'b> { /* private fields */ }
Expand description

A kernel builder.

§Examples

// 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:

// 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)?;

Implementations§

source§

impl<'b> KernelBuilder<'b>

source

pub fn new() -> KernelBuilder<'b>

Returns a new kernel builder.

source

pub fn program<'s>( &'s mut self, program: &'b Program ) -> &'s mut KernelBuilder<'b>

Specifies a program object with a successfully built executable.

source

pub fn name<'s, S>(&'s mut self, name: S) -> &'s mut KernelBuilder<'b>
where S: Into<String>,

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

source

pub fn queue<'s>(&'s mut self, queue: Queue) -> &'s mut KernelBuilder<'b>

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.

source

pub fn gwo<'s, D: Into<SpatialDims>>( &'s mut self, gwo: D ) -> &'s mut KernelBuilder<'b>

👎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.

source

pub fn gws<'s, D: Into<SpatialDims>>( &'s mut self, gws: D ) -> &'s mut KernelBuilder<'b>

👎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.

source

pub fn lws<'s, D: Into<SpatialDims>>( &'s mut self, lws: D ) -> &'s mut KernelBuilder<'b>

👎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.

source

pub fn global_work_offset<'s, D: Into<SpatialDims>>( &'s mut self, gwo: D ) -> &'s mut KernelBuilder<'b>

Sets the default global work offset.

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

source

pub fn global_work_size<'s, D: Into<SpatialDims>>( &'s mut self, gws: D ) -> &'s mut KernelBuilder<'b>

Sets the default global work size.

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

source

pub fn local_work_size<'s, D: Into<SpatialDims>>( &'s mut self, lws: D ) -> &'s mut KernelBuilder<'b>

Sets the default local work size.

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

source

pub fn arg<'s, T, A>(&'s mut self, arg: A) -> &'s mut KernelBuilder<'b>
where T: OclPrm, A: Into<ArgValConverter<'b, T>>,

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

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

§Example
let kern = ocl_pq.kernel_builder("multiply_by_scalar")
    .arg(&100.0f32)
    .arg(&source_buffer)
    .arg(&result_buffer)
    .build()?;
source

pub fn arg_buf<'s, T, M>( &'s mut self, buffer: &'b M ) -> &'s mut KernelBuilder<'b>
where T: OclPrm, M: 'b + AsMem<T> + MemCmdAll,

👎Deprecated since 0.18.0: 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.

source

pub fn arg_img<'s, T, M>( &'s mut self, image: &'b M ) -> &'s mut KernelBuilder<'b>
where T: OclPrm, M: 'b + AsMem<T> + MemCmdAll,

👎Deprecated since 0.18.0: 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.

source

pub fn arg_smp<'s>( &'s mut self, sampler: &'b Sampler ) -> &'s mut KernelBuilder<'b>

👎Deprecated since 0.18.0: 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.

source

pub fn arg_scl<'s, T>(&'s mut self, scalar: T) -> &'s mut KernelBuilder<'b>
where T: OclPrm,

👎Deprecated since 0.18.0: Use ::arg instead.

Adds a new argument specifying the value: scalar.

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

source

pub fn arg_vec<'s, T>(&'s mut self, vector: T) -> &'s mut KernelBuilder<'b>
where T: OclPrm,

👎Deprecated since 0.18.0: Use ::arg instead.

Adds a new argument specifying the value: vector.

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

source

pub fn arg_loc<'s, T>(&'s mut self, length: usize) -> &'s mut KernelBuilder<'b>
where T: OclPrm,

👎Deprecated since 0.18.0: 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.

source

pub fn arg_sampler<'s>( &'s mut self, sampler: &'b Sampler ) -> &'s mut KernelBuilder<'b>

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

source

pub fn arg_local<'s, T>( &'s mut self, length: usize ) -> &'s mut KernelBuilder<'b>
where T: OclPrm,

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.

source

pub fn arg_named<'s, T, S, A>( &'s mut self, name: S, arg: A ) -> &'s mut KernelBuilder<'b>
where S: Into<Cow<'static, str>>, T: OclPrm, A: Into<ArgValConverter<'b, T>>,

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
// 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)?;
source

pub fn arg_buf_named<'s, T, S, M>( &'s mut self, name: S, buffer_opt: Option<&'b M> ) -> &'s mut KernelBuilder<'b>
where S: Into<Cow<'static, str>>, T: OclPrm, M: 'b + AsMem<T> + MemCmdAll,

👎Deprecated since 0.18.0: 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().

source

pub fn arg_img_named<'s, T, S, M>( &'s mut self, name: S, image_opt: Option<&'b M> ) -> &'s mut KernelBuilder<'b>
where S: Into<Cow<'static, str>>, T: OclPrm, M: 'b + AsMem<T> + MemCmdAll,

👎Deprecated since 0.18.0: 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().

source

pub fn arg_smp_named<'s, S>( &'s mut self, name: S, sampler_opt: Option<&'b Sampler> ) -> &'s mut KernelBuilder<'b>
where S: Into<Cow<'static, str>>,

👎Deprecated since 0.18.0: 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().

source

pub fn arg_scl_named<'s, T>( &'s mut self, name: &'static str, scalar: T ) -> &'s mut KernelBuilder<'b>
where T: OclPrm,

👎Deprecated since 0.18.0: 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().

source

pub fn arg_vec_named<'s, T>( &'s mut self, name: &'static str, vector: T ) -> &'s mut KernelBuilder<'b>
where T: OclPrm,

👎Deprecated since 0.18.0: 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().

source

pub fn arg_sampler_named<'s>( &'s mut self, name: &'static str, sampler_opt: Option<&'b Sampler> ) -> &'s mut KernelBuilder<'b>

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().

source

pub unsafe fn disable_mem_arg_retention<'s>( &'s mut self ) -> &'s mut KernelBuilder<'b>

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.

source

pub unsafe fn disable_arg_type_check<'s>( &'s mut self ) -> &'s mut KernelBuilder<'b>

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.

source

pub fn build(&self) -> OclResult<Kernel>

Builds and returns a new Kernel

Trait Implementations§

source§

impl<'b> Debug for KernelBuilder<'b>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'b> Unpin for KernelBuilder<'b>

§

impl<'b> UnwindSafe for KernelBuilder<'b>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.