Skip to content

Commit 7f0a986

Browse files
authored
Switch cufinufft from setup.py to pyproject.toml (#507)
* py: fix install target for cufinufft * py: switch to pyproject.toml for cufinufft Also, find library by looking in package directory instead of loading C extension. * ci: ensure cufinufft install in Jenkins * ci: run GPU tests in py310 To install the latest PyCUDA, we need NumPy >= 2.0, which in turn requires Python >= 3.9. * ci: update torch for py310 compat
1 parent a812c6e commit 7f0a986

File tree

5 files changed

+82
-109
lines changed

5 files changed

+82
-109
lines changed

Jenkinsfile

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pipeline {
1616
}
1717
environment {
1818
HOME = "$WORKSPACE"
19-
PYBIN = "/opt/python/cp38-cp38/bin"
19+
PYBIN = "/opt/python/cp310-cp310/bin"
2020
LIBRARY_PATH = "$WORKSPACE/build"
2121
LD_LIBRARY_PATH = "$WORKSPACE/build"
2222
}
@@ -46,11 +46,19 @@ pipeline {
4646
'''
4747
sh '${PYBIN}/python3 -m venv $HOME'
4848
sh '''#!/bin/bash -ex
49+
cuda_arch="70"
4950
source $HOME/bin/activate
51+
5052
python3 -m pip install --no-cache-dir --upgrade pip
53+
python3 -m pip install \
54+
--no-cache-dir \
55+
--config-settings=cmake.define.CMAKE_CUDA_ARCHITECTURES="${cuda_arch}" \
56+
python/cufinufft
57+
'''
58+
sh '''#!/bin/bash -ex
59+
source $HOME/bin/activate
5160
python3 -m pip install --no-cache-dir --upgrade pycuda cupy-cuda112 numba
52-
python3 -m pip install --no-cache-dir torch==1.10.2+cu111 -f https://download.pytorch.org/whl/torch_stable.html
53-
python3 -m pip install --no-cache-dir python/cufinufft
61+
python3 -m pip install --no-cache-dir torch==1.12.1+cu113 -f https://download.pytorch.org/whl/torch_stable.html
5462
python3 -m pip install --no-cache-dir pytest
5563
python -c "from numba import cuda; cuda.cudadrv.libs.test()"
5664
python3 -m pytest --framework=pycuda python/cufinufft

python/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ if(FINUFFT_USE_CPU)
66
endif ()
77
endif()
88

9-
if(FINUFFT_USE_GPU)
10-
install(TARGETS finufft_gpu LIBRARY DESTINATION cufinufft)
9+
if(FINUFFT_USE_CUDA)
10+
install(TARGETS cufinufft LIBRARY DESTINATION cufinufft)
1111
endif()

python/cufinufft/cufinufft/_cufinufft.py

+22-24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import warnings
1111
import importlib.util
12+
import pathlib
13+
import numpy as np
1214

1315
from ctypes import c_double
1416
from ctypes import c_int
@@ -20,31 +22,27 @@
2022
c_float_p = ctypes.POINTER(c_float)
2123
c_double_p = ctypes.POINTER(c_double)
2224

23-
# TODO: See if there is a way to improve this so it is less hacky.
2425
lib = None
25-
# Try to load a local library directly.
26-
try:
27-
lib = ctypes.cdll.LoadLibrary('libcufinufft.so')
28-
except OSError:
29-
pass
30-
31-
# Should that not work, try to find the full path of a packaged lib.
32-
# The packaged lib should have a py/platform decorated name,
33-
# and be rpath'ed the true CUDA C cufinufft library through the
34-
# Extension and wheel systems.
35-
try:
36-
if lib is None:
37-
# Find the library.
38-
lib_path = importlib.util.find_spec('cufinufft.cufinufftc').origin
39-
# Get the full path for the ctypes loader.
40-
full_lib_path = os.path.realpath(lib_path)
41-
42-
# Load the library,
43-
# which rpaths the libraries we care about.
44-
lib = ctypes.cdll.LoadLibrary(full_lib_path)
45-
46-
except Exception:
47-
raise ImportError('Failed to find a suitable cufinufft library')
26+
# Try to load the library as installed in the Python package.
27+
path = pathlib.Path(__file__).parent.resolve()
28+
library_names = ["libcufinufft", "cufinufft"]
29+
for lib_name in library_names:
30+
try:
31+
lib = np.ctypeslib.load_library(lib_name, path)
32+
break
33+
except OSError:
34+
# Paranoid, in case lib is set to something and then an exception is thrown
35+
lib = None
36+
37+
if lib is None:
38+
# If that fails, try to load the library from the system path.
39+
libname = find_library('cufinufft')
40+
if libname is not None:
41+
lib = ctypes.cdll.LoadLibrary(libname)
42+
# we probably should add a version check and trow a warning if the version is different
43+
else:
44+
# if that does not work, cufinufft is not installed correctly.
45+
raise ImportError("Failed to find a suitable cufinufft library.")
4846

4947

5048
def _get_NufftOpts():

python/cufinufft/pyproject.toml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[build-system]
2+
requires = [
3+
"scikit-build-core >= 0.4.3",
4+
"cmake >= 3.19",
5+
"ninja >= 1.9.0",
6+
]
7+
build-backend = "scikit_build_core.build"
8+
9+
[project]
10+
name = "cufinufft"
11+
description = "Non-uniform fast Fourier transforms on the GPU"
12+
version = "2.2.0"
13+
readme = "README.md"
14+
requires-python = ">=3.8"
15+
dependencies = ["numpy"]
16+
authors = [
17+
{name = "Yu-shuan Melody Shih"},
18+
{name = "Garrett Wright"},
19+
{name = "Joakim Anden"},
20+
{name = "Johannes Blascke"},
21+
{name = "Alex Barnett"}]
22+
maintainers = [{name = "Joakim Anden", email = "[email protected]"}]
23+
classifiers = [
24+
"Intended Audience :: Science/Research",
25+
"License :: OSI Approved :: Apache Software License",
26+
"Programming Language :: Python :: 3",
27+
"Programming Language :: C++",
28+
"Operating System :: POSIX :: Linux",
29+
"Environment :: GPU",
30+
"Topic :: Scientific/Engineering :: Mathematics"
31+
]
32+
33+
[tool.scikit-build]
34+
# Protect the configuration against future changes in scikit-build-core
35+
minimum-version = "0.4"
36+
# Setuptools-style build caching in a local directory
37+
build-dir = "build/{wheel_tag}"
38+
39+
# Tell skbuild to look for the CMakeLists.txt file two directories up.
40+
cmake.source-dir = "../../"
41+
cmake.targets = ["cufinufft"]
42+
cmake.define = {"FINUFFT_BUILD_PYTHON" = "ON", "FINUFFT_USE_CUDA" = "ON", "FINUFFT_USE_CPU" = "OFF", "FINUFFT_ENABLE_INSTALL" = "OFF", "FINUFFT_STATIC_LINKING" = "OFF"}
43+
44+
wheel.packages = ["cufinufft"]
45+
46+
# Indicate that we don't depend on the CPython API
47+
wheel.py-api = "py3"

python/cufinufft/setup.py

-80
This file was deleted.

0 commit comments

Comments
 (0)