Skip to content

Warn when #[launch_bounds] can only be satisfied by spilling registers #708

Closed

Description

@nh13

What problem does this solve?

#[launch_bounds(max_threads, min_blocks_per_sm)] constrains the register allocator. When the requested occupancy is not achievable within the register budget, ptxas satisfies the bound by spilling — and the attribute then makes the kernel slower, silently. There is no compile-time signal; you find out by benchmarking.

We hit both outcomes from the same attribute with the same bound, on two kernels in one build:

kernel without with #[launch_bounds(256, 2)] delta spill after
A 4.346 / 4.359 s 3.925 / 3.940 s -0.42 s 0 bytes
B 5.268 / 5.274 s 6.803 / 6.799 s +1.53 s 24 bytes

Both kernels landed on exactly 128 registers and both had their PTX .maxntid/.minnctapersm directives verified. The occupancy argument for applying the attribute was identical for the two and predicted nothing. The only thing that separated them was ptxas -v's spill counter.

So the information that decides the outcome is already computed — it is just not surfaced anywhere a user of the attribute will see it.

Proposed API / behavior

Warn at build time when a #[launch_bounds] request results in nonzero spill stores/loads:

warning: `#[launch_bounds(256, 2)]` on `seed_intv_kernel` forced 24 bytes of register spill
   = note: the requested 2 blocks/SM needs <= 128 registers; the kernel wants more
   = help: relax min_blocks_per_sm, or reduce register pressure

Alternatives considered

Running ptxas -v and reading spill counters per kernel per configuration, which is what we now do, and which requires a toolkit install plus knowing to look. Benchmarking every kernel with and without the attribute, which is what we did first and which costs a build and a measurement per kernel.

Additional context

Companion to the local-memory-promotion diagnostic I am filing alongside this. Both are "the register allocator lost and only the assembler knows".

Activity

  1. added
    QoL-improvement
    codegen
    on Aug 8, 2026
  2. nihalpasham commented on Aug 11, 2026

    @nihalpasham
    Collaborator

    Implemented by #757 (merged 2026-08-05): ptxas resource reports are parsed on cubin-materialization builds and every #[launch_bounds] kernel that spills registers gets a warning at its definition span, with CUDA_OXIDE_NO_SPILL_WARN=1 as the measured-and-accepted escape hatch. The book section documenting the warning landed with #798.

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

    QoL-improvementcodegen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions