Skip to content

feat(ir): add codegen support for system.sync_src/sync_dst - #2307

Open
Shenggan wants to merge 4 commits into
hw-native-sys:mainfrom
Shenggan:feat/sync-flag-dynamic-event-id
Open

feat(ir): add codegen support for system.sync_src/sync_dst#2307
Shenggan wants to merge 4 commits into
hw-native-sys:mainfrom
Shenggan:feat/sync-flag-dynamic-event-id

Conversation

@Shenggan

@Shenggan Shenggan commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Adds support for manual pipelining, as demonstrated in:

https://github.com/Shenggan/pypto-gemm/blob/main/hpgemm_step4_manual_pipeline.py

Performance results are available in:

https://github.com/Shenggan/pypto-gemm/blob/main/README.md

Adds PTO codegen for static or dynamic (ScalarType(INDEX)) event_id operand on system.sync_src/sync_dst, lowering to pto.set_flag/pto.wait_flag.

Supporting pieces:

  • IR: op registration and static-xor-dynamic operand type deduction (src/ir/op/sync_ops/sync.cpp); Python IR/DSL wrappers accepting an Expr event_id (python/pypto/ir/op/system_ops.py, python/pypto/language/op/system_ops.py)
  • Parser: DSL round-trip for the dynamic operand (tests/ut/language/parser/test_system_ops.py)
  • Tests: IR-level static/dynamic construction and validation (tests/ut/ir/test_sync_flag_ops.py, new), and PTO codegen emission for both forms (TestSyncFlagCodegen in tests/ut/codegen/test_pto_codegen_ops.py)

a kernel contains any manual sync_src/sync_dst call, PTOAS's automatic sync-insertion pass (PTOInsertSync) skips the entire function — it does not insert sync selectively around the manual calls, it opts out of the whole function. So once a kernel goes down the manual-pipelining route, every pipe handoff becomes the author's responsibility.

…m.sync_src/sync_dst

Adds PTO codegen for a dynamic (ScalarType(INDEX)) event_id operand on
system.sync_src/sync_dst, lowering to pto.set_flag_dyn/pto.wait_flag_dyn
alongside the existing static int form (pto.set_flag/pto.wait_flag).
Mirrors the cross-core system.sync_set/sync_wait design, and is needed
for manual multi-buffer pipelining where the flag identity is picked by
a runtime slot index rather than known at compile time.

Supporting pieces:
- IR: op registration and static-xor-dynamic operand type deduction
  (src/ir/op/sync_ops/sync.cpp); Python IR/DSL wrappers accepting an
  Expr event_id (python/pypto/ir/op/system_ops.py,
  python/pypto/language/op/system_ops.py)
- Parser: DSL round-trip for the dynamic operand
  (tests/ut/language/parser/test_system_ops.py)
- Tests: IR-level static/dynamic construction and validation
  (tests/ut/ir/test_sync_flag_ops.py, new), and PTO codegen emission for
  both forms (TestSyncFlagCodegen in
  tests/ut/codegen/test_pto_codegen_ops.py)
Copilot AI balanced review requested due to automatic review settings August 6, 2026 20:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f1c6cbb-9842-472b-9db4-bdda2ee531e1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change adds static and dynamic event-ID support to sync_src and sync_dst. Python DSL wrappers, IR validation, PTO lowering, parser tests, IR tests, and code generation tests now cover both forms.

Changes

Synchronization event ID support

Layer / File(s) Summary
Frontend and IR synchronization contract
python/pypto/ir/op/system_ops.py, python/pypto/language/op/system_ops.py, src/ir/op/sync_ops/sync.cpp
The APIs accept integer or dynamic event IDs. Static IDs use attributes. Dynamic IDs use ScalarType(INDEX) operands. Shared validation checks pipes, ID ranges, and mutually exclusive ID forms.
PTO synchronization lowering
src/backend/common/pto_ops_memory.cpp
sync_src and sync_dst lower to static or dynamic PTO flag operations. The backend validates pipe attributes and static event-ID bounds.
IR contract and validation tests
tests/ut/ir/test_sync_flag_ops.py
Tests cover registration, operand and keyword encoding, valid types, event-ID bounds, invalid dynamic types, and missing IDs.
Code generation and parser tests
tests/ut/codegen/test_pto_codegen_ops.py, tests/ut/language/parser/test_system_ops.py
Tests verify static and dynamic PTO output and parser round trips for dynamic event IDs.

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

Sequence Diagram(s)

sequenceDiagram
  participant PythonDSL
  participant IRSyncOp
  participant PTOCodegen
  participant PTOInstructions
  PythonDSL->>IRSyncOp: submit sync_src or sync_dst with event_id
  IRSyncOp->>IRSyncOp: validate event_id and pipe attributes
  IRSyncOp->>PTOCodegen: lower synchronization operation
  PTOCodegen->>PTOInstructions: emit static or dynamic flag instruction
Loading

Possibly related PRs

  • hw-native-sys/pypto#2091: Related synchronization APIs with dynamic and static event-ID handling for cross-core operations.
  • hw-native-sys/pypto#2240: Related PTO backend code generation and tests for other system synchronization operations.

Poem

A rabbit hops through flags in flight,
Static IDs glow seven-white.
Dynamic numbers bound and run,
Pipes wait beneath the sun.
Parser, IR, and PTO agree—
Syncing neatly, carrot-free.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.13% 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 identifies the main change: adding IR code generation support for system.sync_src and system.sync_dst.
Description check ✅ Passed The description accurately covers manual pipelining, static and dynamic event IDs, IR support, parser coverage, and code generation tests.
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: 1

🤖 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_memory.cpp`:
- Around line 775-787: Update the validation in the pipe setup logic before the
casts used to build pipe_operands, ensuring set_pipe and wait_pipe are each
recognized supported PipeType values rather than only non-negative integers.
Reuse the existing PipeType definitions or validation utility, and reject
unknown values through INTERNAL_CHECK_SPAN before calling ir::PipeTypeToString.
🪄 Autofix

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: af4056a8-0177-4cc7-8064-8cebb958340c

📥 Commits

Reviewing files that changed from the base of the PR and between bf61c8d and c73551d.

📒 Files selected for processing (7)
  • 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/codegen/test_pto_codegen_ops.py
  • tests/ut/ir/test_sync_flag_ops.py
  • tests/ut/language/parser/test_system_ops.py

Comment thread src/backend/common/pto_ops_memory.cpp

@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: c73551d2a8

ℹ️ 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 tests/ut/ir/test_sync_flag_ops.py Outdated
…est parametrize

Reject out-of-range pipe attribute values before casting to ir::PipeType,
instead of only checking non-negativity, so an invalid value fails with
INTERNAL_CHECK_SPAN rather than an unlabeled TypeError from PipeTypeToString.
Also splits the sync flag test's parametrize call to stay under the Ruff
line-length limit.
Copilot AI review requested due to automatic review settings August 7, 2026 07:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 7, 2026 08:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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