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>
impl<'a> HostPin<'a>
Sourcepub fn as_mut_ptr(&self) -> *mut u8
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.
Sourcepub fn len(&self) -> usize
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.
Sourcepub fn alignment(&self) -> usize
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.
Trait Implementations§
impl Send for HostPin<'_>
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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