Skip to content

Commit

Permalink
cuda+py: create dummy source for cufinufft C ext
Browse files Browse the repository at this point in the history
Similarly to what we do for finufft. The issue is that the default gcc
config on certain OSes (Ubuntu 20.04, Rocky 8), libraries are not linked
unless their symbols are explicitly referenced in the source. Since we
have no source, no libraries are linked. The solution is to create a
dummy source that just calls a single function
`cufinufft_default_opts`.
  • Loading branch information
janden committed Dec 18, 2023
1 parent e8d19d2 commit 0907d74
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion python/cufinufft/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import ctypes
from pathlib import Path

from tempfile import mkstemp

from setuptools import setup, Extension

# Description
Expand Down Expand Up @@ -36,6 +38,28 @@
raise(e)
print('cufinufft CUDA shared libraries found, continuing...')

# For certain platforms (e.g. Ubuntu 20.04), we need to create a dummy source
# that calls one of the functions in the FINUFFT dynamic library. The reason
# is that these platforms override the default --no-as-needed flag for ld,
# which means that the linker will only link to those dynamic libraries for
# which there are unresolved symbols in the object files. Since we do not have
# a real source, the result is that no dynamic libraries are linked. To
# prevent this, we create a dummy source so that the library will link as
# expected.
fd, source_filename = mkstemp(suffix='.c', text=True)

with open(fd, 'w') as f:
f.write( \
"""
#include <cufinufft.h>
void PyInit_cufinufftc(void) {
cufinufft_opts opt;
cufinufft_default_opts(&opt);
}
""")


# Python Package Setup
setup(
Expand Down Expand Up @@ -72,10 +96,13 @@
py_modules=['cufinufftc'],
ext_modules=[
Extension(name='cufinufftc',
sources=[],
sources=[source_filename],
libraries=['cufinufft'],
include_dirs=[include_dir],
library_dirs=[library_dir],
runtime_library_dirs=[library_dir],
)
]
)

os.unlink(source_filename)

0 comments on commit 0907d74

Please sign in to comment.