Skip to content

SPIR-V SubgroupReduce generates reduction code for a subgroup size it does not require from Vulkan #25248

Open

Description

@flyingdoog

What happened?

The SPIR-V/Vulkan SubgroupReduce pipeline generates reduction code using the smallest subgroup size in the target configuration, but does not record that size in translation_info. The runtime therefore does not require that size when creating the Vulkan pipeline. When the driver uses a different subgroup size, the tested reductions return incorrect values with exit code 0.

Each thread reads four floats. The generated code uses its assumed subgroup width to decide which invocations write partial sums. A different actual subgroup width can duplicate a partial sum or omit the contribution of an actual subgroup.

On an NVIDIA RTX PRO 6000 Blackwell with a fixed subgroup size of 32, the recorded results were:

--iree-vulkan-target Subgroup sizes in the compiler target configuration N Each of the eight output values Expected value per output
sm_120 32 4096 4096 4096
rdna3 32, 64 4096 4096 4096
adreno 64 4096 2048 4096
valhall 16 1024 2048 1024

The device dump reports subgroup: size=32 ... minSubgroupSize=32 maxSubgroupSize=32 and subgroupSizeControl=yes. The driver is 590.44.01, Vulkan 1.4.325. IREE package release 3.13.0 and nightly 3.14.0rc20261108 give the same results.

These are cross-target runs. On this GPU, the adreno and valhall target configurations make the assumed size differ from the actual size. The rdna3 configuration assumes 32, which matches this GPU.

Under the Khronos validation layer, the adreno case still returns 2048 and produces no subgroup-related message. That run does report a separate VUID-VkShaderModuleCreateInfo-pCode-08737 about NoSignedWrap requiring SPV_KHR_no_integer_wrap_decoration. No required subgroup size was requested.

Source analysis

The code analysis is pinned to main 99f547bc5e88202d6415336d576f90a54a145493.

  • The dynamic and static SubgroupReduce paths in KernelConfig.cpp construct translation_info without the subgroup size used for configuration. The cooperative-matrix path does pass a size. Dynamic SubgroupReduce path, static SubgroupReduce path, cooperative-matrix path
  • The reduction configuration obtains its subgroup size from target.getPreferredSubgroupSize(), which chooses the smallest size in the target configuration. The comment above this choice says the Vulkan side is forced to 32, but the size is used for code generation without being recorded as a requirement. KernelConfig.cpp, IREEGPUAttrs.td
  • VulkanSPIRVTarget.cpp writes 0 to the executable's subgroup-size field when the ABI has no size. The schema defines 0 as unspecified. VulkanSPIRVTarget.cpp, schema
  • The runtime chains VkPipelineShaderStageRequiredSubgroupSizeCreateInfo only when that field is nonzero. executable.c

The same root cause is described in #25021, which is closed and was not merged. This report concerns the incorrect reduction results.

RDNA hypothesis

No AMD hardware was used. Compiler-only scans for rdna1 through rdna4, gfx1100, and gfx1201 at N=4096 and N=1024 recorded selection of SubgroupReduce and translation_info without subgroup_size.

Among these RDNA cases, generated SPIR-V dialect code was inspected only for rdna3 at N=4096. It contains UDiv and UMod by 32 and has no spirv.entry_point_abi specifying a subgroup size. For the other scanned RDNA cases, the assumed width of 32 is inferred from the preferred-size rule and the target configurations.

The RADV source analysis is pinned to Mesa commit 2a0c112adb43d2a3669cce44949e998a53ab7503. radv_physical_device.c initializes cs_wave_size = 64. On GFX10 and newer, enabling the cswave32 performance-test flag changes it to 32. In radv_shader_choose_subgroup_size, the compute default comes from cs_wave_size. The small-workgroup branch chooses wave32 for at most 32 invocations, while larger workgroups use the default or the full-subgroup branch. With the default of 64, the generated rdna3 N=4096 kernel is therefore expected to use wave64 when no size is required. Default wave size, compute default, workgroup-size selection

For the generated rdna3 N=4096 kernel, if the driver actually selects wave64, the predicted output is 8192 per row. Each wave sums 64 threads times four input values, giving 256. The code assumes 32-wide subgroups, so two invocations per actual wave write that same partial sum. There are 32 stored partials, giving 32 times 256 = 8192 instead of 4096.

8192 is a prediction for this N=4096 case, not an AMD measurement. The AMD proprietary driver, AMDVLK, and Windows driver subgroup choices were not checked.

Steps to reproduce your issue

The commands below use the released tools. For the recorded release version:

python -m venv venv
. venv/bin/activate
python -m pip install iree-base-compiler==3.13.0 iree-base-runtime==3.13.0
iree-compile --version
iree-run-module --dump_devices=vulkan

Save this as rowsum_4096.mlir:

func.func @rowsum(%arg0: tensor<8x4096xf32>) -> tensor<8xf32> {
  %cst = arith.constant 0.0 : f32
  %init = tensor.empty() : tensor<8xf32>
  %fill = linalg.fill ins(%cst : f32) outs(%init : tensor<8xf32>) -> tensor<8xf32>
  %r = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0)>], iterator_types = ["parallel", "reduction"]} ins(%arg0 : tensor<8x4096xf32>) outs(%fill : tensor<8xf32>) {
  ^bb0(%in: f32, %out: f32):
    %a = arith.addf %in, %out : f32
    linalg.yield %a : f32
  } -> tensor<8xf32>
  return %r : tensor<8xf32>
}

Compile for adreno and run on the fixed-32 NVIDIA GPU:

iree-compile rowsum_4096.mlir \
  --iree-hal-target-device=vulkan --iree-vulkan-target=adreno \
  -o rowsum_4096_adreno.vmfb
iree-run-module --device=vulkan --module=rowsum_4096_adreno.vmfb \
  --function=rowsum --input=8x4096xf32=1
echo "exit=$?"

Actual output:

8xf32=2048 2048 2048 2048 2048 2048 2048 2048

The exit code is 0. With --iree-vulkan-target=sm_120, the eight values are all 4096. If the machine has multiple GPUs, select the NVIDIA device URI printed by --dump_devices=vulkan instead of the default --device=vulkan.

Experiment: record subgroup_size in compiler IR and resume compilation

This experiment edits the intermediate compiler configuration produced by the released compiler, then resumes compilation from executable-configurations.

Save this helper as record_subgroup_size.py. It requires exactly one matching SubgroupReduce configuration and fails if the expected unrecorded configuration is absent.

import re
import sys
from pathlib import Path


source, destination, size_text = sys.argv[1:]
size = int(size_text)
text = Path(source).read_text()
pattern = (
    r"(translation_info<pipeline = "
    r"#iree_gpu\.spirv_pipeline<SubgroupReduce> "
    r"workgroup_size = \[[0-9, ]+\])>"
)
updated, count = re.subn(
    pattern, lambda match: f"{match[1]} subgroup_size = {size}>", text
)
if count != 1:
    raise SystemExit(f"Expected one unrecorded SubgroupReduce config, found {count}")
Path(destination).write_text(updated)

For the valhall case, create the 1024-column version of the same input:

sed 's/4096/1024/g' rowsum_4096.mlir > rowsum_1024.mlir

Run the following with target=adreno, n=4096, and size=64:

target=adreno
n=4096
size=64
stem="rowsum_${n}_$target"

iree-compile "rowsum_$n.mlir" \
  --iree-hal-target-device=vulkan --iree-vulkan-target="$target" \
  --compile-to=executable-configurations -o "$stem.cfg.mlir"

python record_subgroup_size.py \
  "$stem.cfg.mlir" "$stem.required.cfg.mlir" "$size"

grep 'translation_info' "$stem.required.cfg.mlir"

iree-compile --compile-from=executable-configurations \
  "$stem.required.cfg.mlir" -o "$stem.required.vmfb"

iree-run-module --device=vulkan --module="$stem.required.vmfb" \
  --function=rowsum --input="8x${n}xf32=1"
echo "exit=$?"

This writes subgroup_size = 64 into translation_info. On the recorded NVIDIA device, loading the resulting module fails with:

requires subgroup size 64 outside device range [32, 32]

The recorded exit code is 1. The same commands can be repeated with these parameter combinations:

target n size written into translation_info Recorded result on the fixed-32 NVIDIA GPU
sm_120 4096 32 Eight values of 4096, exit 0
rdna3 4096 32 Eight values of 4096, exit 0
adreno 4096 64 Load error, requires size 64 outside [32, 32], exit 1
valhall 1024 16 Load error, requires size 16 outside [32, 32], exit 1

In the recorded SPIR-V dialect comparison, only two attribute lines changed per target: the export gained a subgroup size and the function gained spirv.entry_point_abi with that size. The generated shader operations were unchanged.

What component(s) does this issue relate to?

Compiler

Version information

  • Release package version: iree-base-compiler and iree-base-runtime 3.13.0.
  • Release iree-compile --version: 3.13.0rc20261016 @ 89ece87b89852100c0a4ac3d515e14842d090967.
  • Nightly: 3.14.0rc20261108 @ 9b906db8e3930074b62ea5deb9e5623eb6a60cae, with the same recorded results.
  • Source analysis: main 99f547bc5e88202d6415336d576f90a54a145493.
  • GPU: NVIDIA RTX PRO 6000 Blackwell Server Edition, driver 590.44.01, Vulkan 1.4.325, Linux x86_64.
  • Device properties: subgroup size 32, minSubgroupSize 32, maxSubgroupSize 32, subgroupSizeControl enabled.
  • Khronos validation layer from Vulkan SDK 1.4.363.0.

Additional context

Recording the subgroup size turns the tested mismatched cross-target runs into explicit load errors. Recording a size only when the compiler target lists multiple valid sizes would leave the adreno and valhall cross-target cases unchanged.

There is also a compatibility tradeoff. The current runtime rejects any nonzero required size when subgroupSizeControl is not enabled, even if the device's actual subgroup width would otherwise match. It also checks the device range and compute-stage support for required subgroup sizes. Runtime checks

Should SubgroupReduce always record the size it assumes, or record it only for targets with multiple valid sizes as proposed in #25021? How should the single-size case interact with devices where subgroupSizeControl is unavailable?

The MLIR reproducers and source analysis were prepared with AI assistance, including Claude Code and Codex. The original experiment commands also used AI assistance. Reported run results and quoted command output come from recorded tool runs. The RDNA/RADV result is a conditional source-based prediction. During this report's preparation, the new metadata-editing helper was checked against a captured configuration line for sizes 32, 64, and 16, and the companion shell script was syntax-checked. The revised helper and command presentation were not rerun through IREE compilation or GPU execution.

Activity

  1. github-actions commented on Nov 11, 2026

    @github-actions

    Hello @flyingdoog 👋

    Thank you for submitting an issue to IREE! It looks like it's your first one.

    The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there.
    Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them below.


    Action required: acknowledge IREE project policies

    IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.

    Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:

    • Issue reporters must fully understand the primary issue and the impact of the problem.
      For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
      For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
    • Contributors must write the summary of the issue themselves, so that the exact impact and scenario is clear to other participants.
    • Issue authors are expected to review and understand all LLM/AI-assisted segments of the report, if any. E.g.: CLI commands and IR reproducers, model/framework details, lowering pipeline details, assumptions about problematic behaviors of IREE components.
    • Substantial use of LLM/generative AI tools must be disclaimed in the header or footer of the issue description.

    Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.


    If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.

    Thank you,
    The IREE Community

  2. flyingdoog commented on Nov 11, 2026

    @flyingdoog
    Author

    I confirm that I understand and accept the proposed policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions