Skip to content

[JIT] Actionable diagnostic for dynamic layout field overflow - #1194

Open
mustafayildirim wants to merge 3 commits into
ROCm:mainfrom
mustafayildirim:fix/1176-layout-field-overflow-diagnostic
Open

mustafayildirim wants to merge 3 commits into
ROCm:mainfrom
mustafayildirim:fix/1176-layout-field-overflow-diagnostic

Conversation

@mustafayildirim

Copy link
Copy Markdown

What

Launching a kernel whose dynamic layout field exceeds its signed packed-ABI width failed with a raw struct.error: 'i' format requires -2147483648 <= number <= 2147483647 out of _LayoutPlan's pack_into (#1176). Per the maintainer analysis in the issue, the offending field is an individual dynamic dimension (e.g. shape[0] after view(-1) of a >2^31-element tensor), not the total element count.

This PR adds a launch-time diagnostic (no ABI change): every generated fill validates its dynamic fields against the plan's packed widths (shape: signed i32; stride: i32 iff use_32bit_stride, else i64) before pack_into, and raises a ValueError naming the JIT argument, field kind, dim index, value, and limit:

ValueError: argument 'OUT': dynamic shape[0] = 2500000000 exceeds the signed
int32 ABI field (max 2147483647). The dynamic-layout buffer packs this field
at a fixed width; keep the oversized dimension static
(mark_shape_dynamic/memref type), reshape/split the tensor, or file an issue
for wider dynamic dims.

The parameter name is stamped onto the plan by _build_call_state and propagated through struct fields as Struct.field, so the diagnostic works on the fast dispatch path. Validation is one compare per dynamic field per argument — only on the launch path, never in the pack fast path when values fit.

Wider dynamic dims (i64 shapes, per the second option in the issue analysis) are deliberately out of scope: they require coordinated Python-ABI + compiler-type changes and device correctness tests on large tensors.

Testing

All on MI325X (gfx942), in-pod build against LLVM e2a39f504fe:

Check Result
Issue's launcher (2.5B-elem view(-1)) on upstream main FAIL — raw struct.error: 'i' format requires ...
Same launcher with this patch PASS — raises ValueError naming arg, shape[0], value, limit
New tests/unit/test_layout_field_overflow.py (4 L0 fill tests + l2_device launch repro) 5/5 PASS
Full tests/unit/ + tests/language/ pytest (gfx942) 2504 passed, 10 skipped, 0 failed

Fixes #1176

Copilot AI lite review requested due to automatic review settings September 25, 2026 00:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved moderate findings affect signed-range validation, diagnostic propagation, and test safety.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds launch-time validation for dynamic layout fields before ABI packing, replacing raw struct.error failures with actionable diagnostics.

Changes:

  • Validates signed shape and stride widths.
  • Propagates JIT argument and struct field names.
  • Adds unit and GPU regression tests.
File Summary and review findings
tests/​unit/​test_layout_field_overflow.py Adds overflow and launch tests. Moderate (1 vote): add CUDA availability guarding. Moderate (1 vote): mark the 10 GB repro large_shape. Nit (1 vote): pair l2_device with rocm_lower.
python/​flydsl/​expr/​struct.py Propagates struct field labels. Moderate (2 votes): propagate top-level parameter/path information through recursive plans to avoid ambiguous diagnostics.
python/​flydsl/​compiler/​jit_function.py Stamps JIT parameter names onto plans. Nit (1 vote): add fast-dispatch coverage asserting the actual parameter name.
python/​flydsl/​compiler/​jit_argument.py Implements ABI-width validation and diagnostics. Moderate (2 votes): accept the full signed lower bound. Nit (3 votes): correct contradictory remediation wording. Nit (1 vote): add DLPack-backed overflow coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/flydsl/compiler/jit_argument.py
Comment thread python/flydsl/expr/struct.py Outdated
Comment thread python/flydsl/compiler/jit_argument.py Outdated
@mustafayildirim

Copy link
Copy Markdown
Author

Copilot review findings addressed in 30f2e0a (+ test fixes in ab52203/34a13c19):

  1. Signed lower bound — overflow_report now checks the full signed range ([-2**31, 2**31-1] for i32, [-2**63, 2**63-1] for i64); a stride of -2**31 packs cleanly and is no longer rejected. Covered by test_signed_min_values_are_accepted.

  2. Struct field paths — diagnostics for struct-typed parameters now compose the full field path (argument 'payload.inner.t') instead of the ambiguous 'Struct.field' (one label shared by every field of that struct type, and un-overridable by the dispatch builder since struct instances are frozen). The struct ABI recursion builds a path_suffix (nested structs included) and _build_call_state stamps the top-level parameter name via the new _stamp_plan_param_names walk. Covered by test_nested_struct_path_in_diagnostic.

  3. Remediation wording — the hint no longer suggests mark_shape_dynamic (which makes the dim more dynamic, the opposite of the workaround); it now says to use a static-layout memref / leave the dim unmarked, or reshape/split the tensor.

Verified on gfx942 (MI325X): 7/7 layout-overflow tests, full tests/unit tests/language suite 2506 passed / 0 failed with a clean cache dir.

)

Launch of a layout-dynamic tensor whose shape or stride exceeds its packed
ABI field width used to surface as a bare struct.error deep in the fill
closure. Validate the fields before packing and raise a ValueError that
names the offending JIT argument, the kind (shape/stride), the dim index,
the value, and the signed width limit; suggest keeping the oversized
dimension static or reshaping/splitting the tensor.

- exact signed bounds (i32/i64, minima included)
- struct-typed parameters compose the full field path
  (argument 'outer.inner') via path_suffix set during the struct ABI
  recursion + _stamp_plan_param_names at dispatch
- tests: overflow messages, signed-min acceptance, struct paths,
  repeated-launch packing, and an l2_device launch repro on gfx942
@mustafayildirim
mustafayildirim force-pushed the fix/1176-layout-field-overflow-diagnostic branch from 34a13c1 to f6589a5 Compare September 28, 2026 16:39

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]:Launch fails with struct.error: 'i' format requires ... for tensors with more than 2^31-1 elements

2 participants