KernelCacheCL

Struct KernelCacheCL 

Source
pub struct KernelCacheCL {
    pub kernel_cache: HashMap<String, Rc<Kernel>>,
}
Expand description

This stores the previously compiled OpenCL kernels.

Fields§

§kernel_cache: HashMap<String, Rc<Kernel>>

Implementations§

Source§

impl KernelCacheCL

Source

pub fn kernel_cache( &mut self, device: &OpenCL, src: &str, ) -> Result<Rc<Kernel>, Box<dyn Error + Sync + Send>>

Returns a cached kernel. If the kernel source code does not exist, a new kernel is created and cached.

§Example
use std::collections::HashMap;
use custos::{OpenCL, opencl::KernelCacheCL};

fn main() -> custos::Result<()> {
    let device = OpenCL::new(0)?;
     
    let mut kernel_cache = KernelCacheCL {
        kernel_cache: HashMap::new(),
    };
     
    let mut kernel_fn = || kernel_cache.kernel_cache(&device, "
        __kernel void test(__global float* test) {}
    ");
     
    let kernel = kernel_fn()?;
    let same_kernel = kernel_fn()?;
     
    assert_eq!(kernel.0, same_kernel.0);
    Ok(())
}

Trait Implementations§

Source§

impl Debug for KernelCacheCL

Source§

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

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

impl Default for KernelCacheCL

Source§

fn default() -> KernelCacheCL

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.