Skip to content

Fix: port a2a3 L2 swimlane Bugs 1+2 to a5 scheduler_cold_path#940

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
hw-native-sys-bot:port/swimlane-bugs-1-2-a5
May 31, 2026
Merged

Fix: port a2a3 L2 swimlane Bugs 1+2 to a5 scheduler_cold_path#940
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
hw-native-sys-bot:port/swimlane-bugs-1-2-a5

Conversation

@hw-native-sys-bot
Copy link
Copy Markdown
Collaborator

Summary

Mechanical backport of two of the four L2 swimlane bugs landed for a2a3 in #936. The a5 file has the identical code shape at the same call site (scheduler_cold_path.cpp:854-860), so the patch is the same shape (+11 / -2 lines).

# Bug Trigger
1 l2_swimlane_aicpu_init_phase uses sched_thread_num_ instead of orch_to_sched_ ? aicpu_thread_num_ : sched_thread_num_ PTO2_ORCH_TO_SCHED=1 + SCHED_PHASES level + aicpu_thread_num_ > sched_thread_num_; under-allocates phase pools and silently drops tail records
2 l2_swimlane_level_ not reset when is_l2_swimlane_enabled() == false (no else branch) Prior enabled launch's cached level leaks into the >= SCHED_PHASES gates in scheduler_dispatch.cpp (a5 site at scheduler_dispatch.cpp:517 reads the same field), writing into an uninitialized phase pool on the disabled-this-launch run

Bug 1's fix mirrors the existing precedent in src/a5/.../scheduler_dispatch.cpp:494 (dump_tensor_init already uses the orch_to_sched_ ternary).

Why only 2 of the 4 bugs

The a5 swimlane subsystem architecturally diverges from a2a3 — Bugs 3 and 4 don't apply in the same form:

  • Bug 3 (AICore rotation slot stale leak): a5 uses a fixed per-core ring (L2SwimlaneAicoreRing with dual_issue_slots), not a rotated buffer pool. src/a5/platform/onboard/aicore/kernel.cpp:113-118 already publishes set_aicore_l2_swimlane_ring(nullptr) in the disabled branch.
  • Bug 4 (resolve_entry invalid kind): a5 L2SwimlaneBufferKind is a binary is_phase flag (only AicpuTask / AicpuPhase, no AicoreTask), so the wrong-typed-pool fall-through doesn't exist in the same form.

Test plan

  • Build all four variants (a5 + a2a3, onboard + sim) clean
  • pytest tests/st/a5/tensormap_and_ringbuffer/dummy_task --platform a5sim passes
  • pre-commit run clean
  • CI green (onboard + sim, a5 + a2a3)

Dependency

Independent of #936 (a2a3) — touches a different arch. Can land in either order.

Mechanical backport of two of the four bugs landed for a2a3 in hw-native-sys#936.
The a5 file has the identical code shape at the same call site
(scheduler_cold_path.cpp:854-860), so the patch is the same shape:

  1. l2_swimlane_aicpu_init_phase phase pool count: pass
     `aicpu_thread_num_` (not `sched_thread_num_`) when
     `orch_to_sched_=true`. Mirrors the existing precedent in
     `src/a5/.../scheduler_dispatch.cpp:494` (`dump_tensor_init`).
     Without this, `PTO2_ORCH_TO_SCHED=1` + `SCHED_PHASES` level +
     `aicpu_thread_num_ > sched_thread_num_` under-allocates phase
     pools and silently drops the tail records.

  2. Reset `l2_swimlane_level_` to DISABLED when
     `is_l2_swimlane_enabled() == false` this launch. Without this,
     a prior enabled launch's cached level leaks into the
     `>= SCHED_PHASES` gates in scheduler_dispatch (a5
     scheduler_dispatch.cpp:517 reads the same field), writing into
     an uninitialized phase pool on the disabled-this-launch run.

a2a3 Bugs 3 and 4 do NOT apply to a5:
  - Bug 3 (AICore rotation slot stale leak): a5 uses a fixed per-core
    ring (`L2SwimlaneAicoreRing` with dual_issue_slots), not a
    rotated buffer pool, and `src/a5/platform/onboard/aicore/kernel.cpp:113-118`
    already publishes `set_aicore_l2_swimlane_ring(nullptr)` in the
    disabled branch.
  - Bug 4 (resolve_entry invalid kind): a5 `L2SwimlaneBufferKind` is
    a binary `is_phase` flag (only AicpuTask/AicpuPhase, no
    AicoreTask), so the wrong-typed-pool fall-through doesn't exist
    in the same form.

Test plan:
  - Build all four variants (a5 + a2a3, onboard + sim) — clean
  - pytest tests/st/a5/.../dummy_task --platform a5sim — passes
  - pre-commit clean
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Warning

Review limit reached

@hw-native-sys-bot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 34 minutes and 38 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 31b87a04-fea9-4e00-ac09-c8e79d809ab8

📥 Commits

Reviewing files that changed from the base of the PR and between f97a2dd and e9ce794.

📒 Files selected for processing (1)
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_cold_path.cpp

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 and usage tips.

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 updates SchedulerContext::init to reset l2_swimlane_level_ to DISABLED when swimlanes are disabled, preventing state leakage from previous launches. It also dynamically determines the number of phase threads based on the orch_to_sched_ flag. The reviewer suggests using int32_t instead of int for phase_threads to ensure type consistency and avoid potential compiler warnings.

@ChaoWao ChaoWao merged commit c06c8b5 into hw-native-sys:main May 31, 2026
15 checks passed
@ChaoWao ChaoWao deleted the port/swimlane-bugs-1-2-a5 branch May 31, 2026 07:37
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