ExpertLru

Struct ExpertLru 

Source
pub struct ExpertLru { /* private fields */ }

Implementations§

Source§

impl ExpertLru

One byte range of a missed expert as a reader thread sees it: (slot, key, ring slot within the half, byte offset, byte length).

Source

pub fn arena_dev(&self) -> DevicePtr

The arena’s device address (slot i starts at i * layout.bytes).

Source

pub fn drain_slot_changes(&mut self) -> Vec<(u32, u32, i32)>

The (layer, expert, slot | -1) changes since the last call: what a device-side slot table has to learn (assignments and evictions).

Source

pub fn is_device(&self) -> bool

The slots are device memory behind a staging ring.

Source

pub fn fetch_many_on<S: ExpertSource + ?Sized>( &mut self, gpu: &dyn GpuBackend, stream: u64, src: &S, keys: &[(u32, u32)], predicted: &[(u32, u32)], threads: usize, ) -> Result<Vec<ExpertSlot>>

One token’s gather on whichever path this cache was built for: the staging ring (device slots), the reader pool (predicted experts started in the background), or scoped reader threads. The copies of a staged fetch are enqueued on stream ahead of the caller’s launches.

Source§

impl ExpertLru

Source

pub fn new( host: *mut u8, dev: DevicePtr, bytes: usize, layout: SlotLayout, ) -> Result<Self>

bytes / layout.bytes slots over the arena at host (device alias dev). Every slot starts empty and at the LRU end.

Source

pub fn n_slots(&self) -> usize

Source

pub fn layout(&self) -> SlotLayout

Source

pub fn resident(&self) -> usize

Experts currently cached.

Source

pub fn contains(&self, layer: u32, expert: u32) -> bool

Source

pub fn stats(&self) -> LruStats

Source

pub fn reset_stats(&mut self)

Source

pub fn begin_token(&mut self)

Open a new epoch: slots fetched from now on are pinned until the next begin_token; everything fetched earlier becomes evictable again.

Source

pub fn slot(&self, i: u32) -> ExpertSlot

Source

pub fn fetch<S: ExpertSource + ?Sized>( &mut self, src: &S, layer: u32, expert: u32, ) -> Result<(ExpertSlot, bool)>

One expert. Returns the slot and whether it was already resident.

Source

pub fn fetch_many<S: ExpertSource + ?Sized>( &mut self, src: &S, keys: &[(u32, u32)], threads: usize, ) -> Result<Vec<ExpertSlot>>

One token’s gather: every key resolved to a slot, misses read on up to threads scoped threads. Duplicate keys are one read. Slots are pinned for the current epoch, so call Self::begin_token first.

Source§

impl ExpertLru

Source

pub fn set_evict_random_pct(&mut self, pct: usize)

Strict LRU or a random victim among the oldest pct% (see take_victim).

Source§

impl ExpertLru

Source

pub fn set_pool( &mut self, src: Arc<dyn ExpertSource + Send + Sync>, threads: usize, )

Read misses (and predictions) on threads persistent readers from src instead of scoped threads per fetch.

Source

pub fn has_pool(&self) -> bool

Source

pub fn fetch_many_prefetching( &mut self, keys: &[(u32, u32)], predicted: &[(u32, u32)], ) -> Result<Vec<ExpertSlot>>

Slots for keys (misses read urgently), reads of predicted experts started in the background, then the wait for keys only.

Source

pub fn prefetch(&mut self, predicted: &[(u32, u32)]) -> Result<()>

Start reading predicted experts in the background (no wait).

Source

pub fn wait_in_flight(&self)

Block until every read in flight has landed (tests, shutdown).

Source

pub fn set_trace(&mut self, path: &str) -> Result<()>

Append every fetch_many to path as one line: microseconds since the cache was built, the layer, the key count, the misses and the evictions of the call, then the expert ids in request order. The exact access sequence, for replaying cache policies offline.

Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,