Skip to main content

HostPin

Struct HostPin 

Source
pub struct HostPin<'a> { /* private fields */ }
Expand description

A stable host address for a tensor’s data, valid until the pin is dropped.

Deliberately carries no lifetime parameter and no reference to the tensor: see the module docs. Cloning is cheap and shares the keepalive.

Implementations§

Source§

impl<'a> HostPin<'a>

Source

pub fn as_ptr(&self) -> *const u8

The pinned host address. Stable until this pin is dropped.

Source

pub fn as_mut_ptr(&self) -> *mut u8

The pinned host address, mutable.

Takes &self rather than &mut self on purpose: a raw pointer handed out here can legitimately coexist with a &mut derived elsewhere (that is the entire point of the pin), so pretending exclusivity via &mut self would be a lie. Writing through it is the caller’s obligation to sequence — see crate::Tensor::sync_for_cpu.

§Safety contract

The caller must not write while a device may be reading, and must bracket CPU access with the sync calls on non-coherent backends.

Source

pub fn len(&self) -> usize

The tensor’s logical byte length, offset-adjusted for sub-region views — not the backing allocation’s capacity.

Backends round allocations up (page size, pitch alignment), and every backend reports the logical length so a consumer cannot mistake padding for data. This is what TFLite’s SetCustomAllocationForTensor wants.

One consequence: for a stride-padded image the pinned window covers shape.product() bytes, which is less than row_stride * height. Use a map guard, which exposes the padded extent, when you need to write whole padded rows.

Source

pub fn is_empty(&self) -> bool

True when the pinned window addresses no bytes.

Source

pub fn alignment(&self) -> usize

Alignment of the pinned address, in bytes.

TFLite requires 64-byte alignment (kDefaultTensorAlignment) unless the caller opts out, and upstream warns that opting out can crash in Invoke(). Page-backed mappings satisfy it, but a non-zero tensor offset can break it — so callers can check rather than assume.

Source

pub unsafe fn as_slice(&self) -> &[u8] ⓘ

The pinned window as a byte slice.

§Safety

The caller must ensure no device write is in flight, and must have bracketed with sync_for_cpu on non-coherent backends.

Trait Implementations§

Source§

impl<'a> Clone for HostPin<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HostPin<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Send for HostPin<'_>

Source§

impl Sync for HostPin<'_>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for HostPin<'a>

§

impl<'a> !UnwindSafe for HostPin<'a>

§

impl<'a> Freeze for HostPin<'a>

§

impl<'a> Unpin for HostPin<'a>

§

impl<'a> UnsafeUnpin for HostPin<'a>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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