cheatah
Class

gpu::linalg::device_array

cheatah-gpu-linalg v0.4.4-alpha — Biome Standard 0.6.3-alpha

A dense, row-major, GPU-resident array.

Models cheatah's ArrayLike (host-resident shape / strides / ndim / size / offset + a uninitialized factory) so it flows through the linalg templates; its elements live in a shared-storage cheatah-gpu buffer.

Functions

fn device_array()=default #

An empty array: no shape, no buffer (assign a factory result to make it real).

fn void write_from(const T *data) #

Upload size() contiguous elements into this (already-allocated) array — device-local memory on Vulkan goes through a staged transfer; unified memory is a memcpy.

Parameters
data

The host elements (size() of them, contiguous; bounds-checked against the allocation).

Complexity

O(n) transfer.

Host allocation

none fresh — the Vulkan staging buffer recycles through the pool.

GPU allocation

none — writes into this array's existing buffer.

Unit testgpu:bridge
fn void to_host(T *out) const #

Copy size() elements back to host memory (the download mirror of write_from — a SYNC POINT).

Parameters
out

The host destination (size() elements of room).

Complexity

O(n) transfer.

Host allocation

none fresh — the Vulkan readback stages through a pooled host-cached buffer.

GPU allocation

none.

Unit testgpu:matmul
fn const std::vector< std::size_t > & shape() const #
Returns

The dimensions, row-major.

Complexity

O(1).

Host allocation

none.

fn const std::vector< std::ptrdiff_t > & strides() const #
Returns

The element strides (C-order, in elements).

Complexity

O(1).

Host allocation

none.

fn std::size_t ndim() const #
Returns

The rank.

Complexity

O(1).

Host allocation

none.

fn std::size_t size() const #
Returns

The element count.

Complexity

O(1).

Host allocation

none.

fn std::size_t offset() const #
Returns

The view offset — always 0 (device arrays are whole-buffer views).

Complexity

O(1).

Host allocation

none.

fn device_array with_shape(std::vector< std::size_t > shape) const #

A new view of the SAME buffer under a different (equal-size) contiguous shape — the zero-copy backend of reshape (shares ownership through the same shared_ptr).

Parameters
shape

The new dimensions (caller guarantees the same element count — reshape validates).

Returns

A sibling array sharing this one's device buffer.

Complexity

O(ndim).

Host allocation

the new shape/strides vectors.

GPU allocation

none — zero-copy by design.

Unit testgpu:elementwise
fn detail::Buffer * buffer() const #
Returns

The backend buffer handle (nullptr for an empty array) — NON-owning: the array keeps ownership, never pass it to release_buffer.

Complexity

O(1).

Host allocation

none.

fn static device_array uninitialized(std::vector< std::size_t > shape) #

Allocate an uninitialized array of the given shape (the factory the allocating linalg fronts call as Array<T>::uninitialized({rows, cols})).

Throws on an element-count overflow and past the 2³²−1 element cap (the 32-bit kernel-indexing invariant).

Parameters
shape

The dimensions, row-major.

Returns

A fresh array whose elements are uninitialized device memory.

Complexity

O(ndim) host metadata work; the buffer is a pooled acquire (hash lookup when recycled, one driver allocation otherwise).

Host allocation

the shape/strides vectors (O(ndim)).

GPU allocation

one pooled device data buffer of size()·sizeof(T) — VRAM (device-local) on Vulkan, shared storage on Metal; released to the pool by the last owner's destructor.

Unit testgpu:matmul
fn static device_array from_host(std::vector< std::size_t > shape, const T *data) #

Allocate and upload size() contiguous row-major elements from host memory.

Parameters
shape

The dimensions, row-major.

data

The host elements (size() of them, contiguous).

Returns

A fresh device array holding a copy of data.

Complexity

O(n) transfer.

Host allocation

the O(ndim) metadata; the Vulkan upload stages through a pooled host-visible buffer.

GPU allocation

one pooled device data buffer of size()·sizeof(T).

Unit testgpu:matmul
fn static std::vector< std::ptrdiff_t > c_order_strides(const std::vector< std::size_t > &shape) #

Constants & variables

var std::shared_ptr< detail::Buffer > buf_ #

Shared owner of the backend buffer: the deleter releases it through the active backend's context when the last device_array sharing it goes away.

var std::vector< std::size_t > shape_ #
var std::vector< std::ptrdiff_t > strides_ #
var std::size_t size_ #

Types

type T value_type #

The element type (the standard-container spelling of T).