fix(vmi): materialize compact group slots as contiguous - #1437
Open
chenshengxin2026 wants to merge 1 commit into
Open
fix(vmi): materialize compact group slots as contiguous#1437chenshengxin2026 wants to merge 1 commit into
chenshengxin2026 wants to merge 1 commit into
Conversation
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.
chenshengxin2026
force-pushed
the
fix/issue-1377-compact-layout
branch
from
September 4, 2026 01:21
0ce5cf3 to
e07e1f1
Compare
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 #1377.
Problem
VMILowerUnifiedToLegacyrewrites every continuouspto.vmi.vloadof 1/2/4/8lanes into a
pto.vmi.group_slot_load, because that is the only lowering thatcan express a bounded short load (
pto.vsldb, a 32-byte block under aPAT_VL{n}mask). The dense path cannot: it needs whole physical chunks or aprovable whole-register over-read, which a
!pto.ptrsource can never supply.The side effect is that the value's layout becomes
num_groupsinstead ofcontiguous, so histogram and scatter consumers that require a contiguouslayout ask for an
ensure_layoutconversion that was never registered: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 = 1andnum_groups <= lanesPerPartputs logical lane i on physical lane i of asingle carrier — exactly what a dense contiguous short vector does
(
getVMIPhysicalArityis 1 on both sides;mapLogicalLaneToPhysicalagreeslane for lane). The conversion is therefore a pure register forward, in either
direction, with no pack/zip/shuffle.
gsFit()in the pattern DSL, used by two symmetric rows inkEnsureLayoutPatterns. It subsumes the previous one-group/one-slot rows.isVMISingleCarrierGroupSlotAlias(inVMILayoutSupport.h) is shared by thetable 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 sodoes the mirror direction, where a dense short vector reaches the compact
group_storealias.group_slot_loadkeeps its!pto.ptrsource requirement.pto.vsldbispointer-only, and PTODSL always hands
pto.vmi.vloada pointer (kernels buildUB buffers with
pto.castptr(..., pto.ptr(dtype, "ub"))), so nothing in theDSL path needs a memref source here.
Scatter
Small-VL
vscatteris not made to work. It reaches the pre-existingfull-physical-chunk gate and is rejected with a stable
VMI-UNSUPPORTED: pto.vmi.scatter ... value requires full physical chunksdiagnostic, which is resolution path 2 in the issue. Documented in
docs/isa/vmi-isa/07-sfu.mdand the PTODSL user guide.Validation
vchist/vdhistVL=1/2/4/8 lower;VL=64/128/256 controls unchanged;
vscatterVL=1/2/4/8 rejected with thedocumented diagnostic).
vmi_newlit suite: every test whose RUN lines usepto-test-optpasses.num_groups = 3, the reversecontiguous -> groupdirection, a 128-bin (
Bin_N0-only) accumulator matching the shape reportedin 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.ptopinnedcontiguous -> num_groups = 8, slots = 8at VL=8 as unsupported. That isprecisely the mirror direction this change enables, so the test was repointed
at
num_groups = 64, slots = 8, which stays unsupported and preserves what thetest was checking.
Follow-up
The alias itself still welds a load strategy to a layout attribute:
VMIGroupSlotLoadOp::verifyforces anum_groupsresult layout even when thevalue is physically indistinguishable from a contiguous one. Decoupling those
is tracked separately and is out of scope here.