[BUG] Constexpr missing in dynamic control-flow regions
Maintainers usually reply within 4 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start by tracing the AST preprocessor's handling of Constexpr parameter annotations and RegionAnalyzer.visit_Call(), using the reduced receiver.store example as the reproduction. The receiver of a Constexpr parameter should not be added to invoked_args or carried through the dynamic if; verify that the example lowers without the plain Python Meta value error.
Written by the indexing model from the issue text.
Description
Which component has the problem?
CuTe DSL
Bug Report
Motivation
I encountered this while implementing FlashAttention. The implementation naturally groups the load and MMA paths into JIT methods on a compile-time configuration object, and selects between them using the runtime warp index. A reduced version looks like this:
class FlashAttention:
@cute.jit
def load(self, tensor, pipeline):
...
@cute.jit
def mma(self, tensor, pipeline):
...
@cute.jit
def fa4_device_body(
fa: cutlass.Constexpr[FlashAttention],
tensor: cute.Tensor,
storage,
):
warp_idx = cute.arch.make_warp_uniform(cute.arch.warp_idx())
pipeline = make_pipeline(
storage=storage,
num_stages=fa.num_stages,
)
if warp_idx < 4:
cute.arch.setmaxregister_decrease(fa.num_producer_regs)
fa.load(tensor, pipeline)
else:
cute.arch.setmaxregister_increase(fa.num_mma_regs)
fa.mma(tensor, pipeline)
Here, self in FlashAttention.load() and FlashAttention.mma() is a compile-time method receiver. The fa parameter in fa4_device_body() refers to the same kind of compile-time object, made explicit by its Constexpr annotation.
Writing the device body as an actual instance method makes this code compile, but only because the compiler has a special case that excludes a receiver whose name is literally self. Passing the same object as a named Constexpr[FlashAttention] parameter should have equivalent staging semantics, but currently does not.
Problem
CuTe DSL treats Constexpr[T] parameters as compile-time Python meta values. They do not have an MLIR representation and must not become arguments or results of runtime control-flow regions.
However, when a method is called through a Constexpr receiver inside a dynamic if, the receiver is incorrectly captured as a region argument:
class Receiver:
@cute.jit
def store(self, output):
...
@cute.kernel
def kernel(receiver: cutlass.Constexpr[Receiver], output: cute.Tensor):
tidx, _, _ = cute.arch.thread_idx()
if tidx == Int32(0):
receiver.store(output)
The region analyzer currently treats the base object of every method call as a mutable runtime value, except when its name is literally self.
Consequently, receiver is added to the values carried through the dynamic if. Lowering then attempts to flatten the plain Python Receiver instance into MLIR values and fails with:
error[TYPE_DYNAMIC_EXPR_UNSUPPORTED]:
A value carried through this `if` is a plain Python value (Meta value)
(a `Receiver`) that cannot be turned into a Runtime value (Staged value)
This means self.method() works because of the existing self special case, while an explicitly annotated receiver: Constexpr[Receiver] does not, despite having the same staging semantics.
Root cause
Constexpr is a property of the original function parameter binding. The AST preprocessor removes parameter annotations while transforming the function, so the later control-flow region analysis no longer knows which names refer to Constexpr parameters.
RegionAnalyzer.visit_Call() therefore sees only a method call on a Python object and adds its receiver to invoked_args.
- Dominant language
- C++
- Stars
- 10.7k
- Forks
- 2.2k
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/cutlass
-
[Bug][CuTeDSL][Fuzz] `utils.gemm.sm100.epilogue` releases the accumulator before `tcgen05.ld` completes: no `tcgen05.wait::ld` before the arrive that lets the next MMA overwrite TMEMPossibly taken @0z5a claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 4 days
-
? - Needs Triage question
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NVIDIA/cutlass#3796 · 1 comment · 1 reaction ·
Maintainers usually reply within 4 days
-
[DOC] IKET quick start omits the GEMM GPU requirement and references a missing examplePossibly taken @0z5a claimed this 11 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 82/100
NVIDIA/cutlass#3761 · 1 comment ·
Maintainers usually reply within 4 days
-
[BUG] CuTe DSL from_dlpack rejects float8_e4m3fn tensors (dtype_map lists Float8E5M2 only)Possibly taken @Ammar-Alnagar claimed this 21 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cutlass#3716 · 1 comment ·
Maintainers usually reply within 4 days
-
EllGemm ColumnMajor-output workspace sizing uses the unswapped problem shape and undersizes split-K semaphoresPossibly taken @XFDG claimed this 49 days ago. OpenCUTLASS C++
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NVIDIA/cutlass#3539 · 2 comments ·
Maintainers usually reply within 4 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Sendspin/sendspin-cpp-cli#111 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
scp-fs2open/fs2open.github.com#7984 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jellyfin/jellyfin-desktop#1290 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
nasa/fprime#6301 · 1 comment ·
Maintainers usually reply within 1 day