[CuTeDSL] Make @cute.struct instances flattenable across scf.if / scf.while#3270
Open
cheshire wants to merge 1 commit into
Open
[CuTeDSL] Make @cute.struct instances flattenable across scf.if / scf.while#3270cheshire wants to merge 1 commit into
cheshire wants to merge 1 commit into
Conversation
….while Fixes NVIDIA#3268 A `@cute.struct` instance captured into an `scf.if` branch or `scf.while` body fails the DSL trace with: DSLRuntimeError: The 'if' statement encountered a user-defined Python object, which cannot be automatically converted into an dynamic expression. This blocks the natural warp-specialization pattern, where each `if warp_idx == <role>:` branch reads its tile from a shared storage struct. A struct instance is fully described by its `base` pointer (already DynamicExpression-aware via `_Pointer`); every field instance is re-derived from `base + static offsets` on construction. Implement the DynamicExpression protocol on each decorated class by forwarding `__get_mlir_types__` / `__extract_mlir_values__` to `base`, and `__new_from_mlir_values__` to a fresh decorator invocation that re-derives the fields from a rebuilt base pointer. Tested in Docker on cutlass-dsl 4.5.1 with six new unit tests in test/python/CuTeDSL/test_struct_in_if.py covering: * the original failing case (storage.get_tensor inside dynamic if), * regression: plain non-branched struct usage still works, * nested struct (struct-of-struct) inside a dynamic if, * if/else with both branches accessing the struct, * if/elif/elif/else (the actual warp-specialization shape), * scf.while body capturing the struct.
|
LGTM @grypp to double check |
grypp
approved these changes
May 27, 2026
Contributor
grypp
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks for contributing
|
|
||
|
|
||
| @cute.struct | ||
| class _Outer: |
Contributor
There was a problem hiding this comment.
we could add a test with union as well.
There was a problem hiding this comment.
I'll add one when landing this internally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3268
A
@cute.structinstance captured into anscf.ifbranch orscf.whilebody fails the DSL trace with:This blocks the natural warp-specialization pattern, where each
if warp_idx == <role>:branch reads its tile from a shared storage struct.A struct instance is fully described by its
basepointer (already DynamicExpression-aware via_Pointer); every field instance is re-derived frombase + static offsetson construction. Implement the DynamicExpression protocol on each decorated class by forwarding__get_mlir_types__/__extract_mlir_values__tobase, and__new_from_mlir_values__to a fresh decorator invocation that re-derives the fields from a rebuilt base pointer.