feat(ir/codegen): minimal host-prequant MXFP8 matmul path - #2147
feat(ir/codegen): minimal host-prequant MXFP8 matmul path#2147yanghaoran29 wants to merge 1 commit into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe PR adds ChangesMX scale integration
Estimated code review effort: 5 (Critical) | ~90 minutes Sequence Diagram(s)sequenceDiagram
participant PythonAPI
participant TileIR
participant PTOCodegen
participant PTOAS
PythonAPI->>TileIR: Emit tile.load or tile.move with MX metadata
TileIR->>PTOCodegen: Deduce layout and generate PTO operations
PTOCodegen->>PTOCodegen: Defer scale fill and valid-shape updates
PTOCodegen->>PTOAS: Produce MX-aware PTOAS output
PTOAS->>PTOAS: Insert flags, barriers, and FIFO ordering
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eceda96b8a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 8
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
python/pypto/language/op/tile_ops.py (1)
357-408: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
mx_layout's documented "targets Mat by default" never takes effect. All three sites share one root cause:target_memorydefaults toMemorySpace.Vecin both Pythonload()wrappers and is always forwarded as an explicit kwarg, soDeduceTileLoadType's "target_memoryabsent → default toMat" fallback can never fire through the DSL. An MX load called without an explicittarget_memory=MemorySpace.Matsilently produces aVec-spaceTileTypewhosetile_viewis nonetheless laid out forMat(fractal=32, ZZ/NN row/col-major) — an internally inconsistent type.
python/pypto/language/op/tile_ops.py#L357-L408: changetarget_memory's default toNoneand resolve it toMemorySpace.Matwhenmx_layout != "none"(elseMemorySpace.Vec) before calling_ir_ops.load.python/pypto/ir/op/tile_ops.py#L162-L224: apply the sameNone-default +mx_layout-aware resolution before buildingkwargs["target_memory"].src/ir/op/tile_ops/memory.cpp#L146-L169: no change needed once the two Python sites are fixed — the existing fallback becomes reachable and correct.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/pypto/language/op/tile_ops.py` around lines 357 - 408, Update python/pypto/language/op/tile_ops.py lines 357-408 and python/pypto/ir/op/tile_ops.py lines 162-224 so load() uses a None target_memory default, resolving to MemorySpace.Mat for non-"none" mx_layout and MemorySpace.Vec otherwise before forwarding target_memory. Make no direct change in src/ir/op/tile_ops/memory.cpp lines 146-169; its existing absent-target fallback should become reachable and remain unchanged.
🧹 Nitpick comments (4)
src/ir/op/tile_ops/transform.cpp (1)
365-382: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
is_mx_scale_boxkeys only on layout/fractal, not memory space.Any tile that happens to carry
fractal=32with matching row/row or col/col layouts takes the MX path, regardless of whether it is a Mat/LeftScale/RightScale tile. The added equal-byte-width check keeps this safe today, so this is a note rather than a defect — consider additionally gating ontile_type->memory_space_being Mat/LeftScale/RightScale to keep the relaxation as narrow as the comment claims.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/ir/op/tile_ops/transform.cpp` around lines 365 - 382, Narrow the is_mx_scale_box condition to require tile_type->memory_space_ be Mat, LeftScale, or RightScale in addition to the existing fractal and layout checks. Keep the existing equal-byte-width validation and flat none_box handling unchanged.python/pypto/ir/type.py (1)
38-59: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMake prefix matching order-independent instead of relying on dict insertion order.
The correctness of
mem_leftscale_vsmem_left_currently hinges on the literal ordering of this dict, which a future alphabetical sort or refactor would silently break (aLeftScalememref would then inferMemorySpace.Left). Matching the longest prefix removes the hazard and keeps the comment purely informational.♻️ Longest-prefix lookup
def _infer_tile_memory_space_from_memref(memref: MemRef | None) -> MemorySpace | None: if memref is None: return None - for prefix, memory_space in _MEMREF_NAME_PREFIX_TO_SPACE.items(): + for prefix, memory_space in sorted( + _MEMREF_NAME_PREFIX_TO_SPACE.items(), key=lambda kv: len(kv[0]), reverse=True + ): if memref.name_hint.startswith(prefix): return memory_space return None🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/pypto/ir/type.py` around lines 38 - 59, Update _infer_tile_memory_space_from_memref to select the matching entry with the longest prefix rather than relying on _MEMREF_NAME_PREFIX_TO_SPACE insertion order. Preserve the None behavior for absent memrefs and unmatched names, while ensuring mem_leftscale_ and mem_rightscale_ resolve to their specific memory spaces regardless of dictionary ordering.python/pypto/backend/_ptoas_preprocess.py (1)
61-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocstring claims a "~8 line window" but the implementation tracks matches with unbounded lifetime.
mx_nd_varsentries are never evicted, so aTLOADanywhere later in the same scan (not just within ~8 lines) whose source SSA matches any earlierMX_A_NDGlobalTensorgets apipe_barrier(PIPE_ALL)inserted. Likely harmless in practice (SSA names are typically function-scoped/unique), but worth either implementing the described windowing or updating the comment to match the actual (global, per-file) behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/pypto/backend/_ptoas_preprocess.py` around lines 61 - 79, Update the preprocessing loop around mx_nd_vars so MX_A_ND variable entries are only eligible for matching TLOAD statements within the documented preceding ~8 non-empty lines. Evict entries outside that window before checking each TLOAD, while preserving the existing barrier insertion for valid nearby matches.tests/ut/ir/operators/test_tile_ops.py (1)
2389-2401: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding coverage for the new
tile.load(mx_layout=...)/tile.move(target_shape=...)validation paths.This PR introduces several new
CHECKs inDeduceTileLoadType(invalidmx_layoutname, non-FP8E8M0/UINT8 dtype) andDeduceTileMoveType(target_shapeelement-count mismatch, non-statictarget_shapedims) with no direct unit tests in this file.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/ut/ir/operators/test_tile_ops.py` around lines 2389 - 2401, Add direct unit tests in this file for the new validation branches in DeduceTileLoadType and DeduceTileMoveType: invalid mx_layout names, unsupported mx_layout dtypes, target_shape element-count mismatches, and non-static target_shape dimensions. Assert each case raises the expected CHECK/error while retaining coverage for valid load and move behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/backend/common/pto_ops_datamove.cpp`:
- Around line 1219-1233: Update the alias-tile construction in the result buffer
handling block to derive valid_row and valid_col from
GetEffectiveTileView(*result_tile).valid_shape, falling back to
result_tile->shape_ when the effective dimensions are not constant, so partial
validity is preserved. Also add descriptive diagnostic messages to both
INTERNAL_CHECK_SPAN checks for the shape-rank and constant-dimension
requirements.
- Around line 1326-1333: Ensure deferred valid-shape operations registered by
RegisterPendingSetValidShape are consumed before function finalization clears
pending_scale_fills and pending_set_validshapes. Add a finalize-time flush using
TakePendingSetValidShape, or emit the pending set_validshape directly during
finalization, while preserving the existing deferred behavior for pending Scale
fills.
In `@src/backend/common/pto_ops_elementwise.cpp`:
- Around line 548-567: Replace the duplicated local replace_dim lambdas in the
scale and non-scale paths with one shared helper. Prefer deriving
mat_view_ui8_ty and view_ty through codegen::ExtractTileTypeInfo and
codegen::FormatTileBufTypeString, removing the manual replace_dim,
replace_token, and force_dyn_valid textual patching where applicable.
- Around line 568-582: Update the force_dyn_valid lambda to check whether each
find_first_of(",>", start) call returns std::string::npos before replacing the
dimension value. Leave the annotation unchanged when the terminator is missing,
for both v_row and v_col handling, while preserving the existing replacement
behavior when a terminator is found.
- Around line 604-616: Update the tile allocation branch around EmitTileAddr()
to support F8/e8m0 Mat sources with a known src_off during PTOAS planning. When
EmitTileAddr() is false, avoid CHECK(false) and either handle the planner case
separately or emit/alias the same SSA without an addr= operand; retain the
existing alloc_tile addr= path when tile addresses are emitted.
In `@src/backend/common/pto_ops_memory.cpp`:
- Around line 120-122: Validate mx_layout immediately after reading it in the
operation handling code: accept only "none" and the six supported layout names,
and reject any other value explicitly with the existing error mechanism before
computing or using is_mx_load. Preserve the current ND path for "none" and the
MX path for the supported names.
- Around line 227-252: Update the flat_into_2d predicate to require both
caller-provided offsets to be constant zero values before selecting the
flattened view path. Validate offsets_tuple elements alongside the existing
shape and dimension checks, so nonzero or nonconstant offsets use the standard
path; keep the existing zero offsets passed to EmitPartitionViewPTO only when
this predicate succeeds.
In `@src/ir/transforms/canonicalize_io_order_pass.cpp`:
- Around line 330-367: Restrict is_fifo_sticky so tile.move is sticky only for
MX-scale staging or V2C-related tpop results, not ordinary
target_memory=Left/Right Mat→Left/Right transfers. Preserve the existing
tile.tpush/tile.tpop handling, and use the available operation context or
metadata to distinguish cross-core/MX-scale boundary moves from regular
intra-core L1→L0 moves before building the successors chain.
---
Outside diff comments:
In `@python/pypto/language/op/tile_ops.py`:
- Around line 357-408: Update python/pypto/language/op/tile_ops.py lines 357-408
and python/pypto/ir/op/tile_ops.py lines 162-224 so load() uses a None
target_memory default, resolving to MemorySpace.Mat for non-"none" mx_layout and
MemorySpace.Vec otherwise before forwarding target_memory. Make no direct change
in src/ir/op/tile_ops/memory.cpp lines 146-169; its existing absent-target
fallback should become reachable and remain unchanged.
---
Nitpick comments:
In `@python/pypto/backend/_ptoas_preprocess.py`:
- Around line 61-79: Update the preprocessing loop around mx_nd_vars so MX_A_ND
variable entries are only eligible for matching TLOAD statements within the
documented preceding ~8 non-empty lines. Evict entries outside that window
before checking each TLOAD, while preserving the existing barrier insertion for
valid nearby matches.
In `@python/pypto/ir/type.py`:
- Around line 38-59: Update _infer_tile_memory_space_from_memref to select the
matching entry with the longest prefix rather than relying on
_MEMREF_NAME_PREFIX_TO_SPACE insertion order. Preserve the None behavior for
absent memrefs and unmatched names, while ensuring mem_leftscale_ and
mem_rightscale_ resolve to their specific memory spaces regardless of dictionary
ordering.
In `@src/ir/op/tile_ops/transform.cpp`:
- Around line 365-382: Narrow the is_mx_scale_box condition to require
tile_type->memory_space_ be Mat, LeftScale, or RightScale in addition to the
existing fractal and layout checks. Keep the existing equal-byte-width
validation and flat none_box handling unchanged.
In `@tests/ut/ir/operators/test_tile_ops.py`:
- Around line 2389-2401: Add direct unit tests in this file for the new
validation branches in DeduceTileLoadType and DeduceTileMoveType: invalid
mx_layout names, unsupported mx_layout dtypes, target_shape element-count
mismatches, and non-static target_shape dimensions. Assert each case raises the
expected CHECK/error while retaining coverage for valid load and move behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b40bd2d4-e7bc-49e4-86f4-443f542253e9
📒 Files selected for processing (26)
.gitignoreinclude/pypto/codegen/pto/pto_codegen.hinclude/pypto/ir/memory_space.hinclude/pypto/ir/pipe.hinclude/pypto/ir/reinterpret_view_semantics.hinclude/pypto/ir/tile_view_semantics.hinclude/pypto/ir/transforms/utils/attrs.hpython/bindings/modules/ir.cpppython/pypto/backend/_ptoas_preprocess.pypython/pypto/ir/op/tile_ops.pypython/pypto/ir/type.pypython/pypto/language/op/tile_ops.pypython/pypto/language/parser/type_resolver.pypython/pypto/pypto_core/ir.pyisrc/backend/common/pto_ops_datamove.cppsrc/backend/common/pto_ops_elementwise.cppsrc/backend/common/pto_ops_memory.cppsrc/backend/common/soc.cppsrc/codegen/pto/pto_codegen.cppsrc/codegen/pto/pto_type_utils.cppsrc/ir/memref.cppsrc/ir/op/tile_ops/memory.cppsrc/ir/op/tile_ops/transform.cppsrc/ir/transforms/canonicalize_io_order_pass.cppsrc/ir/transforms/memory_reuse_pass.cpptests/ut/ir/operators/test_tile_ops.py
- Scope tile.reshape layout inheritance to MX scale fractal=32 only so existing rmsnorm / mixed-matmul paths keep InferTileLayoutFromShape (fixes UT vector-split, ST treshape boxed↔none_box, pypto-lib-model). - Drop drive-by Bias from IsCubeMemorySpace; revert unrelated .gitignore. - Match FIFO sticky ops to registered tpush_to_*/tpop_from_* names. - Default mx_layout loads to Mat; tighten mx_layout/flat-store checks. - clang-tidy includes; add Ascend950 LeftScale/RightScale memspace UTs.
…e-sys#2147 Cover SoC mem_graph edges for MX scale sidecars alongside existing capacity checks.
Add Ascend950 LeftScale/RightScale memory spaces (L0A/L0B MX scale buffers, SoC capacity, loc=scaling) and the scale data path: tile.load mx_layout, Mat↔Scale move with target_shape and deferred fill until tget_scale_addr, FP4/FP8E8M0 reinterpret_view aliases, and ptoas ND-flat → mx_a_zz preprocess. No MX quant/matmul ops yet. Phase 2 of the hw-native-sys#2117 split (includes former Phase 1.2). Depends on FP8E8M0 (hw-native-sys#2144). Refs hw-native-sys#1975. Interface alignment (memspace + scale data path): pto-isa (A5 / MX): TileType::ScaleLeft / ScaleRight — L0A/L0B MX scale buffers (include/pto/common/type.hpp); payload float8_e8m0_t Layout::MX_A_ZZ / MX_A_ND / MX_A_DN — activation scale GM layouts; TLoadMxCube* (AZZ2ZZ / AND2ZZ / …); SFractal=32 row-major ZZ Layout::MX_B_NN / MX_B_ND / MX_B_DN — weight scale layouts; col-major NN for MX_B_* TMov CommonCheckMX — uint8_t Mat → float8_e8m0 ScaleLeft/Right GetScaleAddr(Left/Right) — bind Scale tile to L0 sidecar before fill (sidecar bind-then-fill; Mat→Mat tmov illegal on A5) PTOAS (v0.48+ dialect / EmitC): loc=scaling + !pto.f8E8M0 → TileType::ScaleLeft|ScaleRight (ui8 + scaling wrongly maps to Fixpipe TileType::Scaling; LeftScale/RightScale share one MLIR loc `scaling` until distinct) #pto.layout<mx_a_zz|mx_a_nd|…|mx_b_nn|…> on make_tensor_view / tload → Layout::MX_*; InferPTOLayout prefers mx_a_zz/mx_b_nn for !pto.f8E8M0 Mat+fractal=32 pto.tmov Mat→scaling — must follow tget_scale_addr (matches PTOA5NormalizeTMovPass); PyPTO defers fill until then EmitC preprocess: float8_e8m0/uint8 MX_A_ZZ → MX_A_ND so TLoad uses AND2ZZ (activation scales are ND-flat on GM); MTE3 drain before Vec TPUSH; pipe_barrier before MX_A_ND TLOAD after AIV store PyPTO ↔ interface: MemorySpace::LeftScale ↔ loc=scaling + !pto.f8E8M0 ↔ ScaleLeft MemorySpace::RightScale ↔ loc=scaling + !pto.f8E8M0 ↔ ScaleRight tile.load(..., mx_layout=mx_a_zz|…) ↔ #pto.layout<…> ↔ Layout::MX_* tile.move Mat→LeftScale/RightScale ↔ deferred tmov after GetScaleAddr FP8E8M0 / UINT8 scale payload ↔ float8_e8m0_t (1-byte MX exp) Dependencies: - PyPTO: FP8E8M0 dtype (hw-native-sys#2144 / DataType::FP8E8M0) - PTOAS: v0.48+ (loc=scaling, MX layouts, NormalizeTMov) - pto-isa: A5 MX TileType + Layout + TLoadMx / TMov / GetScaleAddr Also includes review/CI fixes for hw-native-sys#2147: - Scope tile.reshape layout inheritance to MX scale fractal=32 only - Stamp memory_space_ on tile.move only for LeftScale/RightScale - FIFO-sticky: registered tpush_to_*/tpop_from_* + Scale moves only - Drop drive-by Bias from IsCubeMemorySpace; do not change .gitignore - Default mx_layout loads to Mat; tighten mx_layout / flat-store checks - Ascend950 LeftScale/RightScale capacity and Mat→Scale path UTs
63aaca6 to
60c0546
Compare
Add Ascend950 LeftScale/RightScale memory spaces (L0A/L0B MX scale buffers, SoC capacity, loc=scaling) and the scale data path: tile.load mx_layout, Mat↔Scale move with target_shape and deferred fill until tget_scale_addr, FP4/FP8E8M0 reinterpret_view aliases, and ptoas ND-flat → mx_a_zz preprocess. No MX quant/matmul ops yet. Phase 2 of the hw-native-sys#2117 split (includes former Phase 1.2). Depends on FP8E8M0 (hw-native-sys#2144). Refs hw-native-sys#1975. Also includes review fixes for hw-native-sys#2147: - Drop unused TakePending*/DeferTFree/TakeDeferredTFreeCount (flush API already lives in feat/mx-quant-ops and feat/mx-matmul-ops) - Assert no unflushed deferred scale fills at GenerateFunction end - Use INTERNAL_UNREACHABLE_SPAN for the unsupported f8 Mat→Scale path - Align _barrier_before_mx_a_nd_tload comment with no-distance-cutoff code Co-authored-by: Cursor <cursoragent@cursor.com>
60c0546 to
c3bd91b
Compare
Add Ascend950 LeftScale/RightScale memory spaces (L0A/L0B MX scale buffers, SoC capacity, loc=scaling) and the scale data path: tile.load mx_layout, Mat↔Scale move with target_shape and deferred fill until tget_scale_addr, FP4/FP8E8M0 reinterpret_view aliases, and ptoas ND-flat → mx_a_zz preprocess. No MX quant/matmul ops yet. Phase 2 of the hw-native-sys#2117 split (includes former Phase 1.2). Depends on FP8E8M0 (hw-native-sys#2144). Refs hw-native-sys#1975. Also includes review/CI fixes for hw-native-sys#2147: - Drop unused TakePending*/DeferTFree/TakeDeferredTFreeCount (flush API already lives in feat/mx-quant-ops and feat/mx-matmul-ops) - Assert no unflushed deferred scale fills at GenerateFunction end - Use INTERNAL_UNREACHABLE_SPAN for the unsupported f8 Mat→Scale path - Align _barrier_before_mx_a_nd_tload comment with no-distance-cutoff code - Narrow TileType.shape dims via isinstance(ConstInt) for pyright Co-authored-by: Cursor <cursoragent@cursor.com>
c3bd91b to
5d9ba49
Compare
Add Ascend950 LeftScale/RightScale memory spaces (L0A/L0B MX scale buffers, SoC capacity, loc=scaling) and the scale data path: tile.load mx_layout, Mat↔Scale move with target_shape and deferred fill until tget_scale_addr, FP4/FP8E8M0 reinterpret_view aliases, and ptoas ND-flat → mx_a_zz preprocess. No MX quant/matmul ops yet. Phase 2 of the hw-native-sys#2117 split (includes former Phase 1.2). Depends on FP8E8M0 (hw-native-sys#2144). Refs hw-native-sys#1975. Also includes review/CI fixes for hw-native-sys#2147: - Drop unused TakePending*/DeferTFree/TakeDeferredTFreeCount (flush API already lives in feat/mx-quant-ops and feat/mx-matmul-ops) - Assert no unflushed deferred scale fills at GenerateFunction end - Use INTERNAL_UNREACHABLE_SPAN for the unsupported f8 Mat→Scale path - Align _barrier_before_mx_a_nd_tload comment with no-distance-cutoff code - Narrow TileType.shape dims via isinstance(ConstInt) for pyright
5d9ba49 to
ae356cc
Compare
Add Ascend950 LeftScale/RightScale memory spaces (L0A/L0B MX scale buffers, SoC capacity, loc=scaling) and the scale data path: tile.load mx_layout, Mat↔Scale move with target_shape and deferred fill until tget_scale_addr, FP4/FP8E8M0 reinterpret_view aliases, and ptoas ND-flat → mx_a_zz preprocess. No MX quant/matmul ops yet. Phase 2 of the hw-native-sys#2117 split (includes former Phase 1.2). Depends on FP8E8M0 (hw-native-sys#2144). Refs hw-native-sys#1975. Also includes review/CI fixes for hw-native-sys#2147: - Drop unused TakePending*/DeferTFree/TakeDeferredTFreeCount (flush API already lives in feat/mx-quant-ops and feat/mx-matmul-ops) - Assert no unflushed deferred scale fills at GenerateFunction end - Use INTERNAL_UNREACHABLE_SPAN for the unsupported f8 Mat→Scale path - Align _barrier_before_mx_a_nd_tload comment with no-distance-cutoff code - Narrow TileType.shape dims via isinstance(ConstInt) for pyright after rewrite; raise if PTOAS changed its layout spelling. count equals expected Vec-TPUSH count.
6de65d9 to
1a1c54e
Compare
Add Ascend950 LeftScale/RightScale memory spaces (L0A/L0B MX scale buffers, SoC capacity, loc=scaling) and the scale data path: tile.load mx_layout, Mat↔Scale move with target_shape and deferred fill until tget_scale_addr, and FP8E8M0 reinterpret_view aliases. Reject FP8E5M2 reinterpret on Ascend950. No MX quant/matmul ops or MXFP4 aliases yet (those land in hw-native-sys#2117 with ND rewrite / AIC PIPE_ALL barriers). Phase 2 of the hw-native-sys#2117 split (includes former Phase 1.2). Depends on FP8E8M0 (hw-native-sys#2144). Refs hw-native-sys#1975. Also includes review/CI fixes for hw-native-sys#2147: - Drop unused TakePending*/DeferTFree/TakeDeferredTFreeCount (flush API already lives in feat/mx-quant-ops and feat/mx-matmul-ops) - Assert no unflushed deferred scale fills at GenerateFunction end - Use INTERNAL_UNREACHABLE_SPAN for the unsupported f8 Mat→Scale path - Narrow TileType.shape dims via isinstance(ConstInt) for pyright - Drop fragile PTOAS C++ regex post-process (MX_A_ZZ→ND, MTE3 drain, pipe_barrier); defer sync/layout fixes to hw-native-sys#2117
1a1c54e to
3dc95df
Compare
Treat FP4 tile shape/valid_shape as packed storage units (K/2) while scale groups and matmul K-matching use logical element counts. Re-allow INT8↔FP4 reinterpret_view aliases for MXFP4 paths (kept out of hw-native-sys#2147).
3dc95df to
281311b
Compare
Treat FP4 tile shape/valid_shape as packed storage units (K/2) while scale groups and matmul K-matching use logical element counts. Re-allow INT8↔FP4 reinterpret_view aliases for MXFP4 paths (kept out of hw-native-sys#2147).
…-sys#2117 Re-introduce V2C/scale FIFO sticky (moved out of hw-native-sys#2147), dedupe TakePending helpers after rebase, allow FP4/INT8 matmul_mx data while still rejecting FP8E5M2, and document hw-native-sys#2117 ISA/PTOAS extension constraints (en/zh).
281311b to
e458aa5
Compare
…-sys#2147 - src/ir/op/tile_ops/mx.cpp: drop unused "pypto/ir/type_inference.h"; add <optional> for std::nullopt used at the TileType memref arg - src/ir/transforms/canonicalize_io_order_pass.cpp: drop redundant <any> (already provided transitively by pypto/core/any_cast.h)
|
我按当前 head 阻塞问题
建议拆出或简化当前 PR 名称是 minimal host-prequant,但还包含未来 另外,不建议因为 A5 MX matmul 不支持 E5M2,就让通用、跨后端的 总结:基础方向合理,但建议先解决以上 5 个阻塞问题,并把未来 |
28141a6 to
90de75e
Compare
|
Fixed in
|
15b5e71 to
5660c6f
Compare
Add a minimal Ascend950 MX block-scale GEMM data path for host-prequant
MXFP8: Left/Right data tiles plus LeftScale/RightScale → Acc.
IR / language
- Register tile.matmul_mx (FP8E4M3FN × FP8E8M0 → FP32 Acc) with physical
alignment M%16 / K%64 / N%32 and separate physical/valid scale-group
checks ceil(K/32) so PyPTO rejects cases that would fail PTOAS
matmul_mx vs tget_scale_addr verifiers.
- Register tile.tget_scale_addr (DPS, in-place on dst_scale) for
LeftScale↔Left / RightScale↔Right address bind.
- Extend tile.load with mx_layout={mx_a_zz,mx_b_nn} (Mat-only, fractal=32)
and tile.move destinations LeftScale/RightScale (UINT8→FP8E8M0 for
loc=scaling). Reject FP8E5M2 at matmul_mx only.
- Add MemorySpace::{LeftScale,RightScale}, Cube SoC budget (4KB each),
Mat→scale mem-graph edges, and MemoryReuse L0 exemption.
Codegen
- Emit pto.tmatmul.mx / pto.tget_scale_addr; MX loads rebind
make_tensor_view with #pto.layout<mx_*>; Left/RightScale map to
MLIR loc=scaling.
- Emit Mat→scale pto.tmov in source order (PTOAS PTOA5NormalizeTMovPass
reorders bind-before-fill). Drop unused matmul_mx_acc/bias hooks.
- Elide same-addr tile.move only when layout *and* shape match.
Correctness (mx_layout + InferTileMemorySpace)
- OpRegistry stamps target_memory=Mat into Call kwargs when mx_layout is
set but target_memory was omitted, so type and kwargs stay in sync.
- InferFromOp forces Mat for mx_layout loads; Phase-3 rewrite preserves
the DeduceTileLoadType fractal=32 TileView instead of rebuilding via
GetImplicitTileView (ordinary Mat NZ would strip fractal and break
TLoadMxCube*).
Tests / CI
- UT for IR validation, memspace layouts, kwargs stamping, Infer fractal
preservation; codegen UT for tmov-before-tget ordering; a5/a5sim ST
with host-prequant golden (wired into CI a5sim allowlist).
5660c6f to
c9635d3
Compare
Summary
Minimal host-prequant MXFP8 matmul on Ascend950 (AIC):
mx_layoutloadmovewithPendingScaleFill(flush attget_scale_addr)tile.tget_scale_addr→pto.tget_scale_addrtile.matmul_mx→pto.tmatmul.mxDepends on #2144. Refs #1975.
Docs: operators MX constraints (en/zh).
pto-isa (hardware / ISA)
TileType::ScaleLeft/ScaleRight↔ PyPTOLeftScale/RightScalefloat8_e8m0_t; this PR data = FP8E4M3FN only (reject FP8E5M2);K%32==0, fractal=32MX_A_*→ row-major ZZ;MX_B_*→ col-major NN;TLoadMxCube*TMovCommonCheckMXuint8_tMat →float8_e8m0ScaleLeft/Right; canonical: ui8 Mat reshape then ui8→f8 ScaleGetScaleAddr(Left/Right)before sidecar fill; provisional Mat/alloc addr is invalidtmatmul_mx: M↑16, K↑64, N↑32 (fp8)PTOAS (dialect / EmitC)
loc=scalingloc=scaling, EmitC picks ScaleLeft/Right!pto.f8E8M0ui8+scalingbecomes FixpipeTileType::Scaling; convert before Scaletreshapetmovinto scalingtmov[1,G]musttreshapeto[M,K/32](or B-side shape) firsttget_scale_addrbefore Mat→scaling fill; PyPTOPendingScaleFillflushes at tget#pto.layout/ mx loadmx_a_zz/mx_b_nn/ …; this PR ST uses host ZZ/NN (AZZ2ZZ)pto.tmatmul.mx+pto.tget_scale_addrTest plan
test_mx_scale_memspace,test_mx_ops(incl. reject E5M2),test_mx_ops_codegentest_matmul_mx_compiles_ptoason a5/a5sim; device numeric on a5Co-authored-byon tip commitmain