Skip to content

Load the GPU BiCGSTAB solver at runtime so GPU-enabled wheels import without CUDA#161

Merged
FilipovicLado merged 9 commits into
masterfrom
gpu-runtime-dlopen
Jul 20, 2026
Merged

Load the GPU BiCGSTAB solver at runtime so GPU-enabled wheels import without CUDA#161
FilipovicLado merged 9 commits into
masterfrom
gpu-runtime-dlopen

Conversation

@FilipovicLado

Copy link
Copy Markdown
Member

Problem

Building with VIENNALS_USE_GPU=ON linked libcudart/libcusparse into
_core.so as DT_NEEDED entries. The dynamic loader resolves those when Python
dlopens the extension module so on a machine
without a CUDA runtime import viennals failed outright:

ImportError: libcudart.so.12: cannot open shared object file

This is what broke the 5.8.3 PyPI wheel.

Approach

Move the CUDA kernels into a separate ViennaLS_GPU shared library and open it
lazily with dlopen() on first use, through a plain C ABI
(lsOxidationBiCGSTABAbi.hpp).

  • _core.so no longer references CUDA at all, so it loads anywhere.
  • If the library or the CUDA runtime is missing, allocGpuBuffers() returns
    null and the existing gpuIsValid() guards fall through to the CPU solver.
  • The nine entry points keep their names, so no call site changed.

New API: GpuMode::Auto

GpuMode::Gpu is documented as "fail if unavailable" and does exactly that —
it raises an error and aborts. GpuMode::Auto is added for the common case:
use the GPU when it's usable, otherwise warn and fall back to the CPU.
GpuMode::Gpu keeps its existing contract. Default remains GpuMode::Cpu.

GPU setup failure paths were restructured into else-if chains. They previously
relied on VIENNACORE_LOG_ERROR throwing to stop execution; with a
non-throwing warning path they would have called into the GPU with a null
handle.

Notes

  • Wheels remain GPU-capable, not self-contained: CUDA is still not bundled,
    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.
  • Version bumped to 5.8.5.

@FilipovicLado
FilipovicLado merged commit 800e15f into master Jul 20, 2026
18 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.

1 participant