Skip to content

Commit

Permalink
moved cufft extension into separate module (#390)
Browse files Browse the repository at this point in the history
* moved cufft extension into separate module

* cleaning up
  • Loading branch information
daurer authored Mar 22, 2022
1 parent 446d2e7 commit 358a30d
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 45 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions cufft/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python

# we should aim to remove the distutils dependency
import setuptools
from distutils.core import setup, Extension
import os

ext_modules = []
cmdclass = {}
# filtered Cuda FFT extension module
try:
from extensions import locate_cuda, get_cuda_version # this raises an error if pybind11 is not available
CUDA = locate_cuda() # this raises an error if CUDA is not available
CUDA_VERSION = get_cuda_version(CUDA['nvcc'])
if CUDA_VERSION < 10:
raise ValueError("filtered cufft requires CUDA >= 10")
from extensions import CustomBuildExt
cufft_dir = "filtered_fft"
ext_modules.append(
Extension("filtered_cufft",
sources=[os.path.join(cufft_dir, "module.cpp"),
os.path.join(cufft_dir, "filtered_fft.cu")]
)
)
cmdclass = {"build_ext": CustomBuildExt}
EXTBUILD_MESSAGE = "The filtered cufft extension has been successfully installed.\n"
except:
EXTBUILD_MESSAGE = '*' * 75 + "\n"
EXTBUILD_MESSAGE += "Could not install the filtered cufft extension.\n"
EXTBUILD_MESSAGE += "Make sure to have CUDA >= 10 and pybind11 installed.\n"
EXTBUILD_MESSAGE += '*' * 75 + "\n"

exclude_packages = []
package_list = setuptools.find_packages(exclude=exclude_packages)
setup(
name='filtered cufft',
version=0.1,
author='Bjoern Enders, Benedikt Daurer, Joerg Lotze',
description='Extension of CuFFT to include pre- and post-filters using callbacks',
packages=package_list,
ext_modules=ext_modules,
cmdclass=cmdclass
)

print(EXTBUILD_MESSAGE)
Empty file.
2 changes: 1 addition & 1 deletion ptypy/accelerate/cuda_pycuda/cufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _load(self, array, pre_fft, post_fft, symmetric, forward):
else:
self.post_fft_ptr = 0

from ptypy import filtered_cufft
import filtered_cufft
self.fftobj = filtered_cufft.FilteredFFT(
self.batches,
self.arr_shape[0],
Expand Down
44 changes: 1 addition & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env python

# we should aim to remove the distutils dependency
import distutils
import setuptools #, setuptools.command.build_ext
import setuptools
from distutils.core import setup
import os
import sys

CLASSIFIERS = """\
Expand Down Expand Up @@ -66,42 +64,6 @@ def write_version_py(filename='ptypy/version.py'):
except:
vers = VERSION

ext_modules = []
cmdclass = {}
# filtered Cuda FFT extension module
"""
Alternative options for this switch:
1. Put the cufft extension module as a separate python package with its own setup.py and
put an optional dependency into ptypy (extras_require={ "cufft": ["pybind11"] }), so that
when users do pip install ptypy it installs it without that dependency, and if users do
pip install ptypy[cufft] it installs the optional dependency module
2. Use an environment variable to control the setting, as sqlalchemy does for its C extensions,
or detect if cuda is available on the system and enable it in this case, etc.
"""
try:
from extensions import locate_cuda, get_cuda_version # this raises an error if pybind11 is not available
CUDA = locate_cuda() # this raises an error if CUDA is not available
CUDA_VERSION = get_cuda_version(CUDA['nvcc'])
if CUDA_VERSION < 10:
raise ValueError("ptypy cufft requires CUDA >= 10")
from extensions import CustomBuildExt
cufft_dir = os.path.join('ptypy', 'accelerate', 'cuda_pycuda', 'cuda', 'filtered_fft')
ext_modules.append(
distutils.core.Extension("ptypy.filtered_cufft",
sources=[os.path.join(cufft_dir, "module.cpp"),
os.path.join(cufft_dir, "filtered_fft.cu")]
)
)
cmdclass = {"build_ext": CustomBuildExt}
EXTBUILD_MESSAGE = "ptypy has been successfully installed with the pre-compiled cufft extension.\n"
except:
EXTBUILD_MESSAGE = '*' * 75 + "\n"
EXTBUILD_MESSAGE += "ptypy has been installed without the pre-compiled cufft extension.\n"
EXTBUILD_MESSAGE += "If you require cufft, make sure to have CUDA >= 10 and pybind11 installed.\n"
EXTBUILD_MESSAGE += '*' * 75 + "\n"

exclude_packages = []
package_list = setuptools.find_packages(exclude=exclude_packages)
setup(
Expand All @@ -120,8 +82,4 @@ def write_version_py(filename='ptypy/version.py'):
'scripts/ptypy.new',
'scripts/ptypy.csv2cp',
'scripts/ptypy.run'],
ext_modules=ext_modules,
cmdclass=cmdclass
)

print(EXTBUILD_MESSAGE)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from test.accelerate_tests.cuda_pycuda_tests import PyCudaTest, have_pycuda

if have_pycuda():
from ptypy.filtered_cufft import FilteredFFT
from filtered_cufft import FilteredFFT

class CuFFTInitTest(PyCudaTest):

Expand Down

0 comments on commit 358a30d

Please sign in to comment.