__builtin_fmaf compiles to a call to libm fmaf; a * b + c gets an inline fmadd.s (1.9x on a matrix-vector kernel)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Verilog
- スター
- 2.4k
- フォーク
- 563
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 71
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
vortexgpgpu/vortex のほかの issue
-
RV64 signed DIV/REM restores the sign from bit 31対応中かも @zzf2024 が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
vortexgpgpu/vortex#501 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
fpu: sign-extend RV64 FCVT.WU positive overflow results対応中かも @zzf2024 が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
vortexgpgpu/vortex#499 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
WGMMA: the next kernel can compute with the previous kernel's B row left in the B buffer (rtlsim)対応中かも @youzi27 が 2 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
vortexgpgpu/vortex#558 ·
メンテナーはふだん 1 日以内に返信
-
WGMMA: a block-major B tile can read K-major data left in the B buffer (rtlsim)対応中かも @youzi27 が 5 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
vortexgpgpu/vortex#518 ·
メンテナーはふだん 1 日以内に返信
-
TFR tensor core with DSM drops an MXFP4/NVFP4 NaN block scale when its elements are masked対応中かも @youzi27 が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
vortexgpgpu/vortex#516 ·
メンテナーはふだん 1 日以内に返信
vortexgpgpu/vortex の issue をすべて見る
似ている issue
-
lfortran -E exits with status 0 after a C preprocessor error (#error, wrong macro argument count)オープンbug low priority preprocessor
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
area:codegen backend:slang bug direction:output
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
area:pp kind:task
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Inline raw HTML is escaped after an unclosed `_` / `*` / `~` (regression in 18.2.1)対応中かも @O1sumitkumar が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
quickjs-ng/quickjs#1972 ·
メンテナーはふだん 1 日以内に返信