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
impl ModelSession
Sourcepub fn freeze(self, context: &ModelContext) -> Result<ModelDefinition>
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
impl ModelSession
Sourcepub fn in_context(context: &ModelContext) -> Result<Self>
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.
Sourcepub fn open(index: i32) -> Result<Self>
pub fn open(index: i32) -> Result<Self>
Open a device and its shared Loom compiler using the device’s actual target.
Sourcepub fn open_for(index: i32, expected_target: &str) -> Result<Self>
pub fn open_for(index: i32, expected_target: &str) -> Result<Self>
Open a device only when it reports the architecture validated by a model.
Sourcepub fn with_compiler(device: Device, compiler: Compiler) -> Result<Self>
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.
Sourcepub fn allocate(&mut self, bytes: usize) -> Result<Region>
pub fn allocate(&mut self, bytes: usize) -> Result<Region>
Allocate device-local model storage.
Allocate coherent host-local storage visible to the device.
Sourcepub fn weight(&mut self, bytes: &[u8]) -> Result<Region>
pub fn weight(&mut self, bytes: &[u8]) -> Result<Region>
Allocate device-local storage and enqueue its initial contents.
Sourcepub unsafe fn compile(
&mut self,
specifications: &[(&str, Specialization)],
) -> Result<Vec<KernelId>>
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.
Sourcepub fn is_recorded(&self, key: usize) -> bool
pub fn is_recorded(&self, key: usize) -> bool
Whether a graph has already been prepared under key.
Sourcepub unsafe fn record(&mut self, key: usize, commands: &[Command]) -> Result<()>
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.
Sourcepub fn upload(&mut self, region: Region, bytes: &[u8]) -> Result<()>
pub fn upload(&mut self, region: Region, bytes: &[u8]) -> Result<()>
Enqueue a host-to-device transfer at the start of a region.
Sourcepub fn synchronize(&mut self) -> Result<()>
pub fn synchronize(&mut self) -> Result<()>
Wait for all queued session work.
Sourcepub fn reserve_readback(&mut self, bytes: usize) -> Result<()>
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.
Sourcepub fn read(&mut self, region: Region, bytes: &mut [u8]) -> Result<()>
pub fn read(&mut self, region: Region, bytes: &mut [u8]) -> Result<()>
Wait for queued work and copy one region into caller-owned bytes.
Sourcepub fn read_many(&mut self, outputs: &mut [(Region, &mut [u8])]) -> Result<()>
pub fn read_many(&mut self, outputs: &mut [(Region, &mut [u8])]) -> Result<()>
Wait once and copy several regions into caller-owned byte slices.
Sourcepub fn benchmark(
&mut self,
key: usize,
samples: usize,
) -> Result<ForwardTimings>
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.
Sourcepub fn profile_commands(
&mut self,
key: usize,
samples: usize,
) -> Result<Vec<Distribution>>
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.
Sourcepub fn launch_config(
&self,
id: KernelId,
workload_bits: &[u64],
) -> Result<LaunchConfig>
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§
impl !Freeze for ModelSession
impl !RefUnwindSafe for ModelSession
impl !Sync for ModelSession
impl Send for ModelSession
impl Unpin for ModelSession
impl UnsafeUnpin for ModelSession
impl UnwindSafe for ModelSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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