Skip to main content

HandleContainer

Struct HandleContainer 

pub struct HandleContainer<H> { /* private fields */ }
Expand description

Keep all tensor handles in one place and ensure that all resources are used optimally.

Implementations§

§

impl<H> HandleContainer<H>
where H: Clone,

pub fn fork(&self) -> HandleContainer<H>

Fork the container, useful for autotune.

§

impl<H> HandleContainer<H>
where H: Clone,

pub fn new() -> HandleContainer<H>

Create a new HandleContainer

pub fn has_errors(&self) -> bool

Whether any tensor is errored by a failure.

A branch that lets the error checks cost nothing while nothing has failed. False means no error lookup can find anything, so the caller can skip asking — worth a branch where asking costs a boxed iterator over an operation’s inputs.

pub fn register_handle(&mut self, id: TensorId, handle: H)

Register a handle for the given tensor id.

Writing recovers a tensor a failure claimed: the bytes are there now, so the entry stops being Handle::Errored and reads of it succeed again. Every register_* path goes through the same insert, so this holds however the write arrives.

This is what lets work retry. An autotune candidate that fails claims the output it did not write; the next candidate writes it and clears the claim, and execution carries on with nothing downstream skipped.

pub fn has_handle(&self, id: &TensorId) -> bool

Whether a usable handle exists.

False for a tensor claimed by a failure (Handle::Errored): the entry is there, but there is no data behind it.

pub fn get_handle_ref(&self, id: &TensorId) -> Option<&H>

Get the reference to a handle.

None for a tensor claimed by a failure, the same as one that was never produced — the error is delivered by get_handle, at the read, and asked for ahead of time with error.

pub fn set_error(&mut self, id: TensorId, error: TensorError)

Record that error is why id holds no data: the work that was going to write it did not run, so a read of it must fail rather than hand back whatever the tensor id resolves to.

It always displaces whatever is registered. A claim covers exactly the tensors one unit of work was responsible for writing, and a handle registered before that work — an in-place output, aliased to its input while the launch is still being planned — proves nothing about whether the kernel that fills it ever ran.

pub fn claim_unwritten(&mut self, id: TensorId, error: TensorError)

Claim id, but only if nothing wrote it and no failure already claims it.

For the one caller that cannot name its write set: a panic that escaped the strategy walk itself, raised outside every scope, where all that is known is that something in the consumed segment did not finish. Claiming broadly from there would error outputs that other operations wrote, and would overwrite a precise claim with a vaguer one — so it claims only what is neither, which is exactly the set nothing else can account for.

pub fn error(&self, id: &TensorId) -> Option<&TensorError>

The failure that errored id, if one did.

pub fn take_error(&mut self, tensor: &TensorIr) -> Option<TensorError>

The failure tensor carries, released when this read consumes the tensor. The fallible half of get_handle: a read asks for this first and reports it, rather than tripping over the handle that is not there.

The status rule is the one get_handle already applies to a handle. A ReadWrite read is the tensor’s last use, so the failure is released with it — the refcount that clears failures is the tensor’s own, and this read is the last chance to honour it: the reader took ownership of the id, so no later Drop will. A ReadOnly read leaves it, because the tensor is still alive and every later read of it has to report the same cause.

pub fn get_handle(&mut self, id: &TensorId, status: &TensorStatus) -> H

Get the handle for the given tensor id. The status is used to determine if the tensor should be popped out of the current tensor map, necessary for inplace operations.

§Warnings

Make sure the status corresponds to the operation you want to execute the handle on, otherwise you might remove a tensor handle that will be required in the future.

pub fn get_tensor_handle(&mut self, tensor: &TensorIr) -> TensorHandle<H>

Get the tensor handle for the given tensor intermediate representation.

pub fn get_float_tensor<B>( &mut self, tensor: &TensorIr, ) -> <B as BackendTypes>::FloatTensorPrimitive
where B: BackendIr<Handle = H>,

Get the float tensor corresponding to the given tensor intermediate representation.

pub fn get_int_tensor<B>( &mut self, tensor: &TensorIr, ) -> <B as BackendTypes>::IntTensorPrimitive
where B: BackendIr<Handle = H>,

Get the int tensor corresponding to the given tensor intermediate representation.

pub fn get_bool_tensor<B>( &mut self, tensor: &TensorIr, ) -> <B as BackendTypes>::BoolTensorPrimitive
where B: BackendIr<Handle = H>,

Get the bool tensor corresponding to the given tensor intermediate representation.

pub fn get_quantized_tensor<B>( &mut self, tensor: &TensorIr, ) -> <B as BackendTypes>::QuantizedTensorPrimitive
where B: BackendIr<Handle = H>,

Get the quantized tensor corresponding to the given tensor intermediate representation.

pub fn register_float_tensor<B>( &mut self, id: &TensorId, tensor: <B as BackendTypes>::FloatTensorPrimitive, )
where B: BackendIr<Handle = H>,

Register a new float tensor with the corresponding tensor id.

pub fn register_quantized_tensor<B>( &mut self, id: &TensorId, tensor: <B as BackendTypes>::QuantizedTensorPrimitive, )
where B: BackendIr<Handle = H>,

Register a new quantized tensor with the corresponding tensor ids.

pub fn register_int_tensor<B>( &mut self, id: &TensorId, tensor: <B as BackendTypes>::IntTensorPrimitive, )
where B: BackendIr<Handle = H>,

Register a new int tensor with the corresponding tensor id.

pub fn register_bool_tensor<B>( &mut self, id: &TensorId, tensor: <B as BackendTypes>::BoolTensorPrimitive, )
where B: BackendIr<Handle = H>,

Register a new bool tensor with the corresponding tensor id.

pub fn remove_handle(&mut self, id: TensorId) -> Option<Handle<H>>

Remove tensor handle from container.

pub fn free(&mut self, tensor: &TensorIr)

Remove tensor handle from container if writable

pub fn num_handles(&self) -> usize

Returns the number of handles.

pub fn handle_ids(&self) -> impl Iterator<Item = &TensorId>

Returns the IDs of all currently registered handles.

Useful for snapshotting which handles exist at a point in time (e.g., before executing on a forked context) so that newly registered output handles can be detected afterwards.

Trait Implementations§

§

impl<H> Debug for HandleContainer<H>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<H> Default for HandleContainer<H>

§

fn default() -> HandleContainer<H>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<H> Freeze for HandleContainer<H>

§

impl<H> RefUnwindSafe for HandleContainer<H>
where H: RefUnwindSafe,

§

impl<H> Send for HandleContainer<H>
where H: Send,

§

impl<H> Sync for HandleContainer<H>
where H: Sync,

§

impl<H> Unpin for HandleContainer<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for HandleContainer<H>

§

impl<H> UnwindSafe for HandleContainer<H>
where H: UnwindSafe,

Blanket Implementations§

§

impl<T> Adaptor<()> for T

§

fn adapt(&self)

Adapt the type to be passed to a metric.
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
§

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<K, Q> Comparable<Q> for K
where K: Borrow<Q> + ?Sized, Q: Ord + ?Sized,

§

fn compare(&self, key: &Q) -> Ordering

Compare self to key and return their ordering.
§

impl<K, Q> Equivalent<Q> for K
where K: Borrow<Q> + ?Sized, Q: Eq + ?Sized,

§

fn equivalent(&self, key: &Q) -> bool

Compare self to key and return true if they are equal.
§

impl<T> ErasedDestructor for T
where T: 'static,

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

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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
§

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

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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 = 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