Skip to content

Fix build with use_gpu=true#221

Merged
bodono merged 2 commits into
bodono:masterfrom
stephen-huan:fix-build
Jul 22, 2026
Merged

Fix build with use_gpu=true#221
bodono merged 2 commits into
bodono:masterfrom
stephen-huan:fix-build

Conversation

@stephen-huan

Copy link
Copy Markdown
Contributor

When building with python -m pip install -Csetup-args=-Duse_gpu=true -Csetup-args=-Dint32=true ., I get the error

      ../meson.build:303:7: ERROR: Unknown method 'glob' in object.

Indeed the meson documentation for fs doesn't seem to have a glob function. The first commit unfurles the globs.

Next, when I run the GPU_INDIRECT solver, I get

ImportError: <...>/scs/_scs_gpu.cpython-314-x86_64-linux-gnu.so: undefined symbol: cusparseDestroySpMat

It seems it's not linked against cusparse (and cublas). The second commit adds these dependencies, and the solver runs in my testing. If I'm somehow building the library wrong, please let me know.

Fixes #168. (While writing this PR I just noticed #168 (comment)... :p)

@bodono

bodono commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Thanks for doing this!

@bodono
bodono merged commit 3564b3b into bodono:master Jul 22, 2026
35 checks passed
bodono added a commit that referenced this pull request Jul 22, 2026
Neither the use_gpu build nor the cuBLAS/cuSPARSE linking (fixed in #221)
was covered by CI. Add a build_gpu job that installs the CUDA toolkit
libraries from conda-forge and builds with -Duse_gpu=true. Linking
against cuBLAS/cuSPARSE needs the toolkit but not a physical GPU, so the
job builds and link-checks without running the solver.

A shared library links successfully even with undefined symbols, so the
job asserts via readelf that _scs_gpu records libcublas and libcusparse
as NEEDED entries -- the #221 bug was a missing link that only surfaced
at import time as `undefined symbol: cusparseDestroySpMat`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bodono added a commit that referenced this pull request Jul 22, 2026
The GPU backend requires 32-bit integers; meson errors out otherwise
(meson.build:173). Match the documented use_gpu build invocation from #221.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bodono added a commit that referenced this pull request Jul 22, 2026
* Scope CUDA link deps to their targets in meson.build

The use_gpu block appended cuda/cublas/cusparse to the shared `_deps`
list, so those libraries leaked into every extension module defined
afterwards (_scs_mkl, _scs_accelerate, _scs_cudss) when use_gpu was
combined with those backends. link_cudss had the same issue with
cuda/cudss. Build a per-target dependency list (mirroring the existing
`_mkl_deps = _deps + [...]` pattern) instead of mutating `_deps`.

Also note in a comment that the GPU sources are listed explicitly
because Meson's fs module has no glob(), and must be kept in sync with
the .c files in the submodule.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: add build-only GPU job to validate use_gpu link path

Neither the use_gpu build nor the cuBLAS/cuSPARSE linking (fixed in #221)
was covered by CI. Add a build_gpu job that installs the CUDA toolkit
libraries from conda-forge and builds with -Duse_gpu=true. Linking
against cuBLAS/cuSPARSE needs the toolkit but not a physical GPU, so the
job builds and link-checks without running the solver.

A shared library links successfully even with undefined symbols, so the
job asserts via readelf that _scs_gpu records libcublas and libcusparse
as NEEDED entries -- the #221 bug was a missing link that only surfaced
at import time as `undefined symbol: cusparseDestroySpMat`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: build GPU with int32=true (required by GPU backend)

The GPU backend requires 32-bit integers; meson errors out otherwise
(meson.build:173). Match the documented use_gpu build invocation from #221.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: locate installed _scs_gpu via sysconfig, not import

Importing scs from the repo root resolved the local ./scs source
directory (a namespace package, __file__ is None) instead of the
installed package, leaving the .so path empty. Find the extension under
sysconfig platlib instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ci: find installed _scs_gpu via shell, avoid nested-quote issue

pixi run stripped the inner single quotes from the python -c snippet,
so sysconfig.get_path('platlib') became a bare name (NameError). Locate
the .so with find over the pixi env lib dir instead of invoking python.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@stephen-huan
stephen-huan deleted the fix-build branch July 23, 2026 18:09
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.

Meson GPU build fails due to undefined ext_modules and common_sources

2 participants