Skip to content
class

CpuStorage

CpuStorage

CPU tensor storage backed by a posix_memalign allocation.

Ownership is shared: multiple TensorImpl views may hold a copy of ptr that points into the same physical allocation. The VersionCounter is also shared so a mutation through one view is visible to every other view that aliases the same bytes.

All Apple Accelerate / BLAS / vDSP code paths read and write this variant.

See Also

DataBuffer — allocator-layer twin. GpuStorage — GPU sibling variant. SharedStorage — unified-memory sibling variant.

Attributes

ptrstd::shared_ptr<std::byte[]>
64-byte aligned heap allocation, shared with every aliasing view.
nbytesstd::size_t
Allocated capacity in bytes (for a block view, the block's byte span).
dtypeDtype
Element type. Default Dtype::F32.
versionstd::shared_ptr<VersionCounter>
Shared mutation counter; in-place ops call bump_version.
offset_in_allocationstd::size_t
Byte offset of ptr.get() from the start of the underlying physical allocation. 0 when ptr points at the start of the allocation.
allocation_nbytesstd::size_t
Total byte size of the underlying physical allocation. 0 means the handle spans the full allocation (i.e. nbytes).

Constructors

1
ctor

CpuStorage

void CpuStorage()

Default-constructs an empty CpuStorage (null pointer, zero bytes, default F32 dtype, fresh version counter).

Methods

3
fnconst

bump_version

void bump_version()

Atomically increments the shared version counter.

fnconst

get_version

→std::uint64_t
int get_version()

Reads the current version counter value.

Returns

std::uint64_t

Monotonically non-decreasing snapshot of mutation count.

fnconst

to_data_buffer

→StoragePtr
int to_data_buffer()

Wraps this CpuStorage back into a DataBuffer.

No allocation occurs — the returned StoragePtr aliases the same ptr and shares the same version counter.

Returns

StoragePtr

Heap-allocated DataBuffer mirroring this storage's fields.