Repository navigation
[Engine] put the fallback after an exiting if constexpr branch in its else - #5062
Draft
slyfox1186 wants to merge 1 commit into
Draft
slyfox1186 wants to merge 1 commit into
slyfox1186 wants to merge 1 commit into
Conversation
… else nvcc printed warning Niko1221#128-D "loop is not reachable" 208 times per build (issue Niko1221#1585). Nine kernels end an `if constexpr` branch with `return` or `continue` and then run their plain path after it, so in every instantiation that takes the branch the plain path is dead code: - native_bf16.cu bf16_f32_mmvf_rows_kernel (TS) - native_mmvq.cu native_mmvq_multi_kernel (TS) - fused_gr.cu gr_down_v3_kernel (RB && R2V > 1) - iq_kernels.cu s26_gu_l_kernel, s26_down_l_kernel, s27_gu_kernel, s27_down_kernel (TS) and native_gu_lds_kernel (TI) - dflash2.cu gemm8_kernel (!COMPUTE, which was a plain if on the template parameter and is now if constexpr) Each plain path now sits in the branch's else, so it is no longer instantiated where it cannot run. The bodies keep their indentation, as native_bf16.cu's wrapped plain loop does, so the diff is only the branch structure. The generated code is unchanged: every kernel in the five objects compiles to the same SASS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
A CUDA build prints nvcc warning #128-D "loop is not reachable" 208 times (reported in #1585, which was closed in the
three-day sweep and still reproduces on
ffa80d73). Nine kernels end anif constexprbranch withreturnorcontinueand run their plain path after it. In every instantiation that takes the branch, the plain path is deadcode, and nvcc warns once per instantiation:
native_bf16.cubf16_f32_mmvf_rows_kernelTSnative_mmvq.cunative_mmvq_multi_kernelTSfused_gr.cugr_down_v3_kernelRB && R2V > 1iq_kernels.cus26_gu_l_kernel,s26_down_l_kernel,s27_gu_kernel,s27_down_kernelTSiq_kernels.cunative_gu_lds_kernelTIdflash2.cugemm8_kernel!COMPUTEAfter this change the same build prints no #128-D, and the generated code is unchanged.
Related discussion
#1585 (closed by the stale sweep, not fixed). This is a focused fix with no change in behavior.
Approach
Each plain path moves into the branch's
else, so it is no longer instantiated where it cannot run. Thereturnorcontinuethat ended the branch goes away, because theelsenow reaches the same end of the function or loopbody.
gemm8_kerneltested its template parameter with a plainif (!COMPUTE); that becomesif constexpr.The bodies keep their indentation, the way
native_bf16.cualready wraps its plain loop at lines 182-196, so the diffis only the branch structure: 19 lines in 5 files, identical with
git diff -w.Validation
Linux x86-64, RTX 4090 (sm_89), CUDA 13.4.92, host GCC 15.2.0, the engine build's own nvcc command lines
(
-O3 --use_fast_math --generate-code=arch=compute_89,code=[compute_89,sm_89]) onffa80d73.Passed:
ffa80d73gives 208 --gpus with mixed architectures fails: engine not rebuilt when adding a GPU with a different compute capability #128-Dwarnings, all at these nine places (fused_gr 16, native_mmvq 147, native_bf16 32, iq_kernels 11, dflash2 2).
The other warnings in those files are unchanged (generate: residency-table uploads wait for their own copy before the non-blocking streams read the table #550
dflash2.cu:775, #20199iq_kernels.cu:3840, #20058iq_kernels.cu:5583).cuobjdump -sassof each object before and after (anonymous-namespace names normalized, sincethey hash the source path) is byte-identical for all 1917 kernels: native_bf16 128, native_mmvq 1005,
fused_gr 211, dflash2 83, iq_kernels 490.
Failed:
none observed
Not run:
backend-specific code, but I have no AMD or Intel GPU toolchain here to compile it.
Limits
Only #128-D is addressed. The build's other warnings (#63 shift count in
qsa_select.cu:2501, #20280 ins2_expert_grouped.cu, #611, #550, #20199, #20058) are separate problems.