gpu::linalg
cheatah-gpu-linalg v0.4.4-alpha — Biome Standard 0.6.3-alpha
Classes
device_array— A dense, row-major, GPU-resident array.device_location— The location tag fordevice_array.
Concepts
BridgeElement— BridgeElement<T>: the element types the host bridge accepts — every real/complex float width, because no device kernel is involved (contrast GpuElement, which gates real device kernels).GpuComplexElement— GpuComplexElement<T>: the complex elements the seam-wired product/reduction kernels support (c64/c128 — float2/double2 on the device, layout-identical to std::complex).GpuElement— GpuElement<T>: the REAL element types this library has GPU kernels for; constraining here means an unsupported element is a clean "no device overload" rather than a null-named dispatch.GpuField— GpuField<T>: any element with device kernels — the constraint of the seam-wired routines (matmul/outer/conj_transpose/kron/dot/vdot/inner/trace).
Functions
Device cholesky — host bridge (download → cheatah host kernel → upload).
out | The pre-allocated n×n device factor L (filled by upload). |
a | The n×n symmetric positive-definite device operand (throws otherwise, from the host kernel). |
host O(n³) (cheatah's column-by-column Cholesky) + O(n²) elements over the bus.
host f64 copies of a and the factor (O(n²) each; an f32 element adds one O(n²) conversion vector per transfer) + the host kernel's own O(n²) private factor scratch.
none — out was allocated by cheatah's front; transfers recycle the context's pooled staging buffers.
gpu:bridgeDevice inv — host bridge (LU with partial pivoting + whole-identity back-solve).
out | The pre-allocated n×n device inverse. |
a | The square device operand (a singular matrix throws, from the host kernel). |
host O(n³) + O(n²) elements over the bus.
host f64 copies of a and the result (O(n²) each) + the host kernel's LU and identity back-solve scratch (O(n²)); f32 adds conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice pinv — host bridge (Moore–Penrose pseudo-inverse via Golub–Reinsch SVD; the result is the transposed shape n×m for an m×n input).
out | The pre-allocated n×m device pseudo-inverse. |
a | The m×n device operand (any shape). |
host iterative O(n³) via SVD + O(m·n) elements over the bus.
host f64 copies of a and the result + the host kernel's SVD/assembly scratch (O(m·n)); f32 adds conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice matrix_power — host bridge (binary exponentiation; negative n via the host inverse).
out | The pre-allocated square device result Aⁿ. |
a | The square device operand. |
n | The integer exponent (0 yields the identity). |
host O(n³·log|n|) by binary exponentiation + O(n²) elements over the bus.
host f64 copies of a and the result + the binary-exponentiation products' own intermediates on the host; f32 adds conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice solve — host bridge (x from A·x = b via LU with partial pivoting).
out | The pre-allocated length-n device solution vector. |
a | The n×n device coefficient matrix. |
b | The length-n device right-hand side. |
host O(n³) + O(n²) elements over the bus.
host f64 copies of a, b and x + the host kernel's O(n²) LU scratch; f32 adds conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice lstsq — host bridge (min ‖Ax−b‖, computed as pinv(A)·b on the host).
out | The pre-allocated device solution (a.cols × b.cols). |
a | The m×n device coefficient matrix. |
b | The m×k device right-hand side. |
host iterative O(n³) via SVD + O(m·n) elements over the bus.
host f64 copies of a, b and x + the intermediate n×m pseudo-inverse and its SVD scratch on the host; f32 adds conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice svdvals — host bridge (descending singular values, length min(m,n) — the values-only fast path of the Golub–Reinsch reduction, a large constant factor below the full svd).
out | The pre-allocated length-min(m,n) device singular-value vector. |
a | The m×n device operand. |
host iterative O(n³) + O(m·n) elements over the bus.
host f64 copies of a and the values + the reduction's own O(m·n) workspace on the host; f32 adds conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice qr — host bridge (reduced Householder QR; requires rows ≥ cols, from the host kernel).
q | The pre-allocated m×n device orthonormal factor. |
r | The pre-allocated n×n device upper-triangular factor. |
a | The m×n device operand. |
host O(n³) + O(m·n) elements over the bus.
host f64 copies of a and both factors + the host kernel's O(m²) private factorization scratch; f32 adds conversion vectors.
none — q and r pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice svd — host bridge (Golub–Reinsch; requires rows ≥ cols, from the host kernel).
u | The pre-allocated m×n device left-singular-vector factor. |
s | The pre-allocated length-n device singular-value vector (descending). |
vh | The pre-allocated n×n device Vᴴ factor. |
a | The m×n device operand. |
host iterative O(n³) + O(m·n) elements over the bus.
host f64 copies of a and all three factors + the reduction's own O(m·n) workspace on the host; f32 adds conversion vectors.
none — outputs pre-allocated by cheatah's front; pooled staging only.
gpu:bridgevoid eig(Array< ndarray::complex_of_t< T > > &values, Array< ndarray::complex_of_t< T > > &vectors, const Array< T > &a)
#
Device eig — host bridge (Hessenberg + shifted QR; COMPLEX outputs from a real or complex square input, since a real matrix can have complex eigenpairs).
values | The pre-allocated length-n complex device spectrum. |
vectors | The pre-allocated n×n complex device eigenvector matrix (columns). |
a | The n×n device operand. |
host iterative O(n³) + O(n²) elements over the bus.
host c128 copies of a's widening plus both outputs + the host kernel's O(n²) factorization/eigenvector scratch; narrower elements add conversion vectors.
none — outputs pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice eigvals — host bridge (the COMPLEX spectrum of a real or complex square matrix, descending; symmetric input routes through tridiagonal QL on the host, the rest through Hessenberg + shifted QR).
out | The pre-allocated length-n complex device spectrum. |
a | The n×n device operand. |
host iterative O(n³) + O(n²) elements over the bus.
host c128 copies of the operand and spectrum + the host iteration's own O(n²) scratch; narrower elements add conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgevoid eigh(Array< ndarray::real_base_t< T > > &values, Array< T > &vectors, const Array< T > &a)
#
Device eigh — host bridge (Householder tridiagonalization + QL for a symmetric/Hermitian input: a REAL spectrum plus eigenvectors matching the input's element type).
values | The pre-allocated length-n REAL device spectrum (descending). |
vectors | The pre-allocated n×n device eigenvector matrix (input's element type). |
a | The n×n symmetric/Hermitian device operand. |
host iterative O(n³) + O(n²) elements over the bus.
host f64/c128 copies of the operand and both outputs + the host solver's own O(n²) scratch; narrower elements add conversion vectors.
none — outputs pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice eigvalsh — host bridge (the REAL spectrum of a symmetric/Hermitian matrix, descending — tridiagonal QL skipping the eigenvector accumulation).
out | The pre-allocated length-n REAL device spectrum. |
a | The n×n symmetric/Hermitian device operand. |
host iterative O(n³) + O(n²) elements over the bus.
host copies of the operand and spectrum + the host solver's own O(n²) scratch; narrower elements add conversion vectors.
none — out pre-allocated by cheatah's front; pooled staging only.
gpu:bridgeDevice det — host bridge (LU with partial pivoting; pivot product × permutation sign).
out | The caller's scalar determinant (narrowed back to |
a | The square device operand. |
host O(n³) + O(n²) elements downloaded.
one host f64 copy of a + the host kernel's O(n²) LU scratch; f32 adds a conversion vector.
none — download-only; pooled staging.
gpu:bridgeDevice slogdet — host bridge (sign and log|det| via LU — the overflow-safe determinant).
out | The caller's SLogDet result (plain doubles). |
a | The square device operand. |
host O(n³) + O(n²) elements downloaded.
one host f64 copy of a + the host kernel's O(n²) LU scratch; f32 adds a conversion vector.
none — download-only; pooled staging.
gpu:bridgeDevice cond — host bridge (largest/smallest singular-value ratio from a Golub–Reinsch SVD).
out | The caller's scalar condition number. |
a | The device operand. |
host iterative O(n³) via SVD + O(n²) elements downloaded.
one host f64 copy of a + the host kernel's O(n²) factorization scratch; f32 adds a conversion vector.
none — download-only; pooled staging.
gpu:bridgeDevice matrix_rank — host bridge (SVD singular-value thresholding).
out | The caller's rank (cheatah's signed integer). |
a | The device operand. |
host iterative O(n³) via SVD + O(n²) elements downloaded.
one host f64 copy of a + the host kernel's O(n²) factorization scratch; f32 adds a conversion vector.
none — download-only; pooled staging.
gpu:bridgeDevice norm — host bridge (L2 for vectors, Frobenius for matrices — dispatched on rank by the host kernel).
out | The caller's scalar norm. |
a | The device operand (any rank). |
host O(size) over the elements + the same O(size) downloaded.
one host f64 copy of a (the host kernel itself sums in place); f32 adds a conversion vector.
none — download-only; pooled staging.
gpu:bridgeWhether 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.
true when the backend context is (or can be) live; false when bring-up failed.
O(1) after the first call (the probe result is cached).
none after the first call.
none.
gpu:guardsWhy 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.
The bring-up failure message, or the empty string while the device is available.
O(1) after the first call (the reason is cached).
one cached string on the first call.
none.
gpu:guardsvoid im2col2d(Array< T > &col, const Array< T > &x, long long B, long long C, long long H, long long W, long long KH, long long KW, long long OH, long long OW, long long stride, long long pad)
#
Device batched 2-D im2col GATHER into the caller's column block: col[(c·KH+kh)·KW+kw, b·OO + oh·OW + ow] = x[b, c, oh·stride − pad + kh, ow·stride − pad + kw] with out-of-plane (padding) cells written as ZEROS — a FULL overwrite, so a reused workspace needs no zeroing pass.
One thread per col element, writes contiguous. Mirrors the host reference's element order and zero-padding exactly (pure data movement — bit-identical).
col | The [C·KH·KW, B·OH·OW]-element device destination (workspace, overwritten). |
x | The [B, C·H·W]-element device input block, laid out [B][C][H][W]. |
B | The batch size. |
C | The input channel count. |
H | The input plane height. |
W | The input plane width. |
KH | The kernel height. |
KW | The kernel width. |
OH | The output plane height ((H + 2·pad − KH)/stride + 1). |
OW | The output plane width. |
stride | The spatial step (≥ 1). |
pad | The symmetric zero padding (≥ 0). Throws on an operand size mismatch. |
O(B·C·KH·KW·OH·OW) device work in one blocking dispatch.
none — the 10-uint dims scratch recycles through the pool.
none — both data buffers are the caller's.
gpu:convvoid col2im2d(Array< T > &dx, const Array< T > &dcol, long long B, long long C, long long H, long long W, long long KH, long long KW, long long OH, long long OW, long long stride, long long pad)
#
Device batched 2-D col2im — the EXACT adjoint of im2col2d, in GATHER form: each dx cell sums its ≤ KH·KW contributing dcol cells (skipping stride-incompatible and out-of-range kernel offsets), one thread per dx element, FULL overwrite (the scatter-add's zeroing folded in).
The kh-major accumulation order matches the host reference's scatter-add per cell, so the result is bit-identical — and deterministic by construction, no atomics.
dx | The [B, C·H·W]-element device input-gradient block, overwritten. |
dcol | The [C·KH·KW, B·OH·OW]-element device column gradients. |
B | The batch size. |
C | The input channel count. |
H | The input plane height. |
W | The input plane width. |
KH | The kernel height. |
KW | The kernel width. |
OH | The output plane height. |
OW | The output plane width. |
stride | The spatial step (≥ 1). |
pad | The symmetric zero padding (≥ 0). Throws on an operand size mismatch. |
O(B·C·H·W·KH·KW) device work in one blocking dispatch (≤ KH·KW adds per cell).
none — the 10-uint dims scratch recycles through the pool.
none — both data buffers are the caller's.
gpu:convvoid conv_bias_act(Array< T > &a, const Array< T > &yc, const Array< T > &bias, long long B, long long F, long long OO, long long act_code)
#
Device conv forward epilogue, fused THREE-in-one — bias add + activation + layout transpose: a[(b·F+f)·OO + o] = act(yc[f·B·OO + b·OO + o] + bias[f]), taking the GEMM's filter-major [F, B·OO] output to the per-sample [B, F·OO] activation block in ONE dispatch.
One thread per output element. f64 note: tanh/sigmoid evaluate their transcendental in f32 on the device (SPIR-V has no f64 exp/tanh); identity/relu stay full-width exact.
a | The [B, F·OO]-element device activation block, overwritten. |
yc | The [F, B·OO]-element device GEMM output. |
bias | The F-element device bias row. |
B | The batch size. |
F | The filter (output-channel) count. |
OO | The output plane element count OH·OW. |
act_code | The activation selector: 0 = identity, 1 = relu, 2 = tanh, 3 = sigmoid (throws on any other code, and on an operand size mismatch). |
O(B·F·OO) device work in one blocking dispatch.
none — content-cached dims scratch only.
none — all three data buffers are the caller's.
gpu:convvoid conv_act_grad(Array< T > &dyc, const Array< T > &d, const Array< T > &a, long long B, long long F, long long OO, long long act_code)
#
Device conv backward epilogue (the adjoint of conv_bias_act's act + layout, fused): dyc[f·B·OO + b·OO + o] = d[(b·F+f)·OO + o] · act'(a[(b·F+f)·OO + o]) — the chain-rule step and the transpose back to filter-major in ONE dispatch.
The derivative is evaluated FROM THE OUTPUT a = f(z) (identity' = 1, relu' = [a > 0], tanh' = 1 − a², sigmoid' = a(1 − a)) — pure arithmetic, exact in both element widths, no retained pre-activations.
dyc | The [F, B·OO]-element device delta block, overwritten. |
d | The [B, F·OO]-element device upstream gradient dL/dA. |
a | The [B, F·OO]-element device activations (the forward output). |
B | The batch size. |
F | The filter (output-channel) count. |
OO | The output plane element count OH·OW. |
act_code | The activation selector: 0 = identity, 1 = relu, 2 = tanh, 3 = sigmoid (throws on any other code, and on an operand size mismatch). |
O(B·F·OO) device work in one blocking dispatch.
none — content-cached dims scratch only.
none — all three data buffers are the caller's.
gpu:convadd · 2 overloads
void add(device_array< T > &out, const device_array< T > &a, const device_array< T > &b)#device_array< T > add(const device_array< T > &a, const device_array< T > &b)#out = a + b (same shape).
out | The destination (may alias |
a | The left device operand. |
b | The right device operand (throws on a shape mismatch). |
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
none — all buffers are the caller's.
gpu:elementwisesub · 2 overloads
void sub(device_array< T > &out, const device_array< T > &a, const device_array< T > &b)#device_array< T > sub(const device_array< T > &a, const device_array< T > &b)#out = a − b (same shape).
out | The destination (may alias an operand). |
a | The left device operand. |
b | The right device operand (throws on a shape mismatch). |
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
none.
gpu:elementwisemul · 2 overloads
void mul(device_array< T > &out, const device_array< T > &a, const device_array< T > &b)#device_array< T > mul(const device_array< T > &a, const device_array< T > &b)#out = a ⊙ b, the Hadamard product (same shape).
out | The destination (may alias an operand). |
a | The left device operand. |
b | The right device operand (throws on a shape mismatch). |
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
none.
gpu:elementwisedivide · 2 overloads
void divide(device_array< T > &out, const device_array< T > &a, const device_array< T > &b)#device_array< T > divide(const device_array< T > &a, const device_array< T > &b)#out = a ⊘ b, elementwise division (same shape).
out | The destination (may alias an operand). |
a | The dividend device operand. |
b | The divisor device operand (throws on a shape mismatch). |
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
none.
gpu:elementwiseaxpy · 3 overloads
void axpy(device_array< T > &out, T alpha, const device_array< T > &x, const device_array< T > &y)#device_array< T > axpy(T alpha, const device_array< T > &x, const device_array< T > &y)#void axpy(host_array< T > &out, T alpha, const host_array< T > &x, const host_array< T > &y)#out = α·x + y in ONE dispatch — the fused training-loop primitive (same shapes; operator chaining costs two dispatches and a temporary).
out | The destination (may alias |
alpha | The scalar coefficient. |
x | The scaled device operand. |
y | The added device operand (throws on a shape mismatch). |
O(n) device work in one blocking vec4 dispatch.
none — the 1-element α buffer and dims scratch recycle through the pool.
none.
gpu:elementwise√a elementwise, allocating (cheatah's sqrt ufunc spelling).
a | The device operand. |
A fresh device array holding the elementwise square root.
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
one pooled device data buffer for the result.
gpu:elementwiseeᵃ elementwise, allocating.
f64 note: SPIR-V (and GPU hardware generally) has NO double transcendentals — GLSL.std.450 Exp/Log exist only for 16/32-bit floats — so the double form is evaluated on the HOST over the downloaded elements, full f64 precision; float runs the device kernel.
a | The device operand. |
A fresh device array holding eᵃ.
O(n): one device dispatch for float; a host loop + round-trip for double.
none for float (dims scratch only); one O(n) host vector for the double host path.
one pooled device data buffer for the result.
gpu:elementwiseln a elementwise, allocating (same f64 host-evaluation note as exp).
a | The device operand. |
A fresh device array holding ln a.
O(n): one device dispatch for float; a host loop + round-trip for double.
none for float (dims scratch only); one O(n) host vector for the double host path.
one pooled device data buffer for the result.
gpu:elementwise|a| elementwise, allocating.
a | The device operand. |
A fresh device array holding the elementwise absolute value.
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
one pooled device data buffer for the result.
gpu:elementwisesum · 2 overloads
Σ 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).
a | The device operand (any rank; 0 elements yield T{}). |
The scalar sum, downloaded as ONE element.
O(n) device work; one fused submission (partial + finalize).
none — pooled partial/result scratch; sizeof(T) readback.
none — pooled scratch only.
gpu:elementwisemean · 2 overloads
The arithmetic mean Σ aᵢ / n (n = 0 yields 0, matching an empty sum).
a | The device operand. |
The scalar mean.
O(n) device work (one fused sum) + one host division.
none — pooled partial/result scratch; sizeof(T) readback.
none — pooled scratch only.
gpu:elementwiseoperator+ · 3 overloads
device_array< T > operator+(const device_array< T > &a, const device_array< T > &b)#device_array< T > operator+(const device_array< T > &a, T s)#device_array< T > operator+(T s, const device_array< T > &a)#a + b elementwise (the spelling purr's codegen emits; resolves here by ADL).
a | The left device operand. |
b | The right device operand (throws on a shape mismatch). |
A fresh device array holding the sum.
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
one pooled device data buffer for the result.
gpu:operatorsoperator- · 4 overloads
device_array< T > operator-(const device_array< T > &a, const device_array< T > &b)#device_array< T > operator-(const device_array< T > &a, T s)#device_array< T > operator-(T s, const device_array< T > &a)#device_array< T > operator-(const device_array< T > &a)#a − b elementwise.
a | The left device operand. |
b | The right device operand (throws on a shape mismatch). |
A fresh device array holding the difference.
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
one pooled device data buffer for the result.
gpu:operatorsoperator* · 3 overloads
device_array< T > operator*(const device_array< T > &a, const device_array< T > &b)#device_array< T > operator*(const device_array< T > &a, T s)#device_array< T > operator*(T s, const device_array< T > &a)#a ⊙ b elementwise.
a | The left device operand. |
b | The right device operand (throws on a shape mismatch). |
A fresh device array holding the Hadamard product.
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
one pooled device data buffer for the result.
gpu:operatorsoperator/ · 3 overloads
device_array< T > operator/(const device_array< T > &a, const device_array< T > &b)#device_array< T > operator/(const device_array< T > &a, T s)#device_array< T > operator/(T s, const device_array< T > &a)#a ⊘ b elementwise.
a | The dividend device operand. |
b | The divisor device operand (throws on a shape mismatch). |
A fresh device array holding the quotient.
O(n) device work in one blocking vec4 dispatch.
none — content-cached dims scratch only.
one pooled device data buffer for the result.
gpu:operatorsoperator+= · 2 overloads
device_array< T > & operator+=(device_array< T > &a, const device_array< T > &b)#device_array< T > & operator+=(device_array< T > &a, T s)#a += b in place.
a | The accumulating device operand. |
b | The added device operand. |
a.
O(n) device work in one blocking vec4 dispatch.
none — pooled scratch only.
none — in place.
gpu:operatorsoperator-= · 2 overloads
device_array< T > & operator-=(device_array< T > &a, const device_array< T > &b)#device_array< T > & operator-=(device_array< T > &a, T s)#a −= b in place.
a | The accumulating device operand. |
b | The subtracted device operand. |
a.
O(n) device work in one blocking vec4 dispatch.
none — pooled scratch only.
none — in place.
gpu:operatorsoperator*= · 2 overloads
device_array< T > & operator*=(device_array< T > &a, const device_array< T > &b)#device_array< T > & operator*=(device_array< T > &a, T s)#a ⊙= b in place.
a | The accumulating device operand. |
b | The multiplying device operand. |
a.
O(n) device work in one blocking vec4 dispatch.
none — pooled scratch only.
none — in place.
gpu:operatorsoperator/= · 2 overloads
device_array< T > & operator/=(device_array< T > &a, const device_array< T > &b)#device_array< T > & operator/=(device_array< T > &a, T s)#a ⊘= b in place.
a | The accumulating device operand. |
b | The dividing device operand. |
a.
O(n) device work in one blocking vec4 dispatch.
none — pooled scratch only.
none — in place.
gpu:operatorsThe transfer/dispatch ledger of the process-wide context (uploads, downloads, dispatches).
The live counters (a reference into the context — reads reflect later ops).
O(1).
none.
none.
example:vector_pipelineZero the ledger (examples call this right before a hot loop, then assert on stats).
O(1).
none.
none.
example:vector_pipelineUpload 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).
a | The contiguous host array. |
A device array holding a copy of a's elements.
O(n) transfer.
metadata only — the Vulkan upload stages through a pooled host-visible buffer.
one pooled device data buffer of size()·sizeof(T).
example:vector_pipelineDownload a device array into a fresh host array (same shape + element type).
A SYNC POINT.
a | The device array. |
A host ndarray holding a copy of a's elements.
O(n) transfer.
the O(n) host result; the Vulkan readback stages through a pooled host-cached buffer.
none.
example:mlp_forwardA 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.
shape | The dimensions (cheatah's signed integers; negatives throw). |
value | The fill value. |
A fresh device array of value s.
O(n) device work (real) or O(n) host fill + upload (complex).
none for real elements (pooled scalar/dims scratch); one O(n) host vector for complex.
one pooled device data buffer for the result.
gpu:elementwiseA double device array of zeros (ndarray's zeros) — the device-side fill kernel, no upload.
shape | The dimensions (negatives throw). |
A fresh zeroed device array.
O(n) device work.
none — pooled scalar/dims scratch only.
one pooled device data buffer for the result.
gpu:elementwiseA double device array of ones (ndarray's ones) — the device-side fill kernel, no upload.
shape | The dimensions (negatives throw). |
A fresh device array of ones.
O(n) device work.
none — pooled scalar/dims scratch only.
one pooled device data buffer for the result.
example:batched_inferenceSame shape/element as a, every element value — ADL-reachable, so generic code can call it unqualified on either container.
a | The array whose shape/element is copied. |
value | The fill value. |
A fresh device array of value s.
O(n) device work (real elements fill on device).
none for real elements; one O(n) host vector for complex.
one pooled device data buffer for the result.
Zeros with a's shape/element (ADL-reachable).
a | The array whose shape/element is copied. |
A fresh zeroed device array.
O(n) device work.
none for real elements.
one pooled device data buffer for the result.
Ones with a's shape/element (ADL-reachable).
a | The array whose shape/element is copied. |
A fresh device array of ones.
O(n) device work.
none for real elements.
one pooled device data buffer for the result.
array · 2 overloads
device_array< T > array(const std::vector< T > &values)#device_array< T > array(std::initializer_list< T > values)#A 1-D device array from a host vector (ndarray's array).
values | The host elements. |
A fresh 1-D device array holding a copy of values.
O(n) transfer.
metadata only — pooled staging on Vulkan.
one pooled device data buffer for the result.
example:vector_pipelineA 0-d scalar device array.
value | The element. |
A fresh 0-d device array holding value.
O(1) transfer.
metadata only.
one pooled device data buffer (one size class, 256 B minimum).
Evenly spaced values in [start, stop) with the given step (ndarray's arange; a zero step throws).
start | The first value. |
stop | The exclusive bound. |
step | The (non-zero) increment. |
A fresh 1-D device array of the sequence.
O(n) host generation + O(n) transfer.
one O(n) host vector (the sequence is generated host-side, then uploaded).
one pooled device data buffer for the result.
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).
a | The device array to re-view. |
shape | The new dimensions (same element count). |
A sibling array sharing a's device buffer under the new shape.
O(ndim).
the new shape/strides vectors.
none — zero-copy by design.
example:mlp_forwardRead 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).
a | The device array. |
index | One signed index per dimension. |
The element's value.
O(ndim) index math + an O(1) offset download.
none fresh — the Vulkan readback stages through a pooled host-cached buffer.
none.
example:linear_regression_gdRender like ndarray renders (downloads, then reuses ndarray's own to_string — identical output by construction).
A SYNC POINT.
a | The device array. |
The rendered text.
O(n) download + O(n) formatting.
a full host copy of a plus the string.
none.
Stream form — same rendering as ndarray's operator<< (a SYNC POINT, via to_string).
os | The destination stream. |
a | The device array. |
os.
O(n) download + O(n) formatting.
a full host copy of a plus the string.
none.
Element count as cheatah's signed integer (ndarray's size_of).
a | The device array. |
The element count.
O(1).
none.
none.
Device arrays are always contiguous (parity with ndarray's is_contiguous).
a | The device array (unused — contiguity is structural). |
true, always.
O(1).
none.
none.
Element conversion (ndarray's astype) — HOST round-trip today (documented; a device convert kernel is a listed next step).
a | The device array to convert. |
A fresh device array with each element cast to U.
O(n): download, convert on the host, upload.
two O(n) host vectors (the download and the converted copy).
one pooled device data buffer for the result.
Device GEMM: out = a @ b, row-major, a is M×K, b is K×N, out is M×N.
Invoked by cheatah's allocating matmul(a, b) front (which has already allocated out); routes to the fast 128×128 (or 64-row) register-tiled kernel when the shape tiles exactly, the guarded 64×64 edge kernel otherwise, and the one-dispatch batched kernel for 3-D [B,M,K][B,K,N] operands.
out | The pre-allocated M×N (or B×M×N) device product. |
a | The M×K (or B×M×K) device left operand. |
b | The K×N (or B×K×N) device right operand (throws on an inner-dimension mismatch). |
O(M·N·K) device work (O(B·M·N·K) batched) in one blocking dispatch.
none — the dims scratch is a content-cached pooled buffer (repeat shapes reuse the same handle).
none — all three buffers are the caller's.
gpu:matmul gpu:matmul_batchedDevice outer product: out[n×m] = aᵢ·bⱼ.
Invoked by cheatah's allocating outer(a, b) front; one thread per output element over an m×n 2-D grid, blocking on completion.
out | The pre-allocated n×m device product. |
a | The length-n device vector. |
b | The length-m device vector. |
O(n·m) device work in one blocking dispatch.
none — content-cached dims scratch only.
none — all buffers are the caller's.
gpu:outerDevice conjugate transpose: out[c×r] = aᴴ for an r×c input (the kernel conjugates complex elements; conjugation is the identity for real ones).
Invoked by cheatah's allocating front; one thread per input element, blocking on completion.
out | The pre-allocated c×r device transpose. |
a | The r×c device operand (throws unless 2-D). |
O(r·c) device work in one blocking dispatch.
none — content-cached dims scratch only.
none — both buffers are the caller's.
gpu:transposeDevice Kronecker product: out[(ar·br)×(ac·bc)] = a ⊗ b.
Invoked by cheatah's allocating kron(a, b) front; one thread per output element, blocking on completion.
out | The pre-allocated (ar·br)×(ac·bc) device product. |
a | The ar×ac device left operand (throws unless 2-D). |
b | The br×bc device right operand (throws unless 2-D). |
O(n⁴) in the output area (one multiply per output element).
none — content-cached dims scratch only.
none — all buffers are the caller's.
gpu:krondot · 2 overloads
void dot(T &out, const Array< T > &a, const Array< T > &b)#void dot(Array< T > &out, const Array< T > &a, const Array< T > &b)#Device dot product (bilinear Σ aᵢbᵢ) into the caller's scalar — the DeviceArray overload of cheatah's scalar-out reduction kernel, dispatched as deterministic partial sums (the same bits every run), finalized on device and downloaded as ONE element.
out | The caller's scalar result. |
a | The first device vector. |
b | The second device vector (throws on a length mismatch). |
O(n) device work; one fused submission (partial + finalize).
none — the partial/result scratch recycles through the pooled allocator; the readback is sizeof(T).
none — pooled scratch only.
gpu:dotDevice vdot: the Hermitian Σ conj(aᵢ)·bᵢ for complex elements (its own conjugating kernel); for real elements the conjugation is the identity and it shares dot's kernel.
out | The caller's scalar result. |
a | The first (conjugated) device vector. |
b | The second device vector (throws on a length mismatch). |
O(n) device work; one fused submission (partial + finalize).
none — pooled partial/result scratch; sizeof(T) readback.
none — pooled scratch only.
gpu:dot gpu:complexDevice inner product — the bilinear Σ aᵢbᵢ, identical to dot for flattened vectors (dispatched through the same kernel).
out | The caller's scalar result. |
a | The first device vector. |
b | The second device vector (throws on a length mismatch). |
O(n) device work; one fused submission (partial + finalize).
none — pooled partial/result scratch; sizeof(T) readback.
none — pooled scratch only.
gpu:dotDevice trace (diagonal sum of a 2-D matrix) into the caller's scalar — deterministic partial sums over the strided diagonal, summed on the host in a fixed order.
out | The caller's scalar result. |
a | The r×c device matrix (min(r,c) diagonal elements are summed). |
O(min(r,c)) device work + O(P) host partial summation (P ≤ 256).
none — the P-element partial buffer and dims scratch recycle through the pool.
none — pooled scratch only.
gpu:traceTypes
The host container under its device-parity name: step<host_array>(…) vs step<device_array>(…) is the entire CPU↔GPU switch.
