Load the GPU BiCGSTAB solver at runtime so GPU-enabled wheels import without CUDA#161
Merged
Conversation
…is a workaround for an upstream outage
FilipovicLado
force-pushed
the
gpu-runtime-dlopen
branch
from
July 20, 2026 13:09
b5cf55f to
43c38ab
Compare
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.
Problem
Building with
VIENNALS_USE_GPU=ONlinkedlibcudart/libcusparseinto_core.soasDT_NEEDEDentries. The dynamic loader resolves those when Pythondlopens the extension module so on a machinewithout a CUDA runtime
import viennalsfailed outright:This is what broke the 5.8.3 PyPI wheel.
Approach
Move the CUDA kernels into a separate
ViennaLS_GPUshared library and open itlazily with
dlopen()on first use, through a plain C ABI(
lsOxidationBiCGSTABAbi.hpp)._core.sono longer references CUDA at all, so it loads anywhere.allocGpuBuffers()returnsnull and the existing
gpuIsValid()guards fall through to the CPU solver.New API:
GpuMode::AutoGpuMode::Gpuis documented as "fail if unavailable" and does exactly that —it raises an error and aborts.
GpuMode::Autois added for the common case:use the GPU when it's usable, otherwise warn and fall back to the CPU.
GpuMode::Gpukeeps its existing contract. Default remainsGpuMode::Cpu.GPU setup failure paths were restructured into else-if chains. They previously
relied on
VIENNACORE_LOG_ERRORthrowing to stop execution; with anon-throwing warning path they would have called into the GPU with a null
handle.
Notes
so the GPU engages only for users who already have a CUDA toolkit installed.
Everyone else gets the CPU solver instead of a failed import.