Skip to content

Commit 7fe3c99

Browse files
authored
Merge branch 'flatironinstitute:master' into ker-sym
2 parents eefac07 + 25096f8 commit 7fe3c99

File tree

15 files changed

+307
-113
lines changed

15 files changed

+307
-113
lines changed

CMakeLists.txt

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ if (CMAKE_CXX_COMPILER_ID IN_LIST GNU_LIKE_FRONTENDS)
2929
endif ()
3030

3131
include(CTest)
32+
# Set default build type to Release
33+
if(NOT CMAKE_BUILD_TYPE)
34+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Set the default build type to Release" FORCE)
35+
endif()
3236

3337
if (CMAKE_CXX_COMPILER_ID IN_LIST GNU_LIKE_FRONTENDS)
3438
if (CMAKE_SYSTEM_PROCESSOR MATCHES "ppc|ppc64|powerpc|powerpc64" OR (APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc|ppc64"))
@@ -53,6 +57,7 @@ option(FINUFFT_USE_CUDA "Whether to build CUDA accelerated FINUFFT library (libc
5357
option(FINUFFT_USE_CPU "Whether to build the ordinary FINUFFT library (libfinufft)." ON)
5458
option(FINUFFT_STATIC_LINKING "Whether to link the static FINUFFT library (libfinufft_static)." ON)
5559
option(FINUFFT_BUILD_DEVEL "Whether to build development executables" OFF)
60+
option(FINUFFT_USE_DUCC0 "Whether to use DUCC0 (instead of FFTW) for CPU FFTs" OFF)
5661
# sphinx tag (don't remove): @cmake_opts_end
5762

5863
if (FINUFFT_USE_CPU)
@@ -70,9 +75,21 @@ if (FINUFFT_USE_CPU)
7075
set(FFTW_VERSION 3.3.10)
7176
set(XTL_VERSION 0.7.7)
7277
set(XSIMD_VERSION 13.0.0)
78+
set(DUCC0_VERSION ducc0_0_34_0)
79+
set(FINUFFT_FFTW_LIBRARIES)
7380
include(cmake/setupCPM.cmake)
74-
include(cmake/setupFFTW.cmake)
7581
include(cmake/setupXSIMD.cmake)
82+
if (FINUFFT_USE_DUCC0)
83+
include(cmake/setupDUCC.cmake)
84+
else ()
85+
include(cmake/setupFFTW.cmake)
86+
endif ()
87+
endif ()
88+
89+
if (FINUFFT_USE_DUCC0)
90+
set (FINUFFT_FFTLIBS ducc0)
91+
else ()
92+
set (FINUFFT_FFTLIBS ${FINUFFT_FFTW_LIBRARIES})
7693
endif ()
7794

7895
if (FINUFFT_BUILD_MATLAB)
@@ -101,7 +118,7 @@ endif ()
101118

102119
# This set of sources is compiled twice, once in single precision and once in double precision
103120
# The single precision compilation is done with -DSINGLE
104-
set(FINUFFT_PRECISION_DEPENDENT_SOURCES src/finufft.cpp src/simpleinterfaces.cpp src/spreadinterp.cpp src/utils.cpp fortran/finufftfort.cpp)
121+
set(FINUFFT_PRECISION_DEPENDENT_SOURCES src/finufft.cpp src/fft.cpp src/simpleinterfaces.cpp src/spreadinterp.cpp src/utils.cpp fortran/finufftfort.cpp)
105122

106123
# Set of compilers which behave like gcc
107124
set(FINUFFT_GNU_LIKE_COMPILERS AppleClang Clang GNU)
@@ -122,6 +139,11 @@ endfunction()
122139

123140
# Utility function to link static/dynamic lib
124141
function(finufft_link_test target)
142+
143+
if (FINUFFT_USE_DUCC0)
144+
target_compile_definitions(${target} PRIVATE FINUFFT_USE_DUCC0)
145+
endif ()
146+
125147
if (FINUFFT_STATIC_LINKING)
126148
target_link_libraries(${target} PRIVATE finufft_static)
127149
if (FINUFFT_USE_OPENMP)
@@ -169,37 +191,54 @@ function(set_finufft_options target)
169191
endif ()
170192
endif ()
171193

172-
# FFTW CMAKE file includes the APIs only as an install target, so we need to manually
173-
# include them since we need them for build not for install
174-
# trying to include them directly into the fftw and fftwf targets causes issues with
175-
# the latest version of cmake, so we do it here instead.
176-
if ((NOT FFTW_FOUND) OR (FINUFFT_FFTW_LIBRARIES STREQUAL DOWNLOAD))
177-
list(GET FINUFFT_FFTW_LIBRARIES 0 element)
178-
get_property(FFTW_SOURCE_DIR TARGET ${element} PROPERTY SOURCE_DIR)
179-
set(FFTW_INCLUDE_DIR ${FFTW_SOURCE_DIR}/api)
180-
target_include_directories(${target} PUBLIC ${FFTW_INCLUDE_DIR})
194+
if (FINUFFT_USE_DUCC0)
195+
target_compile_definitions(${target} PRIVATE FINUFFT_USE_DUCC0)
196+
else ()
197+
# FFTW CMAKE file includes the APIs only as an install target, so we need to manually
198+
# include them since we need them for build not for install
199+
# trying to include them directly into the fftw and fftwf targets causes issues with
200+
# the latest version of cmake, so we do it here instead.
201+
if ((NOT FFTW_FOUND) OR (FINUFFT_FFTW_LIBRARIES STREQUAL DOWNLOAD))
202+
list(GET FINUFFT_FFTW_LIBRARIES 0 element)
203+
get_property(FFTW_SOURCE_DIR TARGET ${element} PROPERTY SOURCE_DIR)
204+
set(FFTW_INCLUDE_DIR ${FFTW_SOURCE_DIR}/api)
205+
target_include_directories(${target} PUBLIC ${FFTW_INCLUDE_DIR})
206+
endif ()
181207
endif ()
182-
target_link_libraries(${target} PRIVATE xsimd)
183-
target_link_libraries(${target} PUBLIC ${FINUFFT_FFTW_LIBRARIES})
208+
# target_link_libraries(${target} PRIVATE xsimd)
209+
# target_link_libraries(${target} PUBLIC ${FINUFFT_FFTW_LIBRARIES})
184210
endfunction()
185211

186212
if (FINUFFT_USE_CPU)
187213
# Main finufft libraries
214+
if (FINUFFT_USE_DUCC0)
215+
# okay for now, to be cleaned up
216+
set_finufft_options(ducc0)
217+
endif ()
218+
188219
add_library(finufft_f32 OBJECT ${FINUFFT_PRECISION_DEPENDENT_SOURCES})
189220
target_compile_definitions(finufft_f32 PRIVATE SINGLE)
190221
set_finufft_options(finufft_f32)
222+
target_link_libraries(finufft_f32 PUBLIC ${FINUFFT_FFTLIBS})
223+
target_link_libraries(finufft_f32 PRIVATE xsimd)
191224

192225
add_library(finufft_f64 OBJECT ${FINUFFT_PRECISION_DEPENDENT_SOURCES})
193226
target_compile_definitions(finufft_f64 PRIVATE)
194227
set_finufft_options(finufft_f64)
228+
target_link_libraries(finufft_f64 PUBLIC ${FINUFFT_FFTLIBS})
229+
target_link_libraries(finufft_f64 PRIVATE xsimd)
195230
if (WIN32)
196231
add_library(finufft_f32_dll OBJECT ${FINUFFT_PRECISION_DEPENDENT_SOURCES})
197232
target_compile_definitions(finufft_f32_dll PRIVATE SINGLE dll_EXPORTS FINUFFT_DLL)
198233
set_finufft_options(finufft_f32_dll)
234+
target_link_libraries(finufft_f32_dll PUBLIC ${FINUFFT_FFTLIBS})
235+
target_link_libraries(finufft_f32_dll PRIVATE xsimd)
199236

200237
add_library(finufft_f64_dll OBJECT ${FINUFFT_PRECISION_DEPENDENT_SOURCES})
201238
target_compile_definitions(finufft_f64_dll PRIVATE dll_EXPORTS FINUFFT_DLL)
202239
set_finufft_options(finufft_f64_dll)
240+
target_link_libraries(finufft_f64_dll PUBLIC ${FINUFFT_FFTLIBS})
241+
target_link_libraries(finufft_f64_dll PRIVATE xsimd)
203242
endif ()
204243

205244
add_library(finufft SHARED src/utils_precindep.cpp contrib/legendre_rule_fast.cpp)

cmake/setupDUCC.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CPMAddPackage(
2+
NAME ducc0
3+
GIT_REPOSITORY https://gitlab.mpcdf.mpg.de/mtr/ducc.git
4+
GIT_TAG ${DUCC0_VERSION}
5+
DOWNLOAD_ONLY YES
6+
)
7+
8+
9+
if(ducc0_ADDED)
10+
add_library(ducc0 STATIC
11+
${ducc0_SOURCE_DIR}/src/ducc0/infra/string_utils.cc
12+
${ducc0_SOURCE_DIR}/src/ducc0/infra/threading.cc
13+
${ducc0_SOURCE_DIR}/src/ducc0/infra/mav.cc
14+
${ducc0_SOURCE_DIR}/src/ducc0/math/gridding_kernel.cc
15+
${ducc0_SOURCE_DIR}/src/ducc0/math/gl_integrator.cc
16+
)
17+
target_include_directories(ducc0 PUBLIC ${ducc0_SOURCE_DIR}/src/)
18+
target_compile_options(ducc0 PRIVATE -ffast-math)
19+
target_compile_features(ducc0 PRIVATE cxx_std_17) # private because we do not want to propagate this requirement
20+
21+
if (NOT OpenMP_CXX_FOUND)
22+
find_package(Threads REQUIRED)
23+
target_link_libraries(ducc0 PRIVATE Threads::Threads)
24+
endif ()
25+
endif ()

cmake/setupFFTW.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ if (FINUFFT_FFTW_LIBRARIES STREQUAL DEFAULT OR FINUFFT_FFTW_LIBRARIES STREQUAL D
4444
EXCLUDE_FROM_ALL YES
4545
GIT_SHALLOW YES
4646
)
47-
4847
set(FINUFFT_FFTW_LIBRARIES fftw3 fftw3f)
4948
if (FINUFFT_USE_THREADS)
5049
list(APPEND FINUFFT_FFTW_LIBRARIES fftw3_threads fftw3f_threads)

devel/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ add_executable(foldrescale foldrescale.cpp)
2121
target_link_libraries(foldrescale finufft benchmark xsimd)
2222
add_executable(padding padding.cpp)
2323
target_link_libraries(padding finufft xsimd)
24-
target_compile_options(padding PRIVATE -march=native)
24+
target_compile_options(padding PRIVATE -march=native)

docs/install.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ The basic quick download, building, and test is then:
5959
cd finufft
6060
mkdir build
6161
cd build
62-
cmake .. -D FINUFFT_BUILD_TESTS=ON --install-prefix /path/to/install
62+
cmake .. -D FINUFFT_BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=Release --install-prefix /path/to/install
6363
cmake --build . -j
6464
ctest
6565
cmake --install .
6666
6767
68-
Note: if you don't supply --install-prefix, it will default to ``/usr/local`` on most systems. If you don't
68+
Note: `Release` here is essential to get the best performing version. Also, if you don't supply `--install-prefix`, it will default to ``/usr/local`` on most systems. If you don't
6969
have root access, you must supply a prefix you can write to such as ``$HOME/local``. Now...
7070

7171
In ``build``, this creates ``libfinufft_static.a`` and ``libfinufft.so``, and runs a test that should take a
@@ -104,7 +104,7 @@ For example, to configure, build and test the development preset (which builds t
104104
105105
.. warning::
106106

107-
Intel compilers (unlike GPU compilers) currently engage ``fastmath`` behavior with ``-O2`` or ``-O3``. This may interfere with our use of ``std::isnan`` in our test codes. For this reason in the Intel presets ``icx`` and ``icc`` have set ``-fp-model=strict``. You may get more speed if you remove this flag.
107+
Intel compilers (unlike GPU compilers) currently engage ``fastmath`` behavior with ``-O2`` or ``-O3``. This may interfere with our use of ``std::isfinite`` in our test codes. For this reason in the Intel presets ``icx`` and ``icc`` have set ``-fp-model=strict``. You may get more speed if you remove this flag, or try ``-fno-finite-math-only``.
108108

109109
From other CMake projects, to use ``finufft`` as a library, simply add this repository as a subdirectory using
110110
``add_subdirectory``, and use ``target_link_library(your_executable finufft)``.

include/finufft/defs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@
191191
// -------- FINUFFT's plan object, prec-switching version ------------------
192192
// NB: now private (the public C++ or C etc user sees an opaque pointer to it)
193193

194-
// FFTW is needed since we include a FFTW plan in the FINUFFT plan...
195-
#include <finufft/fftw_defs.h> // (must come after complex.h)
196-
// (other FFT lib headers eg MKL could be here...)
194+
#include <finufft/fft.h> // (must come after complex.h)
197195

198196
// group together a bunch of type 3 rescaling/centering/phasing parameters:
199197
#define TYPE3PARAMS FINUFFTIFY(_type3Params)
@@ -230,7 +228,7 @@ typedef struct FINUFFT_PLAN_S { // the main plan object, fully C++
230228
FLT *phiHat2; // " y-axis.
231229
FLT *phiHat3; // " z-axis.
232230

233-
FFTW_CPX *fwBatch; // (batches of) fine grid(s) for FFTW to plan
231+
CPX *fwBatch; // (batches of) fine grid(s) for FFTW to plan
234232
// & act on. Usually the largest working array
235233

236234
BIGINT *sortIndices; // precomputed NU pt permutation, speeds spread/interp
@@ -249,7 +247,9 @@ typedef struct FINUFFT_PLAN_S { // the main plan object, fully C++
249247
FINUFFT_PLAN innerT2plan; // ptr used for type 2 in step 2 of type 3
250248

251249
// other internal structs; each is C-compatible of course
250+
#ifndef FINUFFT_USE_DUCC0
252251
FFTW_PLAN fftwPlan;
252+
#endif
253253
finufft_opts opts; // this and spopts could be made ptrs
254254
finufft_spread_opts spopts;
255255

include/finufft/fft.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef FINUFFT_INCLUDE_FINUFFT_FFT_H
2+
#define FINUFFT_INCLUDE_FINUFFT_FFT_H
3+
4+
#ifdef FINUFFT_USE_DUCC0
5+
#include "ducc0/fft/fftnd_impl.h"
6+
#define FFTW_FORGET_WISDOM() // temporary hack since some tests call this unconditionally
7+
#define FFTW_CLEANUP() // temporary hack since some tests call this unconditionally
8+
#define FFTW_CLEANUP_THREADS() // temporary hack since some tests call this
9+
// unconditionally
10+
#else
11+
#include "fftw_defs.h"
12+
#endif
13+
#include <finufft/defs.h>
14+
15+
int *gridsize_for_fft(FINUFFT_PLAN p);
16+
void do_fft(FINUFFT_PLAN p);
17+
18+
#endif // FINUFFT_INCLUDE_FINUFFT_FFT_H

include/finufft/test_defs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#include <finufft/utils_precindep.h>
2121
// prec-switching (via SINGLE) to set up FLT, CPX, BIGINT, FINUFFT1D1, etc...
2222
#include <finufft/defs.h>
23-
// since "many" (vector) tests need direct access to FFTW commands...
24-
// (although this now happens to be included in defs.h too)
25-
#include <finufft/fftw_defs.h>
2623

2724
// std stuff for tester src
2825
#include <cstdio>

include/finufft_eitherprec.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,3 @@ FINUFFT_EXPORT int FINUFFT_CDECL FINUFFTIFY(3d3many)(
184184
#undef FINUFFT_PLAN
185185
#undef FINUFFT_PLAN_S
186186
#undef FINUFFT_TYPE3PARAMS
187-
#undef FINUFFT_FFTW_CPX
188-
#undef FINUFFT_FFTW_PLAN

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ SOBJS_PI = src/utils_precindep.o
118118
SOBJSD = $(SOBJS) $(SOBJSF) $(SOBJS_PI)
119119

120120
# double-prec library object files that also need single precision...
121-
OBJS = $(SOBJS) src/finufft.o src/simpleinterfaces.o fortran/finufftfort.o
121+
OBJS = $(SOBJS) src/finufft.o src/simpleinterfaces.o fortran/finufftfort.o src/fft.o
122122
# their single-prec versions
123123
OBJSF = $(OBJS:%.o=%_32.o)
124124
# precision-dependent library object files (compiled & linked only once)...

0 commit comments

Comments
 (0)