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

Open
opened 2026-11-07 16:34:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5062
Author: @slyfox1186
Created: 11/3/2026
Status: 🔄 Open

Base: main ← Head: fix-rows-tsum-unreachable


📝 Commits (1)

  • 9d7312b [Engine] put the fallback after an exiting if constexpr branch in its else

📊 Changes

5 files changed (+19 additions, -19 deletions)

View changed files

📝 src/kernels/cuda/dflash2.cu (+3 -3)
📝 src/kernels/cuda/fused_gr.cu (+2 -2)
📝 src/kernels/cuda/iq_kernels.cu (+10 -10)
📝 src/kernels/cuda/native_bf16.cu (+2 -2)
📝 src/kernels/cuda/native_mmvq.cu (+2 -2)

📄 Description

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.

#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:

  • Warning count before: replaying each of the build's 83 CUDA compile commands on ffa80d73 gives 208 #128-D
    warnings, all at these nine places (fused_gr 16, native_mmvq 147, native_bf16 32, iq_kernels 11, dflash2 2).
  • Warning count after: compiling the five changed files with the same command lines exits 0 and prints no #128-D.
    The other warnings in those files are unchanged (#550 dflash2.cu:775, #20199 iq_kernels.cu:3840, #20058
    iq_kernels.cu:5583).
  • Generated code: cuobjdump -sass of each object before and after (anonymous-namespace names normalized, since
    they 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:

  • 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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5062 **Author:** [@slyfox1186](https://github.com/slyfox1186) **Created:** 11/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-rows-tsum-unreachable` --- ### 📝 Commits (1) - [`9d7312b`](https://github.com/Niko1221/Strata/commit/9d7312bd44ea262d9ce3241bae849a552a56ff54) [Engine] put the fallback after an exiting if constexpr branch in its else ### 📊 Changes **5 files changed** (+19 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/cuda/dflash2.cu` (+3 -3) 📝 `src/kernels/cuda/fused_gr.cu` (+2 -2) 📝 `src/kernels/cuda/iq_kernels.cu` (+10 -10) 📝 `src/kernels/cuda/native_bf16.cu` (+2 -2) 📝 `src/kernels/cuda/native_mmvq.cu` (+2 -2) </details> ### 📄 Description ## 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:** - Warning count before: replaying each of the build's 83 CUDA compile commands on `ffa80d73` gives 208 #128-D warnings, all at these nine places (fused_gr 16, native_mmvq 147, native_bf16 32, iq_kernels 11, dflash2 2). - Warning count after: compiling the five changed files with the same command lines exits 0 and prints no #128-D. The other warnings in those files are unchanged (#550 `dflash2.cu:775`, #20199 `iq_kernels.cu:3840`, #20058 `iq_kernels.cu:5583`). - Generated code: `cuobjdump -sass` of each object before and after (anonymous-namespace names normalized, since they 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:** - 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5301
No description provided.