Fix: Removed false sharing in Completion Watermark and added batched update - #1536
Fix: Removed false sharing in Completion Watermark and added batched update #1536raphael-s-steiner wants to merge 6 commits into
Conversation
Signed-off-by: raphaelsteiner <raphael.steiner@huawei.com>
Signed-off-by: raphaelsteiner <raphael.steiner@huawei.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe shared-memory ring gains centralized completion-flag and watermark helpers, with an alignment and layout assertion update. Orchestration and scheduler paths now use these helpers for fanin checks, completion publication, diagnostics, and watermark advancement. ChangesPolling completion state
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
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/a2a3/runtime/host_build_graph/runtime/pto_shared_memory.h`:
- Around line 116-131: Update update_completed_watermark so a failed
completed_watermark.compare_exchange_strong refreshes the scan state: reset next
from the newly loaded curr_watermark and reload submitted from
fc.current_task_index before rescanning completion flags. Preserve the existing
CAS success loop and completion-flag ordering while ensuring concurrent advances
cannot be overwritten or left behind.
🪄 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: a112fa00-83c4-490b-87d2-d21623888e13
📒 Files selected for processing (4)
src/a2a3/runtime/host_build_graph/runtime/orchestrator_core/pto_orchestrator.cppsrc/a2a3/runtime/host_build_graph/runtime/pto_shared_memory.hsrc/a2a3/runtime/host_build_graph/runtime/scheduler/pto_scheduler.hsrc/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_cold_path.cpp
Signed-off-by: raphaelsteiner <raphael.steiner@huawei.com>
|
Reviewed against the merge-base — the change is correct and all three optimizations are effective:
One request before merge: please squash the 6 commits into one, with a message describing the final change rather than the working process — the current history ("micro optimisation", "precommit", "padding", "batched watermark update", "modularised completion flags") is the kind of step-by-step narration the repo's codestyle rule asks us to keep out of commit messages. |
|
Single commit version of this PR: #1550. |
Summary
completion_flags[id & task_window_mask]load/store into two helpers onPTO2SharedMemoryRingHeader—is_completion_flag_set()/set_completion_flag()— and switches all 6 call sites (orchestrator, scheduler hot path, scheduler cold path) to use them instead.completed_watermarkCAS loop (advance by one slot, retry) withupdate_completed_watermark(), which scans the full contiguous completed prefix locally before issuing one CAS to jump the watermark forward by however many slots are ready — cutting the number of atomic RMW ops oncompleted_watermarkfrom O(advance distance) to O(contention events).alignas(64)totask_window_size, pushing the cold, read-mostly layout metadata onto its own cache line, separate from the hotcompleted_watermarkatomic that's CAS'd on every task completion — removes false sharing between the two.PTO2SharedMemoryRingHeaderlayoutstatic_assert(task_descriptors_offset: 160 → 216) to match; struct size stays 256 bytes.Why
completed_watermarkis CAS'd on the hot completion path for every task and previously shared a cache line with metadata read on nearly every fanin check, so each watermark bump invalidated that line for concurrent readers. Advancing it one slot at a time (instead of scanning the whole completed prefix) also meant up to N CAS attempts when several tasks completed in a burst.Testing
Ran
TestPagedAttention::Case2(a2a3 / tensormap_and_ringbuffer runtime) on NPU 3, 20 rounds each, from a clean build of both branches:Both branches pass golden comparison.
completion_watermarkis faster and meaningfully less jittery — consistent with fewer/cheaper atomic ops on the watermark and the removed false sharing.