Repository navigation
refactor(rknn): split the aperture accounting from the aperture measurements - #957
Merged
Merged
Conversation
…rements
The resident-set arithmetic a sidecar needs when it keeps more than one compiled engine loaded is
model-agnostic; the numbers that drive it are not. So the arithmetic moves to `engine::rknn` and the
numbers stay with the sidecar that measured them.
- `ApertureBudget(mib_per_unit, budget_mib)`: the resident set is the sum of the units the loaded
engines reserve, and a new engine is pinned only while the whole set stays inside the budget. It
holds no ceiling of its own.
- `cosyvoice3/rknn_flow.cpp` keeps `kApertureMiBPerFrame = 5` and `kAperturePinBudgetMiB = 2800`
with the full RK3588 co-residency matrix that derived them, and `pick()` loses its scan over the
slot vector. Engine selection (which rung serves a request) is untouched and stays model-local.
Behaviour is unchanged, measured on RK3588 (Orange Pi 5 Plus) against the recorded pre-move side of
the same stand: one `audiocpp_server` with the flow-estimator ladder
(`cosyvoice3.exec_plan={"flow":{"impl":"rknn",...}}`), 3 cold ladders x 6 alternating-rung requests
(4/10/14/20/26/34 chars -> 118/158/202/192/220/228 mel frames) — all 18 clips bit-identical,
`loads 2` on every run, wall 283.034 -> 281.837 s, peak RSS 5090-5099 -> 5099 MiB.
The arithmetic gets a unit test on that board trace (`rknn_engine_test`): the served sequence must
load exactly two engines and end with a 450-frame resident set, and a 900-frame rung must not fit the
aperture on its own. It reproduces the recorded board numbers, so a budget that evicts a short rung
it should keep fails on a host build.
wOvAN
force-pushed
the
rknn-aperture-ladder
branch
from
October 17, 2026 22:38
0f333f0 to
f32245c
Compare
Owner
|
@wOvAN Thanks! PRs merged! |
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.
What splits
Rework of the first shape of this branch, following the review on #951: engine selection and
residency management are separate concerns, model-specific execution policy stays local, and a
measured RK3588 constraint should not become a universal runtime constant.
engine::rknn: the accounting.ApertureBudget(mib_per_unit, budget_mib)— theresident set is the sum of the units the loaded engines reserve, and a new engine is pinned only
while the whole set stays inside the budget; a unit that cannot share the aperture with the set
evicts it and is itself evicted by the next change of shape. The type holds no ceiling and no cost
of its own, so it carries no board's measurement.
cosyvoice3/rknn_flow.cpp: the measurements.kApertureMiBPerFrame = 5andkAperturePinBudgetMiB = 2800with the full co-residency matrix that derived them (0.27 GiB atS=110, 0.48 at 200, 0.77 at 250, 1.93 at 400, 3.04 at 500, 4.39 at 900, against 661-714 MB engine
files; S=200 x3, 250+250+110 and 110 x4 initialize together at <= 1.81 GiB, S=400 coexists only
with 110/200, S=500 with nothing).
pick()still decides which rung serves a request(smallest compiled length that fits) and what runs off-NPU (the CPU graph past the largest rung).
It loses only its scan over the slot vector, which the budget now accounts.
What can genuinely be shared between CosyVoice3 and Qwen3-TTS
Asked first, so here it is, from the two implementations:
flowspeech_decoderS=110…900), count is the operator's choicefirstis configured; the pair is mandatory, so a budget that refuses one is a load-time assert, not a policySo the intersection is exactly the accounting, which is what this branch moves; selection and the
numbers are not in it. Qwen3-TTS is deliberately not wired to the type here: it has no selection to
feed, and wiring it would mean inventing a policy (refuse the pair, or run one engine) that nobody
measured.
Measurements
RK3588 (Orange Pi 5 Plus), the stand that produced the numbers above: one
audiocpp_serverwithcosyvoice3.exec_plan={"flow":{"impl":"rknn","artifacts":{"main":"...seq110.rknn,...seq200.rknn,..."}}},3 cold ladders × 6 alternating-rung requests (4/10/14/20/26/34 chars → 118/158/202/192/220/228 mel
frames), the pre-move side recorded from the same build tree.
A relocation, and the wall/RSS columns say so.
Validation
rknn_engine_test(existing target, no new registration) replays that board trace throughApertureBudget(5, 2800)on a host build: the served sequence must load exactly two engines andend at a 450-frame resident set,
fits(500)must be false beside 200+250 and true on a clearedbudget, and
fits(900)false on its own. A budget that evicts a short rung it should keep failsctestwithout a board.cosyvoice3/rknn_flow.cppcompiles with-DENGINE_HAVE_RKNN(stubrknn_api.hhere; the boardbuild is the real one,
ENGINE_ENABLE_RKNN=ON, rc=0).tools/check_loader_catalog_sync.py→ok(no spec surface touched).docs/build/rockchip-npu.md: the ladder bullet no longer says «single-resident» (it stopped beingtrue when the estimator ladder started keeping short rungs pinned) and now states which half of
the accounting is shared and which half is a board measurement.