Refactor: rename sche_cpu_num to aicpu_thread_num for honest semantics#854
Merged
poursoul merged 1 commit intoMay 26, 2026
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request renames the variable sche_cpu_num to aicpu_thread_num across the a2a3 and a5 platforms to clarify that it represents the total number of AICPU threads launched. The changes span multiple components, including the runtime, device runners, and executors. Additionally, copyright headers were added to the affinity header files. The review feedback identifies a logical issue in the initialization sequence within aicpu_executor.cpp for both platforms: sched_thread_num_ is calculated before a defensive fixup for a zero thread count, potentially resulting in an incorrect value of -1 when the total thread count is adjusted to 1.
Runtime::sche_cpu_num was a legacy misnomer — its name implied
"scheduler thread count" but its value was always the *total* AICPU
thread count (orch + schedulers). AicpuExecutor::init had to spell out
the split with `sched_thread_num_ = thread_num_ - 1`, where the -1
carved out the orchestrator thread. The runtime field name lied; the
local variable's -1 did the bookkeeping the rename never did.
Renames (no behavior change):
- Runtime::sche_cpu_num → Runtime::aicpu_thread_num (matches the
user-facing CallConfig::aicpu_thread_num field)
- AicpuExecutor::thread_num_ → AicpuExecutor::aicpu_thread_num_
- SchedulerContext::thread_num_ → SchedulerContext::aicpu_thread_num_
(and the init() parameter)
- LOG_ERROR("Invalid thread_num:") → ("Invalid aicpu_thread_num:")
- Comment on Runtime::aicpu_thread_num expanded to describe the
orch/sched split (trb) or the no-split round-robin (hbg)
sched_thread_num_ (the AicpuExecutor / SchedulerContext member that
holds aicpu_thread_num_ - 1) keeps its name — it accurately means
"scheduler subset," and renaming it would only confuse the contrast
with the new total field.
Drive-bys surfaced by reviewers / hooks:
- Reorder the aicpu_thread_num_==0 fixup in AicpuExecutor::init to run
*before* sched_thread_num_ is derived. The pre-existing order left
sched_thread_num_ at -1 in the (currently unreachable) zero-input
edge case while aicpu_thread_num_ itself was corrected to 1.
- Add the standard copyright header to two platform_aicpu_affinity.h
files (pre-existing omission flagged by check-headers).
Mirrored across a5 + a2a3 × tensormap_and_ringbuffer + host_build_graph.
215312b to
f96a12a
Compare
poursoul
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pure rename, no behavior change. `Runtime::sche_cpu_num` was a legacy misnomer — the name implied "scheduler thread count" but the value was always the total AICPU thread count (orch + schedulers). The orch/sched split lived in `AicpuExecutor::init` as `sched_thread_num_ = thread_num_ - 1`, with the `-1` carving out the orchestrator thread. The runtime field name lied; the local `-1` did the bookkeeping the rename never did.
Renames
`sched_thread_num_` (the member holding `aicpu_thread_num_ - 1`) keeps its name — it accurately means "scheduler subset," and renaming it would only confuse the contrast with the new total field.
Drive-by
Two `platform_aicpu_affinity.h` files were missing the standard copyright header — surfaced by `check-headers` because the comment inside them was touched. Added the standard header to both (pre-existing omission, but no-skip rule applies).
Why
After PR #850, the user-facing field is `CallConfig::aicpu_thread_num` (clear: total) but it landed in `Runtime::sche_cpu_num` (confusing: implies scheduler-only). Reading `aicpu_executor.cpp:182-183` you have to figure out from context that `sche_cpu_num` means "total" — only the `-1` on the next line tells you. After this rename the same lines read:
```cpp
aicpu_thread_num_ = runtime->aicpu_thread_num;
sched_thread_num_ = aicpu_thread_num_ - 1; // -1 because the last thread is the orchestrator
```
Self-documenting.
Blast radius
28 files, 164/+122/− across `a5` + `a2a3` × `tensormap_and_ringbuffer` + `host_build_graph`. ChipWorker dlsym ABI is unchanged (the field rename is internal to the host/runtime contract; no exported symbol changed).
Test plan