Skip to content

fix(deps): preload cusolver if cupy is installed#1117

Open
gforsyth wants to merge 7 commits into
rapidsai:release/26.08from
gforsyth:fix_cusolver_dep
Open

fix(deps): preload cusolver if cupy is installed#1117
gforsyth wants to merge 7 commits into
rapidsai:release/26.08from
gforsyth:fix_cusolver_dep

Conversation

@gforsyth

@gforsyth gforsyth commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

I'm testing out smaller base images for wheel testing in #1116 and those tests flagged up that we're missing a cusolver dependency on wheel-only installs (the previous testing images have a full cuda toolkit installed beforehand).

The missing dependency turns out to be due to a cupy bug upstream with wheel-only installs (reported in cupy/cupy#10095).

This is a temporary workaround (if we want one) to enable switching to smaller test images (and also allowing end-users to use cucim on wheel-only installs)

xref rapidsai/build-planning#143
xref rapidsai/ci-imgs#400
xref rapidsai/shared-workflows#521

@gforsyth gforsyth requested review from a team as code owners July 9, 2026 21:41
@gforsyth gforsyth requested a review from KyleFromNVIDIA July 9, 2026 21:41
@gforsyth gforsyth added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Jul 10, 2026

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a blocking suggestion.

If we end up using Python code to pre-load cusolver after you consider this feedback then I think that's ok and I think where you chose is the right place.

But some other thoughts...

  1. if some DSO in cucim needs libcusolver.so.* at runtime, why isn't auditwheel trying to vendor it? Or IS it making a copy? Worth checking, because I don't see it excluded here and would expect to:

python -m auditwheel repair -w "${RAPIDS_WHEEL_BLD_OUTPUT_DIR}" dist/*

  1. I don't think we need a cuda-pathfinder dependency. Could you look into just adding RPATH entries into site-packages/, like we do for RAFT's cusolver dependency?

https://github.com/NVIDIA/raft/blob/99ca82537c2263249018f6bfb53de3d31442f8ca/python/libraft/CMakeLists.txt#L40-L51

Normally when I jump into one of these packaging-codeowners reviewers where I wasn't assigned I remove the auto-assigned person, but leaving @KyleFromNVIDIA here because I think his thoughts on this topic would also be really helpful and possibly different from mine.

Comment thread dependencies.yaml Outdated
- output_types: [requirements, pyproject]
packages:
- cuda-toolkit[cusolver]
- cuda-pathfinder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, this would allow cucim-cu13 to be installed with cuda-toolkit==12.*. I don't think we want that.. We won't catch that in CI because we == pin cuda-toolkit as an additional constraint:

cucim/dependencies.yaml

Lines 185 to 204 in 5c68f29

- matrix:
cuda: "12.2"
use_cuda_wheels: "true"
packages:
- cuda-toolkit==12.2.*
- matrix:
cuda: "12.5"
use_cuda_wheels: "true"
packages:
- cuda-toolkit==12.5.*
- matrix:
cuda: "12.8"
use_cuda_wheels: "true"
packages:
- cuda-toolkit==12.8.*
- matrix:
cuda: "12.9"
use_cuda_wheels: "true"
packages:
- cuda-toolkit==12.9.*

... but that's a CI only thing.

We should ensure the wheel metadata provides a correct solve for users (CUDA 12 for -cu12, CUDA 13 for -cu13).

For this I think we want:

  1. matrices by CUDA major version, with the dependency spelled cuda-toolkit[cusolver]==12.* and cuda-toolkit[cusolver]==13.*
  2. usa_cuda_wheels guards, similar to https://github.com/rapidsai/cudf/blob/dda07069af24236c612dec623f471e946a6cdcfb/dependencies.yaml#L943-L962

The usa_cuda_wheels guards aren't strictly necessary since this project doesn't have devcontainers and isn't part of DLFW builds, but having the spelling be consistent with the rest of RAPIDS would make all-of-RAPIDS updates easier.

@gforsyth

Copy link
Copy Markdown
Contributor Author
  1. if some DSO in cucim needs libcusolver.so.* at runtime, why isn't auditwheel trying to vendor it? Or IS it making a copy? Worth checking, because I don't see it excluded here and would expect to:

This is a good question -- I took another look at the failures and the tracebacks a little more closely and this is looking less like a cucim problem and like maybe more of a cupy problem.

From this run on #1116: https://github.com/rapidsai/cucim/actions/runs/29044082057/job/86214270820?pr=1116

________ test_custom_eigvals_kernels_vs_linalg_eigvalsh[float32-shape1] ________
[gw4] linux -- Python 3.12.13 /pyenv/versions/3.12.13/bin/python
python/cucim/src/cucim/skimage/feature/tests/test_corner.py:351: in test_custom_eigvals_kernels_vs_linalg_eigvalsh
    evs1 = _reference_eigvals_computation(H)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
python/cucim/src/cucim/skimage/feature/tests/test_corner.py:338: in _reference_eigvals_computation
    eigs = cp.linalg.eigvalsh(matrices)[..., ::-1]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/pyenv/versions/3.12.13/lib/python3.12/site-packages/cupy/linalg/_eigenvalue.py:343: in eigvalsh
    import cupyx.cusolver
E   ImportError: libcusolver.so.12: cannot open shared object file: No such file or directory

@gforsyth

Copy link
Copy Markdown
Contributor Author

like maybe more of a cupy problem.

or alternatively, not a problem, just a mismatch. We have all of this wheel loading logic that prefers wheel installations over system installations, but because there CAN be a system installation, we don't fail loudly when we're missing DSOs in wheels.

I wonder if all that's needed for cucim is adding cusolver to the test environment?

@gforsyth

Copy link
Copy Markdown
Contributor Author

I wonder if all that's needed for cucim is adding cusolver to the test environment?

or potentially even simpler, should we be installing the cupy-cuda??x[ctk] extra?

@gforsyth

Copy link
Copy Markdown
Contributor Author

or potentially even simpler, should we be installing the cupy-cuda??x[ctk] extra?

nope, we are already installing the ctk extra in the test runs

@gforsyth

Copy link
Copy Markdown
Contributor Author

nope, we are already installing the ctk extra in the test runs

Ok, this is a cupy bug, reporting upstream, then we can decide what to do here

@gforsyth

Copy link
Copy Markdown
Contributor Author

Reported upstream in cupy/cupy#10095, trying out temporary fixes involving cuda.pathfinder in #1116 (TLDR: I think we can assume cuda.pathfinder is installed without adding a new dependency here, because cupy ships it, so IF cupy is installed, we can attempt to preload libcusolver using pathfinder to avoid the load error)

@gforsyth

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review @jameslamb ! I wouldn't have thought I'd end up at cupy bug when I first saw the tracebacks in #1116

@gforsyth gforsyth changed the title fix(deps): add explicit dependency for cusolver fix(deps): preload cusolver if cupy is installed Jul 10, 2026
@gforsyth

Copy link
Copy Markdown
Contributor Author

Tested these changes here (obviously) and also in #1116 to demonstrate that libcusolver gets correctly loaded from the wheel (since that's the only option in that image)

Comment thread python/cucim/src/cucim/__init__.py Outdated

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for looking into those things I linked, I support the implementation you ended up with.

I read (and subscribed to) the cupy issue, great repo! Thanks for doing that.

It's a nice side benefit of using a slimmer test image, that we can catch issues like this in CI 🙂

@jakirkham jakirkham changed the base branch from main to release/26.08 July 16, 2026 20:37
@jakirkham jakirkham added this to the v26.08.00 milestone Jul 16, 2026
@jakirkham jakirkham added this to cucim Jul 16, 2026
Comment thread python/cucim/src/cucim/__init__.py Outdated
Co-authored-by: jakirkham <jakirkham@gmail.com>

@jakirkham jakirkham left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Gil! 🙏

Have gone ahead and applied reasonable suggestions from here and the upstream issue. Hope that is ok.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants