src/cpu/register_nn.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ─── CPU backend registration (Part 2: Attention, Spectral, Vision & Quant) ─── | ||
| 2 | // | ||
| 3 | // Populates the remaining CPU OpsVTable slots from `register_cpu_nn_ops`, | ||
| 4 | // called by `CpuStaticRegistrar` in `src/cpu/register.cpp`. | ||
| 5 | |||
| 6 | #include <brotensor/detail/dispatch.h> | ||
| 7 | #include <brotensor/tensor.h> | ||
| 8 | |||
| 9 | #include <cstdint> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace brotensor::detail::cpu { | ||
| 13 | |||
| 14 | // ── packed_encoder.cpp ── | ||
| 15 | void flash_attention_packed_qkv_forward(const ::brotensor::Tensor& QKV, | ||
| 16 | const ::brotensor::Tensor& seq_bounds, | ||
| 17 | int num_heads, int window, | ||
| 18 | ::brotensor::Tensor& O); | ||
| 19 | void flash_attention_packed_qkv_backward(const ::brotensor::Tensor& QKV, const ::brotensor::Tensor& dO, | ||
| 20 | const ::brotensor::Tensor& seq_bounds, int num_heads, int window, | ||
| 21 | ::brotensor::Tensor& dQKV); | ||
| 22 | void rope_qkv_packed_inplace(::brotensor::Tensor& QKV, const ::brotensor::Tensor& cos_tbl, | ||
| 23 | const ::brotensor::Tensor& sin_tbl, const ::brotensor::Tensor& pos, | ||
| 24 | int num_heads, int head_dim); | ||
| 25 | void segment_softmax_stats(const ::brotensor::Tensor& logits, | ||
| 26 | const ::brotensor::Tensor& seg_offsets, | ||
| 27 | ::brotensor::Tensor& out); | ||
| 28 | void linear_forward_batched_ex(const ::brotensor::Tensor& W, const ::brotensor::Tensor* bias, | ||
| 29 | const ::brotensor::Tensor& X, int act, int epilogue, | ||
| 30 | ::brotensor::Tensor* workspace, ::brotensor::Tensor& Y); | ||
| 31 | void quantize_rows(const ::brotensor::Tensor& W, ::brotensor::Dtype fmt, ::brotensor::Tensor& Wq, | ||
| 32 | ::brotensor::Tensor& scales); | ||
| 33 | void linear_forward_batched_wq_ex(const ::brotensor::Tensor& Wq, const ::brotensor::Tensor& scales, | ||
| 34 | const ::brotensor::Tensor* bias, const ::brotensor::Tensor& X, int act, | ||
| 35 | int epilogue, ::brotensor::Tensor& Y); | ||
| 36 | void dequantize_rows(const ::brotensor::Tensor& Wq, const ::brotensor::Tensor& scales, ::brotensor::Dtype out, | ||
| 37 | ::brotensor::Tensor& W); | ||
| 38 | |||
| 39 | // ── CHUNK 5 — cross_attention.cpp / self_attention.cpp / | ||
| 40 | // attention_moments.cpp ── | ||
| 41 | void cross_attention_forward(const ::brotensor::Tensor& X, | ||
| 42 | const ::brotensor::Tensor& Ctx, | ||
| 43 | const ::brotensor::Tensor& Wq, | ||
| 44 | const ::brotensor::Tensor& Wk, | ||
| 45 | const ::brotensor::Tensor& Wv, | ||
| 46 | const ::brotensor::Tensor& Wo, | ||
| 47 | const float* d_mask, int num_heads, | ||
| 48 | ::brotensor::Tensor& O); | ||
| 49 | void cross_attention_forward_with_attn(const ::brotensor::Tensor& X, | ||
| 50 | const ::brotensor::Tensor& Ctx, | ||
| 51 | const ::brotensor::Tensor& Wq, | ||
| 52 | const ::brotensor::Tensor& Wk, | ||
| 53 | const ::brotensor::Tensor& Wv, | ||
| 54 | const ::brotensor::Tensor& Wo, | ||
| 55 | const float* d_mask, | ||
| 56 | const ::brotensor::Tensor* attn_logit_bias, | ||
| 57 | int num_heads, | ||
| 58 | ::brotensor::Tensor& O, | ||
| 59 | ::brotensor::Tensor& AttnAvg); | ||
| 60 | void self_attention_forward_train(const ::brotensor::Tensor& X, | ||
| 61 | const ::brotensor::Tensor& Wq, | ||
| 62 | const ::brotensor::Tensor& Wk, | ||
| 63 | const ::brotensor::Tensor& Wv, | ||
| 64 | const ::brotensor::Tensor& Wo, | ||
| 65 | const float* d_mask, int num_heads, | ||
| 66 | ::brotensor::Tensor& Qh, | ||
| 67 | ::brotensor::Tensor& Kh, | ||
| 68 | ::brotensor::Tensor& Vh, | ||
| 69 | ::brotensor::Tensor& Attnh, | ||
| 70 | ::brotensor::Tensor& Yconcat, | ||
| 71 | ::brotensor::Tensor& O); | ||
| 72 | void self_attention_backward(const ::brotensor::Tensor& dO, | ||
| 73 | const ::brotensor::Tensor& X, | ||
| 74 | const ::brotensor::Tensor& Qh, | ||
| 75 | const ::brotensor::Tensor& Kh, | ||
| 76 | const ::brotensor::Tensor& Vh, | ||
| 77 | const ::brotensor::Tensor& Attnh, | ||
| 78 | const ::brotensor::Tensor& Yconcat, | ||
| 79 | const ::brotensor::Tensor& Wq, | ||
| 80 | const ::brotensor::Tensor& Wk, | ||
| 81 | const ::brotensor::Tensor& Wv, | ||
| 82 | const ::brotensor::Tensor& Wo, | ||
| 83 | const float* d_mask, int num_heads, | ||
| 84 | ::brotensor::Tensor& dX, | ||
| 85 | ::brotensor::Tensor& dWq, | ||
| 86 | ::brotensor::Tensor& dWk, | ||
| 87 | ::brotensor::Tensor& dWv, | ||
| 88 | ::brotensor::Tensor& dWo); | ||
| 89 | void attention_token_moments(const ::brotensor::Tensor& Attn, | ||
| 90 | int h_lat, int w_lat, | ||
| 91 | ::brotensor::Tensor& mass, | ||
| 92 | ::brotensor::Tensor& centroid); | ||
| 93 | void cross_attention_forward_train(const ::brotensor::Tensor& X, | ||
| 94 | const ::brotensor::Tensor& Ctx, | ||
| 95 | const ::brotensor::Tensor& Wq, | ||
| 96 | const ::brotensor::Tensor& Wk, | ||
| 97 | const ::brotensor::Tensor& Wv, | ||
| 98 | const ::brotensor::Tensor& Wo, | ||
| 99 | const float* d_mask, int num_heads, | ||
| 100 | ::brotensor::Tensor& Qh, | ||
| 101 | ::brotensor::Tensor& Kh, | ||
| 102 | ::brotensor::Tensor& Vh, | ||
| 103 | ::brotensor::Tensor& Attnh, | ||
| 104 | ::brotensor::Tensor& Yconcat, | ||
| 105 | ::brotensor::Tensor& O); | ||
| 106 | void cross_attention_backward(const ::brotensor::Tensor& dO, | ||
| 107 | const ::brotensor::Tensor& X, | ||
| 108 | const ::brotensor::Tensor& Ctx, | ||
| 109 | const ::brotensor::Tensor& Qh, | ||
| 110 | const ::brotensor::Tensor& Kh, | ||
| 111 | const ::brotensor::Tensor& Vh, | ||
| 112 | const ::brotensor::Tensor& Attnh, | ||
| 113 | const ::brotensor::Tensor& Yconcat, | ||
| 114 | const ::brotensor::Tensor& Wq, | ||
| 115 | const ::brotensor::Tensor& Wk, | ||
| 116 | const ::brotensor::Tensor& Wv, | ||
| 117 | const ::brotensor::Tensor& Wo, | ||
| 118 | const float* d_mask, int num_heads, | ||
| 119 | ::brotensor::Tensor& dX, | ||
| 120 | ::brotensor::Tensor& dCtx, | ||
| 121 | ::brotensor::Tensor& dWq, | ||
| 122 | ::brotensor::Tensor& dWk, | ||
| 123 | ::brotensor::Tensor& dWv, | ||
| 124 | ::brotensor::Tensor& dWo); | ||
| 125 | |||
| 126 | // ── CHUNK 6 — flash_attention.cpp / self_attention_inference.cpp / | ||
| 127 | // resblock.cpp ── | ||
| 128 | void flash_attention_forward(const ::brotensor::Tensor& Q, | ||
| 129 | const ::brotensor::Tensor& K, | ||
| 130 | const ::brotensor::Tensor& V, | ||
| 131 | const float* d_mask, int num_heads, bool causal, | ||
| 132 | ::brotensor::Tensor& O); | ||
| 133 | void flash_attention_windowed_forward(const ::brotensor::Tensor& Q, | ||
| 134 | const ::brotensor::Tensor& K, | ||
| 135 | const ::brotensor::Tensor& V, | ||
| 136 | const float* d_mask, int num_heads, int window, | ||
| 137 | ::brotensor::Tensor& O, bool causal); | ||
| 138 | void flash_attention_gqa_forward(const ::brotensor::Tensor& Q, | ||
| 139 | const ::brotensor::Tensor& K, | ||
| 140 | const ::brotensor::Tensor& V, | ||
| 141 | const float* d_mask, int num_q_heads, int num_kv_heads, | ||
| 142 | bool causal, ::brotensor::Tensor& O); | ||
| 143 | void flash_attention_varlen_forward(const ::brotensor::Tensor& Q, | ||
| 144 | const ::brotensor::Tensor& K, | ||
| 145 | const ::brotensor::Tensor& V, | ||
| 146 | const int32_t* cu_seqlens_q, | ||
| 147 | const int32_t* cu_seqlens_k, | ||
| 148 | int batch_size, int max_seqlen_q, int max_seqlen_k, | ||
| 149 | int num_heads, int head_dim, bool causal, | ||
| 150 | ::brotensor::Tensor& O); | ||
| 151 | void flash_attention_varlen_backward(const ::brotensor::Tensor& Q, | ||
| 152 | const ::brotensor::Tensor& K, | ||
| 153 | const ::brotensor::Tensor& V, | ||
| 154 | const ::brotensor::Tensor& O, | ||
| 155 | const ::brotensor::Tensor& dO, | ||
| 156 | const int32_t* cu_seqlens_q, | ||
| 157 | const int32_t* cu_seqlens_k, | ||
| 158 | int batch_size, int max_seqlen_q, int max_seqlen_k, | ||
| 159 | int num_heads, int head_dim, bool causal, | ||
| 160 | ::brotensor::Tensor& dQ, | ||
| 161 | ::brotensor::Tensor& dK, | ||
| 162 | ::brotensor::Tensor& dV); | ||
| 163 | void flash_attention_qkvo_forward(const ::brotensor::Tensor& X, | ||
| 164 | const ::brotensor::Tensor* Ctx, | ||
| 165 | const ::brotensor::Tensor& Wq, | ||
| 166 | const ::brotensor::Tensor* bq, | ||
| 167 | const ::brotensor::Tensor& Wk, | ||
| 168 | const ::brotensor::Tensor* bk, | ||
| 169 | const ::brotensor::Tensor& Wv, | ||
| 170 | const ::brotensor::Tensor* bv, | ||
| 171 | const ::brotensor::Tensor& Wo, | ||
| 172 | const ::brotensor::Tensor* bo, | ||
| 173 | const float* d_mask, int num_heads, | ||
| 174 | bool causal, ::brotensor::Tensor& O); | ||
| 175 | void flash_attention_qkvo_backward(const ::brotensor::Tensor& X, | ||
| 176 | const ::brotensor::Tensor* Ctx, | ||
| 177 | const ::brotensor::Tensor& Wq, | ||
| 178 | const ::brotensor::Tensor* bq, | ||
| 179 | const ::brotensor::Tensor& Wk, | ||
| 180 | const ::brotensor::Tensor* bk, | ||
| 181 | const ::brotensor::Tensor& Wv, | ||
| 182 | const ::brotensor::Tensor* bv, | ||
| 183 | const ::brotensor::Tensor& Wo, | ||
| 184 | const ::brotensor::Tensor* bo, | ||
| 185 | const float* d_mask, int num_heads, | ||
| 186 | bool causal, | ||
| 187 | const ::brotensor::Tensor& dO, | ||
| 188 | ::brotensor::Tensor& dX, | ||
| 189 | ::brotensor::Tensor* dCtx, | ||
| 190 | ::brotensor::Tensor& dWq, | ||
| 191 | ::brotensor::Tensor* dbq, | ||
| 192 | ::brotensor::Tensor& dWk, | ||
| 193 | ::brotensor::Tensor* dbk, | ||
| 194 | ::brotensor::Tensor& dWv, | ||
| 195 | ::brotensor::Tensor* dbv, | ||
| 196 | ::brotensor::Tensor& dWo, | ||
| 197 | ::brotensor::Tensor* dbo); | ||
| 198 | void flash_attention_backward(const ::brotensor::Tensor& Q, | ||
| 199 | const ::brotensor::Tensor& K, | ||
| 200 | const ::brotensor::Tensor& V, | ||
| 201 | const ::brotensor::Tensor& O, | ||
| 202 | const ::brotensor::Tensor& dO, | ||
| 203 | const float* d_mask, int num_heads, bool causal, | ||
| 204 | ::brotensor::Tensor& dQ, | ||
| 205 | ::brotensor::Tensor& dK, | ||
| 206 | ::brotensor::Tensor& dV); | ||
| 207 | void flash_attention_project_kv(const ::brotensor::Tensor& ctx, | ||
| 208 | const ::brotensor::Tensor& Wk, | ||
| 209 | const ::brotensor::Tensor* bk, | ||
| 210 | const ::brotensor::Tensor& Wv, | ||
| 211 | const ::brotensor::Tensor* bv, | ||
| 212 | ::brotensor::Tensor& K_out, | ||
| 213 | ::brotensor::Tensor& V_out); | ||
| 214 | void flash_attention_q_with_kv_cached_forward(const ::brotensor::Tensor& X, | ||
| 215 | const ::brotensor::Tensor& K, | ||
| 216 | const ::brotensor::Tensor& V, | ||
| 217 | const ::brotensor::Tensor& Wq, | ||
| 218 | const ::brotensor::Tensor* bq, | ||
| 219 | const ::brotensor::Tensor& Wo, | ||
| 220 | const ::brotensor::Tensor* bo, | ||
| 221 | const float* d_mask, | ||
| 222 | int num_heads, bool causal, | ||
| 223 | ::brotensor::Tensor& O); | ||
| 224 | void self_attention_forward(const ::brotensor::Tensor& X, | ||
| 225 | const ::brotensor::Tensor& Wq, | ||
| 226 | const ::brotensor::Tensor& Wk, | ||
| 227 | const ::brotensor::Tensor& Wv, | ||
| 228 | const ::brotensor::Tensor& Wo, | ||
| 229 | const float* d_mask, int num_heads, | ||
| 230 | ::brotensor::Tensor& O); | ||
| 231 | void resblock_forward(const ::brotensor::Tensor& X, | ||
| 232 | const ::brotensor::Tensor& gamma1, | ||
| 233 | const ::brotensor::Tensor& beta1, | ||
| 234 | const ::brotensor::Tensor& W1, | ||
| 235 | const ::brotensor::Tensor* b1, | ||
| 236 | const ::brotensor::Tensor* t_emb_shift, | ||
| 237 | const ::brotensor::Tensor& gamma2, | ||
| 238 | const ::brotensor::Tensor& beta2, | ||
| 239 | const ::brotensor::Tensor& W2, | ||
| 240 | const ::brotensor::Tensor* b2, | ||
| 241 | const ::brotensor::Tensor* Wskip, | ||
| 242 | const ::brotensor::Tensor* bskip, | ||
| 243 | int N, int C_in, int C_out, int H, int W, | ||
| 244 | int num_groups, float eps, ::brotensor::Tensor& Y); | ||
| 245 | void resblock_backward(const ::brotensor::Tensor& X, | ||
| 246 | const ::brotensor::Tensor& gamma1, | ||
| 247 | const ::brotensor::Tensor& beta1, | ||
| 248 | const ::brotensor::Tensor& W1, | ||
| 249 | const ::brotensor::Tensor* b1, | ||
| 250 | const ::brotensor::Tensor* t_emb_shift, | ||
| 251 | const ::brotensor::Tensor& gamma2, | ||
| 252 | const ::brotensor::Tensor& beta2, | ||
| 253 | const ::brotensor::Tensor& W2, | ||
| 254 | const ::brotensor::Tensor* b2, | ||
| 255 | const ::brotensor::Tensor* Wskip, | ||
| 256 | const ::brotensor::Tensor* bskip, | ||
| 257 | int N, int C_in, int C_out, int H, int W, | ||
| 258 | int num_groups, float eps, | ||
| 259 | const ::brotensor::Tensor& dY, | ||
| 260 | ::brotensor::Tensor& dX, | ||
| 261 | ::brotensor::Tensor& dGamma1, | ||
| 262 | ::brotensor::Tensor& dBeta1, | ||
| 263 | ::brotensor::Tensor& dW1, | ||
| 264 | ::brotensor::Tensor* db1, | ||
| 265 | ::brotensor::Tensor* dt_emb_shift, | ||
| 266 | ::brotensor::Tensor& dGamma2, | ||
| 267 | ::brotensor::Tensor& dBeta2, | ||
| 268 | ::brotensor::Tensor& dW2, | ||
| 269 | ::brotensor::Tensor* db2, | ||
| 270 | ::brotensor::Tensor* dWskip, | ||
| 271 | ::brotensor::Tensor* dbskip); | ||
| 272 | |||
| 273 | // ── DiT / diffusion extras — modulate.cpp ── | ||
| 274 | void modulate(const ::brotensor::Tensor& X, const ::brotensor::Tensor& scale, | ||
| 275 | const ::brotensor::Tensor& shift, ::brotensor::Tensor& Y); | ||
| 276 | void broadcast_mul(const ::brotensor::Tensor& X, const ::brotensor::Tensor& v, | ||
| 277 | ::brotensor::Tensor& Y); | ||
| 278 | |||
| 279 | // ── RoPE with explicit cos/sin tables — rope.cpp ── | ||
| 280 | void rope_apply(const ::brotensor::Tensor& X, const ::brotensor::Tensor& cos_tbl, | ||
| 281 | const ::brotensor::Tensor& sin_tbl, int head_dim, int num_heads, | ||
| 282 | ::brotensor::Tensor& Y); | ||
| 283 | void rope_apply_perhead(const ::brotensor::Tensor& X, const ::brotensor::Tensor& cos_tbl, | ||
| 284 | const ::brotensor::Tensor& sin_tbl, int head_dim, int num_heads, | ||
| 285 | ::brotensor::Tensor& Y); | ||
| 286 | void rope_apply_backward(const ::brotensor::Tensor& dY, | ||
| 287 | const ::brotensor::Tensor& cos_tbl, | ||
| 288 | const ::brotensor::Tensor& sin_tbl, | ||
| 289 | int head_dim, int num_heads, ::brotensor::Tensor& dX); | ||
| 290 | |||
| 291 | // ── Self-attention with additive bias — self_attention_bias.cpp ── | ||
| 292 | void self_attention_bias_forward(const ::brotensor::Tensor& X, | ||
| 293 | const ::brotensor::Tensor& Wq, | ||
| 294 | const ::brotensor::Tensor& Wk, | ||
| 295 | const ::brotensor::Tensor& Wv, | ||
| 296 | const ::brotensor::Tensor& Wo, | ||
| 297 | const ::brotensor::Tensor* bq, | ||
| 298 | const ::brotensor::Tensor* bk, | ||
| 299 | const ::brotensor::Tensor* bv, | ||
| 300 | const ::brotensor::Tensor* bo, | ||
| 301 | const float* d_mask, | ||
| 302 | const ::brotensor::Tensor* attn_bias, | ||
| 303 | int num_heads, float scale, | ||
| 304 | ::brotensor::Tensor& O); | ||
| 305 | void rel_pos_bias_xl_forward(const ::brotensor::Tensor& Qv, | ||
| 306 | const ::brotensor::Tensor& Pk, | ||
| 307 | int num_heads, int head_dim, | ||
| 308 | ::brotensor::Tensor& Bias); | ||
| 309 | |||
| 310 | // ── Self-attention with decomposed 2D rel-pos bias (SAM/ViTDet) — | ||
| 311 | // self_attention_decomposed_rel_pos.cpp ── | ||
| 312 | void self_attention_decomposed_rel_pos_forward( | ||
| 313 | const ::brotensor::Tensor& X, | ||
| 314 | const ::brotensor::Tensor& Wq, const ::brotensor::Tensor* bq, | ||
| 315 | const ::brotensor::Tensor& Wk, const ::brotensor::Tensor* bk, | ||
| 316 | const ::brotensor::Tensor& Wv, const ::brotensor::Tensor* bv, | ||
| 317 | const ::brotensor::Tensor& Wo, const ::brotensor::Tensor* bo, | ||
| 318 | const ::brotensor::Tensor& rel_pos_h, const ::brotensor::Tensor& rel_pos_w, | ||
| 319 | int num_heads, int grid_h, int grid_w, float scale, | ||
| 320 | ::brotensor::Tensor& O); | ||
| 321 | void self_attention_decomposed_rel_pos_windowed_forward( | ||
| 322 | const ::brotensor::Tensor& X, | ||
| 323 | const ::brotensor::Tensor& Wq, const ::brotensor::Tensor* bq, | ||
| 324 | const ::brotensor::Tensor& Wk, const ::brotensor::Tensor* bk, | ||
| 325 | const ::brotensor::Tensor& Wv, const ::brotensor::Tensor* bv, | ||
| 326 | const ::brotensor::Tensor& Wo, const ::brotensor::Tensor* bo, | ||
| 327 | const ::brotensor::Tensor& rel_pos_h, const ::brotensor::Tensor& rel_pos_w, | ||
| 328 | int num_heads, int grid_h, int grid_w, int window, float scale, | ||
| 329 | ::brotensor::Tensor& O); | ||
| 330 | |||
| 331 | // ── Spectral / FFT core (brosoundml) — fft.cpp ── | ||
| 332 | void complex_mul(const ::brotensor::Tensor& a, const ::brotensor::Tensor& b, | ||
| 333 | ::brotensor::Tensor& y); | ||
| 334 | void complex_mul_backward(const ::brotensor::Tensor& a, | ||
| 335 | const ::brotensor::Tensor& b, | ||
| 336 | const ::brotensor::Tensor& dY, | ||
| 337 | ::brotensor::Tensor& dA, ::brotensor::Tensor& dB); | ||
| 338 | void complex_abs(const ::brotensor::Tensor& z, ::brotensor::Tensor& y); | ||
| 339 | void complex_abs_backward(const ::brotensor::Tensor& z, | ||
| 340 | const ::brotensor::Tensor& dY, | ||
| 341 | ::brotensor::Tensor& dZ); | ||
| 342 | void complex_angle(const ::brotensor::Tensor& z, ::brotensor::Tensor& y); | ||
| 343 | void complex_from_polar(const ::brotensor::Tensor& mag, | ||
| 344 | const ::brotensor::Tensor& phase, | ||
| 345 | ::brotensor::Tensor& y); | ||
| 346 | void fft(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 347 | void ifft(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 348 | void rfft(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 349 | void irfft(const ::brotensor::Tensor& x, int L, ::brotensor::Tensor& y); | ||
| 350 | void rfft_backward(const ::brotensor::Tensor& dY, int L, | ||
| 351 | ::brotensor::Tensor& dX); | ||
| 352 | void irfft_backward(const ::brotensor::Tensor& dY, ::brotensor::Tensor& dX); | ||
| 353 | |||
| 354 | // ── STFT / iSTFT (brosoundml) — stft.cpp ── | ||
| 355 | void stft(const ::brotensor::Tensor& signal, const ::brotensor::Tensor& window, | ||
| 356 | int N, int n_fft, int hop_length, int win_length, | ||
| 357 | bool center, bool normalized, ::brotensor::Tensor& spec); | ||
| 358 | void stft_backward(const ::brotensor::Tensor& dSpec, | ||
| 359 | const ::brotensor::Tensor& window, | ||
| 360 | int N, int signal_len, int n_fft, int hop_length, | ||
| 361 | int win_length, bool center, bool normalized, | ||
| 362 | ::brotensor::Tensor& dSignal); | ||
| 363 | void istft(const ::brotensor::Tensor& spec, const ::brotensor::Tensor& window, | ||
| 364 | int N, int signal_len, int n_fft, int hop_length, int win_length, | ||
| 365 | bool center, bool normalized, ::brotensor::Tensor& signal); | ||
| 366 | void istft_backward(const ::brotensor::Tensor& dSignal, | ||
| 367 | const ::brotensor::Tensor& window, | ||
| 368 | int N, int signal_len, int n_fft, int hop_length, | ||
| 369 | int win_length, bool center, bool normalized, | ||
| 370 | ::brotensor::Tensor& dSpec); | ||
| 371 | |||
| 372 | // ── 1D convolution family (brosoundml) — conv1d.cpp ── | ||
| 373 | void conv_transpose1d_forward(const ::brotensor::Tensor& X, | ||
| 374 | const ::brotensor::Tensor& Wt, | ||
| 375 | const ::brotensor::Tensor* bias, | ||
| 376 | int N, int C_in, int L, int C_out, int kL, | ||
| 377 | int stride, int padding, int output_padding, | ||
| 378 | int dilation, int groups, ::brotensor::Tensor& Y); | ||
| 379 | void conv_transpose1d_backward_input(const ::brotensor::Tensor& Wt, | ||
| 380 | const ::brotensor::Tensor& dY, | ||
| 381 | int N, int C_in, int L, int C_out, int kL, | ||
| 382 | int stride, int padding, | ||
| 383 | int output_padding, int dilation, | ||
| 384 | int groups, ::brotensor::Tensor& dX); | ||
| 385 | void conv_transpose1d_backward_weight(const ::brotensor::Tensor& X, | ||
| 386 | const ::brotensor::Tensor& dY, | ||
| 387 | int N, int C_in, int L, int C_out, int kL, | ||
| 388 | int stride, int padding, | ||
| 389 | int output_padding, int dilation, | ||
| 390 | int groups, ::brotensor::Tensor& dWt); | ||
| 391 | void conv_transpose1d_backward_bias(const ::brotensor::Tensor& dY, | ||
| 392 | int N, int C_out, int L_out, | ||
| 393 | ::brotensor::Tensor& dB); | ||
| 394 | void causal_conv1d_update(const ::brotensor::Tensor& X, | ||
| 395 | const ::brotensor::Tensor& Wt, | ||
| 396 | const ::brotensor::Tensor* bias, | ||
| 397 | int N, int C, int L_step, int kL, int dilation, | ||
| 398 | ::brotensor::Tensor& state, ::brotensor::Tensor& Y); | ||
| 399 | void pad1d_forward(const ::brotensor::Tensor& X, int N, int C, int L, | ||
| 400 | int pad_left, int pad_right, int mode, | ||
| 401 | ::brotensor::Tensor& Y); | ||
| 402 | void pad1d_backward(const ::brotensor::Tensor& dY, int N, int C, int L, | ||
| 403 | int pad_left, int pad_right, int mode, | ||
| 404 | ::brotensor::Tensor& dX); | ||
| 405 | |||
| 406 | // ── Vocoder / codec activations (brosoundml) — vocoder_activations.cpp ── | ||
| 407 | void snake_forward(const ::brotensor::Tensor& X, | ||
| 408 | const ::brotensor::Tensor& alpha, | ||
| 409 | const ::brotensor::Tensor* beta, | ||
| 410 | int N, int C, int L, ::brotensor::Tensor& Y); | ||
| 411 | void snake_backward(const ::brotensor::Tensor& X, | ||
| 412 | const ::brotensor::Tensor& alpha, | ||
| 413 | const ::brotensor::Tensor* beta, | ||
| 414 | const ::brotensor::Tensor& dY, | ||
| 415 | int N, int C, int L, | ||
| 416 | ::brotensor::Tensor& dX, ::brotensor::Tensor& dAlpha, | ||
| 417 | ::brotensor::Tensor* dBeta); | ||
| 418 | void elu_forward(const ::brotensor::Tensor& x, float alpha, | ||
| 419 | ::brotensor::Tensor& y); | ||
| 420 | void elu_backward(const ::brotensor::Tensor& x, const ::brotensor::Tensor& dY, | ||
| 421 | float alpha, ::brotensor::Tensor& dX); | ||
| 422 | void leaky_relu_forward(const ::brotensor::Tensor& x, float negative_slope, | ||
| 423 | ::brotensor::Tensor& y); | ||
| 424 | void leaky_relu_backward(const ::brotensor::Tensor& x, | ||
| 425 | const ::brotensor::Tensor& dY, | ||
| 426 | float negative_slope, ::brotensor::Tensor& dX); | ||
| 427 | |||
| 428 | // ── Codec quantization (brosoundml CHUNK 5, family D) — codec_quant.cpp ── | ||
| 429 | void vq_encode_forward(const ::brotensor::Tensor& x, | ||
| 430 | const ::brotensor::Tensor& codebook, | ||
| 431 | ::brotensor::Tensor& indices, | ||
| 432 | ::brotensor::Tensor& quantized); | ||
| 433 | void vq_encode_backward(const ::brotensor::Tensor& dQuantized, | ||
| 434 | ::brotensor::Tensor& dX); | ||
| 435 | void fsq_quantize_forward(const ::brotensor::Tensor& x, | ||
| 436 | const ::brotensor::Tensor& levels, | ||
| 437 | ::brotensor::Tensor& quantized, | ||
| 438 | ::brotensor::Tensor& packed_indices); | ||
| 439 | void fsq_quantize_backward(const ::brotensor::Tensor& dQuantized, | ||
| 440 | ::brotensor::Tensor& dX); | ||
| 441 | |||
| 442 | // ── 1D resampling (brosoundml CHUNK 6, family E) — resample1d.cpp ── | ||
| 443 | void resample1d_forward(const ::brotensor::Tensor& X, | ||
| 444 | int N, int C, int L_in, int L_out, int mode, | ||
| 445 | ::brotensor::Tensor& Y); | ||
| 446 | void resample1d_backward(const ::brotensor::Tensor& dY, | ||
| 447 | int N, int C, int L_in, int L_out, int mode, | ||
| 448 | ::brotensor::Tensor& dX); | ||
| 449 | |||
| 450 | // ── log / exp / round elementwise (brosoundml CHUNK 6, family G) | ||
| 451 | // — log_exp_round.cpp ── | ||
| 452 | void log_forward(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 453 | void log_backward(const ::brotensor::Tensor& x, const ::brotensor::Tensor& dY, | ||
| 454 | ::brotensor::Tensor& dX); | ||
| 455 | void exp_forward(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 456 | void exp_backward(const ::brotensor::Tensor& x, const ::brotensor::Tensor& dY, | ||
| 457 | ::brotensor::Tensor& dX); | ||
| 458 | void round_forward(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 459 | void round_backward(const ::brotensor::Tensor& dY, ::brotensor::Tensor& dX); | ||
| 460 | |||
| 461 | // ── Autoregressive logit sampling (brosoundml CHUNK 7, family F) | ||
| 462 | // — sample_logits.cpp ── | ||
| 463 | void sample_logits(const ::brotensor::Tensor& logits, float temperature, | ||
| 464 | int top_k, float top_p, uint64_t key, uint64_t counter, | ||
| 465 | ::brotensor::Tensor& indices); | ||
| 466 | void sample_logits_into(const ::brotensor::Tensor& logits, float temperature, | ||
| 467 | int top_k, float top_p, uint64_t key, | ||
| 468 | ::brotensor::Tensor& counter, | ||
| 469 | ::brotensor::Tensor& scratch, | ||
| 470 | ::brotensor::Tensor& indices); | ||
| 471 | |||
| 472 | // ── Masked-diffusion token selection — masked_diffusion.cpp ── | ||
| 473 | void masked_diffusion_scores(const ::brotensor::Tensor& logits, | ||
| 474 | const ::brotensor::Tensor& tokens, | ||
| 475 | int T, int C, int V, int mask_id, | ||
| 476 | float guidance_scale, float layer_penalty, | ||
| 477 | float position_temperature, float class_temperature, | ||
| 478 | float class_top_frac, uint64_t seed, | ||
| 479 | ::brotensor::Tensor& pred, ::brotensor::Tensor& scores, | ||
| 480 | ::brotensor::Tensor& confidence); | ||
| 481 | void masked_diffusion_commit(const ::brotensor::Tensor& pred, | ||
| 482 | const ::brotensor::Tensor& idx, int k, int step, | ||
| 483 | ::brotensor::Tensor& tokens, | ||
| 484 | ::brotensor::Tensor& unmask_step); | ||
| 485 | |||
| 486 | // ── Counter-based noise generation (Philox 4x32-10) — noise.cpp ── | ||
| 487 | void randn(uint64_t key, uint64_t counter, ::brotensor::Tensor& Y); | ||
| 488 | void sine_source_forward(const ::brotensor::Tensor& f0, const ::brotensor::Tensor& phase0, | ||
| 489 | const ::brotensor::Tensor& w, const ::brotensor::Tensor& b, int upsample, | ||
| 490 | float sample_rate, float sine_amp, float noise_std, float uv_std, uint64_t key, | ||
| 491 | ::brotensor::Tensor& Y); | ||
| 492 | void rand_uniform(uint64_t key, uint64_t counter, ::brotensor::Tensor& Y); | ||
| 493 | void rand_bernoulli(float p, uint64_t key, uint64_t counter, | ||
| 494 | ::brotensor::Tensor& Y); | ||
| 495 | void randn_truncated(float lo, float hi, uint64_t key, uint64_t counter, | ||
| 496 | ::brotensor::Tensor& Y); | ||
| 497 | |||
| 498 | // ── L2 norm + Gated Delta Rule (linear-attention text path) ── | ||
| 499 | // l2_norm.cpp, gated_delta_rule.cpp | ||
| 500 | void l2_norm_forward(const ::brotensor::Tensor& X, | ||
| 501 | int head_dim, int num_heads, float eps, | ||
| 502 | ::brotensor::Tensor& Y); | ||
| 503 | void l2_norm_backward(const ::brotensor::Tensor& X, | ||
| 504 | int head_dim, int num_heads, float eps, | ||
| 505 | const ::brotensor::Tensor& dY, | ||
| 506 | ::brotensor::Tensor& dX); | ||
| 507 | void gated_delta_rule_chunked(const ::brotensor::Tensor& Q, | ||
| 508 | const ::brotensor::Tensor& K, | ||
| 509 | const ::brotensor::Tensor& V, | ||
| 510 | const ::brotensor::Tensor& a_raw, | ||
| 511 | const ::brotensor::Tensor& beta, | ||
| 512 | const ::brotensor::Tensor& log_A, | ||
| 513 | int num_heads, int d_k, int d_v, | ||
| 514 | ::brotensor::Tensor& state, | ||
| 515 | ::brotensor::Tensor& O); | ||
| 516 | void gated_delta_rule_step(const ::brotensor::Tensor& Q, | ||
| 517 | const ::brotensor::Tensor& K, | ||
| 518 | const ::brotensor::Tensor& V, | ||
| 519 | const ::brotensor::Tensor& a_raw, | ||
| 520 | const ::brotensor::Tensor& beta, | ||
| 521 | const ::brotensor::Tensor& log_A, | ||
| 522 | int num_heads, int d_k, int d_v, | ||
| 523 | ::brotensor::Tensor& state, | ||
| 524 | ::brotensor::Tensor& O); | ||
| 525 | |||
| 526 | // ── Qwen3-VL polish: spatial_merge_2x2 + M-RoPE — spatial_merge.cpp / | ||
| 527 | // rope_mrope.cpp ── | ||
| 528 | void spatial_merge_2x2_forward(const ::brotensor::Tensor& X, | ||
| 529 | int N, int C, int H, int W, | ||
| 530 | bool channel_major, | ||
| 531 | ::brotensor::Tensor& Y); | ||
| 532 | void pixel_shuffle_upsample_2x_forward(const ::brotensor::Tensor& X, | ||
| 533 | int N, int C_in, int H, int W, | ||
| 534 | int C_out, ::brotensor::Tensor& Y); | ||
| 535 | void patch_unpack_forward(const ::brotensor::Tensor& tokens, | ||
| 536 | int hp, int wp, int P, int C_total, int C_keep, | ||
| 537 | bool channel_major, ::brotensor::Tensor& Y); | ||
| 538 | void rope_apply_mrope(const ::brotensor::Tensor& X, | ||
| 539 | const ::brotensor::Tensor& cos_t, | ||
| 540 | const ::brotensor::Tensor& sin_t, | ||
| 541 | const ::brotensor::Tensor& cos_h, | ||
| 542 | const ::brotensor::Tensor& sin_h, | ||
| 543 | const ::brotensor::Tensor& cos_w, | ||
| 544 | const ::brotensor::Tensor& sin_w, | ||
| 545 | const int32_t* pos_t, const int32_t* pos_h, | ||
| 546 | const int32_t* pos_w, | ||
| 547 | int head_dim, int num_heads, | ||
| 548 | int d_t, int d_h, int d_w, | ||
| 549 | ::brotensor::Tensor& Y); | ||
| 550 | |||
| 551 | // ── BatchNorm — batch_norm.cpp ── | ||
| 552 | void batch_norm_forward(const ::brotensor::Tensor& X, | ||
| 553 | const ::brotensor::Tensor& gamma, | ||
| 554 | const ::brotensor::Tensor& beta, | ||
| 555 | ::brotensor::Tensor& running_mean, | ||
| 556 | ::brotensor::Tensor& running_var, | ||
| 557 | int N, int C, int H, int W, | ||
| 558 | float eps, float momentum, | ||
| 559 | ::brotensor::Tensor& Y, | ||
| 560 | ::brotensor::Tensor& saved_mean, | ||
| 561 | ::brotensor::Tensor& saved_rstd); | ||
| 562 | void batch_norm_inference(const ::brotensor::Tensor& X, | ||
| 563 | const ::brotensor::Tensor& gamma, | ||
| 564 | const ::brotensor::Tensor& beta, | ||
| 565 | const ::brotensor::Tensor& running_mean, | ||
| 566 | const ::brotensor::Tensor& running_var, | ||
| 567 | int N, int C, int H, int W, | ||
| 568 | float eps, | ||
| 569 | ::brotensor::Tensor& Y); | ||
| 570 | void batch_norm_backward(const ::brotensor::Tensor& X, | ||
| 571 | const ::brotensor::Tensor& gamma, | ||
| 572 | const ::brotensor::Tensor& saved_mean, | ||
| 573 | const ::brotensor::Tensor& saved_rstd, | ||
| 574 | const ::brotensor::Tensor& dY, | ||
| 575 | int N, int C, int H, int W, | ||
| 576 | ::brotensor::Tensor& dX, | ||
| 577 | ::brotensor::Tensor& dGamma, | ||
| 578 | ::brotensor::Tensor& dBeta); | ||
| 579 | |||
| 580 | // ── Image preprocessing helpers — image_preproc.cpp ── | ||
| 581 | void image_normalize(const ::brotensor::Tensor& X, | ||
| 582 | const ::brotensor::Tensor& mean, | ||
| 583 | const ::brotensor::Tensor& std_, | ||
| 584 | int N, int C, int H, int W, | ||
| 585 | ::brotensor::Tensor& Y); | ||
| 586 | void image_u8_to_f32_nhwc_to_nchw(const uint8_t* src, | ||
| 587 | int N, int H, int W, int C, | ||
| 588 | float scale, float bias, | ||
| 589 | ::brotensor::Tensor& Y); | ||
| 590 | void lstm_recurrence(const ::brotensor::Tensor& gates_f, const ::brotensor::Tensor& W_hh_f, | ||
| 591 | const ::brotensor::Tensor* gates_r, const ::brotensor::Tensor* W_hh_r, | ||
| 592 | ::brotensor::Tensor& Y); | ||
| 593 | void lstm_forward_train(const ::brotensor::Tensor& X, const ::brotensor::Tensor& W_ih, | ||
| 594 | const ::brotensor::Tensor& W_hh, | ||
| 595 | const ::brotensor::Tensor* b_ih, const ::brotensor::Tensor* b_hh, | ||
| 596 | const ::brotensor::Tensor* h0, const ::brotensor::Tensor* c0, | ||
| 597 | int T, int B, | ||
| 598 | ::brotensor::Tensor& Y, ::brotensor::Tensor& gates, | ||
| 599 | ::brotensor::Tensor& C, | ||
| 600 | ::brotensor::Tensor* hT, ::brotensor::Tensor* cT); | ||
| 601 | void lstm_backward(const ::brotensor::Tensor& X, const ::brotensor::Tensor& W_ih, | ||
| 602 | const ::brotensor::Tensor& W_hh, | ||
| 603 | const ::brotensor::Tensor* h0, const ::brotensor::Tensor* c0, | ||
| 604 | const ::brotensor::Tensor& Y, const ::brotensor::Tensor& gates, | ||
| 605 | const ::brotensor::Tensor& C, | ||
| 606 | const ::brotensor::Tensor& dY, int T, int B, | ||
| 607 | ::brotensor::Tensor& dX, ::brotensor::Tensor& dW_ih, | ||
| 608 | ::brotensor::Tensor& dW_hh, | ||
| 609 | ::brotensor::Tensor* db_ih, ::brotensor::Tensor* db_hh, | ||
| 610 | ::brotensor::Tensor* dh0, ::brotensor::Tensor* dc0); | ||
| 611 | |||
| 612 | // ── StyleGAN3-R primitives — stylegan_elementwise.cpp / bias_act.cpp / | ||
| 613 | // upfirdn2d.cpp / modulated_conv2d.cpp ── | ||
| 614 | void sin_forward(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 615 | void sin_backward(const ::brotensor::Tensor& x, const ::brotensor::Tensor& dY, | ||
| 616 | ::brotensor::Tensor& dX); | ||
| 617 | void cos_forward(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 618 | void cos_backward(const ::brotensor::Tensor& x, const ::brotensor::Tensor& dY, | ||
| 619 | ::brotensor::Tensor& dX); | ||
| 620 | void rsqrt_forward(const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 621 | void rsqrt_backward(const ::brotensor::Tensor& y, const ::brotensor::Tensor& dY, | ||
| 622 | ::brotensor::Tensor& dX); | ||
| 623 | void pixel_norm_forward(const ::brotensor::Tensor& X, float eps, | ||
| 624 | ::brotensor::Tensor& Y); | ||
| 625 | void pixel_norm_backward(const ::brotensor::Tensor& X, | ||
| 626 | const ::brotensor::Tensor& dY, float eps, | ||
| 627 | ::brotensor::Tensor& dX); | ||
| 628 | void bias_act_forward(const ::brotensor::Tensor& X, const ::brotensor::Tensor* b, | ||
| 629 | int N, int C, int HW, int act, float alpha, | ||
| 630 | float gain, float clamp, ::brotensor::Tensor& Y); | ||
| 631 | void bias_act_backward(const ::brotensor::Tensor& dY, const ::brotensor::Tensor& X, | ||
| 632 | const ::brotensor::Tensor* b, | ||
| 633 | int N, int C, int HW, int act, float alpha, | ||
| 634 | float gain, float clamp, | ||
| 635 | ::brotensor::Tensor& dX, ::brotensor::Tensor* dB); | ||
| 636 | void upfirdn2d_forward(const ::brotensor::Tensor& X, const ::brotensor::Tensor& f, | ||
| 637 | int N, int C, int H, int Wd, int fH, int fW, | ||
| 638 | int up_x, int up_y, int down_x, int down_y, | ||
| 639 | int pad_x0, int pad_x1, int pad_y0, int pad_y1, | ||
| 640 | bool flip_filter, float gain, ::brotensor::Tensor& Y); | ||
| 641 | void upfirdn2d_backward(const ::brotensor::Tensor& dY, const ::brotensor::Tensor& f, | ||
| 642 | int N, int C, int H, int Wd, int fH, int fW, | ||
| 643 | int up_x, int up_y, int down_x, int down_y, | ||
| 644 | int pad_x0, int pad_x1, int pad_y0, int pad_y1, | ||
| 645 | bool flip_filter, float gain, ::brotensor::Tensor& dX); | ||
| 646 | void modulated_conv2d_forward(const ::brotensor::Tensor& X, | ||
| 647 | const ::brotensor::Tensor& W, | ||
| 648 | const ::brotensor::Tensor& s, | ||
| 649 | int N, int C_in, int H, int Wd, | ||
| 650 | int C_out, int kH, int kW, int pad_h, int pad_w, | ||
| 651 | bool demodulate, float eps, | ||
| 652 | ::brotensor::Tensor& dcoef, ::brotensor::Tensor& Y); | ||
| 653 | void modulated_conv2d_backward(const ::brotensor::Tensor& X, | ||
| 654 | const ::brotensor::Tensor& W, | ||
| 655 | const ::brotensor::Tensor& s, | ||
| 656 | const ::brotensor::Tensor& dcoef, | ||
| 657 | const ::brotensor::Tensor& dY, | ||
| 658 | int N, int C_in, int H, int Wd, | ||
| 659 | int C_out, int kH, int kW, int pad_h, int pad_w, | ||
| 660 | bool demodulate, float eps, | ||
| 661 | ::brotensor::Tensor& dX, ::brotensor::Tensor& dW, | ||
| 662 | ::brotensor::Tensor& ds); | ||
| 663 | |||
| 664 | // ── Quantized linear forward & dequant (Q8_0, Q4_K, Q6_K & INT8) via Brass AVX2/FMA JIT ── | ||
| 665 | void dequant_q8_0_to_fp16(const ::brotensor::Tensor& W_q8, ::brotensor::Tensor& W_fp16); | ||
| 666 | void linear_forward_q8_0_fp16(const ::brotensor::Tensor& W_q8, const ::brotensor::Tensor* bias, | ||
| 667 | const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 668 | void linear_forward_batched_q8_0_fp16(const ::brotensor::Tensor& W_q8, const ::brotensor::Tensor* bias, | ||
| 669 | const ::brotensor::Tensor& X_BD, ::brotensor::Tensor& Y_BD); | ||
| 670 | void dequant_q4k_to_fp16(const ::brotensor::Tensor& W_q4k, ::brotensor::Tensor& W_fp16); | ||
| 671 | void linear_forward_q4k_fp16(const ::brotensor::Tensor& W_q4k, const ::brotensor::Tensor* bias, | ||
| 672 | const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 673 | void linear_forward_batched_q4k_fp16(const ::brotensor::Tensor& W_q4k, const ::brotensor::Tensor* bias, | ||
| 674 | const ::brotensor::Tensor& X_BD, ::brotensor::Tensor& Y_BD); | ||
| 675 | void dequant_q6k_to_fp16(const ::brotensor::Tensor& W_q6k, ::brotensor::Tensor& W_fp16); | ||
| 676 | void linear_forward_q6k_fp16(const ::brotensor::Tensor& W_q6k, const ::brotensor::Tensor* bias, | ||
| 677 | const ::brotensor::Tensor& x, ::brotensor::Tensor& y); | ||
| 678 | void linear_forward_batched_q6k_fp16(const ::brotensor::Tensor& W_q6k, const ::brotensor::Tensor* bias, | ||
| 679 | const ::brotensor::Tensor& X_BD, ::brotensor::Tensor& Y_BD); | ||
| 680 | void matmul_int8w_fp16(const ::brotensor::Tensor& W_int8, const ::brotensor::Tensor& scales, | ||
| 681 | const ::brotensor::Tensor& X, ::brotensor::Tensor& Y); | ||
| 682 | void linear_forward_batched_int8w_fp16(const ::brotensor::Tensor& W_int8, const ::brotensor::Tensor& scales, | ||
| 683 | const ::brotensor::Tensor* bias, const ::brotensor::Tensor& X_BD, | ||
| 684 | ::brotensor::Tensor& Y_BD); | ||
| 685 | |||
| 686 | 190 | void register_cpu_nn_ops(::brotensor::detail::OpsVTable& ops) { | |
| 687 | // ── LSTM ── | ||
| 688 | 190 | ops.lstm_recurrence = &lstm_recurrence; | |
| 689 | 190 | ops.lstm_forward_train = &lstm_forward_train; | |
| 690 | 190 | ops.lstm_backward = &lstm_backward; | |
| 691 | |||
| 692 | // ── CHUNK 5 ── | ||
| 693 | 190 | ops.cross_attention_forward = &cross_attention_forward; | |
| 694 | 190 | ops.cross_attention_forward_with_attn | |
| 695 | 190 | = &cross_attention_forward_with_attn; | |
| 696 | 190 | ops.self_attention_forward_train = &self_attention_forward_train; | |
| 697 | 190 | ops.self_attention_backward = &self_attention_backward; | |
| 698 | 190 | ops.attention_token_moments = &attention_token_moments; | |
| 699 | 190 | ops.cross_attention_forward_train | |
| 700 | 190 | = &cross_attention_forward_train; | |
| 701 | 190 | ops.cross_attention_backward = &cross_attention_backward; | |
| 702 | |||
| 703 | // ── CHUNK 6 ── | ||
| 704 | 190 | ops.flash_attention_forward = &flash_attention_forward; | |
| 705 | 190 | ops.flash_attention_gqa_forward = &flash_attention_gqa_forward; | |
| 706 | 190 | ops.flash_attention_windowed_forward | |
| 707 | 190 | = &flash_attention_windowed_forward; | |
| 708 | 190 | ops.flash_attention_varlen_forward | |
| 709 | 190 | = &flash_attention_varlen_forward; | |
| 710 | 190 | ops.flash_attention_varlen_backward | |
| 711 | 190 | = &flash_attention_varlen_backward; | |
| 712 | 190 | ops.flash_attention_packed_qkv_forward | |
| 713 | 190 | = &flash_attention_packed_qkv_forward; | |
| 714 | 190 | ops.flash_attention_packed_qkv_backward | |
| 715 | 190 | = &flash_attention_packed_qkv_backward; | |
| 716 | 190 | ops.rope_qkv_packed_inplace = &rope_qkv_packed_inplace; | |
| 717 | 190 | ops.segment_softmax_stats = &segment_softmax_stats; | |
| 718 | 190 | ops.linear_forward_batched_ex = &linear_forward_batched_ex; | |
| 719 | 190 | ops.quantize_rows = &quantize_rows; | |
| 720 | 190 | ops.dequantize_rows = &dequantize_rows; | |
| 721 | 190 | ops.linear_forward_batched_wq_ex = &linear_forward_batched_wq_ex; | |
| 722 | 190 | ops.flash_attention_qkvo_forward = &flash_attention_qkvo_forward; | |
| 723 | 190 | ops.flash_attention_qkvo_backward | |
| 724 | 190 | = &flash_attention_qkvo_backward; | |
| 725 | 190 | ops.flash_attention_backward = &flash_attention_backward; | |
| 726 | 190 | ops.flash_attention_project_kv = &flash_attention_project_kv; | |
| 727 | 190 | ops.flash_attention_q_with_kv_cached_forward | |
| 728 | 190 | = &flash_attention_q_with_kv_cached_forward; | |
| 729 | 190 | ops.self_attention_forward = &self_attention_forward; | |
| 730 | 190 | ops.resblock_forward = &resblock_forward; | |
| 731 | 190 | ops.resblock_backward = &resblock_backward; | |
| 732 | |||
| 733 | // ── DiT / diffusion extras ── | ||
| 734 | 190 | ops.modulate = &modulate; | |
| 735 | 190 | ops.broadcast_mul = &broadcast_mul; | |
| 736 | 190 | ops.rope_apply = &rope_apply; | |
| 737 | 190 | ops.rope_apply_perhead = &rope_apply_perhead; | |
| 738 | 190 | ops.rope_apply_backward = &rope_apply_backward; | |
| 739 | 190 | ops.self_attention_bias_forward = &self_attention_bias_forward; | |
| 740 | 190 | ops.rel_pos_bias_xl_forward = &rel_pos_bias_xl_forward; | |
| 741 | 190 | ops.self_attention_decomposed_rel_pos_forward = | |
| 742 | &self_attention_decomposed_rel_pos_forward; | ||
| 743 | 190 | ops.self_attention_decomposed_rel_pos_windowed_forward = | |
| 744 | &self_attention_decomposed_rel_pos_windowed_forward; | ||
| 745 | |||
| 746 | // ── Spectral / FFT core (brosoundml) ── | ||
| 747 | 190 | ops.complex_mul = &complex_mul; | |
| 748 | 190 | ops.complex_mul_backward = &complex_mul_backward; | |
| 749 | 190 | ops.complex_abs = &complex_abs; | |
| 750 | 190 | ops.complex_abs_backward = &complex_abs_backward; | |
| 751 | 190 | ops.complex_angle = &complex_angle; | |
| 752 | 190 | ops.complex_from_polar = &complex_from_polar; | |
| 753 | 190 | ops.fft = &fft; | |
| 754 | 190 | ops.ifft = &ifft; | |
| 755 | 190 | ops.rfft = &rfft; | |
| 756 | 190 | ops.irfft = &irfft; | |
| 757 | 190 | ops.rfft_backward = &rfft_backward; | |
| 758 | 190 | ops.irfft_backward = &irfft_backward; | |
| 759 | |||
| 760 | // ── STFT / iSTFT (brosoundml) ── | ||
| 761 | 190 | ops.stft = &stft; | |
| 762 | 190 | ops.stft_backward = &stft_backward; | |
| 763 | 190 | ops.istft = &istft; | |
| 764 | 190 | ops.istft_backward = &istft_backward; | |
| 765 | |||
| 766 | // ── 1D convolution family (brosoundml) ── | ||
| 767 | 190 | ops.conv_transpose1d_forward = &conv_transpose1d_forward; | |
| 768 | 190 | ops.conv_transpose1d_backward_input | |
| 769 | 190 | = &conv_transpose1d_backward_input; | |
| 770 | 190 | ops.conv_transpose1d_backward_weight | |
| 771 | 190 | = &conv_transpose1d_backward_weight; | |
| 772 | 190 | ops.conv_transpose1d_backward_bias | |
| 773 | 190 | = &conv_transpose1d_backward_bias; | |
| 774 | 190 | ops.causal_conv1d_update = &causal_conv1d_update; | |
| 775 | 190 | ops.pad1d_forward = &pad1d_forward; | |
| 776 | 190 | ops.pad1d_backward = &pad1d_backward; | |
| 777 | |||
| 778 | // ── Vocoder / codec activations (brosoundml) ── | ||
| 779 | 190 | ops.snake_forward = &snake_forward; | |
| 780 | 190 | ops.snake_backward = &snake_backward; | |
| 781 | 190 | ops.elu_forward = &elu_forward; | |
| 782 | 190 | ops.elu_backward = &elu_backward; | |
| 783 | 190 | ops.leaky_relu_forward = &leaky_relu_forward; | |
| 784 | 190 | ops.leaky_relu_backward = &leaky_relu_backward; | |
| 785 | |||
| 786 | // ── Codec quantization (brosoundml) ── | ||
| 787 | 190 | ops.vq_encode_forward = &vq_encode_forward; | |
| 788 | 190 | ops.vq_encode_backward = &vq_encode_backward; | |
| 789 | 190 | ops.fsq_quantize_forward = &fsq_quantize_forward; | |
| 790 | 190 | ops.fsq_quantize_backward = &fsq_quantize_backward; | |
| 791 | |||
| 792 | // ── 1D resampling (brosoundml CHUNK 6, family E) ── | ||
| 793 | 190 | ops.resample1d_forward = &resample1d_forward; | |
| 794 | 190 | ops.resample1d_backward = &resample1d_backward; | |
| 795 | |||
| 796 | // ── log / exp / round elementwise (brosoundml CHUNK 6, family G) ── | ||
| 797 | 190 | ops.log_forward = &log_forward; | |
| 798 | 190 | ops.log_backward = &log_backward; | |
| 799 | 190 | ops.exp_forward = &exp_forward; | |
| 800 | 190 | ops.exp_backward = &exp_backward; | |
| 801 | 190 | ops.round_forward = &round_forward; | |
| 802 | 190 | ops.round_backward = &round_backward; | |
| 803 | |||
| 804 | // ── Autoregressive logit sampling (brosoundml CHUNK 7, family F) ── | ||
| 805 | 190 | ops.sample_logits = &sample_logits; | |
| 806 | 190 | ops.sample_logits_into = &sample_logits_into; | |
| 807 | |||
| 808 | // ── Masked-diffusion token selection ── | ||
| 809 | 190 | ops.masked_diffusion_scores = &masked_diffusion_scores; | |
| 810 | 190 | ops.masked_diffusion_commit = &masked_diffusion_commit; | |
| 811 | |||
| 812 | // ── Counter-based noise generation (Philox 4x32-10) ── | ||
| 813 | 190 | ops.randn = &randn; | |
| 814 | 190 | ops.sine_source_forward = &sine_source_forward; | |
| 815 | 190 | ops.rand_uniform = &rand_uniform; | |
| 816 | 190 | ops.rand_bernoulli = &rand_bernoulli; | |
| 817 | 190 | ops.randn_truncated = &randn_truncated; | |
| 818 | |||
| 819 | // ── L2 norm + Gated Delta Rule (linear-attention text path) ── | ||
| 820 | 190 | ops.l2_norm_forward = &l2_norm_forward; | |
| 821 | 190 | ops.l2_norm_backward = &l2_norm_backward; | |
| 822 | 190 | ops.gated_delta_rule_chunked = &gated_delta_rule_chunked; | |
| 823 | 190 | ops.gated_delta_rule_step = &gated_delta_rule_step; | |
| 824 | |||
| 825 | // ── Qwen3-VL polish: spatial_merge_2x2 + M-RoPE ── | ||
| 826 | 190 | ops.spatial_merge_2x2_forward = &spatial_merge_2x2_forward; | |
| 827 | 190 | ops.pixel_shuffle_upsample_2x_forward = &pixel_shuffle_upsample_2x_forward; | |
| 828 | 190 | ops.patch_unpack_forward = &patch_unpack_forward; | |
| 829 | 190 | ops.rope_apply_mrope = &rope_apply_mrope; | |
| 830 | |||
| 831 | // ── BatchNorm (vision backbones) ── | ||
| 832 | 190 | ops.batch_norm_forward = &batch_norm_forward; | |
| 833 | 190 | ops.batch_norm_inference = &batch_norm_inference; | |
| 834 | 190 | ops.batch_norm_backward = &batch_norm_backward; | |
| 835 | |||
| 836 | // ── Image preprocessing helpers ── | ||
| 837 | 190 | ops.image_normalize = &image_normalize; | |
| 838 | 190 | ops.image_u8_to_f32_nhwc_to_nchw = &image_u8_to_f32_nhwc_to_nchw; | |
| 839 | |||
| 840 | // ── StyleGAN3-R synthesis-input primitives ── | ||
| 841 | 190 | ops.sin_forward = &sin_forward; | |
| 842 | 190 | ops.sin_backward = &sin_backward; | |
| 843 | 190 | ops.cos_forward = &cos_forward; | |
| 844 | 190 | ops.cos_backward = &cos_backward; | |
| 845 | 190 | ops.rsqrt_forward = &rsqrt_forward; | |
| 846 | 190 | ops.rsqrt_backward = &rsqrt_backward; | |
| 847 | 190 | ops.pixel_norm_forward = &pixel_norm_forward; | |
| 848 | 190 | ops.pixel_norm_backward = &pixel_norm_backward; | |
| 849 | 190 | ops.bias_act_forward = &bias_act_forward; | |
| 850 | 190 | ops.bias_act_backward = &bias_act_backward; | |
| 851 | 190 | ops.upfirdn2d_forward = &upfirdn2d_forward; | |
| 852 | 190 | ops.upfirdn2d_backward = &upfirdn2d_backward; | |
| 853 | 190 | ops.modulated_conv2d_forward = &modulated_conv2d_forward; | |
| 854 | 190 | ops.modulated_conv2d_backward = &modulated_conv2d_backward; | |
| 855 | |||
| 856 | // ── Quantized linear forward & dequant (Q8_0, Q4_K, Q6_K & INT8) via Brass AVX2/FMA JIT ── | ||
| 857 | 190 | ops.dequant_q8_0_to_fp16 = &dequant_q8_0_to_fp16; | |
| 858 | 190 | ops.linear_forward_q8_0_fp16 = &linear_forward_q8_0_fp16; | |
| 859 | 190 | ops.linear_forward_batched_q8_0_fp16 = &linear_forward_batched_q8_0_fp16; | |
| 860 | 190 | ops.dequant_q4k_to_fp16 = &dequant_q4k_to_fp16; | |
| 861 | 190 | ops.linear_forward_q4k_fp16 = &linear_forward_q4k_fp16; | |
| 862 | 190 | ops.linear_forward_batched_q4k_fp16 = &linear_forward_batched_q4k_fp16; | |
| 863 | 190 | ops.dequant_q6k_to_fp16 = &dequant_q6k_to_fp16; | |
| 864 | 190 | ops.linear_forward_q6k_fp16 = &linear_forward_q6k_fp16; | |
| 865 | 190 | ops.linear_forward_batched_q6k_fp16 = &linear_forward_batched_q6k_fp16; | |
| 866 | 190 | ops.matmul_int8w_fp16 = &matmul_int8w_fp16; | |
| 867 | 190 | ops.linear_forward_batched_int8w_fp16 = &linear_forward_batched_int8w_fp16; | |
| 868 | 190 | } | |
| 869 | |||
| 870 | } // namespace brotensor::detail::cpu | ||
| 871 |