Skip to content

feat(codegen): support soft syncall for mix and aic_only core types#1944

Merged
Hzfengsy merged 3 commits into
hw-native-sys:mainfrom
lyfne123:feat/syncall-soft-mix
Jul 3, 2026
Merged

feat(codegen): support soft syncall for mix and aic_only core types#1944
Hzfengsy merged 3 commits into
hw-native-sys:mainfrom
lyfne123:feat/syncall-soft-mix

Conversation

@lyfne123

@lyfne123 lyfne123 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Extend soft-mode system.syncall — previously limited to core_type="aiv_only" — to core_type="mix" and core_type="aic_only". The pto-isa / ptoas side already implements the soft-mix and soft-aic barriers (SYNCALL_SOFT_MIX_IMPL / SYNCALL_SOFT_AIC_IMPL); this wires up the PyPTO side.

Changes

  • Soft syncall operands now vary by participant set:
    • aiv_only: [gm_workspace, ub_scratch, used_cores]
    • aic_only: [gm_workspace, l1_scratch, used_cores]
    • mix: [gm_workspace, ub_scratch, l1_scratch, used_cores] — a mix barrier rendezvouses AIC + AIV cores, so it is duplicated onto both lanes (SHARED) and each lane uses its own tile (matching pto-isa's soft-mix lowering). used_cores is the total participant count (AIC blocks + AIV subblocks).
  • tile.create(flat_layout=True) — a new flat (non-fractal, slayout=none_box) L1/cbuf staging tile. A normal boxed NZ Mat tile mis-places the 8-int32 counter slots; stamping memory_space=Mat at creation makes InferTileMemorySpace preserve the none_box view instead of overwriting it with the implicit boxed layout.
  • core_affinity classifies system.syncall by core_type (mix→SHARED, aic_only→CUBE, aiv_only→VECTOR) so a mix barrier reaches both lanes rather than being mis-labelled VECTOR from its UB scratch.
  • Generalized codegen operand assembly (3 or 4 operands), widened the convert-to-tile alias check, and round-tripped both scratch tiles through the printer/parser.
  • Docs (EN + ZH) and validation tests updated.

Testing

  • a2a3 device: mix (out = (a + 1) @ b + 1), aic_only (out = a @ b), and the aiv_only soft baseline all pass.
  • ptoas compiles both new forms; ROUNDTRIP verification passes.
  • Unit tests: mixed-kernel / convert-to-tile / tile.create UTs (239) pass; stale aiv_only-only assertion updated.

Related Issues

N/A

Extend soft-mode `system.syncall` (previously aiv_only-only) to
`core_type="mix"` and `core_type="aic_only"`.

- mix carries both a UB (Vec) and a flat L1 (Mat) scratch tile and is
  duplicated onto both the cube and vector lanes (SHARED); aic_only
  carries a single flat L1 scratch on the cube lane. Operand order matches
  pto-isa's soft-mix lowering: [gm_workspace, ub_scratch, l1_scratch,
  used_cores].
- Add `tile.create(flat_layout=True)` for a flat (slayout=none_box) L1/cbuf
  staging tile. A boxed NZ Mat tile mis-places the 8-int32 counter slots;
  stamping memory_space=Mat at creation makes InferTileMemorySpace preserve
  the none_box view.
- Classify `system.syncall` by core_type in core_affinity (mix->SHARED,
  aic_only->CUBE, aiv_only->VECTOR) so a mix barrier reaches both lanes.
- Generalize the codegen operand assembly (3 or 4 operands), widen the
  convert-to-tile alias check, and round-trip both scratch tiles through
  the printer.

Validated on a2a3: mix (out=(a+1)@b+1), aic_only (out=a@b), and the
aiv_only baseline all pass; ptoas compiles both new forms.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request extends the soft-mode system.syncall cross-core barrier to support all core types (aiv_only, aic_only, and mix) rather than just aiv_only. To support this, a new flat_layout option is added to tile.create to allocate a flat, non-fractal L1/cbuf staging tile (slayout=none_box) for cube-participating barriers. The compiler's IR, backend code generation, core affinity classification, and Python printer are updated to handle the varying operands (including multiple scratch tiles for the mix barrier). Extensive system and unit tests are added to verify the new soft barrier modes. There are no review comments to address, so no further feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@coderabbitai

coderabbitai Bot commented Jul 3, 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

Run ID: d7b0445d-ab68-482d-abbe-256e75f0f707

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

This PR generalizes system.syncall soft-mode barriers from supporting only core_type="aiv_only" to also support "aic_only" and "mix", adds a flat_layout option to tile.create for flat L1 staging tiles, and updates validation, MLIR lowering, the Python printer, dependency analysis, core affinity classification, tests, and docs.

Changes

system.syncall soft mode generalization

Layer / File(s) Summary
tile.create flat_layout parameter
python/pypto/ir/op/tile_ops.py, python/pypto/language/op/tile_ops.py, src/ir/op/tile_ops/memory.cpp
Adds optional flat_layout parameter to tile.create in Python and IR layers, validated as mutually exclusive with transpose and requiring target_memory=Mat, driving a creation_space override in DeduceTileCreateTileType.
Python syncall API and IR op validation
python/pypto/language/op/system_ops.py, python/pypto/ir/op/system_ops.py
Reworks pl.system.syncall soft mode to support aiv_only/aic_only/mix with a new scratch_l1 argument and internal UB/L1 scratch-tile helpers; updates syncall_soft op validation for core_type and operand arity (3 or 4 args).
Backend MLIR emission, dependency analysis, and printer
src/backend/common/pto_ops_common.cpp, src/ir/transforms/convert_tensor_to_tile_ops_pass.cpp, src/ir/transforms/python_printer.cpp, src/ir/transforms/utils/core_affinity.cpp
Generalizes MLIR pto.syncall operand validation/emission for 1–2 scratch tiles, updates dependency analysis and printer to handle 3/4-arg forms, and adds core_type-based affinity classification (CUBE/VECTOR/SHARED).
Tests and documentation
tests/st/runtime/cross_core/test_syncall.py, tests/ut/language/parser/test_system_ops.py, docs/en/dev/ir/05-operators.md, docs/zh-cn/dev/ir/05-operators.md
Adds mix-soft and aic-only-soft integration tests, refactors core-count helpers, updates unit test validation assertions, and updates docs to describe per-core-type operand layouts and flat L1 tile creation.

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

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant syncall as pl.system.syncall
  participant TileCreate as pl.tile.create
  participant IROp as syncall_soft (IR)
  participant Backend as pto_ops_common (MLIR emit)

  User->>syncall: syncall(mode="soft", core_type, gm_workspace, used_cores)
  syncall->>syncall: validate core_type in allowlist
  alt core_type is aiv_only or mix
    syncall->>TileCreate: create UB scratch tile
  end
  alt core_type is aic_only or mix
    syncall->>TileCreate: create flat L1 scratch tile (flat_layout=True)
  end
  syncall->>IROp: emit call with 3 or 4 operands
  IROp->>IROp: validate operand arity vs core_type
  IROp->>Backend: lower to pto.syncall
  Backend->>Backend: validate scratch dtypes, build operand/type lists
  Backend-->>User: emitted MLIR pto.syncall op
Loading

Possibly related PRs

  • hw-native-sys/pypto#1876: Adds the original hard/FFTS system.syncall barrier plumbing that this PR extends to the soft-mode variant.
  • hw-native-sys/pypto#1885: Introduces initial mode="soft" support for core_type="aiv_only", which this PR generalizes to aic_only and mix.

Suggested labels: enhancement

Poem

A rabbit hops through cores in sync,
AIC, AIV, mixed in a blink,
Flat L1 tiles now stack up neat,
Barriers soft, no more defeat,
Hop hop hop — three types now meet! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: extending soft syncall support to mix and aic_only core types.
Description check ✅ Passed The description matches the changeset and clearly describes the new soft syncall modes, flat_layout tile support, and related updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@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: 1657cd4725

ℹ️ 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 python/pypto/ir/op/tile_ops.py Outdated

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

🧹 Nitpick comments (1)
tests/ut/language/parser/test_system_ops.py (1)

147-172: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding round-trip tests for the new aic_only/mix soft forms.

test_syncall_soft_round_trip only exercises the 3-arg aiv_only path. The new python_printer.cpp branch adds distinct handling for aic_only (3-arg, scratch= is the L1 tile) and mix (4-arg, adds scratch_l1=) — a dedicated unit test per form would pin down that printer/parser contract independently of the full ST/backend pipeline.

🤖 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/language/parser/test_system_ops.py` around lines 147 - 172, Add
dedicated round-trip tests in test_syncall_soft_round_trip coverage for the new
pl.system.syncall soft forms, since the current test only verifies the aiv_only
path. Add one case that exercises the aic_only branch in python_printer.cpp and
confirms the scratch= L1 tile handling, and another that exercises the mix
branch and verifies scratch_l1= is preserved through AsPython/parse_program. Use
the existing test_syncall_soft_round_trip, Before.as_python, and
pl.parse_program flow to pin down each printer/parser contract independently.
🤖 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.

Nitpick comments:
In `@tests/ut/language/parser/test_system_ops.py`:
- Around line 147-172: Add dedicated round-trip tests in
test_syncall_soft_round_trip coverage for the new pl.system.syncall soft forms,
since the current test only verifies the aiv_only path. Add one case that
exercises the aic_only branch in python_printer.cpp and confirms the scratch= L1
tile handling, and another that exercises the mix branch and verifies
scratch_l1= is preserved through AsPython/parse_program. Use the existing
test_syncall_soft_round_trip, Before.as_python, and pl.parse_program flow to pin
down each printer/parser contract independently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 274943be-fc6c-4773-ba09-e04b931c2501

📥 Commits

Reviewing files that changed from the base of the PR and between 39a13a9 and 1657cd4.

📒 Files selected for processing (13)
  • docs/en/dev/ir/05-operators.md
  • docs/zh-cn/dev/ir/05-operators.md
  • python/pypto/ir/op/system_ops.py
  • python/pypto/ir/op/tile_ops.py
  • python/pypto/language/op/system_ops.py
  • python/pypto/language/op/tile_ops.py
  • src/backend/common/pto_ops_common.cpp
  • src/ir/op/tile_ops/memory.cpp
  • src/ir/transforms/convert_tensor_to_tile_ops_pass.cpp
  • src/ir/transforms/python_printer.cpp
  • src/ir/transforms/utils/core_affinity.cpp
  • tests/st/runtime/cross_core/test_syncall.py
  • tests/ut/language/parser/test_system_ops.py

lyfne123 added 2 commits July 3, 2026 21:04
- Add missing <string> include in core_affinity.cpp (cpplint)
- Wrap over-length soft-syncall core_type error message (ruff E501)
- Apply clang-format / ruff-format to changed files
…1944

Addresses review: inserting flat_layout before span shifted span's
positional slot, so a direct IR caller passing span positionally
(create(shape, dtype, mem, transpose, span)) would bind the Span to
flat_layout and fail AnyCast<bool> in DeduceTileCreateTileType. Restore
span to its original positional position and make flat_layout
keyword-only in both the IR and DSL create helpers.
@Hzfengsy Hzfengsy merged commit 726f678 into hw-native-sys:main Jul 3, 2026
11 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