Skip to content

fix(vmi): materialize compact group slots as contiguous - #1437

Open
chenshengxin2026 wants to merge 1 commit into
mainfrom
fix/issue-1377-compact-layout
Open

fix(vmi): materialize compact group slots as contiguous#1437
chenshengxin2026 wants to merge 1 commit into
mainfrom
fix/issue-1377-compact-layout

Conversation

@chenshengxin2026

@chenshengxin2026 chenshengxin2026 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1377.

Problem

VMILowerUnifiedToLegacy rewrites every continuous pto.vmi.vload of 1/2/4/8
lanes into a pto.vmi.group_slot_load, because that is the only lowering that
can express a bounded short load (pto.vsldb, a 32-byte block under a
PAT_VL{n} mask). The dense path cannot: it needs whole physical chunks or a
provable whole-register over-read, which a !pto.ptr source can never supply.

The side effect is that the value's layout becomes num_groups instead of
contiguous, so histogram and scatter consumers that require a contiguous
layout ask for an ensure_layout conversion that was never registered:

ensure_layout has no registered materialization support:
source/result layouts do not match a supported ensure_layout table row

Fix

Register the relation as a physical invariant rather than as a list of the
group counts the alias happens to emit.

A group packet with num_groups <= slots, lane_stride = 1 and
num_groups <= lanesPerPart puts logical lane i on physical lane i of a
single carrier — exactly what a dense contiguous short vector does
(getVMIPhysicalArity is 1 on both sides; mapLogicalLaneToPhysical agrees
lane for lane). The conversion is therefore a pure register forward, in either
direction, with no pack/zip/shuffle.

  • New table key gsFit() in the pattern DSL, used by two symmetric rows in
    kEnsureLayoutPatterns. It subsumes the previous one-group/one-slot rows.
  • isVMISingleCarrierGroupSlotAlias (in VMILayoutSupport.h) is shared by the
    table matcher and the VPTO materializer, so the two cannot drift.

This also closes neighbouring cases that a group-count list leaves open:
an explicit vload {group = 3} hits the identical diagnostic today, and so
does the mirror direction, where a dense short vector reaches the compact
group_store alias.

group_slot_load keeps its !pto.ptr source requirement. pto.vsldb is
pointer-only, and PTODSL always hands pto.vmi.vload a pointer (kernels build
UB buffers with pto.castptr(..., pto.ptr(dtype, "ub"))), so nothing in the
DSL path needs a memref source here.

Scatter

Small-VL vscatter is not made to work. It reaches the pre-existing
full-physical-chunk gate and is rejected with a stable
VMI-UNSUPPORTED: pto.vmi.scatter ... value requires full physical chunks
diagnostic, which is resolution path 2 in the issue. Documented in
docs/isa/vmi-isa/07-sfu.md and the PTODSL user guide.

Validation

  • Reproduction matrix: 21/21 checks pass (vchist/vdhist VL=1/2/4/8 lower;
    VL=64/128/256 controls unchanged; vscatter VL=1/2/4/8 rejected with the
    documented diagnostic).
  • vmi_new lit suite: every test whose RUN lines use pto-test-opt passes.
  • New/updated coverage: num_groups = 3, the reverse contiguous -> group
    direction, a 128-bin (Bin_N0-only) accumulator matching the shape reported
    in the issue, and negative cases for num_groups > slots,
    lane_stride = 2, and a group count wider than one carrier.

Note for reviewers

vmi_layout_gate_helper_support_invalid.pto pinned
contiguous -> num_groups = 8, slots = 8 at VL=8 as unsupported. That is
precisely the mirror direction this change enables, so the test was repointed
at num_groups = 64, slots = 8, which stays unsupported and preserves what the
test was checking.

Follow-up

The alias itself still welds a load strategy to a layout attribute:
VMIGroupSlotLoadOp::verify forces a num_groups result layout even when the
value is physically indistinguishable from a contiguous one. Decoupling those
is tracked separately and is out of scope here.

VMILowerUnifiedToLegacy rewrites every continuous vload of 1/2/4/8 lanes
into a group_slot_load, because that is the only lowering able to express
a bounded short load: pto.vsldb reads a 32-byte block under a PAT_VL{n}
mask, while the dense path needs whole physical chunks or a provable
whole-register over-read, which a !pto.ptr source can never supply.

The side effect is that the value carries a num_groups layout instead of
contiguous, so histogram and scatter consumers asking for a contiguous
operand request an ensure_layout conversion that was never registered,
and lowering stops with "ensure_layout has no registered materialization
support".

Register that conversion as a physical invariant.  A group packet with
num_groups <= slots, lane_stride = 1 and num_groups <= lanesPerPart puts
logical lane i on physical lane i of a single carrier, which is exactly
what a dense contiguous short vector does: getVMIPhysicalArity is 1 on
both sides and mapLogicalLaneToPhysical agrees lane for lane.  The
conversion is therefore a pure register forward in either direction, with
no pack, zip or shuffle.

The relation is expressed as a table key, gsFit(), used by two symmetric
rows of kEnsureLayoutPatterns, and as isVMISingleCarrierGroupSlotAlias,
which the VPTO materializer shares with the table matcher so the two
cannot drift.  Stating the physical property rather than enumerating the
group counts the alias emits also covers neighbouring shapes that would
otherwise reproduce the same failure: an explicit vload {group = 3}, and
the mirror direction where a dense short vector reaches the compact
group_store alias.  The previous one-group/one-slot rows are subsumed.

Small-VL vscatter stays unsupported.  It now reaches the existing
full-physical-chunk gate and is rejected with a stable VMI-UNSUPPORTED
diagnostic instead of a layout materialization failure; the ISA and
PTODSL docs record that limitation.

vmi_layout_gate_helper_support_invalid pinned contiguous -> num_groups =
8, slots = 8 as unsupported, which is the mirror direction this change
enables, so it now uses num_groups = 64, slots = 8 and keeps testing the
diagnostic it was written for.
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.

[Bug] PTODSL-vmi,vchist/vdhist/vscatter 小 VL 用例触发 Histogram layout materialization 错误

1 participant