mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5100] [Engine] nvcc ignores #pragma clang fp contract(off), so native_moe.cu gates the shared expert with a contracted multiply #2382
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2382
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ackalker on GitHub (Nov 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5100
Area
Engine
Desktop app, Terminal or source?
Source (START-HERE.bat, setup.sh or a build) — a build from
./update.shWhat happened
The engine source says, in three places, that a multiply must be rounded on its own and must not fuse into an
addition, and it asks for that with
#pragma clang fp contract(off). nvcc does not know that pragma: it printswarning #20199-D: unrecognized #pragma in device codefor the two sites it happens to warn about, and it keepscontraction on. In
native_moe.cuthe product is contracted, so the gated shared-expert combine does not round theway its comment says it does.
The two warnings in today's build:
Five places use this pragma. Two of them handle it correctly, and the house pattern is already there:
src/kernels/cuda/iq_kernels.cu:2853-2855and:2883-2885wrap it in#if defined(__HIPCC__)(so it only reachesthe HIP/clang compiler that understands it), and for CUDA they round by hand:
iq_kernels.cu:2863const float h = __fmul_rn(g / (1.0f + __expf(-g)), up[i]);src/kernels/cuda/native_moe.cu:58,src/kernels/cuda/verify_kernels.cu:305,src/kernels/cuda/iq_kernels.cu:3840native_moe.cu:56-61is the one where I can show what nvcc did:src/kernels/cuda/native_moe.cu:35-37says this must matchshared_expert_multi: "one rounded multiply =scale_rows_kernel'sout *= g, then added as before".What I measured (my machine, not the model)
The pragma changes nothing under nvcc. Two copies of the
native_moe.cu:56-64arithmetic, one with the pragmaand one without,
nvcc 13.4 -arch=sm_120 -ptx: the arithmetic instructions are identical, and both containfma.rn.f32. nvcc printed#20199-Dfor the file that had the pragma.The built object has the fused form.
cuobjdump -sassof the object this build produced,build/CMakeFiles/strata_kernels.dir/src/kernels/cuda/native_moe.cu.o, function...combineILb1ELb1EEvPKfS4_S4_PfliS4_(combine<true, true>, i.e.GATED=true), the end of the gated block:R10is the sigmoid (EX2+RCPof1 + exp),R35is the runningsum, so the last line issum = fma(shared[col], g, sum): one rounding, not the multiply-then-add the comment asks for.The in-house fix works. The same snippet with
__fmul_rn(shared[col], g)instead of*givesmul.f32and a separateadd.f32, nofma.Smallest steps that reproduce it
Reproduction status
Reproduced locally (the compilation and the disassembly). What I did not test: I did not run a model, so I have
no bitwise A/B of
STRATA_LFUSE=1against the separatescale_rows+ add path, and I cannot say how many outputsdiffer or whether any check in the repo already catches it. At the other two sites
(
verify_kernels.cu:305,iq_kernels.cu:3840) I ran the same kind of snippet copy and nvcc 13.4 did not fuse theproduct there, so today those two look harmless — the missing
#if defined(__HIPCC__)guard there is latent, not ameasured difference. Marking the whole thing "measured for
native_moe.cuonly".Suggested smallest fix
Use the pattern
iq_kernels.cualready uses (iq_kernels.cu:2863):__fmul_rnfor the product at the three unguarded sites (and#if defined(__HIPCC__)around the pragma so the HIP build still gets it). Two build notes:CMakeLists.txt:666-670already does thesame thing for HIP with
-ffp-contract=off("Keep Q8_K's multiply and magic-bias rounding as separate FP32operations on HIP; contraction to an FMA changes tie results"). There is no CUDA equivalent anywhere in the build,
and
-fmad=falsewould change every other expression in those files, so I would not go that way.CMakeLists.txt:651-665puts--use_fast_mathonsrc/kernels/cuda/native_moe.cu(and 14 othernative_*.cufiles) for CUDA. nvcc documents--use_fast_mathas implying--fmad=true, so for that filecontraction is switched on by a flag as well as by the default. The flag part is from the nvcc documentation, not
measured: my probe had contraction on with and without the flag.
Strata version
Strata 0.2.10 · engine 0.1.56 · source checkout at
ffa80d73(the pinned llama.cpp isffa80d73, ggml 0.24.0)Graphics card, memory and system
RTX 5080 16 GB · 96 GB RAM · Linux (Arch), gcc 16.2.1, CMake 4.4.3, ninja 1.13.2, CUDA/nvcc 13.4
(
-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120)@github-actions[bot] commented on GitHub (Nov 3, 2026):
Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:
Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment
/reopen.Details: CONTRIBUTING.md
@github-actions[bot] commented on GitHub (Nov 3, 2026):
Thanks, this follows the format now.