Struct ocl::Kernel

source ·
pub struct Kernel { /* private fields */ }
Expand description

A kernel which represents a ‘procedure’.

Corresponds to code which must have already been compiled into a program.

Set arguments using ::set_arg or any of the ::set_arg... methods.

Kernel includes features that a raw OpenCL kernel does not, including:

  1. Type-checked arguments (not just size-checked)
  2. Named arguments (with a &'static str name)
  3. Prevention of a potential (difficult to debug) segfault if a buffer or image used by a kernel is dropped prematurely.
  4. Stored defaults for the:
    • Queue
    • Global Work Offset
    • Global Work Size
    • Local Work Size

§Clone and Send

A Kernel may not be cloned but may be sent between threads. This ensures that no two threads create a race condition by attempting to set an argument and enqueue a kernel at the same time. Use the KernelBuilder to create multiple identical kernels (KernelBuilder is clonable and re-usable).

Implementations§

source§

impl Kernel

source

pub fn builder<'p>() -> KernelBuilder<'p>

Returns a new KernelBuilder.

source

pub fn named_arg_idx(&self, name: &'static str) -> Option<u32>

Returns the argument index of a named argument if it exists.

source

pub unsafe fn set_arg_unchecked( &self, arg_idx: u32, arg_val: ArgVal<'_> ) -> OclResult<()>

Sets an argument by index without checks of any kind.

Setting buffer or image (cl_mem) arguments this way may cause segfaults or errors if the buffer goes out of scope at any point before this kernel is dropped.

This also bypasses the check to determine if the type of the value you pass here matches the type defined in your kernel.

source

pub fn set_arg<'a, T, Ai, Av>(&self, idx: Ai, arg: Av) -> OclResult<()>
where T: OclPrm, Ai: Into<ArgIdxSpecifier>, Av: Into<ArgValConverter<'a, T>>,

Sets a Buffer, Image, scalar, or vector argument by index or by name.

§Example
// Create a kernel with arguments corresponding to those in the kernel.
// Just for fun, one argument will be 'named':
let kern = ocl_pq.kernel_builder("multiply_by_scalar")
    .arg(&0)
    .arg(None::<&Buffer<f32>>)
    .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. Just for
// demonstration, we'll set one using an option:
kern.set_arg(0, &COEFF)?;
kern.set_arg(1, Some(&source_buffer))?;
kern.set_arg(2, &result_buffer)?;
source

pub fn set_arg_buf_named<'a, T, M>( &'a self, name: &'static str, buffer_opt: Option<M> ) -> OclResult<()>
where T: OclPrm, M: AsMem<T> + MemCmdAll,

👎Deprecated since 0.18.0: Use ::set_arg instead.

Modifies the kernel argument named: name.

source

pub fn set_arg_img_named<'a, T, M>( &'a self, name: &'static str, image_opt: Option<M> ) -> OclResult<()>
where T: OclPrm, M: AsMem<T> + MemCmdAll,

👎Deprecated since 0.18.0: Use ::set_arg instead.

Modifies the kernel argument named: name.

source

pub fn set_arg_smp_named<'a>( &'a self, name: &'static str, sampler_opt: Option<&Sampler> ) -> OclResult<()>

👎Deprecated since 0.18.0: Use ::set_arg_sampler_named instead.

Sets the value of a named sampler argument.

source

pub fn set_arg_scl_named<'a, T, B>( &'a self, name: &'static str, scalar: B ) -> OclResult<()>
where T: OclPrm, B: Borrow<T>,

👎Deprecated since 0.18.0: Use ::set_arg instead.

Modifies the kernel argument named: name.

source

pub fn set_arg_vec_named<'a, T, B>( &'a self, name: &'static str, vector: B ) -> OclResult<()>
where T: OclPrm, B: Borrow<T>,

👎Deprecated since 0.18.0: Use ::set_arg instead.

Modifies the kernel argument named: name.

source

pub fn set_arg_sampler_named<'a, Ai>( &'a self, idx: Ai, sampler_opt: Option<&Sampler> ) -> OclResult<()>
where Ai: Into<ArgIdxSpecifier>,

Sets the value of a named sampler argument.

source

pub fn cmd(&self) -> KernelCmd<'_>

Returns a command builder which is used to chain parameters of an ‘enqueue’ command together.

source

pub unsafe fn enq(&self) -> OclResult<()>

Enqueues this kernel on the default queue using the default work sizes and offsets.

Shorthand for .cmd().enq()

§Safety

All kernel code must be considered untrusted. Therefore the act of calling this function contains implied unsafety even though the API itself is safe.

source

pub fn set_default_queue(&mut self, queue: Queue) -> &mut Kernel

Changes the default queue.

Returns a ref for chaining i.e.:

kernel.set_default_queue(queue).enqueue(....);

Even when used as above, the queue is changed permanently, not just for the one call. Changing the queue is cheap so feel free to change as often as needed.

If you want to change the queue for only a single call, use: ::cmd.queue(...)...enq()...

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

source

pub fn get_gwo(&self) -> SpatialDims

👎Deprecated since 0.18.0: Use ::global_work_offset instead.

Returns the default global work offset.

source

pub fn get_gws(&self) -> SpatialDims

👎Deprecated since 0.18.0: Use ::global_work_size instead.

Returns the default global work size.

source

pub fn get_lws(&self) -> SpatialDims

👎Deprecated since 0.18.0: Use ::local_work_size instead.

Returns the default local work size.

source

pub fn set_default_global_work_offset( &mut self, gwo: SpatialDims ) -> &mut Kernel

Sets the default global work offset.

source

pub fn set_default_global_work_size(&mut self, gws: SpatialDims) -> &mut Kernel

Sets the default global work size.

source

pub fn set_default_local_work_size(&mut self, lws: SpatialDims) -> &mut Kernel

Sets the default local work size.

source

pub fn default_queue(&self) -> Option<&Queue>

Returns the default queue for this kernel if one has been set.

source

pub fn default_global_work_offset(&self) -> SpatialDims

Returns the default global work offset.

source

pub fn default_global_work_size(&self) -> SpatialDims

Returns the default global work size.

source

pub fn default_local_work_size(&self) -> SpatialDims

Returns the default local work size.

source

pub fn as_core(&self) -> &KernelCore

Returns a reference to the core pointer wrapper, usable by functions in the core module.

source

pub fn info(&self, info_kind: KernelInfo) -> OclResult<KernelInfoResult>

Returns information about this kernel.

source

pub fn wg_info( &self, device: Device, info_kind: KernelWorkGroupInfo ) -> OclResult<KernelWorkGroupInfoResult>

Returns work group information for this kernel.

source

pub fn arg_info( &self, arg_idx: u32, info_kind: KernelArgInfo ) -> OclResult<KernelArgInfoResult>

Returns argument information for this kernel.

source

pub fn name(&self) -> OclResult<String>

Returns the name of this kernel.

source

pub fn num_args(&self) -> OclResult<u32>

Returns the number of arguments this kernel has.

Methods from Deref<Target = KernelCore>§

source

pub fn as_ptr(&self) -> *mut c_void

Returns a pointer, do not store it.

source

pub fn program(&self) -> Result<Program, Error>

Returns the program associated with this kernel.

source

pub fn devices(&self) -> Result<Vec<DeviceId>, Error>

Trait Implementations§

source§

impl Debug for Kernel

source§

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

Formats the value using the given formatter. Read more
source§

impl Deref for Kernel

§

type Target = Kernel

The resulting type after dereferencing.
source§

fn deref(&self) -> &KernelCore

Dereferences the value.
source§

impl Display for Kernel

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Kernel

§

impl !RefUnwindSafe for Kernel

§

impl Send for Kernel

§

impl !Sync for Kernel

§

impl Unpin for Kernel

§

impl UnwindSafe for Kernel

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.