pub struct ModelContext { /* private fields */ }Expand description
Explicitly shared allocation, compilation, and scheduling domain for models.
Implementations§
Source§impl ModelContext
impl ModelContext
Sourcepub fn new(options: RuntimeOptions) -> Result<Self>
pub fn new(options: RuntimeOptions) -> Result<Self>
Construct a context; hardware and compiler initialization remain lazy.
Sourcepub fn runtime(&self) -> &Runtime
pub fn runtime(&self) -> &Runtime
Coordinated runtime shared by every model and tensor in this context.
Sourcepub fn compiler(&self) -> Result<Compiler>
pub fn compiler(&self) -> Result<Compiler>
Lazily obtain the compiler for the selected device’s actual target.
Sourcepub fn allocate(&self, desc: TensorDesc) -> Result<DeviceTensor>
pub fn allocate(&self, desc: TensorDesc) -> Result<DeviceTensor>
Allocate initialized device storage. Empty tensors allocate nothing.
Sourcepub fn allocate_with(
&self,
desc: TensorDesc,
placement: MemoryPlacement,
) -> Result<DeviceTensor>
pub fn allocate_with( &self, desc: TensorDesc, placement: MemoryPlacement, ) -> Result<DeviceTensor>
Allocate a tensor with explicit storage placement. Host-visible IO can be submitted and read back directly without transfer staging or copies.
Sourcepub fn tensor(
&self,
desc: TensorDesc,
view: BufferView,
producer: Completion,
) -> Result<DeviceTensor>
pub fn tensor( &self, desc: TensorDesc, view: BufferView, producer: Completion, ) -> Result<DeviceTensor>
Wrap existing tracked storage without copying. The producer must belong to this runtime or represent already completed initialization.
Sourcepub fn upload(&self, desc: TensorDesc, bytes: &[u8]) -> Result<DeviceTensor>
pub fn upload(&self, desc: TensorDesc, bytes: &[u8]) -> Result<DeviceTensor>
Copy host bytes into owned staging and enqueue upload. The caller may release or mutate its source as soon as this method returns.
Sourcepub fn copy_into(
&self,
destination: &mut DeviceTensor,
byte_offset: usize,
source: &DeviceTensor,
) -> Result<()>
pub fn copy_into( &self, destination: &mut DeviceTensor, byte_offset: usize, source: &DeviceTensor, ) -> Result<()>
Copy a contiguous tensor into a byte-aligned subrange of another tensor. Both tensors must be contiguous and have the same dtype. This updates the destination’s producer dependency, preserving failures from earlier writes. Slot owners survive until the copy drains, even if the source is dropped.
Sourcepub fn concatenate(&self, inputs: &[DeviceTensor]) -> Result<DeviceTensor>
pub fn concatenate(&self, inputs: &[DeviceTensor]) -> Result<DeviceTensor>
Concatenate contiguous tensors along their first axis on the device. Inputs must have identical trailing dimensions, dtype and layout. Empty inputs are allowed; scalars and an empty input list are not.
Sourcepub fn download(&self, tensor: &DeviceTensor) -> Result<TensorReadback>
pub fn download(&self, tensor: &DeviceTensor) -> Result<TensorReadback>
Queue readback after a tensor’s producer, without a host wait.
Sourcepub fn validate(&self, tensor: &DeviceTensor) -> Result<()>
pub fn validate(&self, tensor: &DeviceTensor) -> Result<()>
Reject a tensor from another allocation domain before any work is queued.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModelContext
impl RefUnwindSafe for ModelContext
impl Send for ModelContext
impl Sync for ModelContext
impl Unpin for ModelContext
impl UnsafeUnpin for ModelContext
impl UnwindSafe for ModelContext
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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