Repository navigation
[CUDA] Avoid releasing DXGI adapters during DLL teardown - #4867
Merged
Merged
Conversation
strayberry
marked this pull request as ready for review
November 11, 2026 10:36
strayberry
marked this pull request as draft
November 11, 2026 10:41
This was referenced Nov 11, 2026
[BUG][CUDA][Windows] Process exits with 2170 after successful GPU work during mlx.dll teardown
#4878
Closed
zcbenz
force-pushed
the
fix/cuda-wddm-process-exit
branch
from
November 20, 2026 04:44
ebc3700 to
9d73bc7
Compare
zcbenz
force-pushed
the
fix/cuda-wddm-process-exit
branch
from
November 20, 2026 04:45
9d73bc7 to
455ebc2
Compare
zcbenz
marked this pull request as ready for review
November 20, 2026 04:45
zcbenz
approved these changes
Nov 20, 2026
rcfa
pushed a commit
to cubiculum-ai/mlx
that referenced
this pull request
Nov 26, 2026
…4867) Co-authored-by: Cheng <[email protected]> (cherry picked from commit 2905f33)
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.
On Windows, a program can finish its CUDA work successfully and still exit with
2170(0x87A) whenmlx.dllunloads.The function-local
WddmMemoryBudgetowns DXGI adapter references. Its destructor releases them during DLL teardown, under the loader lock. Microsoft documents that DXGI object creation and release must be avoided from DLLMain; the restriction also applies to static C++ destructors invoked by the CRT.Keep the budget cache alive through process teardown. This intentionally retains its allocation and adapter references until process termination. Repeated explicit DLL unload/reload resource reclamation is outside this change.
Add a separate CTest executable for Windows CUDA shared builds. It verifies that the WDDM budget is initialized, evaluates a GPU reduction, clears streams and returns normally. CTest then checks the actual process exit. Unsupported devices skip with code 77; a 30-second timeout also catches a teardown hang.
Validation
Fresh upstream
fc344c986, Windows x64, RTX 4060 Ti (sm_89, WDDM), driver 610.88, CUDA 13.0.48, cuDNN 9.19, MSVC 19.44, CPU+CUDA shared build.GPU work completed; testing process exit., then failsAll cases in
cuda_tests.cpppass after the fix: 4 cases, 16 assertions, process exit 0. Fullpre-commit run --all-filespasses withPYTHONUTF8=1. The full Python suite and explicit DLL unload/reload were not tested.Follow-up LayerNorm racecheck runs initially hung during termination with Compute Sanitizer 2025.3. Changing only the sanitizer package to 2025.4.0.0 (build 36782660) resolves the observed hang with the same executable, DLLs, CUDA 13.0 build/runtime environment and driver. Both DLL variants include this WDDM fix: without #4866's kernel fix, the scratch test reports 8 failed assertions and 8 hazards, then exits 86; with that kernel fix, both new tests pass 56/56 assertions with 0 hazards and exit 0. Both CUDA Graphs settings complete, and the passing variant was run twice per setting. These controls isolate the hang to the older sanitizer configuration, consistent with NVIDIA's documented Windows exit-hang fixes.
After configuring a Windows CUDA shared build with tests enabled and its runtime dependencies on PATH:
cmake --build build --config Release --target cuda_wddm_exit_test ctest --test-dir build -C Release -R "^cuda_wddm_process_exit$" --repeat until-fail:10 --output-on-failureTo reproduce the original failure, apply only the test changes to
fc344c986and run the same CTest. The original and patched SDKs were kept separate during validation.