Skip to content

[cutedsl] Preserve signed scalar indices and guard computed fragment windows - #4756

Merged
choijon5 merged 1 commit into
mainfrom
choijon5/helion-b200/shared/8
Nov 28, 2026
Merged

choijon5 merged 1 commit into
mainfrom
choijon5/helion-b200/shared/8

Conversation

@choijon5

@choijon5 choijon5 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PRs:


[cutedsl] Preserve signed scalar indices and guard computed fragment windows

A negative scalar subscript counts from the end of its axis. Computed
fragments previously suppressed such a dynamic scalar or staged its
window at a different address than the ordinary walk. Widen the signed
scalar before adding the actual axis extent, preserving shifted tile
origins. Stage a slab or a vector packet only when its geometric and
source-level access bounds are established. Preserve operand widths for
runtime offsets, limits and comparisons. The simulator now rejects a
negative scratch index; selected tests use its existing Int32 hook to
model explicit narrowing, not arbitrary fixed-width arithmetic.

Compatibility: valid negative scalar subscripts now address elements from
the end on these computed-fragment paths, with or without an explicit
mask. For a global tensor access in a computed fragment, tensor indices still
check both bounds: a negative lane reads zero or skips its store, including
after Cartesian promotion or when staging a runtime window. Completed
CTA-local scratch retains its own indexing rules: an unmasked local load
can wrap a proved negative coordinate.
No public RefMode or Triton policy changes. A program that wants a wrapped
tensor row across backends must normalize it explicitly.

Testing: the rebased source passed 137 CuTe CPU tests (signed coordinates,
packet strides, index domains, transport/value codegen and the private-loop
and captured-index atomic selections) and 36 CuTe GPU tests on B200 4
(fragment index domains, vector I/O and the private-scalar-loop and
captured-index native atomic selections); zero failed. This includes
native Int16-row/Int32-column reads and writes with positive and negative
lanes, explicit normalization, live eager references, and both guards
around the output view. Checked source generated from a real shifted
window retains the runtime end through its actual output loop; a
large, disjoint expanded CPU input verifies pre-add widening in a slab
without allocating the large logical tensor. Scoped strict lint passed.

The checked scalar-grid case executes its complete generated fragment
and observes one write at each expected address (2, 6, 10, 14), with
values 3, 7, 11, 15. The shared address oracle is unchanged from main.
All 4×128 lane coordinates run, including the earlier shared stages.
A modulo-32 lane, later rebinding, and another lane-one write produced
16, 16 and 8 writes, respectively, and all were detected. This final
correction passed 107 CuTe CPU cases and strict lint.

The common slab axis remains runtime-guarded for both static and
dynamic partial widths. Both bindings at five columns and the aligned
six-column case with poisoned padding matched exactly, even with
vector loads requested. The varying slab union and vector eligibility
checks still apply. A common window starting at -1 can use checked scalar
loads under static and dynamic binding. A static window starting at -4
retains its predicated four-lane packet; the negative packet is untouched
and the packet at zero supplies columns 0..3. Negative varying windows
are still refused. All four shifted-window hosts match pristine main,
and all 43 signed-coordinate CPU cases passed. On B200 7 the signed
scalar and requested packet configurations passed all 16 launches (four
static/dynamic × -1/-4 bindings on two inputs): every output and both
canaries matched. Only the aligned static -4 case issued the x packet.
The native test skips cleanly when CUDA is unavailable.

Review notes:

  • Cartesian promotion in RefMode does not grant Python-style wrapping in
    a device loop: true eager subscripts and explicit unmasked load/store
    clamp a negative read and drop its write. A physically padded, same-card
    comparison with pristine main confirms the computed-fragment zero/drop
    behavior retained here and raw offsets in ordinary Triton. Only explicit
    normalization gives the same wrap across these global access paths.

  • The proposed unconditional lower bound on the common packet start would
    suppress a working packet on main. The first packet of an aligned -4
    window is wholly below zero and is masked to zero; the next packet
    begins at zero. Only aligned, complete packets within the upper bound
    are admitted. An unaligned start follows the checked scalar path.

autoreview passed: claude, codex

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 26, 2026
@choijon5
choijon5 force-pushed the choijon5/helion-b200/shared/7 branch from 5a9e672 to 8d0f672 Compare November 26, 2026 16:22
@choijon5
choijon5 force-pushed the choijon5/helion-b200/shared/8 branch from f2f3395 to 6b69b3f Compare November 26, 2026 16:22
@choijon5
choijon5 marked this pull request as draft November 26, 2026 17:03
@choijon5
choijon5 changed the base branch from choijon5/helion-b200/shared/7 to main November 26, 2026 17:03
@choijon5
choijon5 force-pushed the choijon5/helion-b200/shared/8 branch from 6b69b3f to d82a655 Compare November 26, 2026 17:03
@choijon5
choijon5 changed the base branch from main to choijon5/helion-b200/shared/7 November 26, 2026 17:04
@choijon5
choijon5 marked this pull request as ready for review November 26, 2026 17:04
@choijon5
choijon5 force-pushed the choijon5/helion-b200/shared/7 branch from 58e98ff to 364b500 Compare November 28, 2026 04:18
…windows

A negative scalar subscript counts from the end of its axis. Computed
fragments previously suppressed such a dynamic scalar or staged its
window at a different address than the ordinary walk. Widen the signed
scalar before adding the actual axis extent, preserving shifted tile
origins. Stage a slab or a vector packet only when its geometric and
source-level access bounds are established. Preserve operand widths for
runtime offsets, limits and comparisons. The simulator now rejects a
negative scratch index; selected tests use its existing Int32 hook to
model explicit narrowing, not arbitrary fixed-width arithmetic.

Compatibility: valid negative scalar subscripts now address elements from
the end on these computed-fragment paths, with or without an explicit
mask. For a global tensor access in a computed fragment, tensor indices still
check both bounds: a negative lane reads zero or skips its store, including
after Cartesian promotion or when staging a runtime window. Completed
CTA-local scratch retains its own indexing rules: an unmasked local load
can wrap a proved negative coordinate.
No public RefMode or Triton policy changes. A program that wants a wrapped
tensor row across backends must normalize it explicitly.

Testing: the rebased source passed 137 CuTe CPU tests (signed coordinates,
packet strides, index domains, transport/value codegen and the private-loop
and captured-index atomic selections) and 36 CuTe GPU tests on B200 4
(fragment index domains, vector I/O and the private-scalar-loop and
captured-index native atomic selections); zero failed. This includes
native Int16-row/Int32-column reads and writes with positive and negative
lanes, explicit normalization, live eager references, and both guards
around the output view. Checked source generated from a real shifted
window retains the runtime end through its actual output loop; a
large, disjoint expanded CPU input verifies pre-add widening in a slab
without allocating the large logical tensor. Scoped strict lint passed.

The checked scalar-grid case executes its complete generated fragment
and observes one write at each expected address (2, 6, 10, 14), with
values 3, 7, 11, 15. The shared address oracle is unchanged from main.
All 4×128 lane coordinates run, including the earlier shared stages.
A modulo-32 lane, later rebinding, and another lane-one write produced
16, 16 and 8 writes, respectively, and all were detected. This final
correction passed 107 CuTe CPU cases and strict lint.

The common slab axis remains runtime-guarded for both static and
dynamic partial widths. Both bindings at five columns and the aligned
six-column case with poisoned padding matched exactly, even with
vector loads requested. The varying slab union and vector eligibility
checks still apply. A common window starting at -1 can use checked scalar
loads under static and dynamic binding. A static window starting at -4
retains its predicated four-lane packet; the negative packet is untouched
and the packet at zero supplies columns 0..3. Negative varying windows
are still refused. All four shifted-window hosts match pristine main,
and all 43 signed-coordinate CPU cases passed. On B200 7 the signed
scalar and requested packet configurations passed all 16 launches (four
static/dynamic × -1/-4 bindings on two inputs): every output and both
canaries matched. Only the aligned static -4 case issued the x packet.
The native test skips cleanly when CUDA is unavailable.

Review notes:
- Cartesian promotion in RefMode does not grant Python-style wrapping in
  a device loop: true eager subscripts and explicit unmasked load/store
  clamp a negative read and drop its write. A physically padded, same-card
  comparison with pristine main confirms the computed-fragment zero/drop
  behavior retained here and raw offsets in ordinary Triton. Only explicit
  normalization gives the same wrap across these global access paths.

- The proposed unconditional lower bound on the common packet start would
  suppress a working packet on main. The first packet of an aligned -4
  window is wholly below zero and is masked to zero; the next packet
  begins at zero. Only aligned, complete packets within the upper bound
  are admitted. An unaligned start follows the checked scalar path.

autoreview passed: claude, codex

stack-info: PR: #4756, branch: choijon5/helion-b200/shared/8
@choijon5
choijon5 marked this pull request as draft November 28, 2026 04:51
@choijon5
choijon5 changed the base branch from choijon5/helion-b200/shared/7 to main November 28, 2026 04:51
@choijon5
choijon5 force-pushed the choijon5/helion-b200/shared/8 branch from d82a655 to 46008ab Compare November 28, 2026 04:51
@choijon5 choijon5 changed the title [cutedsl] Preserve signed indices in computed fragment reads and writes [cutedsl] Preserve signed scalar indices and guard computed fragment windows Nov 28, 2026
@choijon5
choijon5 marked this pull request as ready for review November 28, 2026 04:51
@choijon5
choijon5 merged commit cca61cb into main Nov 28, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants