Skip to content

feat: update comm ops ods and add testcases#648

Open
FangRui0 wants to merge 1 commit intohw-native-sys:mainfrom
FangRui0:comm_op
Open

feat: update comm ops ods and add testcases#648
FangRui0 wants to merge 1 commit intohw-native-sys:mainfrom
FangRui0:comm_op

Conversation

@FangRui0
Copy link
Copy Markdown
Contributor

@FangRui0 FangRui0 commented May 9, 2026

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 refactors the PTO communication dialect by renaming collective operations, implementing a more readable custom assembly format, and updating the EmitC lowering to utilize a new ParallelGroup abstraction. Feedback on the changes suggests improving the robustness of the MLIR Python bindings in the new test samples by explicitly handling optional operands with None and using keyword arguments for operation attributes to prevent potential positional argument mismatches.

is_root = arith.CmpIOp(arith.CmpIPredicate.eq, my_rank, c1_i32).result
root_if = scf.IfOp(is_root, [], hasElse=False)
with InsertionPoint(root_if.then_block):
pto.TBroadcastOp(src, ping, group, 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In MLIR Python bindings, operations with AttrSizedOperandSegments and Optional operands typically require all positional arguments to be provided in order. Since TBroadcastOp has an optional pong operand before the variadic group, passing group as the third positional argument might lead to a type mismatch or incorrect IR generation. It is safer to pass None for the optional pong and use keyword arguments for attributes like root.

Suggested change
pto.TBroadcastOp(src, ping, group, 1)
pto.TBroadcastOp(src, ping, None, group, root=1)

is_root = arith.CmpIOp(arith.CmpIPredicate.eq, my_rank, c1_i32).result
root_if = scf.IfOp(is_root, [], hasElse=False)
with InsertionPoint(root_if.then_block):
pto.CommTGatherOp(dst, ping, group, 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the broadcast operation, CommTGatherOp has an optional pong operand. The current positional call skips it, which may cause issues with standard MLIR Python bindings. Using explicit None for optional operands and keyword arguments for attributes is recommended.

Suggested change
pto.CommTGatherOp(dst, ping, group, 1)
pto.CommTGatherOp(dst, ping, None, group, root=1)

is_root = arith.CmpIOp(arith.CmpIPredicate.eq, my_rank, c1_i32).result
root_if = scf.IfOp(is_root, [], hasElse=False)
with InsertionPoint(root_if.then_block):
pto.CommTScatterOp(src, ping, group, 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The positional arguments here skip the optional pong operand. To ensure robustness across different MLIR binding versions, please provide None for the optional operand and use a keyword argument for the root attribute.

Suggested change
pto.CommTScatterOp(src, ping, group, 1)
pto.CommTScatterOp(src, ping, None, group, root=1)

Comment on lines +65 to +72
pto.TReduceOp(
dst,
acc,
recv,
group,
pto.ReduceOpAttr.get(pto.ReduceOp.Sum, ctx),
1,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The TReduceOp has an optional recvPong operand. The current call passes group in its place positionally. Additionally, attributes like reduceOp and root should ideally be passed as keyword arguments to avoid ambiguity and potential binding errors.

Suggested change
pto.TReduceOp(
dst,
acc,
recv,
group,
pto.ReduceOpAttr.get(pto.ReduceOp.Sum, ctx),
1,
)
pto.TReduceOp(
dst,
acc,
recv,
None,
group,
reduceOp=pto.ReduceOpAttr.get(pto.ReduceOp.Sum, ctx),
root=1,
)

@reedhecre
Copy link
Copy Markdown

reedhecre commented May 9, 2026

Codex Review

该评论由 review 机器人自动更新。

  • PR: feat: update comm ops ods and add testcases #648 feat: update comm ops ods and add testcases
  • Author: FangRui0
  • Base/Head: main / comm_op
  • Head SHA: 9ada56e8eebb
  • Trigger: PR 有新提交
  • Generated At: 2026-05-09T12:14:48Z
  • Previous Head SHA: 1223b1077300
  • Status: completed

Summary

PR #648 introduces backward-incompatible communication-op IR changes: it renames collective mnemonics and removes parsing support for the previously accepted p2p/signal syntax.

Findings

  1. P2 Renaming `comm_tgather`/`comm_tscatter` breaks existing textual IR compatibility include/PTO/IR/PTOOps.td:1778

This changes the public op names from pto.comm.comm_tgather / pto.comm.comm_tscatter to pto.comm.tgather / pto.comm.tscatter, but there is no parser alias or compatibility shim for the old spellings. origin/main still documents and tests the old mnemonics, so any existing .pto IR using them will stop assembling after this lands. The v0 opcode table was updated to emit only the new names as well, so old textual IR and bytecode/text round-trips no longer preserve the previous contract.

  1. P2 New comm-op assembly formats drop support for the previously accepted PTO IR syntax include/PTO/IR/PTOOps.td:1671

The assembly form for pto.comm.tput, tget, tnotify, twait, and ttest now only accepts the new parenthesized syntax (buf(...), typed signal operands, etc.). There is no custom parser support for the old surface syntax that origin/main documents (for example pto.comm.tput %dst, %src, %ping ... and pto.comm.tnotify %sig, %v ...). Existing .pto files written against the current syntax will fail to parse after upgrade, which is a user-visible compatibility regression.

Signed-off-by: FangRui <fangrui_95@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants