CPU Attention · Complete Calls, Shared Contractions, and Exponential Modes¶
On Xeon Platinum 8470Q (cores 0–7), Mojo and Weft lower @I.kernel and @I.program attention workloads through KIR and CPU (cpu@formed → cpu@tasked → cpu@buffers) using oneDNN BF16/FP16 BRGEMM microkernels and OpenMP/Weft task scheduling. Round-by-round quartiles are archived in cpu-attention-exp-modes.csv; full summary counts appear in the five-exit same-semantics scoreboard.
Inter-Member Shared Computation (flash_attention_backward)¶
| Complete Call on Xeon (ms, cores 0–7) | Mojo (Before → Shared / SDPA) | Weft (Before → Shared / SDPA) |
|---|---|---|
flash_attention_backward |
162.43 → 95.70 / 118.47 | 174.97 → 103.66 / 124.20 |
attention_unscaled_max |
23.54 → 23.87 / 31.65 | 28.79 → 28.94 / 32.36 |
alibi_attention |
29.95 → 31.88 / 60.21 | 30.35 → 32.70 / 60.58 |
Both CPU exits select an outer K/V loop over 256×256 tiles with 32 independent head tasks across 8 physical cores and private dQ accumulators:
- Shared
QKanddO·VᵀacrossdQ,dK,dV: RecomputingPanddSseparately across members required 7 GEMMs per causal block; sharing proven equivalent contractions in@I.programcomposition reduces this to 5 MKL/oneDNN GEMMs per causal block (5,760 calls total across 32 heads × 36 causal blocks). - Numerical verification: Measured against a same-input FP64 oracle, both
MojoandWeftachievedQ/dK/dVRMSE ratios of0.950,0.511, and0.483relative to fused ATen SDPA, passingdynamo_same(k=3, max_k=10)as well as non-finite mask boundary probes.
Exponential Contract (SLEEF u10 vs Licensed fexp_u20)¶
- Default (
I.exp(x)): Matches Inductor'sCppVecOverrides.exp(SLEEF u10, 1 ULP target) across both x86 AVX-512 and RISC-V RVV (SG2044). - Explicit weight approximation (
I.exp(x, approximate=True)): Attachesafnonly to the narrowed BF16/FP16 attention weight exponential while keeping online rescaling in ordinary FP32, matching ATen CPUFlashAttentionKernel'sfexp_u20polynomial contract (KIR numerical contracts). - Non-finite causal guard: Pre-packed V tiles inspect exponent bits during packing; if any
NaNor±Infis present, causal prefix truncation falls back to scanning the full K extent so IEEE0 * NaN = NaNpropagation matches the source specification.