Repository navigation
Automate PyPI releases with prebuilt CUDA wheels - #122
Merged
Merged
Conversation
Build manylinux wheels for Linux x86_64 and aarch64 with cibuildwheel and publish them with trusted publishing: TestPyPI on manual dispatch, PyPI on release. - cupdlpx is built with CUDA 13 and loads the CUDA runtime from the cuda-toolkit pip packages (>=13.0,<14), so it can share an environment with PyTorch and other CUDA 13 packages. - cupdlpx-cu12 is an optional CUDA 12 backend installed with cupdlpx[cu12] for drivers older than R580 and GPUs older than Turing. - import cupdlpx picks a backend from the driver version, GPU 0 and any cuSPARSE already loaded in the process; CUPDLPX_BACKEND forces one. - A build with cuSPARSE 12.8.1+ headers now chooses cusparseSpMVOp or cusparseSpMV at run time from the loaded cuSPARSE version. - Bump the version to 0.4.1.
Keep the dynamic metadata provider and the cupdlpx-cu12 project next to the Python package, and include only Python sources from python/ in the sdist so bytecode caches are not packaged.
Use python/ as the dynamic metadata provider path and python/cupdlpx_cu12 as the cupdlpx-cu12 package directory, and include only Python sources from python/ in the sdist so bytecode caches are not packaged.
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.
Fixes #121
Summary
Automate PyPI releases with a GitHub Actions workflow (
.github/workflows/wheels.yml). Until now, PyPI only had sdists ofcupdlpx, so everypip installcompiled cuPDLPx locally and needed a CUDA toolkit.With this PR:
pypienvironment.pip install cupdlpxthen needs only an NVIDIA driver.Shipping prebuilt CUDA binaries needs a few supporting changes:
cupdlpxis built with CUDA 13 and gets the CUDA libraries from thecuda-toolkitpip packages (>=13.0,<14). This range lets it share an environment with PyTorch and other CUDA 13 packages. It requires an R580+ driver and compute capability 7.5+.cupdlpx-cu12is an optional CUDA 12 backend, installed withpip install "cupdlpx[cu12]", for drivers that only support CUDA 12.4–12.x and GPUs with compute capability 5.0–7.2. The import name is alwayscupdlpx, and the backend is chosen automatically at import.cusparseSpMVOporcusparseSpMVat run time, because the CUDA 13 runtime in a user's environment may be older than 13.3.v0.4.0GitHub release points to d17f53e, which has no wheel workflow, so 0.4.0 can no longer be published from this pipeline.Release workflow (
.github/workflows/wheels.yml)workflow_dispatch)manylinux_2_28, a 2×2 matrix (x86_64 / aarch64 × CUDA 13.5 / 12.9). CUDA comes from NVIDIA's RHEL 8 repo.auditwheelexcludes the CUDA libraries.torch.test/test_loader.py.testpypi/pypienvironments.Backend selection (
python/cupdlpx/_core.py)import cupdlpxloads the first usable backend, CUDA 13 first, then CUDA 12. It checks three things:cuDriverGetVersion. CUDA 13 needs a 13.0+ driver; CUDA 12 needs 12.4+.CUDA_VISIBLE_DEVICESandCUDA_DEVICE_ORDER.libcusparse.so.12, so a copy loaded by another package (e.g. PyTorch) takes priority. The loader reads its version from/proc/self/mapsandcusparseGetProperty, then rejects a backend from the other CUDA generation (< 12.6 is CUDA 12, ≥ 12.6 is CUDA 13) or one older than its minimum. It rescans before each candidate.When a backend is selected, its pip CUDA libraries are preloaded with
RTLD_LOCAL.CUPDLPX_BACKEND=cu13|cu12|sourceforces a choice; a forced backend skips the driver and GPU checks but still gets the cuSPARSE check. If no backend fits, theImportErrorlists the reason for each backend and the install command.Runtime SpMV backend (
src/spmv_backend.cu)A build against cuSPARSE ≥ 12.8.1 (CUDA 13.3+) now chooses the SpMV backend at run time instead of compile time:
cusparseSpMVOpwhen the loaded cuSPARSE is ≥ 12.8.1, andcusparseSpMVotherwise (e.g. the CUDA 13.0–13.2 runtime that PyTorch pins).RTLD_NOW, so strong references would fail at import on an older cuSPARSE.Packaging and build
python/metadata_provider.py(scikit-build-core dynamic metadata): adds thecuda-toolkitdependency only for wheel builds (CUPDLPX_WHEEL_CUDA), and adds thecu12extra pinned to the same version.python/cupdlpx_cu12/pyproject.toml: builds the same sources into thecupdlpx_cu12package, depending onnvidia-*-cu12(≥ 12.4)._build_info.pyrecords the package version, CUDA version, cuSPARSE version and pip CUDA major.pythoninstall component goes into the wheel..pyfiles frompython/, so bytecode caches are no longer packaged.requires-pythonis now>=3.11.Testing
Local wheels (CUDA 13.3 and 12.9 builds), H100 with driver 595 (CUDA 13.2):
CUPDLPX_BACKEND=cu12RTLD_GLOBAL)pytest test/(142 tests, including 22 new loader tests) passes for CUDA 13.3 auto, forced cu12, and CUDA 13.0 auto.pip install --dry-runresolves together with PyPItorch2.15 (which pinscuda-toolkit==13.2.2) and withtorchcu128.spmv_backend.cucompiles with CUDA 12.4, 12.9, 13.1 and 13.3.Not verified yet:
Setup needed before publishing
cupdlpx: ownerMIT-Lu-Lab, repositorycuPDLPx, workflowwheels.yml, environmentpypi(testpypion TestPyPI).cupdlpx-cu12.pypi(with required reviewers) andtestpypi.v0.4.1to publish to PyPI.