|
| | CUDABackend () |
| |
| | ~CUDABackend () override |
| |
| | CUDABackend (const CUDABackend &)=delete |
| |
| CUDABackend & | operator= (const CUDABackend &)=delete |
| |
| DeviceType | device () const noexcept override |
| | Which device this backend's buffers reside on.
|
| |
| void * | allocate (size_t bytes) override |
| | Allocates a buffer of the given size.
|
| |
| void | free (void *ptr) noexcept override |
| | Frees a buffer previously returned by allocate(). Safe to call with nullptr.
|
| |
| void | copy (void *dst, const void *src, size_t bytes, CopyDirection dir) override |
| | Copies bytes between buffers.
|
| |
| void | fill (void *ptr, float value, size_t n) override |
| | Fills every element of a float buffer with a constant value.
|
| |
| void | gemm (const float *a, const float *b, float *out, size_t m, size_t k, size_t n) override |
| | Row-major matrix multiply: out = a * b.
|
| |
| void | elementwise (ElementwiseOp op, const float *in, float *out, size_t n) override |
| | Applies a unary elementwise operation to every element of a buffer.
|
| |
| void | add (const float *a, const float *b, float *out, size_t n) override |
| | Elementwise binary addition: out[i] = a[i] + b[i] for i in [0, n).
|
| |
| void | mul (const float *a, const float *b, float *out, size_t n) override |
| | Elementwise binary (Hadamard) multiplication: out[i] = a[i] * b[i] for i in [0, n).
|
| |
| void | gemm_ex (const float *a, bool transpose_a, const float *b, bool transpose_b, float *out, size_t m, size_t k, size_t n, float beta) override |
| | General row-major matrix multiply: out = op(A) * op(B) + beta * out.
|
| |
| void | column_sums (const float *in, float *out, size_t rows, size_t cols, float beta) override |
| | Per-column sum of a (rows x cols) row-major matrix: out[j] = beta*out[j] + sum_i in[i][j].
|
| |
| void | add_row_vector (const float *in, const float *row, float *out, size_t rows, size_t cols) override |
| | Broadcast row add: out[i][j] = in[i][j] + row[j] for a (rows x cols) matrix.
|
| |
| void | elementwise_backward (ElementwiseOp op, const float *x, const float *grad_out, float *grad_in, size_t n) override |
| | Activation backward: grad_in[i] = grad_out[i] * f'(x[i]), f = op, x = the forward input.
|
| |
| void | axpby (float alpha, const float *x, float beta, const float *y, float *out, size_t n) override |
| | out[i] = alpha * x[i] + beta * y[i]. out may alias x or y.
|
| |
| float | dot (const float *a, const float *b, size_t n) override |
| | Dot product sum_i a[i]*b[i], returned to the host.
|
| |
| void | softmax_rows (const float *in, float *out, size_t rows, size_t cols) override |
| | Row-wise softmax of a (rows x cols) matrix, max-subtracted. out may alias in.
|
| |
| void | softmax_rows_backward (const float *y, const float *dy, float *dx, size_t rows, size_t cols) override |
| | Softmax backward from its output y: dx[i][j] = y[i][j] * (dy[i][j] - sum_k y[i][k]*dy[i][k]).
|
| |
| void | logsumexp_rows (const float *in, float *out, size_t rows, size_t cols) override |
| | Per-row log-sum-exp, max-subtracted: out[i] = log sum_j exp(in[i][j]).
|
| |
| void | adam_step (float *param, const float *grad, float *m, float *v, size_t n, float lr, float beta1, float beta2, float eps, float bias_correction1, float bias_correction2) override |
| | One fused Adam update over n parameters.
|
| |
| float | sum (const float *in, size_t n) override |
| | sum_i in[i], returned to the host. Same reduction order as dot(). Synchronizes.
|
| |
| void | dropout_forward (const float *in, float *out, float *mask, size_t n, float p, float scale, uint64_t seed, uint64_t offset) override |
| | Inverted dropout with a counter-based RNG: element i is dropped iff uniform(seed, offset + i) < p; kept elements are scaled by scale.
|
| |
| void | bce_with_logits (const float *logits, const float *target, float *out, size_t n) override |
| | Per-element binary cross-entropy with logits: out[i] = max(x, 0) - x*y + log1p(exp(-|x|)), x = logits[i], y = target[i].
|
| |
| void | bce_with_logits_grad (const float *logits, const float *target, float *grad, size_t n, float scale) override |
| | BCE-with-logits gradient: grad[i] = (sigmoid(x) - y) * scale, using the overflow-free sigmoid (exp(x) / (1 + exp(x)) for x < 0).
|
| |
| void | layer_norm_forward (const float *in, const float *gamma, const float *beta, float *xhat, float *out, float *row_std, size_t rows, size_t cols, float eps) override |
| | LayerNorm forward per row: xhat = (x - mean)/sqrt(var + eps), out = gamma*xhat + beta.
|
| |
| void | layer_norm_backward (const float *grad_out, const float *gamma, const float *xhat, const float *row_std, float *grad_in, size_t rows, size_t cols) override |
| | LayerNorm input gradient per row, from the cached xhat and per-row std.
|
| |
| void | rms_norm_forward (const float *in, const float *gamma, float *out, float *row_rms, size_t rows, size_t cols, float eps) override |
| | RMSNorm forward per row: out = gamma * x / sqrt(mean(x^2) + eps).
|
| |
| void | rms_norm_backward (const float *grad_out, const float *gamma, const float *in, const float *row_rms, float *grad_in, float *gamma_terms, size_t rows, size_t cols) override |
| | RMSNorm input gradient per row, plus gamma_terms[r][i] = grad_out * x / rms – the per-row contributions column_sums then reduces into gamma's gradient.
|
| |
| void | rope_rotate (const float *in, const float *cos_table, const float *sin_table, float *out, size_t num_slices, size_t seq_len, size_t head_dim, bool inverse) override |
| | Rotary position embedding over (num_slices, seq_len, head_dim) data.
|
| |
| void | permute_0213 (const float *in, float *out, size_t d0, size_t d1, size_t d2, size_t d3) override |
| | Swaps the middle two axes: in (d0, d1, d2, d3) -> out (d0, d2, d1, d3).
|
| |
| void | gather_rows (const float *table, const float *indices, float *out, size_t count, size_t dim) override |
| | out[i][:] = table[indices[i]][:] for count rows of width dim.
|
| |
| void | scatter_add_rows (const float *src, const float *indices, float *table, size_t count, size_t dim) override |
| | table[indices[i]][:] += src[i][:] for i = 0..count-1, in increasing i.
|
| |
| void | tanh_gaussian_forward (const float *mean, const float *log_std, const float *eps, float *action, float *std_cache, float *log_prob, size_t rows, size_t cols, float stabilizer, double half_log_two_pi) override |
| | TanhGaussianPolicy sampling per (rows, cols) row: action = tanh(mean + exp(log_std)*eps), std_cache = exp(log_std), log_prob[r] accumulated in double.
|
| |
| void | tanh_gaussian_backward (const float *action, const float *std_cache, const float *eps, const float *grad_action, const float *grad_log_prob, float *grad_mean, float *grad_log_std, size_t n, float stabilizer) override |
| | TanhGaussianPolicy gradients w.r.t. mean and log_std, per element.
|
| |
| void | lrp_linear (const float *x, const float *w, const float *z, const float *r, float *r_in, size_t rows, size_t in_features, size_t out_features, float eps) override |
| | LinearModule epsilon rule: r_in[n][i] = sum_j (x[n][i] w[i][j] / stab(z[n][j])) r[n][j].
|
| |
| void | lrp_residual_split (const float *a, const float *b, const float *r, float *r_a, float *r_b, size_t n, float eps) override |
| | Epsilon split of a residual sum y = a + b: r_a = (a / stab(y)) r, r_b = (b / stab(y)) r.
|
| |
| void | lrp_bilinear_elementwise (const float *a, const float *b, const float *r, float *r_out, size_t n, float eps) override |
| | Eq. 15 for an elementwise product c = a*b: r_out = (a b / (2c + eps sign c)) r (same for both).
|
| |
| void | lrp_bilinear_matmul (const float *a, const float *b, const float *o, const float *r_o, float *r_a, float *r_b, size_t slices, size_t m, size_t p, size_t q, float eps, bool b_transposed) override |
| | Eq. 15 for slices independent matmuls O = A @ B (A (M x P), B (P x Q), O and r_o (M x Q)).
|
| |
| void | lrp_softmax_rows (const float *x, const float *y, const float *r, float *r_in, size_t rows, size_t cols) override |
| | SoftmaxModule rule per row: r_in = x * (r - y * sum(r)).
|
| |
| void | lrp_rope (const float *x, const float *y, const float *r, const float *cos_table, const float *sin_table, float *r_in, size_t slices, size_t seq_len, size_t head_dim, float eps) override |
| | RoPEModule epsilon rule over (slices, seq_len, head_dim), tables as for rope_rotate.
|
| |
| void | logic_pointwise (LogicOp op, int norm, const float *a, const float *b, const float *g_or_r, const float *y, float *out_a, float *out_b, size_t n, float eps) override |
| | One elementwise pass of Conjunction/Disjunction for operands a, b.
|
| |
| void | aggregator_forward (const float *x, float *mean_pow, float *out, size_t n, size_t cols, float p) override |
| | AggregatorModule power mean over the leading axis of an (n, cols) input, per column.
|
| |
| void | aggregator_backward (const float *x, const float *mean_pow, const float *grad_out, float *grad_in, size_t n, size_t cols, float p) override |
| | AggregatorModule input gradient, per column.
|
| |
| void | aggregator_lrp (const float *x, const float *mean_pow, const float *r_out, float *r_in, size_t n, size_t cols, float p, float eps) override |
| | AggregatorModule epsilon rule, per column.
|
| |
| void | im2col (const float *in, float *col, size_t n, size_t c, size_t h, size_t w, const ConvGeometry &geometry) override |
| | Unfolds (n, c, h, w) into (n, c*kh*kw, out_h*out_w) patches, with out_h = (h + 2*pad_h - kh) / stride_h + 1 (likewise out_w). Taps that fall in the zero padding read 0.
|
| |
| void | col2im_add (const float *col, float *out, size_t n, size_t c, size_t h, size_t w, const ConvGeometry &geometry) override |
| | Folds (n, c*kh*kw, out_h*out_w) patches back, adding into out (n, c, h, w).
|
| |
| void | add_channel_vector (const float *in, const float *vec, float *out, size_t n, size_t c, size_t inner) override |
| | out[i][ch][k] = in[i][ch][k] + vec[ch] over (n, c, inner). out may alias in.
|
| |
| void | lrp_conv (const float *col, const float *kernel, const float *pre_bias, const float *r, float *r_col, size_t n, size_t out_channels, size_t p, size_t q, float eps) override |
| | Conv2D epsilon rule in patch space: r_col (n, p, q) from the cached patches, the kernel (out_channels, p) and the pre-bias outputs (n, out_channels, q).
|
| |
| void | lrp_stabilized_divide (const float *r, const float *denom, const float *gate, float *out, size_t n, float eps, LrpGate gate_mode) override |
| | Gated stabilized division, the one non-gemm step of the affine LRP rules: out[i] = passes(gate[i]) ? r[i] / (denom[i] + eps sign(denom[i])) : 0, sign(0) = +1.
|
| |
| void | max_pool_forward (const float *in, float *out, float *argmax, size_t planes, size_t h, size_t w, size_t kh, size_t kw) override |
| | Non-overlapping max pool over planes of (h, w); argmax = flat in-plane index (first max wins).
|
| |
| void | max_unpool (const float *src, const float *argmax, float *dst, size_t planes, size_t h, size_t w, size_t kh, size_t kw) override |
| | dst[plane][argmax] = src for every pooled element; dst must be zeroed by the caller.
|
| |
| void | avg_pool_forward (const float *in, float *out, size_t planes, size_t h, size_t w, size_t kh, size_t kw) override |
| | Non-overlapping average pool over planes of (h, w).
|
| |
| void | avg_pool_backward (const float *grad_out, float *grad_in, size_t planes, size_t h, size_t w, size_t kh, size_t kw) override |
| | Spreads grad_out / (kh*kw) over each window; grad_in must be zeroed by the caller.
|
| |
| void | lrp_avg_pool (const float *x, const float *r, float *r_in, size_t planes, size_t h, size_t w, size_t kh, size_t kw, float eps) override |
| | AvgPool2D epsilon rule; r_in must be zeroed by the caller.
|
| |
| void | batch_norm_forward (const float *in, const float *gamma, const float *beta, float *xhat, float *out, float *channel_std, size_t n, size_t c, size_t spatial, float eps) override |
| | BatchNorm over (n, spatial) per channel of (n, c, spatial) data.
|
| |
| void | batch_norm_backward (const float *grad_out, const float *gamma, const float *xhat, const float *channel_std, float *grad_in, float *gamma_grad, float *beta_grad, size_t n, size_t c, size_t spatial) override |
| | BatchNorm input gradient plus this call's gamma/beta gradients (overwritten, per channel).
|
| |
| void | batch_norm_update_running (const float *in, float *running_mean, float *running_var, size_t n, size_t c, size_t spatial, float momentum) override |
| | Folds this batch's per-channel mean and unbiased variance into the running ones (PyTorch's momentum rule; the variance is kept when a channel has one value). FND-5.
|
| |
| void | batch_norm_eval_forward (const float *in, const float *gamma, const float *beta, const float *running_mean, const float *running_var, float *xhat, float *out, float *channel_std, size_t n, size_t c, size_t spatial, float eps) override |
| | Eval-mode BatchNorm from the running statistics: a per-channel affine map. FND-5.
|
| |
| void | batch_norm_eval_backward (const float *grad_out, const float *gamma, const float *xhat, const float *channel_std, float *grad_in, float *gamma_grad, float *beta_grad, size_t n, size_t c, size_t spatial) override |
| | Eval-mode BatchNorm gradient: grad_out * gamma / std, plus gamma/beta gradients (overwritten, per channel). FND-5.
|
| |
| void | group_norm_forward (const float *in, const float *gamma, const float *beta, float *xhat, float *out, float *group_std, size_t n, size_t c, size_t spatial, size_t num_groups, float eps) override |
| | GroupNorm per (example, group) of (n, c, spatial) data; group_std is (n, num_groups).
|
| |
| void | group_norm_backward (const float *grad_out, const float *gamma, const float *xhat, const float *group_std, float *grad_in, float *gamma_grad, float *beta_grad, size_t n, size_t c, size_t spatial, size_t num_groups) override |
| | GroupNorm input gradient plus this call's gamma/beta gradients (overwritten, per channel).
|
| |
| void | copy_2d (float *dst, size_t dst_stride, const float *src, size_t src_stride, size_t rows, size_t cols) override |
| | Strided 2-D copy: rows of cols floats from src (row stride src_stride) to dst (row stride dst_stride) – e.g. one timestep of an (N, L, D) sequence.
|
| |
| void | accumulate_rows (const float *in, float *out, size_t rows, size_t cols) override |
| | out[j] += in[i][j] for i = 0..rows-1 in order, accumulating straight into out.
|
| |
| void | recurrent_cell (RecurrentCellOp op, const RecurrentCellArgs &args, size_t n) override |
| | One fused recurrent-cell pass over n elements (see RecurrentCellOp for slots).
|
| |
| void | gru_lrp_hprev (const float *h_prev, const float *w_hn, const float *hn, const float *r_term_b, const float *direct, float *r_hprev, size_t rows, size_t hidden, float eps) override |
| | GRU's R_hprev for (rows, hidden): the recurrent epsilon-rule sum through W_hn, with each element's direct term inserted where the original loop added it.
|
| |
| void | ssm_pass (SsmPassOp op, const SsmPassArgs &args) override |
| | One fused Mamba / RWKV / RetNet pass (see SsmPassOp for lanes and slots).
|
| |
| void | rl_rows (RlRowOp op, const RlRowArgs &args) override |
| | One fused RL loss / target / Polyak pass (see RlRowOp for lanes and slots).
|
| |
| void | top_k_rows (const float *in, float *values, float *indices, size_t rows, size_t cols, size_t k, bool largest) override |
| | Per row of a row-major (rows, cols) matrix: the k largest (or smallest) values in rank order into values (rows, k), and their column indices into indices (rows, k) as whole-number floats.
|
| |
| virtual | ~DeviceBackend ()=default |
| |