Skip to content

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 QK and dO·Vᵀ across dQ, dK, dV: Recomputing P and dS separately across members required 7 GEMMs per causal block; sharing proven equivalent contractions in @I.program composition 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 Mojo and Weft achieve dQ / dK / dV RMSE ratios of 0.950, 0.511, and 0.483 relative to fused ATen SDPA, passing dynamo_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's CppVecOverrides.exp (SLEEF u10, 1 ULP target) across both x86 AVX-512 and RISC-V RVV (SG2044).
  • Explicit weight approximation (I.exp(x, approximate=True)): Attaches afn only to the narrowed BF16/FP16 attention weight exponential while keeping online rescaling in ordinary FP32, matching ATen CPU FlashAttentionKernel's fexp_u20 polynomial contract (KIR numerical contracts).
  • Non-finite causal guard: Pre-packed V tiles inspect exponent bits during packing; if any NaN or ±Inf is present, causal prefix truncation falls back to scanning the full K extent so IEEE 0 * NaN = NaN propagation matches the source specification.