Core, data, and cryptography
Root matrix, data, and cryptography values with C++-parity FnMatrix and FnHash operations.
Examples
Core
Functions
ADL hooks for range-for and std::begin/end (member API is PascalCase).
Prepend OA_TITLE_VIEWPORT to a custom title (no automatic separator) User can add separator in their custom title if desired Returns OA_TITLE_VIEWPORT for empty/null input or if already starts with it
── Exp / log ───────────────────────────────────────────────────────────────
BF16 < -> FP32 conversion (truncation, not rounding — matches storage.slang)
── Rounding / sign / abs ───────────────────────────────────────────────────
Explicitly publish buffered host output. Use after write("\r...") for an immediately visible same-line progress update; print does not auto-flush.
Smart human-readable duration: "3s", "45s", "2m 30s", "1h 15m", "2d 6h"
Uppercase hex with 0x prefix (PCI / vulkan id style, no leading-zero padding).
format integer with comma-separated thousands (e.g. 9521568 → "9,521,568")
Comma-separated decimal for oa::U64 (full range; for log readability only).
── Classification ──────────────────────────────────────────────────────────
log a right-aligned summary line: " (label): type(dims) 1,234" width 60 between left text and right value. Used by model summaries and device info.
═══════════════════════════════════════════════════════════════════════════════ memcpy — Zero-overhead for all sizes ═══════════════════════════════════════════════════════════════════════════════
═══════════════════════════════════════════════════════════════════════════════ memcpyStream — Explicit non-temporal cache policy ═══════════════════════════════════════════════════════════════════════════════
Overlap-safe byte move. Keep this distinct from memcpy so callers make the aliasing contract visible and the compiler selects the appropriate lowering.
═══════════════════════════════════════════════════════════════════════════════ MEMSET / MEMZERO / MEMCMP (defined in memory.cpp) ═══════════════════════════════════════════════════════════════════════════════
Scalar two-argument min/max (the oa::min / oa::max replacement — distinct from minElement/maxElement which scan a range). Returns by const & like std, so ties return the first argument.
parse duration string: "30s", "5m", "20m", "2h", "1d", "1w", "1mo", "1y" Bare number (no suffix) treated as seconds. Returns 0 on parse failure.
oa::Filter is now auto-generated in type.gen.h
oa::Precision is now auto-generated in type.gen.h
═══════════════════════════════════════════════════════════════════════════════ PREFETCH / CACHE CONTROL ═══════════════════════════════════════════════════════════════════════════════
Python-like record output. print adds exactly one newline; write does not. Each complete call is serialized against other OA print/write calls to the same stream. Status reports host I/O failures without exceptions.
Saturating / safe arithmetic and byte helpers
ScalarType is auto-generated in type.gen.h.
── Trig ────────────────────────────────────────────────────────────────────
── Roots / powers ──────────────────────────────────────────────────────────
Stable insertion sort is intentionally used for the small control-plane collections that require stable ordering. It performs no allocation and keeps equal elements in their original order.
Deliberately not named `swap`: an unconstrained `oa::swap(T & , T & )` enters argument-dependent lookup for every OA type and collides with the Standard Library's own generic swap inside algorithms such as std::sort.
Classes
2 members
9 members
20 members
12 members
22 members
2 members
AutogradMeta — per-tensor autograd state (PyTorch-style nullptr-optimized). Inference tensors pay zero bytes: autograd_ stays nullptr. Invariants: - leaf ⇔ !gradFn - leaf with requiresGrad owns a persistent grad matrix (Tier 1) - non-leaf has gradFn; grad is not populated unless retainGrad (v1: unsupported)
Source4 members
8 members
oa::Channel <T > — bounded MPMC channel (multiple-producer, multiple-consumer). Bounded ring buffer with blocking send/recv and non-blocking trySend/tryRecv. Supports graceful shutdown via close() which unblocks all waiters. usage: oa::Channel <oa ::Matrix> ch(16); // capacity 16 ch.send(tensor); // blocks if full auto t = ch.recv(); // blocks if empty, returns nullopt if closed ch.close(); // unblocks all waiters
Source0 members
0 members
14 members
8 members
30 members
0 members
8 members
8 members
8 members
0 members
35 members
Datetime — human-readable UTC date/time over the system clock. For logs, debugging, display. NEVER for consensus or deterministic math.
3 members
1 members
7 members
Any vulkan physical device kind (discrete, integrated, VkCpu/OAV, virtual, other). Not hardware "GPU" only.
22 members
0 members
0 members
4 members
Integer override: returns parsed env value if set+non-empty+parsable, else returns inDefault. Parsing accepts decimal only.
String override: returns env value if set+non-empty, else returns inDefault as an oa::String. Empty value falls back to inDefault.
1 members
24 members
Filesystem — stateless host-filesystem operations. oa::Path owns lexical path manipulation. oa::Paths owns OA location discovery.
42 members
12 members
8 members
Records this operation's backward kernels into the active graph. The tape owns traversal and execution cadence; nodes only describe their adjoints.
0 members
0 members
23 members
19 members
13 members
───────────────────────────────────────────────────────────────────────────── Image — semantic wrapper around oa::Matrix ─────────────────────────────────────────────────────────────────────────────
Source13 members
───────────────────────────────────────────────────────────────────────────── ImageBatch — uniform batch of images ─────────────────────────────────────────────────────────────────────────────
Source7 members
7 members
6 members
1 members
1 members
1 members
1 members
11 members
3 members
A component is a small value, not a closed framework enum or a mutable registry entry. OA supplies neutral built-ins through Builtin; downstream libraries define their own named constexpr values from one-to-four-character tags without modifying OA or acquiring process-global state. namespace ChainLog { inline constexpr LogComponent Consensus{"CONS"}; }
0 members
11 members
0 members
Stateful log output is an explicitly owned host session. oa::Engine creates one from these options and selects it for the thread that owns the engine. The Log* macros use that selected session and fall back to stderr before an engine exists or on a thread that has not selected one.
Source0 members
0 members
0 members
0 members
10 members
Read-only whole-file mapping with RAII ownership. Linux uses mmap. Other platforms retain a read-only owned byte buffer until a native mapping implementation is added.
Source68 members
A multidimensional semantic value backed by OA-managed storage. A matrix carries shape, element stride, dtype, device, byte-offset, and optional autograd metadata. Copying a matrix shares its storage and autograd state. Metadata-only views also alias storage; use `clone()` when independent storage is required. Matrix operations use OA's Vulkan execution path. Direct host observation is an explicit synchronization boundary, not a CPU compute fallback. Stateful device ownership remains with `oa::Engine`; a matrix only retains the storage required for its value and recorded graph lifetime.
Defer addition of one contribution into this leaf's gradient accumulator.
inContributionin — Gradient contribution with a compatible element count.
Read one logical flat element as FP32. This host observation submits and waits for recorded work when required and performs device readback when storage is not host-accessible.
inIdxin — Row-major logical flat index. It must be in range.
Returns — The selected value converted to FP32.
Copy this matrix into independent storage through `oa::FnMatrix::copy`.
Returns — The independent copy, or an empty matrix when this matrix is empty.
Return an independently stored row-major matrix with the same values. The current non-row-major path may cross a host-access boundary while materializing the result.
Returns — A contiguous copy, or an empty matrix when allocation fails.
Record a copy or dtype conversion into existing destination storage. Both matrices must have storage and compatible element counts. Missing storage leaves this matrix unchanged.
inOtherin — Source values to copy.
Return a read-only pointer when this matrix is host-accessible. This function does not make a device-only allocation host-visible and does not synchronize recorded GPU work.
Returns — Pointer to this view's first byte, or `nullptr` when inaccessible.
Return a writable pointer when this matrix is host-accessible. This function does not make a device-only allocation host-visible and does not synchronize recorded GPU work.
Returns — Pointer to this view's first byte, or `nullptr` when inaccessible.
Replace shared autograd metadata before attaching a producer node.
inRequiresGradin — Initial tracking state for the detached metadata.
Read a single-element matrix as FP32. This host observation submits and waits for recorded work when required. The matrix must contain exactly one element.
Returns — The scalar value converted to FP32.
Allocate and fill a matrix through `oa::FnMatrix::full`.
inShapein — Logical dimensions of the matrix.
inFillValuein — Value written to every element.
inDtypein — Scalar representation used by the allocation.
Reorder dimensions and element strides without copying storage. Negative dimension indices are accepted. Every source dimension must occur exactly once.
inDimsin — Source dimension for every output dimension.
Returns — A strided storage-sharing view; an empty matrix for an invalid permutation, or this matrix unchanged when the rank does not match.
Create a storage-sharing view with a new shape. This method currently has the same row-major element-count contract as `view()` and does not materialize a copy.
inNewShapein — Logical shape of the returned view.
Returns — The storage-sharing view, or an empty matrix on count mismatch.
Write one logical flat element from FP32. The index must be in range. Device-only storage uses an explicit upload after completing prior recorded work.
inIdxin — Row-major logical flat index to update.
inValuein — Value converted to the matrix dtype and written.
Enable or disable leaf-gradient tracking. Enabling tracking lazily allocates a persistent gradient accumulator. Disabling it preserves allocated gradient storage for reuse.
inValuein — Whether this leaf should accumulate gradients.
Return the size of one logical dimension. Negative indices count from the final dimension, so `-1` names the last dimension. The resolved index must be in range.
inDimin — Dimension index to query.
Returns — Number of elements along the resolved dimension.
Remove one size-one dimension without copying storage.
inDimin — Dimension to remove.
Returns — A storage-sharing view, or this matrix unchanged when the dimension is invalid or is not size one.
Exchange two dimensions through the canonical matrix operation path.
inDim0in — First dimension to exchange.
inDim1in — Second dimension to exchange.
Returns — A matrix with the requested dimensions exchanged.
Insert a size-one dimension without copying storage.
inDimin — Position of the inserted dimension.
Returns — A storage-sharing view with rank increased by one.
Create a metadata-only row-major view with a new shape. The new shape must contain exactly the same number of elements. The returned matrix shares storage and byte offset with this matrix.
inNewShapein — Logical shape of the returned view.
Returns — The storage-sharing view, or an empty matrix on count mismatch.
10 members
MatrixShape — dimensions of an oa::Matrix (OA's N-D array), rank up to OA_MAX_TENSOR_DIMS. Construct with brace-init for any rank: MatrixShape{m, n} // rank-2 MatrixShape{n, c, h, w} // rank-4 (e.g. conv NCHW) The variadic constructor keeps brace initialization without importing the hosted initializer-list or exception runtime.
0 members
0 members
memory capacity for value-only device descriptors. VkCpu reports host physical RAM because that identity is process-independent. Other vulkan descriptors do not identify a live allocator or physical device and return zero; query the exact oa::Engine for live vulkan budget/usage.
Source0 members
0 members
5 members
7 members
8 members
9 members
2 members
22 members
23 members
9 members
0 members
17 members
Fixed default seed → reproducible by default. Provide a seed for a specific stream; inSeq selects an independent stream for the same seed (two generators with the same seed but different inSeq never correlate).
3 members
0 members
22 members
15 members
4 members
oa::RwLock <T > — reader-writer lock wrapping a value. Multiple concurrent readers OR one exclusive writer. Uses oa::SharedMutex under the hood. usage: oa::RwLock <oa ::Vector <oa ::Matrix>> cache; { auto r = cache.read(); use(*r); } // shared { auto w = cache.write(); w->push_back(t); } // exclusive
Source0 members
0 members
0 members
0 members
0 members
0 members
0 members
0 members
0 members
0 members
0 members
4 members
2 members
18 members
3 members
oa::Spinlock — PAUSE spinlock + SFENCE unlock Replaces std::mutex for short critical sections. Uncontended: ~1-2ns (vs ~18-22ns for futex). Contended: PAUSE loop stays in userspace (no kernel call).
Source0 members
0 members
16 members
1 members
13 members
9 members
47 members
23 members
Array binding (string literals AND fixed-size char buffers). Length is the C-string length bounded by the array capacity — i.e. up to the first ' \ 0', else the full N. For an exact-sized literal this equals the historical N-1, so the constexpr name tables are unchanged; for a short string in a larger buffer (e.g. snprintf into char[16]) it stops at the real terminator instead of capturing the embedded NUL + uninitialised tail (which silently corrupted dotted module paths in checkpoint serialization).
1 members
13 members
8 members
oa::Task <T > — lightweight async result (future/promise). producer calls complete(value) or fail(status) exactly once. consumer calls wait() or tryGet() to retrieve the result. Supports then() for continuation chaining. usage: auto task = oa::makeShared <oa ::Task <oa ::Matrix>>(); pool.submitTask([task] { task->complete(computeSomething()); }); auto result = task->wait(); // blocks until complete
Source6 members
9 members
Native thread owner. Creation is explicit and fallible; destruction never waits or detaches implicitly. A live thread must be joined or detached by its owning session before this value is destroyed.
Source8 members
0 members
oa::ThreadPool — work-stealing thread pool with CPU affinity. Workers each own a bounded channel. submit() round-robins jobs. When a worker's own queue is empty, it steals from siblings. Optional CPU pinning via oa::CpuTopology (P-cores preferred). usage: auto pool = oa::ThreadPool::create(); // auto-detect cores pool.submit([] { doWork(); }); // fire-and-forget auto t = pool.submitTask([] { return 42; }); // get future auto val = t->wait(); // blocks, returns 42 pool.shutdown(); // drains and waits explicitly
Source28 members
0 members
10 members
19 members
12 members
───────────────────────────────────────────────────────────────────────────── Validation — global validation controller ─────────────────────────────────────────────────────────────────────────────
Enable / disable. Debug: on by default. release (OA_ENABLE_VALIDATION): off by default. call initFromEnv() once at startup to apply OA_VALIDATION / OA_VALIDATION_SEVERITY.
Read OA_VALIDATION and OA_VALIDATION_SEVERITY from the process environment. call once before any OA_VALIDATE macro fires (e.g. Engine::create).
21 members
56 members
12 members
12 members
3 members
3 members
Enums
None · InvalidAlignment · SizeOverflow · OutOfMemory
Core · Runtime · Engine · Compute · Ml · Data · Vision · Video · Audio · Render · Ui · Plot · Animation · Network · Crypto · Python · App · Mcp
Performance · Efficiency · Unknown
Fast · Stable · Deterministic
Nearest · Linear
───────────────────────────────────────────────────────────────────────────── ImageFormat (channel meaning) ─────────────────────────────────────────────────────────────────────────────
Gray · GrayAlpha · Rgb · Rgba · Bgr · Bgra
───────────────────────────────────────────────────────────────────────────── ImageLayout (tensor shape interpretation) ─────────────────────────────────────────────────────────────────────────────
Nchw · Nhwc · Chw · Hwc · Hw
Trace · Debug · Info · Warn · Error · Fatal · Off
Auto · Fp32 · Bf16
MEMORY LOCATION Logical placement for buffers (not a silicon map). Discrete vs SoC: - Discrete GPU (e.g. dGPU in a Strix-class laptop): Device = separate VRAM; Host = system RAM; Shared = CPU-mapped VRAM (ReBAR / Smart access memory / large BAR) — same VRAM bytes, two views. - Unified memory / UMA soCs (Apple Silicon, Snapdragon X Elite, many iGPUs): one DRAM pool for CPU + GPU + NPU. vulkan often exposes heaps with HOST_VISIBLE and DEVICE_LOCAL on the same memory — treat that as shared (one pool, visible to both). Pure pageable CPU malloc with no device mapping stays Host. Device means "allocated as device-local / GPU-primary" even when it is physically the same DRAM as the CPU (allocator hint + visibility flags), not a second chip. NPU-only carve-outs without a separate vulkan heap are not a fourth category here until modeled.
Host · Device · Shared
Relaxed · Consume · Acquire · Release · AcquireRelease · Sequential
allocation intent carried by semantic values and engine requests. This is distinct from MemoryLocation: Auto is unresolved policy, while HostUpload and HostReadback name transfer direction. The Runtime allocator resolves the intent against the selected device and records the result on its private physical-storage descriptor.
Auto · DeviceLocal · HostUpload · HostReadback · Unified
process-wide numerical execution policy. Core owns the vocabulary and its environment mapping; Runtime consumes it through oa::EngineConfig.
Fast · Stable · Deterministic
Ordered non-value inputs that affect operation meaning. matrices, images, audio values, and video frames remain semantic values; these attributes preserve scalar/configuration data independently of runtime push layouts.
Boolean · SignedInteger · UnsignedInteger · Float · String · Shape · Enum
StraightLine · Conditional · Loop
None · Reverse
MatchInput · PromoteFloat · Explicit
None · ReadInputs · WriteOutputs
Dispatch · Gemm
MatchInput · Broadcast · MatMulNt · Explicit
None · Matrix · Image · Audio · VideoFrame · QuantMatrix
FP32 · BF16 · FP64
Out · Error
Float32 · BFloat16 · Float16 · Int8 · Int32 · UInt8 · Float64 · Int16 · Int64 · UInt16 · UInt32 · UInt64 · Bool · Complex64 · Complex128
STATUS CODES
Ok · Cancelled · Unknown · InvalidArgument · DeadlineExceeded · NotFound · AlreadyExists · PermissionDenied · ResourceExhausted · FailedPrecondition · Aborted · OutOfRange · Unimplemented · Internal · Unavailable · DataLoss · Unauthenticated · VulkanError · DeviceNotFound · OutOfMemory · PipelineError · ShaderCompileError · InvalidSignature · InvalidBlock · InvalidTransaction · InsufficientFunds · InsufficientMargin · Slashed · OrderRejected · PositionNotFound · MarketClosed · PriceLimitExceeded · QuantityTooSmall · ModelNotLoaded · ShapeMismatch · DtypeMismatch · GradientExplosion · CheckpointCorrupt · ConnectionFailed · Timeout · TlsError · DnsError · FileNotFound · FileCorrupt · PermissionError · DiskFull
───────────────────────────────────────────────────────────────────────────── Severity ─────────────────────────────────────────────────────────────────────────────
Verbose · Info · Warning · Error · Fatal
Constants & Variables
const UsizeSource const char *constSource const F64Source const F32Source const F32Source const F32Source const F32Source const F32Source const F64Source const F64Source const F64Source const F64Source const UsizeSource const DeviceSource const I32Source const I32Source const I64Source const I64Source const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const boolSource const RateSource const RateSource const F64Source const RateSource const RateSource const F64Source const F32Source const PlacementTagSource const char *constSource const ScalarTypeSource const UsizeSource const F64Source const U64Source const char *constSource Functions
abs: Element-wise absolute value: out = |A|.
add: Element-wise addition: out = A + B.
in-place operations
addScalar: Scalar addition: out = A + Scalar.
argmax: Find index of maximum value: out = argmax(A).
--- Pooling ---
avgPool2dBwd: backward for 2D average pooling.
batchNorm2dBwd: backward pass for BatchNorm2d.
biasAdd: Add bias vector: out = A + Bias (broadcasted).
bmm: per-batch matrix multiply, A[N,M,K] @ B[N,K,P] = out[N,M,P].
bmmNt: per-batch matrix multiply with transposed right operand storage, A[N,M,K] @ B[N,P,K]^T = out[N,M,P].
--- dtype cast --- cast: allocate a new matrix of inDtype and convert inSrc into it. castInto: convert inSrc into the pre-allocated outDst in place.
channelNorm: fused LayerNorm over the channel axis of [B,C,T] without transposing. Replaces Transpose+LayerNorm+transpose (3 dispatches) with 1.
channelNormRelu: fused channelNorm + ReLU on [B,C,T].
clampMax: Element-wise clamp max: out = min(A, Max).
clampMin: Element-wise clamp min: out = max(A, Min).
col2Im1d: backward of im2Col1d — fold a column-matrix gradient [N*outL, inC*K] back into input shape [N, inC, L], accumulating over overlapping windows.
conv1dBwdData: backward for 1D convolution (input gradient).
conv1dBwdWeight: fused weight and bias gradient for 1D convolution.
conv1dGemm: 1-D convolution executed as im2col + a single matmul. inX [N, inC, L], inWeight [outC, inC, K], inBias [outC] -> [N, outC, outL]
conv1dReluGemm: conv1dGemm with the ReLU folded into the GEMM bias epilogue.
--- Conv2d ---
conv2dBwdData: backward for 2D convolution (input gradient).
conv2dBwdWeight: fused weight and bias gradient for 2D convolution.
convTranspose2d: 2D transposed convolution (learnable upsampling). input: [N, inC, H, W], weight: [inC, outC, K, K], Bias: [outC] output: [N, outC, H_out, W_out] where H_out = (H - 1) * S - 2P + K.
convTranspose2dBwdData: backward for 2D transposed convolution (input gradient).
convTranspose2dBwdWeight: fused weight and bias gradient for 2D transposed convolution.
copy: Copy tensor data: out = A.
--- Transfer --- Copy device matrix data to host memory. inBytes must be >= inSrc.byteSize().
cos: Element-wise cosine: out = cos(A).
Materialize a Float32 matrix with the logical shape retained by inInput.
detach: stop-gradient. Returns a view that SHARES inSelf's device buffer but carries no autograd linkage (leaf, requiresGrad=false), so backward terminates here. Metadata-only: no kernel, no copy. This is the primitive the straight- through estimator needs.
div: Element-wise division: out = A / B.
divScalar: Scalar division: out = A / Scalar.
Inverted dropout. inP must be [0,1).
elu: ELU activation: out = A if A > 0 else Alpha * (exp(A) - 1).
eluBwd: backward pass for ELU activation. Computes: dInput = dOutput * (x > 0 ? 1 : alpha * exp(x))
--- Factory functions ---
--- empyrealm operations ---
exp: Element-wise exponential: out = exp(A).
fill: Create a Float32 matrix filled with a constant value.
fillInPlace: Replace every value in an existing matrix.
flashAttentionCausal: IO-aware causal scaled dot-product attention. Q/K/V and output use contiguous [batchHeads, sequence, headDim] storage.
flashAttentionCausalBwd: explicit adjoint for the FlashAttention autograd node.
Indexing
geglu: GEGLU activation: out = A[:N] * GELU(A[N:]).
gegluBwd: backward pass for GEGLU activation.
inInputin — forward INPUT (up||gate); up*GELU(gate) is not invertible
gelu: GELU activation: out = GELU(A).
geluBwd: backward pass for GELU activation. Computes: dInput = dOutput * gelu'(x)
inInputin — forward INPUT x (gelu'(x) is a function of input, not output)
gruCellLinear: fused GRU recurrent step — Linear(h, W_hh) + gruCellPointwise. Replaces the per-timestep pair of dispatches with one kernel. The hidden projection required by reverse mode is retained internally rather than exposed as an output parameter.
gruCellPointwise: fused GRU pointwise forward. r = sigmoid(gatesI[r] + gatesH[r]) z = sigmoid(gatesI[z] + gatesH[z]) n = tanh(gatesI[n] + r * gatesH[n]) h_new = (1 - z) * n + z * hPrev
inGatesIin — [B, 3H] input projection (reset|update|candidate along dim 1) or [B*T, 3H] with inTimeOffset = t*B to index row t without Slice
inGatesHin — [B, 3H] hidden projection
inHiddenin — [B, H] previous hidden state
inHiddenSizein — H
inTimeOffsetin — row offset into inGatesI (in units of 3H), default 0
gruCellPointwiseBwd: fused GRU pointwise backward. Returns gradients w.r.t. gatesI, gatesH and the previous hidden state.
inTimeOffsetin — row offset into inGatesI / dGatesI (in rows of 3H), default 0
inBatchStridein — row stride between batches in inGatesI (T for batch-major, 1 for contiguous), default 1
gruScan: whole-sequence GRU recurrent scan in ONE dispatch (one workgroup per batch, looping all timesteps). Mathematically identical to running gruCellLinear for each timestep, but collapses S dispatches into 1. The recurrent weight/bias gradient is computed separately via linearWeightBiasBwd on the saved hPrev.
inGatesIin — [B*S, 3H] precomputed input projection (row b*S+t = timestep t)
inSeqLenin — S
gruScanBwd: BPTT recurrence scan (backward of gruScan) in ONE dispatch. Produces gradients w.r.t. the input projection gatesI and the hidden projection gatesH (the latter drives the separate linearWeightBiasBwd weight-grad call).
im2Col1d: unfold a 1-D conv input [N, inC, L] into the GEMM-ready column matrix [N*outL, inC*K]. The building block of conv1dGemm.
layerNorm: Affine layer normalization over the last dimension: out = ((A - mean(A)) / sqrt(var(A) + Eps)) * Weight + Bias.
layerNormBwd: backward pass for LayerNorm.
leakyRelu: Leaky ReLU activation: out = max(Alpha * A, A).
leakyReluBwd: backward pass for LeakyReLU activation. Computes: dInput = dOutput * (x > 0 ? 1 : alpha)
linear: linear layer (fully connected). output = input @ weight^T + bias
inXin — [batch, inFeatures]
inWeightin — [outFeatures, inFeatures]
inBiasin — [outFeatures] (optional)
linearDataBwd: backward for linear layer (input gradient). Computes: dInput = dOutput @ weight^T
linearDataReluBwd: fused linear data gradient followed by ReLU backward. Computes: dInput = (dOutput @ weight) * (activation > 0)
linearGelu: fused linear + GELU. output = GELU(input @ weight^T + bias) The fused forward discards the pre-activation; the autograd node recomputes it (one GEMM) for geluBwd in the backward pass.
linearRelu: fused linear + ReLU. output = reLU(input @ weight^T + bias)
linearReluBwdData: fused in-layer linearRelu(x,W,b) backward, data path. For y = reLU(x @ W^T + b), computes dx = (dy * (act > 0)) @ W in a single dispatch. gate is applied INSIDE the inner sum (no materialization of dz), the opposite fusion direction of linearDataReluBwd.
linearSilu: fused linear + SiLU. output = siLU(input @ weight^T + bias)
linearWeightBiasBwd: fused weight and bias gradient for linear layer. Computes: dWeight = input^T @ dOutput, dBias = sum(dOutput, dim=0)
linearWeightBwd: backward for linear layer (weight gradient). Computes: dWeight = input^T @ dOutput
log: Element-wise natural log: out = log(A).
logSoftmax: Stable log-softmax over the selected dimension; -1 selects the last dimension.
--- Mamba-3 MIMO selective scan ---
--- Mamba3Preprocess: fused in_proj split + RMSNorm + dt + A·dt ---
--- Mamba-3 SISO selective scan ---
matMulNt: oa::Matrix multiplication: B is [N,K] and out = A @ Bᵀ (the OA weight convention, shared with Linear/attention; NOT PyTorch-standard A with B as [K,N]). For batched/standard A use Bmm. Router resolves precision at context execution.
max: Reduce all values by maximum; dim is retained as a compatibility parameter and is not a dimensional reduction.
maxPool2dBwd: backward for 2D max pooling.
mean: Reduce by arithmetic mean; a valid non-negative Dim produces a keep-dimension axis reduction, while -1 produces a full reduction.
mergeHeads: [B*H,S,D/H] -> [B*S,D]. exact inverse of splitHeads.
mish: Mish activation: out = A * tanh(softplus(A)).
mishBwd: backward pass for Mish activation.
inInputin — forward INPUT x (mish'(x) depends on x directly)
mul: Element-wise multiplication: out = A * B.
neg: Element-wise negation: out = -A.
philoxNormal: Generate normal-distribution random values with Philox.
philoxUniform: Generate uniform-distribution random values with Philox.
pow: Element-wise power: out = A^Exponent.
quantize Float32 storage into one native OA Q4 or Q8 weight value. The returned value retains the source shape; its physical planes remain private.
reciprocal: Element-wise reciprocal: out = 1 / A.
relu: ReLU activation: out = max(0, A).
reluBwd: backward pass for ReLU activation. Computes: dInput = dOutput * (forwardOutput > 0)
Shape helpers
reshape: Reshape tensor to new shape (view operation, no copy).
--- ResidualRmsNorm: fused residual + RmsNorm ---
rmsNorm: Weighted root mean square normalization over the last dimension: out = (A / sqrt(mean(A^2) + Eps)) * Weight.
rmsNormBwd: backward pass for RmsNorm.
LayerNorm and RmsNorm forward declarations are generated from MlFnMatrixNorm.toml.
rmsNormGatedBwd: backward for rmsNormGated (normBeforeGate = true). Returns grads w.r.t. x, weight, bias, z.
rnnCellLinear: fused vanilla-RNN recurrent step — Linear(h, W_hh) + rnnCellPointwise. Replaces the per-timestep pair of dispatches with one kernel. inGatesI is the whole input projection [B*T, H]; inTimeOffset/inBatchStride index the current timestep's row directly, so oa::Rnn needs no per-step Slice. The hidden projection required by reverse mode is retained internally rather than exposed as an output parameter.
rnnCellPointwise: fused vanilla-RNN pointwise forward, h_new = tanh(gatesI + gatesH).
inGatesIin — [B, H] input projection (W_ih x + b_ih)
inGatesHin — [B, H] hidden projection (W_hh h_prev + b_hh)
rnnCellPointwiseBwd: fused vanilla-RNN pointwise backward. Returns gradients w.r.t. gatesI and gatesH (both equal to dL/da). inGatesI is the whole-sequence [B*T, H] projection; inTimeOffset/inBatchStride select this timestep's rows so dGatesI is scattered into the full buffer (zeros elsewhere).
rnnScan: whole-sequence vanilla-RNN recurrent scan in ONE dispatch. Mathematically identical to running rnnCellLinear for each timestep, but collapses S dispatches into 1. The recurrent weight/bias gradient is computed separately via linearWeightBiasBwd on the saved hPrev.
inGatesIin — [B*S, H] precomputed input projection (row b*S+t = timestep t)
rnnScanBwd: BPTT recurrence scan (backward of rnnScan) in ONE dispatch.
samples one class per last-axis row. temperature < = 0 is greedy; inTopK < = 0 keeps the full vocabulary; inTopP is clamped to (0,1].
Extract first element as F32 scalar (requires single-element matrix).
scale: Scalar multiplication: out = A * Scalar.
--- RNG --- seed the host-side seed generator. call once at startup for reproducibility.
sigmoid: Sigmoid activation: out = 1 / (1 + exp(-A)).
sigmoidBwd: backward pass for Sigmoid activation. Computes: dInput = dOutput * sigmoid(x) * (1 - sigmoid(x))
silu: SiLU (Swish) activation: out = A * sigmoid(A).
siluBwd: backward pass for SiLU activation.
inInputin — forward INPUT x (silu'(x) is a function of input, not output)
siluMul: SiLU on first half, multiply with second half: out = SiLU(A[:N]) * A[N:].
siluMulBwd: backward pass for SiluMul activation.
inInputin — forward INPUT (gate||up); the forward output is not invertible
sin: Element-wise sine: out = sin(A).
slice: Materialize the half-open interval [Start, End) along one dimension.
softmax: Stable softmax over the selected dimension; -1 selects the last dimension.
backward ops
softmaxScaledMasked: fused transformer attention score normalisation. Computes: out = softmax(scores * scale + mask) over the last dimension.
softmaxScaledMaskedBwd: backward for the fused attention score op. Returns dScores = softmaxOut * (dOut - sum(dOut * softmaxOut)) * scale.
softplus: Softplus: out = log(1+exp(A)), computed stably as max(A,0)+log1p(exp(-|A|)) (no f32 overflow).
softplusBwd: backward pass for Softplus activation.
inForwardOutputin — output y = softplus(a) from the forward pass
Returns — dOut * sigmoid(a) = dOut * (1 - e^-y)
splitHeads: [B*S,D] -> [B*H,S,D/H]. Multi-head permutation.
sqrt: Element-wise square root: out = sqrt(A).
Element-wise binary ops — broadcast-aware.
subScalar: Scalar subtraction: out = A - Scalar.
sum: Reduce by summation; a valid non-negative Dim produces a keep-dimension axis reduction, while -1 produces a full reduction.
swiglu: SwiGLU activation: out = SiLU(gate) * up.
tanh: Tanh activation: out = tanh(A).
tanhBwd: backward pass for Tanh activation. Computes: dInput = dOutput * (1 - tanh(x)^2), using saved tanh(x) output.
transpose: Materialize a swap of the last two axes for rank-2 or rank-3 matrices.
upsampleBwd: backward pass for Upsample (Nearest or Bilinear).
vqAssign: vector-quantization nearest-code assignment (VQ-VAE codebook lookup). inZe: [N, D] latents. inCodebook: [K, D] codes. Returns the per-row argmin index (int32 [N]) and the gathered winning code (float [N, D]) by squared L2 distance.
vqEmaUpdate: EMA codebook update + dead-code reinit (van den Oord 2017). The codebook is NOT gradient-trained; each entry tracks the running mean of encoder outputs assigned to it, and dead codes are revived from live encoder rows. inZe [N,D], inIdx [N] int32 (from vqAssign), ioEmbedSum [K,D], ioClusterSize [K], outCodebook [K,D]. inDecay = EMA γ; inEps = division floor; inDeadThreshold = revive codes whose EMA count falls below it; inSeed = per-step seed; inNormalize rescales each codebook row to unit RMS (cosine VQ).
--- Configuration --- weight allocation follows the precision of the active engine context.
Crypto
Functions
Fixed-size serialization. Parsing is length-checked and never reads from a raw pointer without a caller-supplied extent.
Sign a hash directly
verify a hash signature
Classes
Functions
Batch Keccak-f[1600] permutation. input/output [N, 200] bytes (25 lanes × u64 per state). out-of-place.
Merkle root by GPU SHAKE-256 pair reduction. input [N, 32] leaf hashes, N a power of two; output [1, 32] root. Bit-identical to oa::merkleRoot for power-of-two leaf counts. Use oa::merkleRoot (CPU) for arbitrary counts, and oa::verifyMerkleProof (CPU) for inclusion proofs.
SHAKE-128 batch XOF. input [N, msgLen] bytes; output [N, ceil(outLen/8)*8] bytes (16-byte default). Row i = SHAKE128(message i).
SHAKE-256 batch XOF. input [N, msgLen] bytes; output [N, ceil(outLen/8)*8] bytes (32-byte default). Row i = SHAKE256(message i).