__builtin_fmaf compiles to a call to libm fmaf; a * b + c gets an inline fmadd.s (1.9x on a matrix-vector kernel)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start with the Vortex LLVM lowering of __builtin_fmaf and llvm.fma.f32, then reproduce with the supplied RISC-V target and kernel flags. Inspect the FMA-related cases in tests/regression/flash_attn and compare flash_attn_tcu_wg. Done means the intended fused semantics are confirmed and the lowering produces the expected inline fmadd.s without changing results.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What
__builtin_fmaf becomes a tail call to libm's fmaf, and libm's fmaf is itself just fmadd.s plus ret. The plain expression a * b + c is contracted to an inline fmadd.s.
This is with the Vortex LLVM (clang 20.1.8, vortexgpgpu/llvm f44a6bb) and the kernel flags the regression tests use: --target=riscv32-unknown-elf -march=rv32imaf -mabi=ilp32f -O3 -Xclang -target-feature -Xclang +xvortex ....
float f_builtin(float a, float b, float c) { return __builtin_fmaf(a, b, c); }
float f_contract(float a, float b, float c) { return a * b + c; }
<_Z9f_builtinfff>:
auipc t1, 0x0 R_RISCV_CALL_PLT fmaf
jr t1
<_Z10f_contractfff>:
fmadd.s fa0, fa0, fa1, fa2
ret
Cost
Inside a loop, each fused multiply-add becomes a call, a return and register moves. The loop's FMA results also funnel through fa0.
Measured on a bf16 matrix-vector kernel (one core, 32 threads × 8 warps, SimX, a 3072 × 576 product) after replacing __builtin_fmaf with an inline-asm fmadd.s:
- cycles: 1,691,965 → 880,889 (1.92×);
- instructions: about 702k → 425k per product;
- results: identical.
In the tree
tests/regression/flash_attnwith #520 has 27 calls tofmaf, from the software exp's polynomial. We can switch #520'sexpf_fasttoa * b + cif you'd like.flash_attn_tcu_wghas none.
Question
Is the libcall intended?
Upstream RISC-V LLVM lowers llvm.fma.f32 to fmadd.s when the F extension is present. If Vortex's fmadd.s is an IEEE fused multiply-add, doing the same here would speed up every kernel that calls fmaf or __builtin_fmaf. If it isn't exactly fused, that would explain the libcall, but then a * b + c contracting to it is the case to check.
🤖 Generated with Claude Code
- Lingua principale
- Verilog
- Stelle
- 2.4k
- Fork
- 563
- Merge medio
- 1g 7h
- PR unite (30g)
- 71
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vortexgpgpu/vortex
-
RV64 signed DIV/REM restores the sign from bit 31Forse già presa @zzf2024 l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
vortexgpgpu/vortex#501 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
fpu: sign-extend RV64 FCVT.WU positive overflow resultsForse già presa @zzf2024 l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
vortexgpgpu/vortex#499 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
WGMMA: the next kernel can compute with the previous kernel's B row left in the B buffer (rtlsim)Forse già presa @youzi27 l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
vortexgpgpu/vortex#558 ·
I maintainer di solito rispondono entro 1 giorno
-
WGMMA: a block-major B tile can read K-major data left in the B buffer (rtlsim)Forse già presa @youzi27 l’ha presa 5 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
vortexgpgpu/vortex#518 ·
I maintainer di solito rispondono entro 1 giorno
-
TFR tensor core with DSM drops an MXFP4/NVFP4 NaN block scale when its elements are maskedForse già presa @youzi27 l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
vortexgpgpu/vortex#516 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di vortexgpgpu/vortex
Issue simili
-
lfortran -E exits with status 0 after a C preprocessor error (#error, wrong macro argument count)Apertabug low priority preprocessor
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
area:codegen backend:slang bug direction:output
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area:pp kind:task
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Inline raw HTML is escaped after an unclosed `_` / `*` / `~` (regression in 18.2.1)Forse già presa @O1sumitkumar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
quickjs-ng/quickjs#1972 ·
I maintainer di solito rispondono entro 1 giorno