Skip to content

feat(distributed): add multicore HOST AllReduce - #2160

Open
sunkaixuan2018 wants to merge 1 commit into
hw-native-sys:mainfrom
sunkaixuan2018:skx/multicore-allreduce-design
Open

feat(distributed): add multicore HOST AllReduce#2160
sunkaixuan2018 wants to merge 1 commit into
hw-native-sys:mainfrom
sunkaixuan2018:skx/multicore-allreduce-design

Conversation

@sunkaixuan2018

Copy link
Copy Markdown
Contributor

Summary

  • add a compile-time core_num option to HOST tensor AllReduce while preserving the single-core default
  • synthesize and validate one signal lane per logical block, then launch a synchronized backend-specific AIV grid
  • partition AllReduce chunks by block identity and document the API, lowering, launch, and signal contracts in English and Chinese
  • add unit, codegen, and multi-device NPU coverage for idle lanes, wide signal strides, and multi-chunk execution

Testing

  • ruff check .
  • ruff format --check .
  • pyright
  • targeted unit tests: 262 passed
  • full unit tests: 7801 passed, 2 skipped
  • NPU system tests: 3 passed on A2/A3 (2x2, 2x4, and 4x2 rank/core cases)

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a keyword-only core_num parameter to pld.tensor.allreduce, propagates it through IR, signal synthesis, host lowering, code generation, and runtime templates, and adds multicore validation, codegen coverage, hardware tests, and design documentation.

Changes

HOST AllReduce multicore support

Layer / File(s) Summary
API, IR, and signal synthesis
python/pypto/..., src/ir/op/distributed/..., src/ir/transforms/synthesize_allreduce_signals_pass.cpp, docs/...
core_num is validated and preserved through the public API and IR; implicit signals use [world_size, core_num] and corresponding buffer sizes.
Host lowering and validation
src/ir/transforms/lower_host_tensor_collectives_pass.cpp, src/ir/op/distributed/collective.cpp, src/ir/transforms/lower_composite_ops_pass.cpp, tests/ut/ir/transforms/*
Host mesh allreduce forwards core_num, validates lane capacity and packed layouts, and rejects unsupported ring or InCore multicore cases.
Launch and kernel execution
src/codegen/distributed/distributed_ops_codegen.cpp, python/pypto/runtime/builtins/collectives/allreduce/templates/*, tests/ut/codegen/distributed/*
Orchestration receives a fifth scalar, configures synchronized multicore launches, and the kernel uses block-strided work and per-block signal addressing.
Integration validation and proposals
tests/st/distributed/test_l3_host_tensor_allreduce_multicore.py, docs/*/dev/proposals/*
The hardware test checks reduced outputs and every signal lane; proposal documents define launch, signal, SPMD, and acceptance contracts.

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

Possibly related issues

Possibly related PRs

Suggested labels: bug

Poem

A bunny adds lanes, four hops in a row,
Signals bloom where the core counters flow.
Mesh paths awaken, ring paths wait,
Blocks share tiles at synchronized gate.
“Hop!” says the rabbit, “the sums now agree!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.90% 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 is concise and accurately summarizes the main change: multicore HOST AllReduce support.
Description check ✅ Passed The description is clearly related to the changeset and matches the documented API, lowering, launch, and test updates.
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: cc80601c8b

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

CHECK(pypto::backend::BackendConfig::IsConfigured())
<< "builtin.tensor.allreduce codegen requires a configured backend";
const auto* backend = pypto::backend::GetBackend();
const int max_block_dim = backend->GetCoreCount(ir::CoreType::CUBE);

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 Use the AIV capacity for AIV launches

The generated builtin is submitted with rt_submit_aiv_task, so its maximum launch width must come from CoreType::VECTOR, not CoreType::CUBE. The configured 910B model has 48 vector cores versus 24 cube cores, and 950 has 36 versus 18, so valid requests such as core_num=32 are incorrectly rejected even though the target device has enough AIV cores.

Useful? React with 👍 / 👎.

for loop in _collect_for_stmts(host.body)
if isinstance(loop.body, ir.EvalStmt)
and isinstance(loop.body.expr, ir.Call)
and loop.body.expr.op.name == "builtin.tensor.allreduce"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Route operator literals through the registry

Replace this raw .op.name literal comparison, and the equivalent new comparisons in the signal-synthesis test, with ir.get_op("...").name. A typo or operator rename currently makes the comprehension silently select no nodes and fail later with an ambiguous assertion instead of reporting the invalid operator at the comparison site, contrary to the repository's required operator-identity convention. .claude/rules/operator-identity-checks.mdL5-L13

Useful? React with 👍 / 👎.

@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 `@docs/en/dev/proposals/host_allreduce_spmd_multicore.md`:
- Around line 5-6: Update the proposal status to reflect that multicore HOST
AllReduce is implemented and validated, replacing the outdated unimplemented
wording in docs/en/dev/proposals/host_allreduce_spmd_multicore.md lines 5-6 and
the matching Chinese wording in
docs/zh-cn/dev/proposals/host_allreduce_spmd_multicore.md line 5; mark both
documents as implemented/historical or describe only remaining limitations.

In `@src/codegen/distributed/distributed_ops_codegen.cpp`:
- Around line 227-230: Update the core_num capacity check in the
builtin.tensor.allreduce generation path to use
backend->GetCoreCount(ir::CoreType::VECTOR), matching the AIV launch capacity
used by launch_core_count_method (set_block_num/set_core_num), while preserving
the existing validation and error message behavior.
🪄 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: 6df44fe7-0c7f-4507-adf5-fb27864e075d

📥 Commits

Reviewing files that changed from the base of the PR and between 768c6f9 and cc80601.

📒 Files selected for processing (24)
  • docs/en/dev/distributed_ops.md
  • docs/en/dev/passes/37-synthesize_allreduce_signals.md
  • docs/en/dev/passes/39-lower_host_tensor_collectives.md
  • docs/en/dev/proposals/host_allreduce_spmd_multicore.md
  • docs/zh-cn/dev/distributed_ops.md
  • docs/zh-cn/dev/passes/37-synthesize_allreduce_signals.md
  • docs/zh-cn/dev/passes/39-lower_host_tensor_collectives.md
  • docs/zh-cn/dev/proposals/host_allreduce_spmd_multicore.md
  • python/pypto/ir/op/distributed/tensor_ops.py
  • python/pypto/language/distributed/op/tensor_ops.py
  • python/pypto/runtime/builtins/collectives/allreduce/templates/entry.cpp.in
  • python/pypto/runtime/builtins/collectives/allreduce/templates/kernel.cpp.in
  • src/codegen/distributed/distributed_ops_codegen.cpp
  • src/ir/op/distributed/allreduce.cpp
  • src/ir/op/distributed/collective.cpp
  • src/ir/transforms/lower_composite_ops_pass.cpp
  • src/ir/transforms/lower_host_tensor_collectives_pass.cpp
  • src/ir/transforms/synthesize_allreduce_signals_pass.cpp
  • tests/st/distributed/test_l3_host_tensor_allreduce_multicore.py
  • tests/ut/codegen/distributed/test_host_orch_distributed.py
  • tests/ut/ir/test_distributed_ops.py
  • tests/ut/ir/transforms/test_lower_composite_ops.py
  • tests/ut/ir/transforms/test_lower_host_tensor_collectives.py
  • tests/ut/ir/transforms/test_materialize_comm_domain_scopes.py

Comment on lines +5 to +6
Proposed design for the first hardware-validation implementation. This document
does not describe an implemented feature yet.

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

Update the proposal status to reflect the implemented feature.

These statements say multicore HOST AllReduce is not implemented, while this PR implements and validates it. Mark the proposals as implemented/historical, or revise the wording to identify only remaining limitations.

  • docs/en/dev/proposals/host_allreduce_spmd_multicore.md#L5-L6: replace the “does not describe an implemented feature yet” status.
  • docs/zh-cn/dev/proposals/host_allreduce_spmd_multicore.md#L5-L5: replace “目前还没有实现对应功能” with matching implemented/historical status.
📍 Affects 2 files
  • docs/en/dev/proposals/host_allreduce_spmd_multicore.md#L5-L6 (this comment)
  • docs/zh-cn/dev/proposals/host_allreduce_spmd_multicore.md#L5-L5
🤖 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 `@docs/en/dev/proposals/host_allreduce_spmd_multicore.md` around lines 5 - 6,
Update the proposal status to reflect that multicore HOST AllReduce is
implemented and validated, replacing the outdated unimplemented wording in
docs/en/dev/proposals/host_allreduce_spmd_multicore.md lines 5-6 and the
matching Chinese wording in
docs/zh-cn/dev/proposals/host_allreduce_spmd_multicore.md line 5; mark both
documents as implemented/historical or describe only remaining limitations.

Comment on lines +227 to +230
const int max_block_dim = backend->GetCoreCount(ir::CoreType::CUBE);
CHECK(core_num <= max_block_dim) << "builtin.tensor.allreduce core_num (" << core_num
<< ") exceeds the backend logical block capacity (" << max_block_dim
<< ")";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C3 'GetCoreCount\(|GetLaunchSpecCoreCountMethod|set_block_num|set_core_num|CoreType::(CUBE|VECTOR)' include src tests

Repository: hw-native-sys/pypto

Length of output: 29309


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== distributed allreduce relevant section =="
sed -n '190,245p' src/codegen/distributed/distributed_ops_codegen.cpp

echo "== backend core count implementation =="
sed -n '365,405p' src/backend/common/backend.cpp
sed -n '110,190p' src/backend/common/soc.cpp

echo "== handler counts and set methods =="
rg -n -C4 'GetLaunchSpecCoreCountMethod|set_block_num|set_core_num|block_num|core_num|available_cluster_count|available_aiv_count' include/pypto backend templates src tests/ut/codegen/distributed src/codegen/distributed | head -n 220

echo "== locate allreduce templates =="
fd -a 'allreduce|tensor.allreduce|builtin_tensor_allreduce|collective' | sed 's#^\./##' | head -n 200

echo "== allreduce template relevant files =="
python3 - <<'PY'
from pathlib import Path
for p in Path('.').rglob('*'):
    if p.is_file() and 'allreduce' in p.name.lower().replace('_', '').replace('-', ''):
        print(p)
PY

Repository: hw-native-sys/pypto

Length of output: 29702


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate allreduce templates =="
git ls-files | rg -n -i 'allreduce|collectives|builtins' | head -n 200

echo "== allreduce template files =="
python3 - <<'PY'
from pathlib import Path
matches = []
base = '.'
for p in Path(base).rglob('*'):
    if not p.is_file():
        continue
    s = str(p)
    if 'allreduce' in s.lower() or ('collectives' in s.lower() and 'allreduce' in p.name.lower()):
        matches.append(s)
matches.sort()
for m in matches:
    print(m)
PY

echo "== allreduce template content (if any) =="
python3 - <<'PY'
from pathlib import Path
for p in Path('.').rglob('*'):
    if not p.is_file():
        continue
    if 'allreduce' in p.name.lower() or ('collectives' in p.parent.name.lower() and p.exists()):
        try:
            text = p.read_text(errors='ignore')
        except Exception as e:
            print(f"UNREADABLE {p}: {e}")
            continue
        if 'allreduce' in text.lower() or 'submit_allreduce_kernel' in text or 'core_count' in text:
            print(f"\n== {p} ==")
            print(text[:6000])
PY

Repository: hw-native-sys/pypto

Length of output: 50377


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in \
  python/pypto/runtime/builtins/collectives/allreduce/templates/entry.cpp.in \
  python/pypto/runtime/builtins/collectives/allreduce/templates/kernel.cpp.in \
  python/pypto/runtime/builtins/collectives/allreduce/templates/kernel_config.py.in \
  tests/ut/codegen/distributed/test_host_orch_distributed.py \
  tests/st/distributed/test_l3_host_tensor_allreduce_multicore.py
do
  echo "== ${f##*/} =="
  sed -n '1,260p' "$f"
done

echo "== backend handlers =="
sed -n '1,70p' include/pypto/backend/910B/backend_910b_handler.h
sed -n '1,70p' include/pypto/backend/950/backend_950_handler.h

Repository: hw-native-sys/pypto

Length of output: 37292


Use VECTOR core count for AIV launch capacity.

builtin.tensor.allreduce renders AIV dispatch with launch_core_count_method (set_block_num / set_core_num), while this check caps core_num against CoreType::CUBE. 950 has fewer AIV/available cluster cores than AIC cores in this config, so 950 can accept values it cannot launch and may reject valid valid 910B AIV launch widths; base the check on the same VECTOR runtime capacity used for the AIV allreduce grid.

🤖 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/codegen/distributed/distributed_ops_codegen.cpp` around lines 227 - 230,
Update the core_num capacity check in the builtin.tensor.allreduce generation
path to use backend->GetCoreCount(ir::CoreType::VECTOR), matching the AIV launch
capacity used by launch_core_count_method (set_block_num/set_core_num), while
preserving the existing validation and error message behavior.

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