Skip to content

feat(rknn): let the board state its aperture ceiling - #979

Closed
wOvAN wants to merge 1 commit into
0xShug0:mainfrom
wOvAN:rknn-aperture-budget-knob
Closed

wOvAN wants to merge 1 commit into
0xShug0:mainfrom
wOvAN:rknn-aperture-budget-knob

Conversation

@wOvAN

@wOvAN wOvAN commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Why

#970 moved the aperture accounting into the shared RKNN layer and left the ceiling, 3900 MiB, as a constant in the CosyVoice3 flow sidecar, where it is honest: it is a measurement of one board. That leaves every other board inheriting a number measured on RK3588, and the only way to change it is to edit a model file.

This adds the dial the same layer already has for the other board-specific request (AUDIOCPP_RKNN_CORE_MASK in framework/rknn/engine.cpp): AUDIOCPP_RKNN_APERTURE_MIB.

What

  • Unset keeps the measured 3900 MiB, so an RK3588 deployment that sets nothing is bit-identical to #970.
  • A positive value is the per-process resident budget in the driver's own unit (MiB).
  • Zero turns the accounting off and pins every rung the deployment declares. A malformed value reads as zero for the same reason: a typo must not silently mean a one-megabyte budget, which would evict on every request.
  • The effective budget is traced once per process (cosyvoice3.flow.dit.rknn.aperture_budget_mib) so a deployment can be audited from its log file.

No new option surface: this is board bring-up, not a per-request knob, and the session options are spec-validated, so a guard/bring-up dial does not belong in a family's schema.

Validation

PC (x86_64, -DENGINE_BUILD_TESTS=ON -DENGINE_BUILD_EXTENDED_TESTS=ON): engine_model_cosyvoice3 builds (the whole block is inside #if defined(ENGINE_HAVE_RKNN), so a PC build is unchanged), python3 tools/check_loader_catalog_sync.py passes.

Board (Orange Pi 5 Plus, RK3588, 31 GiB, native aarch64 build with -DENGINE_ENABLE_RKNN=ON -DENGINE_RKNN_INCLUDE_DIR=/usr/local/include -DENGINE_RKNN_LIBRARY=/usr/lib/librknnrt.so), one cold server per row, cosyvoice3-q8_0.gguf plus the six-rung flow_estimator_seq{110,200,250,400,500,900}.rknn ladder, requests alternating rung 200 (n=4/10) and rung 400 (n=50):

/root/pinladder/ab11-run.sh <tag> <binary> <AUDIOCPP_RKNN_APERTURE_MIB> [request series]
env loads (count of flow.dit.rknn.load_ms) resident trace wall total peak RSS
unset 2 1129, 3744 142.5 s 6.20 GiB
=3900 2 1129, 3744 142.3 s 6.21 GiB
=2555 6 1129, 2615, 1129, 2615, 1129 154.3 s 5.07 GiB
=0, series 4 50 72 2 1129, 3744 third request fails at 4.7 s 6.85 GiB

Unset and =3900 agree to within 0.2% of wall on all six requests, which is the default-preserving claim. =2555 shows the dial acting: 200+400 (3744 MiB) no longer fits, so every length change evicts and re-inits (loads 2 -> 6), costing +8.3% wall and returning 1.13 GiB of RSS. =0 pins 200+400, which this board does admit at 3744 MiB, and the next longer rung dies at init with the driver's own answer: CosyVoice3 flow estimator RKNN: rknn_init failed with code -6, surfaced as rc=500 with the server surviving - that is the documented price of declaring a set wider than the aperture, and the reason the default stays the measured number.

Audio is unaffected by the dial: rung 200 and rung 400 renders are f2864dfeb0f5... and b127028a9ee3... in all three accounting rows.

Limits

The dial is model-local, like the measurement it dials. When a second family grows a ladder it should read the same env var, at which point the reading belongs in framework/rknn next to the core mask; one consumer is not worth moving it.

`0xShug0#970` shipped the aperture accounting with RK3588's measured per-process
ceiling, 3900 MiB, as a constant in the CosyVoice3 flow sidecar. The accounting
is shared (`rknn::ApertureBudget`) and the number is not, so the number needs a
dial: `AUDIOCPP_RKNN_APERTURE_MIB` overrides it in the spirit of the
`AUDIOCPP_RKNN_CORE_MASK` read beside it, and zero (the reading of a malformed
value too, so a typo cannot silently mean one megabyte) turns the accounting off
and pins every rung the deployment declares. The default is the measured
3900 MiB, so an RK3588 deployment that sets nothing is unchanged; a board that
has not been measured opts out without a code edit, at the price of a failed
`rknn_init` if its declared set is wider than its aperture.

Effective budget is traced once per process
(`cosyvoice3.flow.dit.rknn.aperture_budget_mib`) so a deployment can be audited
from its log.
@0xShug0

0xShug0 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

The board-configurable ceiling is useful, but:

@wOvAN

wOvAN commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Both review points from here are folded into #975, which now carries the same knob under one name: aperture_budget_mib() in cosyvoice3/rknn_flow.cpp, reading AUDIOCPP_RKNN_APERTURE_MIB (unset → 3900, 0 disables accounting), with the trace key cosyvoice3.flow.dit.rknn.aperture_budget_mib kept as-is — so after both land there is exactly one definition, no second rknn_aperture_budget_mib.

The RKNN-enabled compilation concern is verified on hardware: the reworked #975 tree builds clean natively on the RK3588 board with ENGINE_ENABLE_RKNN=ON (models piper/kokoro/qwen3/cosyvoice3/f5/voxcpm2), and rknn_engine_test plus server_config_test pass there against the real librknnrt.so 2.3.2.

Resolving this in favor of #975 to keep the residency work one reviewable stack; the code lands through that PR either way.

@wOvAN

wOvAN commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #975 (head 1014af3): single aperture_budget_mib() with the AUDIOCPP_RKNN_APERTURE_MIB env knob and the same trace key, and RKNN-enabled compilation verified green on the RK3588 board. Closing in favor — the code lands through that PR.

@wOvAN wOvAN closed this Oct 19, 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.

2 participants