fix: load Windows backend modules with altered search path#227
Conversation
|
Chat app preview removed for |
There was a problem hiding this comment.
Pull request overview
This PR improves Windows CUDA backend loading by preloading bundled CUDA redistributable DLLs (e.g., cudart, cublas, cublasLt) from the resolved native backend bundle directory before attempting to load ggml-cuda.dll. This makes CUDA backend discovery less dependent on PATH/current working directory behavior on Windows and adds a regression test plus a changelog entry.
Changes:
- Preload Windows CUDA dependency DLLs (by absolute path) before loading the CUDA backend module, keeping the
DynamicLibraryhandles alive for the service lifetime. - Add a unit test verifying dependency selection and preload ordering for the Windows CUDA bundle layout.
- Document the fix under a new
## Unreleasedsection inCHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/src/backends/llama_cpp/llama_cpp_service.dart | Adds Windows-only dependency preloading and helper logic to select/sort CUDA DLLs. |
| test/unit/backends/llama_cpp/llama_cpp_service_test.dart | Adds regression coverage for Windows CUDA dependency selection/order. |
| CHANGELOG.md | Documents the Windows CUDA preload fix under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7ba8287 to
10fe7c8
Compare
|
On the PR branch ( The empty reason is Win32 error 126 (module not found). Testing the bundled
So preloading the redistributables doesn't resolve it — the loader still can't find the CUDA module's dependencies in the bundle dir. Adding the bundle directory to the DLL search path does. Confirmed end-to-end: with the bundle dir on Suggest loading the backend with |
|
Thanks — this is exactly the missing loader behavior. Preloading I updated the PR to temporarily preload the backend module itself with The latest head |
|
Confirmed fixed on Before this commit the same probe printed |
Summary
LoadLibraryExW(..., LOAD_WITH_ALTERED_SEARCH_PATH)before handing the same path to llama.cpp'sggml_backend_load().CHANGELOG.md.Context
Elana reported in
leehack/llamadart-native#22thatllamadart-nativeb9694bundlescudart64_12.dll,cublas64_12.dll, andcublasLt64_12.dllbeside the CUDA backend, butllamadartstill fails to load CUDA with an empty reason and enumerates 0 devices. Upstream llama.cpp b9700 CUDA works on the same RTX 5050, so this points at Windows dependency resolution in the package load path rather than the CUDA binary itself.On Windows, preloading the CUDA redistributables by absolute path is not enough if llama.cpp later calls plain
LoadLibraryWforggml-cuda.dll; Windows can still fail to resolve module-owned transitive imports from the bundle directory. The package-side fix now preloads the backend module withLOAD_WITH_ALTERED_SEARCH_PATH, then releases the temporary preload reference afterggml_backend_load()takes ownership through the llama.cpp registry path.Existing issue check
leehack/llamadart-native#22.leehack/llamadartissues/PRs forCUDA DLL Windows,ggml-cuda,cudart64 cublas64,LoadLibraryEx, andbackend dependencies; no open duplicate package-side PR was found. Older related issues/PRs include Blackwell (RTX 50-series, sm_120) unsupported on Windows: Vulkan crash + CUDA runtime too old #111, Windows build bundles CUDA DLLs despite backends: [vulkan, cpu] configuration #114, and Filter backend-owned runtime DLLs #115.Test Plan
dart format lib/src/backends/llama_cpp/llama_cpp_service.dart test/unit/backends/llama_cpp/llama_cpp_service_test.dartgit diff --check origin/watcher/windows-cuda-dll-preload..HEADdart analyze lib/src/backends/llama_cpp/llama_cpp_service.dart test/unit/backends/llama_cpp/llama_cpp_service_test.dartdart test test/unit/backends/llama_cpp/llama_cpp_service_test.dart- 72 tests passed locally on macOSwindowsBackendDependencyPathsand clarifying that it returns absolute paths; resolved the now-outdated thread.e2f68f9c35fc15df25b04e319828e6506ebdd335passed:Analyze & Lint, companion packages,Native Prompt Reuse Parity, docs build, Linux VM coverage, Chrome web tests,Test Native (macos-latest),Test Native (windows-latest), coverage aggregator, and chat app PR preview.e2f68f9on the RTX 5050 with the native bundle directory not onPATH;listGpuDevices(probeBackends: [GpuBackend.cuda])loadedggml-cuda.dllfrom.dart_tool/liband enumerated the RTX 5050 successfully.Follow-up
PATHvalidation result.