pub struct MappedRanges { /* private fields */ }Expand description
Byte ranges of a file in array storage: each range memory-mapped on its own (without a
copy, on a Mac with a GPU; read elsewhere), so the bytes between them are neither mapped,
wired nor counted. For loads that keep some of a file’s tensors. The file must not be
modified while it is mapped (see MappedFile).
use nuvec_core::{DType, MappedRanges};
let page = MappedRanges::page_size();
let path = std::env::temp_dir().join("nuvec-mapped-ranges-doc.bin");
let mut bytes = vec![0u8; 3 * page];
bytes[2 * page..2 * page + 8].copy_from_slice(&[1.0f32, 2.0].map(f32::to_le_bytes).concat());
std::fs::write(&path, &bytes).unwrap();
let file = MappedRanges::open(&path, &[(2 * page as u64, page as u64)])?; // the last page only
assert_eq!(file.array(2 * page, DType::F32, &[2])?.to_vec::<f32>()?, vec![1.0, 2.0]);
assert!(file.array(0, DType::F32, &[2]).is_err()); // not mappedImplementations§
Source§impl MappedRanges
impl MappedRanges
Sourcepub fn page_size() -> usize
pub fn page_size() -> usize
The granularity of mappings: range offsets must be multiples of it.
Sourcepub fn open(path: impl AsRef<Path>, ranges: &[(u64, u64)]) -> Result<Self>
pub fn open(path: impl AsRef<Path>, ranges: &[(u64, u64)]) -> Result<Self>
Maps each (offset, length) range of the file at path (offsets multiples of
Self::page_size, ranges disjoint and increasing).
Sourcepub fn mapped_size(&self) -> u64
pub fn mapped_size(&self) -> u64
The bytes mapped, page-rounded (what the GPU allocator’s mapped counts).
Trait Implementations§
Source§impl Clone for MappedRanges
impl Clone for MappedRanges
Auto Trait Implementations§
impl !RefUnwindSafe for MappedRanges
impl !UnwindSafe for MappedRanges
impl Freeze for MappedRanges
impl Send for MappedRanges
impl Sync for MappedRanges
impl Unpin for MappedRanges
impl UnsafeUnpin for MappedRanges
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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
Mutably borrows from an owned value. Read more
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> 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> ⓘ
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 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> ⓘ
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