Skip to content

fix(a2a3): revert #2523 level3 TMP; pin ptoas v0.57 - #2563

Open
yanghaoran29 wants to merge 1 commit into
hw-native-sys:mainfrom
yanghaoran29:fix/a2a3-tci-emit-2arg
Open

fix(a2a3): revert #2523 level3 TMP; pin ptoas v0.57#2563
yanghaoran29 wants to merge 1 commit into
hw-native-sys:mainfrom
yanghaoran29:fix/a2a3-tci-emit-2arg

Conversation

@yanghaoran29

@yanghaoran29 yanghaoran29 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

The current three-argument tile.ci path is suspected to be broken (pypto#2558 / pypto-lib#1072).

#2523 (Upgrade PTOAS to v0.60) coupled A2/A3 level-3 explicit tmp — InitMemRef synthesizing compiler-owned scratch for implicit tile.ci, narrowing tile.cast, and some tile.sort32 — with ptoas v0.60. On the FAIL stack, 24 kernels / 29 calls gain tci + f32 scratch vs PASS (ptoas 0.57, 2-arg tci). The vector TCI+tmp implementation runs on PIPE_V while Op::TCI is labeled PIPE_S; packed prefill EP=2 nt=128 NaNs at tok127.

This PR does not git revert all of #2523 (later main commits such as #2559 / #2372 must stay). It rolls back the TMP coupling surface only, as #2523 itself notes toolchain + scratch must move together:

  1. toolchain/versions.env: PTOAS v0.60 → v0.57 (pre-Upgrade PTOAS to v0.60 and pin runtime to 0659e29 #2523 wheel hashes)
  2. Ascend910B RequiresLevel3TmpScratchfalse: InitMemRef no longer runs MaterializePtoLevel3ScratchMutator for implicit ci/tcvt/sort32 scratch on A2/A3 (PyPTO / DSA-RP planners). Explicit caller-provided tmp= is unchanged.
  3. UT expectations aligned to 2-arg implicit tile.ci / 1-arg implicit narrowing cast / 2-arg implicit sort32, and relaxed level3 static-view codegen checks while the flag is off
  4. ST skips (ptoas 0.57 ABI gaps, not core to the NaN fix):
    • MX: test_matmul_mx.py, test_quant_mx.py, test_quantized_matmul_mx.py (MX pack/layout needs ptoas v0.60)
    • test_fillpad_expand.py (tfillpad_expand static-shape mismatch on v0.57)

Not in this PR: the earlier _ptoas_preprocess post-ptoas TCI 3→2 rewrite (removed). Runtime submodule stays at current main pin. Upstream fix still needed: correct vector TCI pipe labeling / ptoas fence handshake.

Bisect notes (true dumps via PYPTO_LIB=pypto-lib; 0 dumps = false PASS)

Experiment Result
FAIL stack: ptoas 0.60 + level3 tci tmp EP=2 nt=128 tok127 NaN
PASS stack: ptoas 0.57 / 2-arg tci PASS (86 dumps)
Remove f16→i8 tcvt-tmp only still tok127 NaN
Hand-edit TCI 3→2 on FAIL kernels PASS
pto-isa scalar fallback (3-arg ignores tmp) PASS
PIPE_V barrier / V↔S roundtrip after 3-arg TCI hang
Dual PIPE_ALL + ban tmp/sorted reuse still NaN

Test plan

  • Focused UT: test_backend_handler, TestPtoLevel3Scratch, TestLevel3StaticViewCodegen, TestMrgSortCodegen::test_static_aligned_sort32_*, test_ci_output_does_not_alias_compiler_scratch
  • MX + fillpad_expand ST: module pytestmark skip
  • CI green on ptoas v0.57 from toolchain/versions.env
  • Onboard EP=2 prefill nancheck: blocked locally on virgin upstream/main + current pypto-lib by unrelated OutlineIncoreScopes AssignStmt var is not a Var after mutation (prefill_csa.py:182) — not caused by this TMP revert; needs separate fix before true-dump onboard sign-off

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cbe620d6-e433-4e87-9d52-403461bd87d0

📥 Commits

Reviewing files that changed from the base of the PR and between 8ccd97d and 9b1af49.

📒 Files selected for processing (5)
  • src/backend/common/pto_ops_elementwise.cpp
  • src/ir/transforms/init_memref.cpp
  • tests/ut/codegen/test_pto_codegen_ops.py
  • tests/ut/ir/transforms/test_init_memref.py
  • tests/ut/ir/transforms/test_memory_reuse.py

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

A2/A3 level3 tile.ci no longer materializes compiler-owned scratch. Its code generation emits a two-argument scalar form, while non-level3 three-argument handling remains unchanged. Tests now validate the updated IR and PTO output.

Changes

A2/A3 TCI scratch behavior

Layer / File(s) Summary
Disable synthesized TCI scratch
src/ir/transforms/init_memref.cpp, tests/ut/ir/transforms/test_init_memref.py, tests/ut/ir/transforms/test_memory_reuse.py
GetScratchSpec returns no scratch for tile.ci on A2/A3 level3. Tests verify two-argument calls for supported integer result types and preserve explicit temporary operands.
Emit scalar TCI operands
src/backend/common/pto_ops_elementwise.cpp, tests/ut/codegen/test_pto_codegen_ops.py
Level3 code generation omits the tile.ci temporary operand and always uses the current result target for the destination. PTO codegen tests verify the two-argument form.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 9b1af

The change keeps A2/A3 tile.ci emission in the intended two-argument form to avoid the device pipeline mismatch, with no actionable merge-blocking risk remaining after normal checks and review.

Poem

A rabbit watched the scratch tiles fade

Two little args are now arrayed
The result target takes its place
No extra f32 leaves a trace
Tests hop neatly through the code
And TCI follows its lighter road

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the A2/A3 level3 TMP rollback and the PTOAS v0.57 pin, which are the main changes in the pull request.
Description check ✅ Passed The description is directly related to the changes. It explains the suspected three-argument tile.ci issue, the TMP rollback, the PTOAS version change, affected tests, skips, and validation status.
  • Fix all pre-merge checks with AI

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b1af4925c

ℹ️ 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".

Comment thread src/ir/transforms/init_memref.cpp Outdated
Comment on lines +332 to +337
if (IsOp(call, "tile.ci") && call->args_.size() == 2) {
if (!materialize_a2a3_scratch_) return std::nullopt;
auto result_type = As<TileType>(call->GetType());
INTERNAL_CHECK_SPAN(result_type, span) << "tile.ci result must be TileType before InitMemRef";
// PTOAS v0.60 level3 TCI tmp width: 192 FP32 cols for 32-bit dst, 448 for 16-bit dst.
const int64_t cols =
result_type->dtype_.GetBit() == 32 ? kA2A3CiScratchColsInt32 : kA2A3CiScratchColsInt16;
return PtoScratchSpec{MakeStaticShape({1, cols}, span), DataType::FP32, "ci"};
// Do not materialize A2/A3 level3 TCI scratch. The 3-arg (dst, start, f32
// tmp) path is implemented with vector ops on PIPE_V but Op::TCI is still
// labeled PIPE_S, so ptoas emits wait(V→S)/set(S→V) and device outputs can
// go non-finite (pypto#2558 / pypto-lib#1072). Keep the 2-arg scalar TCI.
return std::nullopt;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Align the InitMemRef docs with two-argument TCI

Update the pass documentation alongside this behavior change: docs/en/dev/passes/32-init_memref.md still states at lines 10, 48, 286, and 304 that InitMemRef materializes and tests A2/A3 tile.ci scratch, and the corresponding Chinese document repeats those claims. Users and maintainers will therefore expect the allocation that this branch now deliberately suppresses; document the scalar two-argument exception in both languages.

AGENTS.md reference: AGENTS.md:L59-L60

Useful? React with 👍 / 👎.

@yanghaoran29
yanghaoran29 force-pushed the fix/a2a3-tci-emit-2arg branch 2 times, most recently from cc11f30 to 46e0088 Compare August 30, 2026 12:19
@yanghaoran29 yanghaoran29 changed the title fix(a2a3): emit 2-arg pto.tci without level3 f32 tmp fix(a2a3): force emit 2-arg pto.tci without level3 f32 tmp Aug 30, 2026
@yanghaoran29
yanghaoran29 force-pushed the fix/a2a3-tci-emit-2arg branch 2 times, most recently from 8213b87 to 0e93c7a Compare August 30, 2026 23:34
@yanghaoran29 yanghaoran29 changed the title fix(a2a3): force emit 2-arg pto.tci without level3 f32 tmp fix(a2a3): rewrite level3 TCI to 2-arg after ptoas Aug 30, 2026
@yanghaoran29
yanghaoran29 force-pushed the fix/a2a3-tci-emit-2arg branch from 0e93c7a to 5273fad Compare August 31, 2026 02:21
@yanghaoran29 yanghaoran29 changed the title fix(a2a3): rewrite level3 TCI to 2-arg after ptoas fix(a2a3): revert #2523 level3 TMP; pin ptoas v0.57 Aug 31, 2026
@yanghaoran29
yanghaoran29 force-pushed the fix/a2a3-tci-emit-2arg branch from 5273fad to 82a6240 Compare August 31, 2026 02:37
当前三参数版本 tile.ci 疑似存在问题(pypto#2558 / pypto-lib#1072)。

hw-native-sys#2523 (Upgrade PTOAS to v0.60) coupled A2/A3 level-3 explicit tmp
(InitMemRef compiler-owned scratch for tile.ci / narrowing cast / sort32)
with ptoas v0.60. The 3-arg vector TCI+tmp path is PIPE_V while Op::TCI
is labeled PIPE_S — packed prefill EP=2 nt=128 NaNs at tok127.

This change rolls back that TMP coupling as one unit (per hw-native-sys#2523's own
note that toolchain + codegen/scratch must move together):

- toolchain/versions.env: PTOAS v0.60 → v0.57 (pre-hw-native-sys#2523 hashes)
- Ascend910B RequiresLevel3TmpScratch → false (disables InitMemRef
  MaterializePtoLevel3ScratchMutator for ci/tcvt/sort32)
- Align UT expectations to 2-arg / no compiler scratch
- Skip all MX ST samples (matmul_mx / quant_mx / quantized_matmul_mx)
- Skip fillpad_expand ST (tfillpad static-shape ABI needs ptoas v0.60)

Does not keep the prior _ptoas_preprocess TCI 3→2 workaround.
Runtime submodule left at main tip. Formal fix remains correcting
vector TCI pipe labeling / ptoas handshake upstream.

Verified: focused UTs for handler / InitMemRef / codegen / MemoryReuse.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant