cheatah
Module

gpulinalg

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

Functions

fn cheatah::gpu::linalg::device_array< double > scalar_slot() #

A 1-element device array — the resident slot a loss accumulator lives in (purr cannot spell device_array<double>::uninitialized({1}), so the module provides it).

Returns

A fresh uninitialized 1-element device array.

Complexity

O(1).

Host allocation

metadata only.

GPU allocation

one pooled device data buffer (one 256 B size class).

Unit testexample:purr
fn bool available() noexcept #

Whether the device context can come up on this machine — a cached one-shot probe that NEVER throws.

This is the runtime "is there a GPU?" question (the nullopt-probe pattern at the linalg layer): gate work on it instead of hand-rolling a try/catch around a first dispatch. detail::ctx() itself still throws on first touch when the device is genuinely required.

Returns

true when the backend context is (or can be) live; false when bring-up failed.

Complexity

O(1) after the first call (the probe result is cached).

Host allocation

none after the first call.

GPU allocation

none.

Unit testgpu:guards
fn const std::string & unavailable_reason() noexcept #

Why available() is false — the probe's exception text, "" while available.

The consumer's skip note ("gpu lane skipped: …") should carry this instead of inventing its own reason.

Returns

The bring-up failure message, or the empty string while the device is available.

Complexity

O(1) after the first call (the reason is cached).

Host allocation

one cached string on the first call.

GPU allocation

none.

Unit testgpu:guards
fn device_array< T > to_device(const host_array< T > &a) #

Upload a host array into a fresh device array (same shape + element type; the operand must be contiguous — pack first via ndarray's reshape/copy if it is a strided view, else this throws).

Parameters
a

The contiguous host array.

Returns

A device array holding a copy of a's elements.

Complexity

O(n) transfer.

Host allocation

metadata only — the Vulkan upload stages through a pooled host-visible buffer.

GPU allocation

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

Unit testexample:vector_pipeline
fn host_array< T > to_host(const device_array< T > &a) #

Download a device array into a fresh host array (same shape + element type).

A SYNC POINT.

Parameters
a

The device array.

Returns

A host ndarray holding a copy of a's elements.

Complexity

O(n) transfer.

Host allocation

the O(n) host result; the Vulkan readback stages through a pooled host-cached buffer.

GPU allocation

none.

Unit testexample:mlp_forward
fn T get(const device_array< T > &a, const std::vector< long long > &index) #

Read ONE element by signed multi-index (ndarray's get) — a single-element SYNC POINT (exactly sizeof(T) crosses the bus; throws on a rank mismatch or an out-of-range index).

Parameters
a

The device array.

index

One signed index per dimension.

Returns

The element's value.

Complexity

O(ndim) index math + an O(1) offset download.

Host allocation

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

GPU allocation

none.

Unit testexample:linear_regression_gd
fn std::string to_string(const device_array< T > &a) #

Render like ndarray renders (downloads, then reuses ndarray's own to_string — identical output by construction).

A SYNC POINT.

Parameters
a

The device array.

Returns

The rendered text.

Complexity

O(n) download + O(n) formatting.

Host allocation

a full host copy of a plus the string.

GPU allocation

none.

fn long long size_of(const device_array< T > &a) #

Element count as cheatah's signed integer (ndarray's size_of).

Parameters
a

The device array.

Returns

The element count.

Complexity

O(1).

Host allocation

none.

GPU allocation

none.

fn device_array< double > zeros(const std::vector< long long > &shape) #

A double device array of zeros (ndarray's zeros) — the device-side fill kernel, no upload.

Parameters
shape

The dimensions (negatives throw).

Returns

A fresh zeroed device array.

Complexity

O(n) device work.

Host allocation

none — pooled scalar/dims scratch only.

GPU allocation

one pooled device data buffer for the result.

Unit testgpu:elementwise
fn device_array< double > ones(const std::vector< long long > &shape) #

A double device array of ones (ndarray's ones) — the device-side fill kernel, no upload.

Parameters
shape

The dimensions (negatives throw).

Returns

A fresh device array of ones.

Complexity

O(n) device work.

Host allocation

none — pooled scalar/dims scratch only.

GPU allocation

one pooled device data buffer for the result.

Unit testexample:batched_inference
fn device_array< T > full(const std::vector< long long > &shape, T value) #

A device array of the given shape, every element value (ndarray's full).

Real elements fill ON DEVICE (no host staging vector, no PCIe upload); complex elements take the staged-upload fallback.

Parameters
shape

The dimensions (cheatah's signed integers; negatives throw).

value

The fill value.

Returns

A fresh device array of value s.

Complexity

O(n) device work (real) or O(n) host fill + upload (complex).

Host allocation

none for real elements (pooled scalar/dims scratch); one O(n) host vector for complex.

GPU allocation

one pooled device data buffer for the result.

Unit testgpu:elementwise
fn device_array< T > arange(T start, T stop, T step) #

Evenly spaced values in [start, stop) with the given step (ndarray's arange; a zero step throws).

Parameters
start

The first value.

stop

The exclusive bound.

step

The (non-zero) increment.

Returns

A fresh 1-D device array of the sequence.

Complexity

O(n) host generation + O(n) transfer.

Host allocation

one O(n) host vector (the sequence is generated host-side, then uploaded).

GPU allocation

one pooled device data buffer for the result.

fn device_array< T > reshape(const device_array< T > &a, const std::vector< long long > &shape) #

Reshape — ZERO-COPY: device arrays are always contiguous, so the new view shares the buffer (throws on a negative dimension, an element-count overflow, or a count mismatch).

Parameters
a

The device array to re-view.

shape

The new dimensions (same element count).

Returns

A sibling array sharing a's device buffer under the new shape.

Complexity

O(ndim).

Host allocation

the new shape/strides vectors.

GPU allocation

none — zero-copy by design.

Unit testexample:mlp_forward
fn void axpy(device_array< T > &out, T alpha, const device_array< T > &x, const device_array< T > &y) #

out = α·x + y in ONE dispatch — the fused training-loop primitive (same shapes; operator chaining costs two dispatches and a temporary).

Parameters
out

The destination (may alias x or y).

alpha

The scalar coefficient.

x

The scaled device operand.

y

The added device operand (throws on a shape mismatch).

Complexity

O(n) device work in one blocking vec4 dispatch.

Host allocation

none — the 1-element α buffer and dims scratch recycle through the pool.

GPU allocation

none.

Unit testgpu:elementwise
fn T sum(const device_array< T > &a) #

Σ aᵢ over the whole array — the DETERMINISTIC partial-sum contract (a size-picked one- or two-stage partial kernel + an on-device finalize, fused into one submission; fixed association order, so the same bits come back every run).

Parameters
a

The device operand (any rank; 0 elements yield T{}).

Returns

The scalar sum, downloaded as ONE element.

Complexity

O(n) device work; one fused submission (partial + finalize).

Host allocation

none — pooled partial/result scratch; sizeof(T) readback.

GPU allocation

none — pooled scratch only.

Unit testgpu:elementwise
fn T mean(const device_array< T > &a) #

The arithmetic mean Σ aᵢ / n (n = 0 yields 0, matching an empty sum).

Parameters
a

The device operand.

Returns

The scalar mean.

Complexity

O(n) device work (one fused sum) + one host division.

Host allocation

none — pooled partial/result scratch; sizeof(T) readback.

GPU allocation

none — pooled scratch only.

Unit testgpu:elementwise
fn const detail::Context::TransferStats & stats() #

The transfer/dispatch ledger of the process-wide context (uploads, downloads, dispatches).

Returns

The live counters (a reference into the context — reads reflect later ops).

Complexity

O(1).

Host allocation

none.

GPU allocation

none.

Unit testexample:vector_pipeline
fn void reset_stats() #

Zero the ledger (examples call this right before a hot loop, then assert on stats).

Complexity

O(1).

Host allocation

none.

GPU allocation

none.

Unit testexample:vector_pipeline