Skip to content

Commit

Permalink
Merge remote-tracking branch 'flatiron/master' into perftests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamonDinoia committed Aug 28, 2024
2 parents 98525fc + 01b5577 commit aded209
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 34 deletions.
28 changes: 19 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ endif()
# double precision The single precision compilation is done with -DSINGLE
set(FINUFFT_PRECISION_DEPENDENT_SOURCES
src/finufft.cpp src/fft.cpp src/simpleinterfaces.cpp src/spreadinterp.cpp
src/utils.cpp fortran/finufftfort.cpp)
src/utils.cpp)

# If we're building for Fortran, make sure we also include the translation
# layer.
if(FINUFFT_BUILD_FORTRAN)
list(APPEND FINUFFT_PRECISION_DEPENDENT_SOURCES fortran/finufftfort.cpp)
endif()

# set linker flags for sanitizer
set(FINUFFT_SANITIZER_FLAGS)
Expand All @@ -137,7 +143,7 @@ function(enable_asan target)
endif()
endfunction()

set(CPM_DOWNLOAD_VERSION 0.40.0)
set(CPM_DOWNLOAD_VERSION 0.40.2)
include(cmake/setupCPM.cmake)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
Expand Down Expand Up @@ -280,13 +286,17 @@ if(FINUFFT_USE_CPU)
endif()

if(FINUFFT_USE_CUDA)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
message(
"FINUFFT WARNING: No CUDA architecture supplied via '-DCMAKE_CUDA_ARCHITECTURES=...', defaulting to 'native'"
)
message(
"See: https://developer.nvidia.com/cuda-gpus for more details on what architecture to supply."
)
if(NOT DEFINED FINUFFT_CUDA_ARCHITECTURES)
if(DEFINED CMAKE_CUDA_ARCHITECTURES)
set(FINUFFT_CUDA_ARCHITECTURES "{$CMAKE_CUDA_ARCHITECTURES}")
else()
message(
"FINUFFT WARNING: No CUDA architecture supplied via '-DFINUFFT_CUDA_ARCHITECTURES=...', defaulting to 'native'"
)
message(
"See: https://developer.nvidia.com/cuda-gpus for more details on what architecture to supply."
)
endif()
endif()
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pipeline {
source $HOME/bin/activate
python3 -m pip install --no-cache-dir --upgrade pycuda cupy-cuda112 numba
python3 -m pip install --no-cache-dir torch==1.12.1+cu113 -f https://download.pytorch.org/whl/torch_stable.html
python3 -m pip install --no-cache-dir pytest
python3 -m pip install --no-cache-dir pytest pytest-mock
python -c "from numba import cuda; cuda.cudadrv.libs.test()"
python3 -m pytest --framework=pycuda python/cufinufft
python3 -m pytest --framework=numba python/cufinufft
Expand Down
22 changes: 16 additions & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,35 @@ set(EXAMPLES
set(EXAMPLES_OPENMP threadsafe1d1 threadsafe2d2f)
set(EXAMPLES_C guru1d1c simple1d1c simple1d1cf)

find_library(MATH_LIBRARY m)

foreach(EXAMPLE ${EXAMPLES})
add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
target_compile_features(${EXAMPLE} PRIVATE cxx_std_17)
target_compile_features(${EXAMPLE} PRIVATE cxx_std_14)
target_link_libraries(${EXAMPLE} PRIVATE finufft)
enable_asan(${EXAMPLE})
if(CMAKE_PROJECT_NAME STREQUAL "FINUFFT")
enable_asan(${EXAMPLE})
endif()
endforeach()

foreach(EXAMPLE ${EXAMPLES_C})
add_executable(${EXAMPLE} ${EXAMPLE}.c)
target_link_libraries(${EXAMPLE} PRIVATE finufft)
target_compile_features(${EXAMPLE} PRIVATE cxx_std_17)
enable_asan(${EXAMPLE})
if(CMAKE_PROJECT_NAME STREQUAL "FINUFFT")
enable_asan(${EXAMPLE})
endif()
if(MATH_LIBRARY)
target_link_libraries(${EXAMPLE} PRIVATE ${MATH_LIBRARY})
endif()
endforeach()

if(FINUFFT_USE_OPENMP)
foreach(EXAMPLE ${EXAMPLES_OPENMP})
add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
target_link_libraries(${EXAMPLE} PRIVATE finufft OpenMP::OpenMP_CXX)
target_compile_features(${EXAMPLE} PRIVATE cxx_std_17)
enable_asan(${EXAMPLE})
target_compile_features(${EXAMPLE} PRIVATE cxx_std_11)
if(CMAKE_PROJECT_NAME STREQUAL "FINUFFT")
enable_asan(${EXAMPLE})
endif()
endforeach()
endif()
20 changes: 11 additions & 9 deletions fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
add_library(directft OBJECT
directft/dirft1d.f directft/dirft1df.f
directft/dirft2d.f directft/dirft2df.f
directft/dirft3d.f directft/dirft3df.f)
add_library(
directft OBJECT directft/dirft1d.f directft/dirft1df.f directft/dirft2d.f
directft/dirft2df.f directft/dirft3d.f directft/dirft3df.f)

set(FORTRAN_EXAMPLES guru1d1 nufft1d_demo nufft2d_demo nufft2dmany_demo nufft3d_demo simple1d1)
set(FORTRAN_EXAMPLES guru1d1 nufft1d_demo nufft2d_demo nufft2dmany_demo
nufft3d_demo simple1d1)

foreach(EXAMPLE ${FORTRAN_EXAMPLES})
add_executable(fort_${EXAMPLE} examples/${EXAMPLE}.f)
add_executable(fort_${EXAMPLE}f examples/${EXAMPLE}f.f)
add_executable(fort_${EXAMPLE} examples/${EXAMPLE}.f)
add_executable(fort_${EXAMPLE}f examples/${EXAMPLE}f.f)

target_link_libraries(fort_${EXAMPLE} PRIVATE directft finufft)
target_link_libraries(fort_${EXAMPLE}f PRIVATE directft finufft)
target_link_libraries(fort_${EXAMPLE} PRIVATE directft finufft
${FINUFFT_FFTLIBS})
target_link_libraries(fort_${EXAMPLE}f PRIVATE directft finufft
${FINUFFT_FFTLIBS})
endforeach()
2 changes: 1 addition & 1 deletion perftest/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ target_compile_features(cuperftest PRIVATE cxx_std_17)
set_target_properties(
cuperftest
PROPERTIES LINKER_LANGUAGE CUDA
CUDA_ARCHITECTURES ${FINUFFT_CUDA_ARCHITECTURES}
CUDA_ARCHITECTURES "${FINUFFT_CUDA_ARCHITECTURES}"
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON)
1 change: 1 addition & 0 deletions python/cufinufft/cufinufft/_cufinufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import importlib.util
import pathlib
import numpy as np
from ctypes.util import find_library

from ctypes import c_double
from ctypes import c_int
Expand Down
7 changes: 6 additions & 1 deletion python/cufinufft/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ build-backend = "scikit_build_core.build"
[project]
name = "cufinufft"
description = "Non-uniform fast Fourier transforms on the GPU"
version = "2.2.0"
readme = "README.md"
requires-python = ">=3.8"
dependencies = ["numpy"]
Expand All @@ -31,6 +30,7 @@ classifiers = [
"Environment :: GPU",
"Topic :: Scientific/Engineering :: Mathematics"
]
dynamic = ["version"]

[tool.scikit-build]
# Protect the configuration against future changes in scikit-build-core
Expand All @@ -47,3 +47,8 @@ wheel.packages = ["cufinufft"]

# Indicate that we don't depend on the CPython API
wheel.py-api = "py3"

[tool.scikit-build.metadata.version]
# Instead of hardcoding the version here, extract it from the source files.
provider = "scikit_build_core.metadata.regex"
input = "cufinufft/__init__.py"
25 changes: 25 additions & 0 deletions python/cufinufft/tests/test_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest

import numpy as np
from ctypes.util import find_library


# Check to make sure the fallback mechanism works if there is no bundled
# dynamic library.
@pytest.mark.skip(reason="Patching seems to fail in CI")
def test_fallback(mocker):
def fake_load_library(lib_name, path):
if lib_name in ["libcufinufft", "cufinufft"]:
raise OSError()
else:
return np.ctypeslib.load_library(lib_name, path)

# Block out the bundled library.
mocker.patch("numpy.ctypeslib.load_library", fake_load_library)

# Make sure an error is raised if no system library is found.
if find_library("cufinufft") is None:
with pytest.raises(ImportError, match="suitable cufinufft"):
import cufinufft
else:
import cufinufft
2 changes: 1 addition & 1 deletion python/finufft/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ input = "finufft/__init__.py"
build-verbosity = 1
# Not building for PyPy and musllinux for now.
skip = "pp* *musllinux*"
test-requires = "pytest"
test-requires = ["pytest", "pytest-mock"]
test-command = "pytest {project}/python/finufft/test"

[tool.cibuildwheel.linux]
Expand Down
20 changes: 20 additions & 0 deletions python/finufft/test/test_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

import numpy as np
from ctypes.util import find_library

@pytest.mark.skip(reason="Patching seems to fail in CI")
def test_fallback(mocker):
def fake_load_library(lib_name, path):
if lib_name in ["libfinufft", "finufft"]:
raise OSError()
else:
return np.ctypeslib.load_library(lib_name, path)

mocker.patch("numpy.ctypeslib.load_library", fake_load_library)

if find_library("finufft") is None:
with pytest.raises(ImportError, match="suitable finufft"):
import finufft
else:
import finufft
9 changes: 4 additions & 5 deletions src/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ target_include_directories(cufinufft_common_objects
set_target_properties(
cufinufft_common_objects
PROPERTIES POSITION_INDEPENDENT_CODE ${FINUFFT_SHARED_LINKING}
CUDA_ARCHITECTURES ${FINUFFT_CUDA_ARCHITECTURES}
CUDA_ARCHITECTURES "${FINUFFT_CUDA_ARCHITECTURES}"
CUDA_SEPARABLE_COMPILATION ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON)
Expand All @@ -60,7 +60,7 @@ target_include_directories(cufinufft_objects PUBLIC ${CUFINUFFT_INCLUDE_DIRS})
set_target_properties(
cufinufft_objects
PROPERTIES POSITION_INDEPENDENT_CODE ${FINUFFT_SHARED_LINKING}
CUDA_ARCHITECTURES ${FINUFFT_CUDA_ARCHITECTURES}
CUDA_ARCHITECTURES "${FINUFFT_CUDA_ARCHITECTURES}"
CUDA_SEPARABLE_COMPILATION ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON)
Expand All @@ -78,12 +78,11 @@ endif()

set_target_properties(
cufinufft
PROPERTIES CUDA_ARCHITECTURES ${FINUFFT_CUDA_ARCHITECTURES}
PROPERTIES CUDA_ARCHITECTURES "${FINUFFT_CUDA_ARCHITECTURES}"
CUDA_SEPARABLE_COMPILATION ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
CUDA_ARCHITECTURES ${FINUFFT_CUDA_ARCHITECTURES})
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
target_compile_features(cufinufft PRIVATE cxx_std_17)

if(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion test/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ foreach(srcfile ${test_src})
target_compile_features(${executable} PUBLIC cxx_std_17)
set_target_properties(
${executable} PROPERTIES LINKER_LANGUAGE CUDA CUDA_ARCHITECTURES
${FINUFFT_CUDA_ARCHITECTURES})
"${FINUFFT_CUDA_ARCHITECTURES}")
message(STATUS "Adding test ${executable}"
" with CUDA_ARCHITECTURES=${FINUFFT_CUDA_ARCHITECTURES}"
" and INCLUDE=${CUFINUFFT_INCLUDE_DIRS}")
Expand Down

0 comments on commit aded209

Please sign in to comment.