Skip to content

Refactor: move comm-domain demos to scene tests - #1677

Closed
doraemonmj wants to merge 1 commit into
hw-native-sys:mainfrom
doraemonmj:refactor/issue-1616-scene-test-demos
Closed

Refactor: move comm-domain demos to scene tests#1677
doraemonmj wants to merge 1 commit into
hw-native-sys:mainfrom
doraemonmj:refactor/issue-1616-scene-test-demos

Conversation

@doraemonmj

Copy link
Copy Markdown
Contributor

Summary

  • convert seven L3 communication-domain demos from hand-built Workers to scene-test cases and goldens
  • keep each domain orchestration beside its kernels so the communication API remains readable
  • point readers who need the complete direct Worker lifecycle to the L3 allreduce walkthrough

Testing

  • pre-commit hooks
  • pytest collection for a2a3, a2a3sim, a5, and a5sim variants
  • standalone deferred-notify on a2a3sim and a5sim
  • a2a3sim deferred-notify with --rounds 2
  • offline callable compilation for all onboard-only a2a3/a5 classes
  • onboard execution (blocked: onboard-arch-precheck cannot identify silicon because npu-smi DCMI initialization fails with -8005)

Fixes #1616

- Keep each communication-domain orchestration beside its kernels
- Replace hand-built Workers and tolerance loops with cases and goldens
- Point direct Worker API readers to the L3 allreduce walkthrough

Fixes hw-native-sys#1616
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request converts seven communication-domain demos from standalone Worker and CLI runners to SceneTestCase tests. It adds declarative orchestration, callable metadata, generated arguments, golden validation, and CASES-based documentation.

Changes

a2a3 SceneTestCase migration

Layer / File(s) Summary
Notification and deferred-notify orchestration
examples/a2a3/tensormap_and_ringbuffer/{async_notify_demo,deferred_notify_demo}/test_*.py
The demos now allocate communication buffers, submit per-rank tasks, declare callables, generate tensor arguments, and compute golden outputs through SceneTestCase.
SDMA completion orchestration
examples/a2a3/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py
The SDMA demo now stages per-rank inputs, declares its callable and case configuration, and validates peer results through generated goldens.

a5 SceneTestCase migration

Layer / File(s) Summary
Notification and deferred-notify orchestration
examples/a5/tensormap_and_ringbuffer/{async_notify_demo,deferred_notify_demo}/test_*.py
The demos now use declarative communication setup, callable metadata, two-rank cases, generated tensors, and peer-result golden validation.
SDMA and URMA completion orchestration
examples/a5/tensormap_and_ringbuffer/{sdma_async_completion_demo,urma_deferred_completion_demo}/test_*.py
The completion demos now use SceneTestCase execution, workspace gating, CASES metadata, communication buffers, and golden results.

Routing and example documentation

Layer / File(s) Summary
CASES and Worker walkthrough documentation
docs/capability-survey.md, examples/{a2a3,a5}/tensormap_and_ringbuffer/README.md, examples/a5/tensormap_and_ringbuffer/{sdma_async_completion_demo,urma_deferred_completion_demo}/README.md
The documentation now describes CASES-based platform and device-count routing and links to the direct Worker communication-domain walkthrough.

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

Possibly related PRs

Poem

A rabbit hops through CASES bright,
Two ranks share results left and right.
Scene tests gather tasks in line,
Golden tensors make checks align.
Worker paths now close with care. 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR converts the demos and adds goldens, but it removes standalone entry points and does not consolidate shared orchestration as issue #1616 requests. Preserve standalone python execution and factor shared orchestration where required, or update issue #1616 to explicitly revise those objectives.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: refactoring communication-domain demos into scene tests.
Description check ✅ Passed The description accurately covers the scene-test refactor, documentation updates, testing, and known onboard execution limitation.
Out of Scope Changes check ✅ Passed The documentation updates support the refactor and do not introduce unrelated code changes.

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 commented Aug 4, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@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

🧹 Nitpick comments (2)
examples/a2a3/tensormap_and_ringbuffer/deferred_notify_demo/test_deferred_notify_demo.py (1)

104-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Duplicated generate_args and compute_golden across the migrated demos.

The same bodies appear in examples/a2a3/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py, examples/a2a3/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py, and the four a5 demos. The linked issue asks for shared helper modules and consolidation of near-duplicate a2a3 and a5 implementations. A small shared helper for per-rank tensor specs and peer-rotation goldens would remove six copies. Keep the orchestration functions next to their kernels as the PR describes.

🤖 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
`@examples/a2a3/tensormap_and_ringbuffer/deferred_notify_demo/test_deferred_notify_demo.py`
around lines 104 - 117, Extract the repeated generate_args and compute_golden
logic into a shared helper module for the migrated tensor-map/ringbuffer demos,
including per-rank tensor specification creation and peer-rotation golden
computation. Update the a2a3 and a5 demo test classes to reuse those helpers
while keeping orchestration functions beside their kernels; remove the
duplicated method bodies across the affected demos.
examples/a5/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py (1)

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

Guard the standalone path against a missing SDMA workspace.

pytest.mark.skipif only affects pytest collection. SceneTestCase.run_module at line 139 ignores pytest markers. If a user runs python test_sdma_async_completion_demo.py -p a5 without SIMPLER_ENABLE_PTO_SDMA_WORKSPACE, the case runs and fails inside the device path.

examples/a5/tensormap_and_ringbuffer/urma_deferred_completion_demo/test_urma_deferred_completion_demo.py already solves this: _require_urma_workspace_enabled() runs first in the orchestration function at line 49 and raises a clear RuntimeError. Mirror that pattern here.

♻️ Proposed guard
+def _require_sdma_workspace_enabled():
+    if not _sdma_workspace_enabled():
+        raise RuntimeError(
+            "sdma_async_completion_demo requires host runtime built with "
+            f"{_SDMA_WORKSPACE_ENV}=ON; set it before rebuilding simpler."
+        )
+
+
 def sdma_async_completion_orch_fn(orch, callables, task_args, config):
+    _require_sdma_workspace_enabled()
     input_nbytes = N * DTYPE_NBYTES

Also applies to: 73-77

🤖 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
`@examples/a5/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py`
at line 40, Update sdma_async_completion_orch_fn to call a dedicated workspace
guard before entering the device execution path, mirroring
_require_urma_workspace_enabled() in the URMA demo. Ensure the guard checks
SIMPLER_ENABLE_PTO_SDMA_WORKSPACE and raises a clear RuntimeError when the
workspace is unavailable, covering standalone SceneTestCase.run_module execution
as well as pytest.
🤖 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
`@examples/a2a3/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py`:
- Around line 91-108: Update generate_args to make each rank’s input tensor
rank-dependent by incorporating rank into the per-element value, such as a
rank-based offset plus i % 251, while preserving the existing dtype and tensor
structure. Leave compute_golden unchanged so it continues deriving expected
outputs from each rank’s own input.

In
`@examples/a5/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py`:
- Line 10: Update the module docstring in test_async_notify_demo.py to describe
only the notification-counter smoke test, removing the “deferred-completion”
wording while preserving the existing onboard a5 context.

---

Nitpick comments:
In
`@examples/a2a3/tensormap_and_ringbuffer/deferred_notify_demo/test_deferred_notify_demo.py`:
- Around line 104-117: Extract the repeated generate_args and compute_golden
logic into a shared helper module for the migrated tensor-map/ringbuffer demos,
including per-rank tensor specification creation and peer-rotation golden
computation. Update the a2a3 and a5 demo test classes to reuse those helpers
while keeping orchestration functions beside their kernels; remove the
duplicated method bodies across the affected demos.

In
`@examples/a5/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py`:
- Line 40: Update sdma_async_completion_orch_fn to call a dedicated workspace
guard before entering the device execution path, mirroring
_require_urma_workspace_enabled() in the URMA demo. Ensure the guard checks
SIMPLER_ENABLE_PTO_SDMA_WORKSPACE and raises a clear RuntimeError when the
workspace is unavailable, covering standalone SceneTestCase.run_module execution
as well as pytest.
🪄 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: 4b3ed449-b3f4-40bd-be00-5d0c9ab9fb40

📥 Commits

Reviewing files that changed from the base of the PR and between c634693 and 1ba0d92.

📒 Files selected for processing (12)
  • docs/capability-survey.md
  • examples/a2a3/tensormap_and_ringbuffer/README.md
  • examples/a2a3/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py
  • examples/a2a3/tensormap_and_ringbuffer/deferred_notify_demo/test_deferred_notify_demo.py
  • examples/a2a3/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py
  • examples/a5/tensormap_and_ringbuffer/README.md
  • examples/a5/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py
  • examples/a5/tensormap_and_ringbuffer/deferred_notify_demo/test_deferred_notify_demo.py
  • examples/a5/tensormap_and_ringbuffer/sdma_async_completion_demo/README.md
  • examples/a5/tensormap_and_ringbuffer/sdma_async_completion_demo/test_sdma_async_completion_demo.py
  • examples/a5/tensormap_and_ringbuffer/urma_deferred_completion_demo/README.md
  • examples/a5/tensormap_and_ringbuffer/urma_deferred_completion_demo/test_urma_deferred_completion_demo.py

Comment on lines +91 to +108
def generate_args(self, params):
specs = []
for rank in range(NRANKS):
inp = torch.tensor([float(i % 251) / 10.0 for i in range(N)], dtype=torch.float32)
specs.extend(
[
Tensor(f"in_{rank}", inp),
Tensor(f"out_{rank}", torch.zeros(N, dtype=torch.float32)),
Tensor(f"result_{rank}", torch.zeros(N, dtype=torch.float32)),
]
)
return TaskArgsBuilder(*specs)

def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--platform", default="a2a3")
parser.add_argument("-d", "--device", default="0-1")
args = parser.parse_args()
return run(args.platform, parse_device_range(args.device))
def compute_golden(self, args, params):
for rank in range(NRANKS):
expected_out = getattr(args, f"in_{rank}") * 2.0
getattr(args, f"out_{rank}").copy_(expected_out)
getattr(args, f"result_{rank}").copy_(expected_out + 1.0)

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect the async notify kernels to confirm local vs peer data flow.
fd -t f -p 'a2a3/tensormap_and_ringbuffer/async_notify_demo/kernels' -x sed -n '1,200p' {}

Repository: hw-native-sys/simpler

Length of output: 10053


Make the per-rank input rank-dependent.

Each rank computes out = in * 2 only from in_{rank}, so a rank-swap can still pass if every rank uses the same input values. Use a rank-offset input, such as rank * 1000 + (i % 251), so the golden fails when data from the wrong rank is used locally.

🤖 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
`@examples/a2a3/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py`
around lines 91 - 108, Update generate_args to make each rank’s input tensor
rank-dependent by incorporating rank into the per-element value, such as a
rank-based offset plus i % 251, while preserving the existing dtype and tensor
structure. Leave compute_golden unchanged so it continues deriving expected
outputs from each rank’s own input.

# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
"""Notification counter + deferred completion smoke test for onboard a5."""
"""Notification counter and deferred-completion smoke test for onboard a5."""

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

Correct the module docstring.

This module tests the notification-counter path. The phrase "deferred-completion" describes the deferred_notify_demo and sdma_async_completion_demo scenarios. Remove it here to keep the demo docs accurate.

📝 Proposed docstring fix
-"""Notification counter and deferred-completion smoke test for onboard a5."""
+"""Notification counter smoke test for onboard a5."""
📝 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
"""Notification counter and deferred-completion smoke test for onboard a5."""
"""Notification counter smoke test for onboard a5."""
🤖 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
`@examples/a5/tensormap_and_ringbuffer/async_notify_demo/test_async_notify_demo.py`
at line 10, Update the module docstring in test_async_notify_demo.py to describe
only the notification-counter smoke test, removing the “deferred-completion”
wording while preserving the existing onboard a5 context.

@doraemonmj doraemonmj closed this Aug 4, 2026
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.

[Code Health] L3 comm-domain examples hand-roll a Worker and their own verification, which @scene_test already supports

1 participant