Skip to content

revert: InsertCommFence pass — buggy ptoas 0.50 dependency (#2076) - #2138

Merged
zhangqi-chen merged 1 commit into
hw-native-sys:mainfrom
YunjiQin:revert/insert-comm-fence-2076
Jul 25, 2026
Merged

revert: InsertCommFence pass — buggy ptoas 0.50 dependency (#2076)#2138
zhangqi-chen merged 1 commit into
hw-native-sys:mainfrom
YunjiQin:revert/insert-comm-fence-2076

Conversation

@YunjiQin

Copy link
Copy Markdown
Collaborator

Summary

Reverts #2076 (feat(passes): InsertCommFence — cacheinvalid + fence for data-before-signal, commit 60a3df40). That change targets ptoas 0.50, whose current build has a bug, so the pass, its codegen changes, and the toolchain bump are being backed out until a fixed ptoas is available.

This restores the pre-#2076 state:

  • Removes the InsertCommFence pass (src/ir/transforms/insert_comm_fence_pass.cpp), its Default/DebugTile pipeline registration, bindings, stubs, and docs (43-insert_comm_fence.md).
  • Reverts the CommRemoteOffset inlining and the distributed remote-op codegen changes.
  • Reverts the ptoas 0.50 toolchain bump in toolchain/versions.env and the TPUT drain barrier.

Doc-ordering fix (not a plain revert)

The original #2076 diff to .claude/rules/pass-doc-ordering.md bundled two table rows: entry 42 (classify_iter_arg_carry, from an earlier commit whose row was missing) and entry 43 (insert_comm_fence). A mechanical revert would drop both. Since the ClassifyIterArgCarry pass still exists and runs last in the pipeline, entry 42 is kept (relabelled "Last pass") and only entry 43 is removed.

Testing

  • Build + test suite green on the reverted tree
  • Pass pipeline verified: insert_comm_fence fully removed from pass_manager.py; classify_iter_arg_carry is now the last pass

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change centralizes distributed remote-offset computation into per-dtype helpers, restricts cacheinvalid to tensor regions, removes InsertCommFence across the build and pass interfaces, updates related tests and documentation, and pins PTOAS to v0.48.

Changes

Distributed remote-offset codegen

Layer / File(s) Summary
Helper contract and emission
include/pypto/codegen/pto/pto_codegen.h, src/codegen/pto/pto_codegen.cpp, src/backend/common/pto_ops_distributed.cpp
Per-dtype CommRemoteOffset_<dtype> helpers are registered and emitted from communication-layout data; distributed operations call them before addptr and make_tensor_view.
Validation and documentation
tests/ut/codegen/distributed/test_distributed_pto_codegen.py, docs/en/dev/distributed_ops.md, docs/zh-cn/dev/distributed_ops.md
Tests and documentation now describe helper-based offset calculation and call-site remote view construction. TPUT barrier assertions are updated.

Cache invalidation and pass cleanup

Layer / File(s) Summary
Region-only cacheinvalid
python/pypto/ir/op/system_ops.py, python/pypto/language/op/system_ops.py, src/backend/common/pto_ops_memory.cpp, src/ir/op/sync_ops/sync.cpp, tests/ut/...
The no-argument whole-GM form is removed; cacheinvalid now requires tensor, shapes, and offsets.
InsertCommFence removal
src/ir/transforms/..., include/pypto/ir/transforms/..., python/.../passes*, CMakeLists.txt, tests/ut/ir/transforms/..., docs/...
The pass implementation, public declarations, bindings, pipeline entries, tests, and pass documentation are removed or updated.

Toolchain pin

Layer / File(s) Summary
PTOAS version update
toolchain/versions.env
The PTOAS version changes from v0.50 to v0.48 with updated architecture checksums.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DistributedOp
  participant PTOCodegen
  participant CommRemoteOffset_dtype
  participant RemoteView
  DistributedOp->>PTOCodegen: Register remote offset dtype
  PTOCodegen->>CommRemoteOffset_dtype: Emit helper(ctx, peer)
  DistributedOp->>CommRemoteOffset_dtype: func.call(ctx, peer)
  DistributedOp->>RemoteView: addptr and make_tensor_view(offset)
Loading

Possibly related PRs

Poem

A bunny hops through helper calls,
With dtype paths inside the halls.
Fences fade and views align,
Cacheinvalid draws a smaller line.
PTOAS rolls to forty-eight—
Hop, compile, and celebrate! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly reflects the main change: reverting InsertCommFence due to a ptoas 0.50 dependency bug.
Description check ✅ Passed The description matches the changeset and explains the revert scope, codegen rollback, and doc-ordering exception.
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.

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 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 `@include/pypto/codegen/pto/pto_codegen.h`:
- Around line 533-548: Correct the stale caller references in the documentation:
in include/pypto/codegen/pto/pto_codegen.h lines 533-548, update the
EmitCommRemoteView reference to pto_ops_distributed.cpp; in
src/codegen/pto/pto_codegen.cpp lines 436-441, update the
EmitCommRemoteOffsetHelpers() comment to reference
src/backend/common/pto_ops_distributed.cpp. No code behavior changes are needed.

In `@src/backend/common/pto_ops_memory.cpp`:
- Around line 821-822: Update the diagnostic string in the system.cacheinvalid
argument-count check to report the established order `(tensor, shapes,
offsets)`, matching the handler and both Python layers; leave the validation
logic unchanged.
🪄 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: d21a1b34-5446-492e-85e1-1ac8df9c45ac

📥 Commits

Reviewing files that changed from the base of the PR and between efb7837 and ffef169.

📒 Files selected for processing (27)
  • .claude/rules/pass-doc-ordering.md
  • CMakeLists.txt
  • docs/en/dev/distributed_ops.md
  • docs/en/dev/passes/43-insert_comm_fence.md
  • docs/zh-cn/dev/distributed_ops.md
  • docs/zh-cn/dev/passes/43-insert_comm_fence.md
  • include/pypto/codegen/pto/pto_codegen.h
  • include/pypto/ir/transforms/pass_properties.h
  • include/pypto/ir/transforms/passes.h
  • include/pypto/ir/transforms/utils/op_predicates.h
  • python/bindings/modules/passes.cpp
  • python/pypto/ir/op/system_ops.py
  • python/pypto/ir/pass_manager.py
  • python/pypto/language/op/system_ops.py
  • python/pypto/pypto_core/passes.pyi
  • src/backend/common/pto_ops_distributed.cpp
  • src/backend/common/pto_ops_memory.cpp
  • src/codegen/pto/pto_codegen.cpp
  • src/ir/op/sync_ops/sync.cpp
  • src/ir/transforms/insert_comm_fence_pass.cpp
  • src/ir/transforms/utils/op_predicates.cpp
  • tests/ut/codegen/distributed/test_distributed_pto_codegen.py
  • tests/ut/codegen/test_pto_codegen_ops.py
  • tests/ut/ir/transforms/test_insert_comm_fence.py
  • tests/ut/ir/transforms/test_pass_manager.py
  • tests/ut/language/parser/test_system_ops.py
  • toolchain/versions.env
💤 Files with no reviewable changes (15)
  • docs/zh-cn/dev/passes/43-insert_comm_fence.md
  • docs/en/dev/passes/43-insert_comm_fence.md
  • src/ir/transforms/insert_comm_fence_pass.cpp
  • CMakeLists.txt
  • python/pypto/ir/pass_manager.py
  • python/pypto/pypto_core/passes.pyi
  • tests/ut/codegen/test_pto_codegen_ops.py
  • tests/ut/language/parser/test_system_ops.py
  • tests/ut/ir/transforms/test_pass_manager.py
  • include/pypto/ir/transforms/utils/op_predicates.h
  • src/ir/transforms/utils/op_predicates.cpp
  • python/bindings/modules/passes.cpp
  • include/pypto/ir/transforms/pass_properties.h
  • include/pypto/ir/transforms/passes.h
  • tests/ut/ir/transforms/test_insert_comm_fence.py

Comment on lines +533 to +548
/**
* @brief Register a dtype that needs a ``@CommRemoteOffset_<dtype>``
* helper, and return the helper function name.
*
* Called by op lowering code (``EmitCommRemoteView`` in
* ``pto_ops_common.cpp``) at the moment a ``func.call`` to the helper
* is emitted. Any op that routes peer addressing through
* ``EmitCommRemoteView`` automatically gets the matching helper emitted
* at module-flush time — no separate pre-walk of the IR is needed.
*
* Validates that the dtype is byte-sized (sub-byte dtypes have no
* whole-byte element stride and so have no well-defined cross-rank
* offset). Failing here surfaces the error at the op call site rather
* than at module-emission time.
*/
std::string RegisterCommRemoteOffsetHelper(const DataType& dtype);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix stale pto_ops_common.cpp reference — EmitCommRemoteView is defined in pto_ops_distributed.cpp. Both comments describe the same caller relationship but point to the wrong source file.

  • include/pypto/codegen/pto/pto_codegen.h#L533-L548: update the RegisterCommRemoteOffsetHelper doc to say EmitCommRemoteView lives in pto_ops_distributed.cpp, not pto_ops_common.cpp.
  • src/codegen/pto/pto_codegen.cpp#L436-L441: update the comment above EmitCommRemoteOffsetHelpers() to reference src/backend/common/pto_ops_distributed.cpp.
📍 Affects 2 files
  • include/pypto/codegen/pto/pto_codegen.h#L533-L548 (this comment)
  • src/codegen/pto/pto_codegen.cpp#L436-L441
🤖 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 `@include/pypto/codegen/pto/pto_codegen.h` around lines 533 - 548, Correct the
stale caller references in the documentation: in
include/pypto/codegen/pto/pto_codegen.h lines 533-548, update the
EmitCommRemoteView reference to pto_ops_distributed.cpp; in
src/codegen/pto/pto_codegen.cpp lines 436-441, update the
EmitCommRemoteOffsetHelpers() comment to reference
src/backend/common/pto_ops_distributed.cpp. No code behavior changes are needed.

Comment on lines 821 to +822
INTERNAL_CHECK_SPAN(op->args_.size() == 3, op->span_)
<< "system.cacheinvalid takes 0 (whole-GM) or 3 arguments (tensor, shapes, offsets), got "
<< op->args_.size();
<< "system.cacheinvalid takes 3 arguments (tensor, offsets, shapes), got " << op->args_.size();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Correct the argument order in the diagnostic.

Line 822 says (tensor, offsets, shapes), but this handler—and both Python layers—use (tensor, shapes, offsets). Invalid IR will be diagnosed with the wrong call order.

Proposed fix
-        << "system.cacheinvalid takes 3 arguments (tensor, offsets, shapes), got " << op->args_.size();
+        << "system.cacheinvalid takes 3 arguments (tensor, shapes, offsets), got " << op->args_.size();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
INTERNAL_CHECK_SPAN(op->args_.size() == 3, op->span_)
<< "system.cacheinvalid takes 0 (whole-GM) or 3 arguments (tensor, shapes, offsets), got "
<< op->args_.size();
<< "system.cacheinvalid takes 3 arguments (tensor, offsets, shapes), got " << op->args_.size();
INTERNAL_CHECK_SPAN(op->args_.size() == 3, op->span_)
<< "system.cacheinvalid takes 3 arguments (tensor, shapes, offsets), got " << op->args_.size();
🤖 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/backend/common/pto_ops_memory.cpp` around lines 821 - 822, Update the
diagnostic string in the system.cacheinvalid argument-count check to report the
established order `(tensor, shapes, offsets)`, matching the handler and both
Python layers; leave the validation logic unchanged.

@zhangqi-chen
zhangqi-chen merged commit d64380c into hw-native-sys:main Jul 25, 2026
12 checks passed
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.

2 participants