Skip to content

fix(npu): disable XRT's residency controller so NPU buffers stay resi… - #1221

Merged
alfxu-amd merged 1 commit into
mainfrom
fix/aie2p-xrt-residency-controller
Dec 3, 2026
Merged

alfxu-amd merged 1 commit into
mainfrom
fix/aie2p-xrt-residency-controller

Conversation

@alfxu-amd

Copy link
Copy Markdown
Collaborator

On any internal machines, the XRT driver has enabled residency controller, which means under memory pressure, it will release the bo buffer (make it system memory) and only make it a bo buffer again once a command is using it. That slows down the flm and may also crash the npu runlist.

This PR fix it by manually set the disable_residency_controller as true.

For platforms that are not able to run new build, before run flm, do:

cmd:
set Runtime.disable_residency_controller=true

PowerShell (the dot in the name needs this syntax):
${env:Runtime.disable_residency_controller} = "true"

Then run flm, and the problem can be solved.

…dent

On aie2p Windows (driver ...4480), qwen3.6-moe's weights show up as system
memory while the model loads and only become NPU memory at the first
request.

The MCDM XRT shim (XRT-MCDM src/umd/shim) makes every BO resident when it
is allocated (alloc_bo_type -> D3DKMTMakeResident, CantTrimFurther). Its
residency controller, on by default since XRT-MCDM 7710e2a9 (2025-12),
registers for Windows trim notifications. On a trim it evicts the BOs of
every command not run since the last trim, including BOs created resident
whose command never ran, and makes them resident again at the next submit.
qwen3.6-moe builds its layer runs before its weights load, so a trim
during the long load pushes the weight BOs back to system memory until the
first request.

flm now sets Runtime.disable_residency_controller=true in
open_npu_device(), before the shared NPU device opens and before any BO is
allocated, in every Windows XRT build, with or without corelib. BOs then
keep the residency they get at allocation. ryzenai-corelib sets the same
value. If XRT has already read the key, flm warns.

Trade-off: XRT no longer releases idle NPU buffers under system memory
pressure; a loaded model's weights stay resident for the model's life.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Security scan found no critical or high findings on lines changed by this pull request

View the security scan run for complete reports.

“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta.

@tawei-amd
tawei-amd self-requested a review December 2, 2026 16:59
@tawei-amd

Copy link
Copy Markdown
Collaborator

@alfxu-amd tested on a lab machine. worked and safe to merge

@tawei-amd
tawei-amd requested a review from zaneni6 December 2, 2026 17:07
@alfxu-amd
alfxu-amd merged commit 79bc51f into main Dec 3, 2026
88 checks passed
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.

3 participants