pub struct NativeSession<T> { /* private fields */ }Expand description
Owned stream-bound model state scheduled alongside prepared GPU graphs.
Stages execute synchronously on the calling thread and may borrow inputs and progress callbacks. They reserve the compute lane, without blocking unrelated upload/download/NPU lanes. Earlier submissions drain before admission; later compute cannot overtake a waiting stage. Admission uses the runtime’s bounded submission capacity. This is a stage boundary, not asynchronous inference or separate transfer scheduling within a stage.
Implementations§
Source§impl<T> NativeSession<T>
impl<T> NativeSession<T>
Sourcepub unsafe fn new(
runtime: &Runtime,
state: T,
fence: fn(&mut T) -> Result<()>,
) -> Self
pub unsafe fn new( runtime: &Runtime, state: T, fence: fn(&mut T) -> Result<()>, ) -> Self
Own a model’s private native state and its completion fence.
§Safety
State must own every private stream, graph and allocation used by its
stages, on this runtime’s selected device. fence must drain all those
streams before returning success, including after a failed stage. No
concurrent external access to this state is allowed. Construction must
leave no pending work; subsequent work must go through Self::run.
Sourcepub fn state(&self) -> Result<&T>
pub fn state(&self) -> Result<&T>
Inspect idle model metadata. Returns DeviceLost after quarantine.
Sourcepub unsafe fn run<R>(&mut self, stage: impl FnOnce(&mut T) -> R) -> Result<R>
pub unsafe fn run<R>(&mut self, stage: impl FnOnce(&mut T) -> R) -> Result<R>
Reserve compute, run a borrowed stage, then fence on every exit path.
Client errors may be returned as R = Result<_, ClientError> and do not
poison a successfully drained session. A panic is resumed after fencing.
A failed or panicking fence quarantines the entire owner, including its
allocation charges, and rejects all subsequent stages.
§Safety
The stage must retain all resources until the fence, submit only on the
owned streams, and not expose pending raw uses outside this session.
It must not transfer private native owners out of the state, including
through its return value; quarantine must retain the complete owner.
Stages may access only private native storage, not coordinated buffers;
use Graph::gpu_scoped for operations needing tracked memory hazards.
Do not wait for coordinated compute or another native session in this
runtime from the callback: this stage already holds its compute lane.
Auto Trait Implementations§
impl<T> Freeze for NativeSession<T>
impl<T> RefUnwindSafe for NativeSession<T>
impl<T> Send for NativeSession<T>
impl<T> Sync for NativeSession<T>
impl<T> Unpin for NativeSession<T>
impl<T> UnsafeUnpin for NativeSession<T>
impl<T> UnwindSafe for NativeSession<T>
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