Skip to content

[Engine] put the fallback after an exiting if constexpr branch in its else - #5062

Draft
slyfox1186 wants to merge 1 commit into
Niko1221:mainfrom
slyfox1186:fix-rows-tsum-unreachable
Draft

slyfox1186 wants to merge 1 commit into
Niko1221:mainfrom
slyfox1186:fix-rows-tsum-unreachable

Conversation

@slyfox1186

Copy link
Copy Markdown

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 an if constexpr branch with return or
continue and run their plain path after it. In every instantiation that takes the branch, the plain path is dead
code, and nvcc warns once per instantiation:

File Kernel Branch
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
iq_kernels.cu native_gu_lds_kernel TI
dflash2.cu gemm8_kernel !COMPUTE

After 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. The return or
continue that ended the branch goes away, because the else now reaches the same end of the function or loop
body. gemm8_kernel tested its template parameter with a plain if (!COMPUTE); that becomes if constexpr.

The bodies keep their indentation, the way native_bf16.cu already wraps its plain loop at lines 182-196, so the diff
is 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]) on ffa80d73.

Passed:

Failed:
none observed

Not run:

  • HIP, SYCL and Metal builds. The change is plain C++17 control flow inside device templates, with no
    backend-specific code, but I have no AMD or Intel GPU toolchain here to compile it.
  • Hardware execution. Identical SASS means the sm_89 kernels are the same instructions as before.

Limits

Only #128-D is addressed. The build's other warnings (#63 shift count in qsa_select.cu:2501, #20280 in
s2_expert_grouped.cu, #611, #550, #20199, #20058) are separate problems.

… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant