Cache

Struct Cache 

Source
pub struct Cache<D>
where D: RawConv,
{ pub nodes: HashMap<Ident, Rc<<D as CacheReturn>::CT>>, /* private fields */ }

Fields§

§nodes: HashMap<Ident, Rc<<D as CacheReturn>::CT>>

Implementations§

Source§

impl<D> Cache<D>
where D: RawConv,

Source

pub fn add_node<'a, T, S>( &mut self, device: &'a D, node: Ident, _add_node: impl AddGraph, ) -> Buffer<'a, T, D, S>
where S: Shape, D: Alloc<'a, T, S> + RawConv,

Adds a new cache entry to the cache. The next get call will return this entry if the Ident is correct.

§Example
use custos::prelude::*;
use custos::Ident;

let device = CPU::new();
let cache: Buffer = device
    .cache()
    .add_node(&device, Ident { idx: 0, len: 7 }, ());

let ptr = device
    .cache()
    .nodes
    .get(&Ident { idx: 0, len: 7 })
    .unwrap()
    .clone();

assert_eq!(cache.host_ptr(), ptr.ptr as *mut f32);
Source

pub fn get<'a, T, S>( device: &'a D, len: usize, add_node: impl AddGraph, ) -> Buffer<'a, T, D, S>
where S: Shape, D: Alloc<'a, T, S> + RawConv,

Retrieves cached pointers and constructs a Buffer with the pointers and the given length. If a cached pointer doesn’t exist, a new Buffer will be added to the cache and returned.

§Example
use custos::prelude::*;

let device = CPU::new();
     
let cache_entry: Buffer = Cache::get(&device, 10, ());
let new_cache_entry: Buffer = Cache::get(&device, 10, ());

assert_ne!(cache_entry.ptrs(), new_cache_entry.ptrs());

set_count(0);

let first_entry: Buffer = Cache::get(&device, 10, ());
assert_eq!(cache_entry.ptrs(), first_entry.ptrs());

Trait Implementations§

Source§

impl<D> CacheAble<D> for Cache<D>
where D: RawConv,

Source§

fn retrieve<T, S>( device: &D, len: usize, add_node: impl AddGraph, ) -> Buffer<'_, T, D, S>
where S: Shape, D: for<'b> Alloc<'b, T, S>,

Source§

impl<D> Debug for Cache<D>
where D: Debug + RawConv, <D as CacheReturn>::CT: Debug,

Source§

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

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

impl<D> Default for Cache<D>
where D: RawConv,

Source§

fn default() -> Cache<D>

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

Auto Trait Implementations§

§

impl<D> Freeze for Cache<D>

§

impl<D> RefUnwindSafe for Cache<D>

§

impl<D> !Send for Cache<D>

§

impl<D> !Sync for Cache<D>

§

impl<D> Unpin for Cache<D>
where D: Unpin,

§

impl<D> UnwindSafe for Cache<D>

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.