Skip to main content

ModelSession

Struct ModelSession 

Source
pub struct ModelSession { /* private fields */ }
Expand description

A resident model’s exclusive stream, storage, kernels and reusable graphs.

The session infers graph edges from Binding::access at byte-region granularity. Independent regions may overlap; reads follow the last writer, and writes follow both the last writer and every intervening reader.

Implementations§

Source§

impl ModelSession

Source

pub fn freeze(self, context: &ModelContext) -> Result<ModelDefinition>

Transfer code and immutable weights to a coordinated context. All raw graphs are destroyed after synchronization, before adopting allocations. Scratch and host staging are discarded; prepared slots initialize their own scratch. Values needed across inferences must use Self::weight.

Source§

impl ModelSession

Source

pub fn in_context(context: &ModelContext) -> Result<Self>

Prepare on a shared context’s GPU, compiler and allocation budget. The native loading stream charges weights, scratch and staging before allocation; freezing into the same context does not charge weights twice.

Source

pub fn open(index: i32) -> Result<Self>

Open a device and its shared Loom compiler using the device’s actual target.

Source

pub fn open_for(index: i32, expected_target: &str) -> Result<Self>

Open a device only when it reports the architecture validated by a model.

Source

pub fn with_compiler(device: Device, compiler: Compiler) -> Result<Self>

Create a session with an explicitly selected compiler.

The compiler profile must match the device architecture; mismatches are rejected before any native code is loaded.

Source

pub fn target(&self) -> &Target

Architecture selected by the device and compiler.

Source

pub fn allocate(&mut self, bytes: usize) -> Result<Region>

Allocate device-local model storage.

Source

pub fn allocate_shared(&mut self, bytes: usize) -> Result<Region>

Allocate coherent host-local storage visible to the device.

Source

pub fn weight(&mut self, bytes: &[u8]) -> Result<Region>

Allocate device-local storage and enqueue its initial contents.

Source

pub unsafe fn compile( &mut self, specifications: &[(&str, Specialization)], ) -> Result<Vec<KernelId>>

Compile and load a batch of trusted embedded Loom kernels.

Returned IDs follow request order and remain valid for this session.

§Safety

Every source is compiled to native code. The caller must trust it not to violate the buffer and scalar contracts later supplied to Self::record.

Source

pub fn is_recorded(&self, key: usize) -> bool

Whether a graph has already been prepared under key.

Source

pub unsafe fn record(&mut self, key: usize, commands: &[Command]) -> Result<()>

Record commands once, inferring the minimal buffer hazard dependencies.

Keys are unique within the session; use Self::is_recorded when a shape-dependent preparation path can run more than once.

§Safety

Each dispatch must match its compiled kernel: scalar types, binding order, accessible extents and declared access modes must describe every read and write the native kernel can perform. Regions that may alias outside this session require the caller to provide equivalent ordering.

Source

pub fn upload(&mut self, region: Region, bytes: &[u8]) -> Result<()>

Enqueue a host-to-device transfer at the start of a region.

Source

pub fn replay(&mut self, key: usize) -> Result<()>

Enqueue one replay of a prepared graph.

Source

pub fn synchronize(&mut self) -> Result<()>

Wait for all queued session work.

Source

pub fn reserve_readback(&mut self, bytes: usize) -> Result<()>

Preallocate reusable coherent storage for combined readback.

Readback also grows this storage automatically; reserving avoids an allocation on the first inference.

Source

pub fn read(&mut self, region: Region, bytes: &mut [u8]) -> Result<()>

Wait for queued work and copy one region into caller-owned bytes.

Source

pub fn read_many(&mut self, outputs: &mut [(Region, &mut [u8])]) -> Result<()>

Wait once and copy several regions into caller-owned byte slices.

Source

pub fn benchmark( &mut self, key: usize, samples: usize, ) -> Result<ForwardTimings>

Compare synchronized graph replay with the equivalent direct commands.

Transfers are excluded. Ten untimed alternating warm-up pairs precede the requested samples to limit ordering and cache bias.

Source

pub fn profile_commands( &mut self, key: usize, samples: usize, ) -> Result<Vec<Distribution>>

Profile each prepared command as an isolated synchronized submission.

This is a diagnostic view of per-command host latency, not an estimate of graph contribution: it includes dispatch and synchronization overhead and removes graph overlap. One unmeasured warm-up precedes each command’s samples. Commands execute repeatedly and may change resident outputs.

Source

pub fn launch_config( &self, id: KernelId, workload_bits: &[u64], ) -> Result<LaunchConfig>

Evaluate compiler launch geometry while preparing a model graph. Workload bits follow the kernel definition’s workload signature, which can differ from the scalar arguments supplied to the device entry.

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> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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