From 358a30df7a8650f62c3e0c07325491c3ed9f619b Mon Sep 17 00:00:00 2001 From: "Benedikt J. Daurer" Date: Tue, 22 Mar 2022 16:21:27 +0000 Subject: [PATCH] moved cufft extension into separate module (#390) * moved cufft extension into separate module * cleaning up --- extensions.py => cufft/extensions.py | 0 .../cuda => cufft}/filtered_fft/.gitignore | 0 .../cuda => cufft}/filtered_fft/Makefile | 0 .../filtered_fft/compiler_flags_info.txt | 0 .../cuda => cufft}/filtered_fft/errors.h | 0 .../filtered_fft/filtered_fft.cu | 0 .../filtered_fft/filtered_fft.h | 0 .../cuda => cufft}/filtered_fft/module.cpp | 0 .../filtered_fft/smoke_test.cpp | 0 .../cuda => cufft}/filtered_fft/test_Makefile | 0 cufft/setup.py | 45 +++++++++++++++++++ .../cuda_pycuda/cuda/filtered_fft/__init__.py | 0 ptypy/accelerate/cuda_pycuda/cufft.py | 2 +- setup.py | 44 +----------------- .../fft_tests/cufft_init_test.py | 2 +- 15 files changed, 48 insertions(+), 45 deletions(-) rename extensions.py => cufft/extensions.py (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/.gitignore (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/Makefile (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/compiler_flags_info.txt (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/errors.h (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/filtered_fft.cu (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/filtered_fft.h (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/module.cpp (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/smoke_test.cpp (100%) rename {ptypy/accelerate/cuda_pycuda/cuda => cufft}/filtered_fft/test_Makefile (100%) create mode 100644 cufft/setup.py delete mode 100644 ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/__init__.py diff --git a/extensions.py b/cufft/extensions.py similarity index 100% rename from extensions.py rename to cufft/extensions.py diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/.gitignore b/cufft/filtered_fft/.gitignore similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/.gitignore rename to cufft/filtered_fft/.gitignore diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/Makefile b/cufft/filtered_fft/Makefile similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/Makefile rename to cufft/filtered_fft/Makefile diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/compiler_flags_info.txt b/cufft/filtered_fft/compiler_flags_info.txt similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/compiler_flags_info.txt rename to cufft/filtered_fft/compiler_flags_info.txt diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/errors.h b/cufft/filtered_fft/errors.h similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/errors.h rename to cufft/filtered_fft/errors.h diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/filtered_fft.cu b/cufft/filtered_fft/filtered_fft.cu similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/filtered_fft.cu rename to cufft/filtered_fft/filtered_fft.cu diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/filtered_fft.h b/cufft/filtered_fft/filtered_fft.h similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/filtered_fft.h rename to cufft/filtered_fft/filtered_fft.h diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/module.cpp b/cufft/filtered_fft/module.cpp similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/module.cpp rename to cufft/filtered_fft/module.cpp diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/smoke_test.cpp b/cufft/filtered_fft/smoke_test.cpp similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/smoke_test.cpp rename to cufft/filtered_fft/smoke_test.cpp diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/test_Makefile b/cufft/filtered_fft/test_Makefile similarity index 100% rename from ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/test_Makefile rename to cufft/filtered_fft/test_Makefile diff --git a/cufft/setup.py b/cufft/setup.py new file mode 100644 index 000000000..8cba2f560 --- /dev/null +++ b/cufft/setup.py @@ -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) diff --git a/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/__init__.py b/ptypy/accelerate/cuda_pycuda/cuda/filtered_fft/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ptypy/accelerate/cuda_pycuda/cufft.py b/ptypy/accelerate/cuda_pycuda/cufft.py index 686171342..d10e82b1a 100644 --- a/ptypy/accelerate/cuda_pycuda/cufft.py +++ b/ptypy/accelerate/cuda_pycuda/cufft.py @@ -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], diff --git a/setup.py b/setup.py index 888325251..08e932562 100644 --- a/setup.py +++ b/setup.py @@ -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 = """\ @@ -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( @@ -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) \ No newline at end of file diff --git a/test/accelerate_tests/cuda_pycuda_tests/fft_tests/cufft_init_test.py b/test/accelerate_tests/cuda_pycuda_tests/fft_tests/cufft_init_test.py index ac28436b4..c1894cc31 100644 --- a/test/accelerate_tests/cuda_pycuda_tests/fft_tests/cufft_init_test.py +++ b/test/accelerate_tests/cuda_pycuda_tests/fft_tests/cufft_init_test.py @@ -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):