pub struct TensorArena {
pub regions: Vec<ArenaRegion>,
pub region_size: usize,
pub stats: ArenaStats,
}Expand description
Bump-allocating arena for inference-pipeline tensors.
Allocations are O(1) — a bump pointer is incremented and, when a region is
exhausted, a new fixed-size region is appended. Freeing all tensors is
O(regions) via reset_all.
Fields§
§regions: Vec<ArenaRegion>All memory regions, ordered by creation time.
region_size: usizeDefault size (bytes) for each new region.
stats: ArenaStatsCumulative statistics.
Implementations§
Source§impl TensorArena
impl TensorArena
Sourcepub fn new(region_size: usize) -> Self
pub fn new(region_size: usize) -> Self
Construct a new arena whose regions will be region_size bytes each.
Sourcepub fn allocate(&mut self, size: usize) -> ArenaSlice
pub fn allocate(&mut self, size: usize) -> ArenaSlice
Allocate size bytes from the arena and return an ArenaSlice.
If the current (last) region cannot satisfy the request a new region is
created. size is always rounded up to the next multiple of
ARENA_ALIGN internally.
Sourcepub fn reset_all(&mut self)
pub fn reset_all(&mut self)
Reset every region’s bump pointer, allowing all memory to be reused.
Outstanding ArenaSlice handles become stale after this call.
Sourcepub fn region_count(&self) -> usize
pub fn region_count(&self) -> usize
Number of regions (slabs) currently held.
Sourcepub fn total_capacity(&self) -> u64
pub fn total_capacity(&self) -> u64
Total capacity in bytes across all regions.
Sourcepub fn total_used(&self) -> u64
pub fn total_used(&self) -> u64
Total bytes that have been bump-allocated (not yet reset).
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Overall utilization as total_used / total_capacity.
Returns 0.0 if there are no regions.
Auto Trait Implementations§
impl Freeze for TensorArena
impl RefUnwindSafe for TensorArena
impl Send for TensorArena
impl Sync for TensorArena
impl Unpin for TensorArena
impl UnsafeUnpin for TensorArena
impl UnwindSafe for TensorArena
Blanket Implementations§
impl<T> Allocation for T
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> 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