diff --git a/CMakeLists.txt b/CMakeLists.txt index 15579e366..33fd421d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,13 +402,12 @@ SET(ENABLE_FLOAT ON CACHE BOOL "" FORCE) SET(BUILD_TESTS OFF CACHE BOOL "" FORCE) # SIMD codelets are runtime-dispatched (cpuid), so enabling AVX2 does NOT require an AVX2 CPU # -- FFTW falls back at runtime. The codelet sets are arch-specific, so guard by processor: -# x86 gets SSE2/AVX/AVX2, aarch64 (e.g. Grace on DGX Spark) gets NEON; other arches build scalar. +# x86 gets SSE2/AVX/AVX2, aarch64 (Apple Silicon, Grace on DGX Spark) gets NEON - added below the +# FetchContent, as FFTW's CMake build has no switch for it; other arches build scalar. IF (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64") SET(ENABLE_SSE2 ON CACHE BOOL "" FORCE) SET(ENABLE_AVX ON CACHE BOOL "" FORCE) SET(ENABLE_AVX2 ON CACHE BOOL "" FORCE) -ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") - SET(ENABLE_NEON ON CACHE BOOL "" FORCE) ENDIF() FetchContent_Declare(fftw URL https://www.fftw.org/fftw-3.3.10.tar.gz @@ -419,6 +418,19 @@ FetchContent_MakeAvailable(fftw) # the build tree (FetchContent) leaves the header unreachable. On Linux a system-installed # fftw3.h masks this; on Windows it does not. Add the source-tree api/ dir for build-tree use. TARGET_INCLUDE_DIRECTORIES(fftw3f INTERFACE $) +# NEON: only FFTW's autotools build knows it (--enable-neon); its CMake build silently builds scalar +# code on ARM (and ignores an ENABLE_NEON, as this file once set). So the NEON codelets are added +# the way its CMakeLists adds the SSE2/AVX ones: the sources, and HAVE_NEON so that dft/conf.c and +# rdft/conf.c register them - as a definition, because its config.h template carries HAVE_NEON only +# as a comment. NEON is part of every aarch64 CPU, so no compiler flag is needed. It is single +# precision, which is all that is built here. Measured on Apple Silicon against the scalar build +# (same results to 1e-8): the indexer's batched 1D r2c 1.8x faster at a power-of-two length and 1.3x +# at 730, the 2D r2c of the beam-centre search 1.9x, a 128^3 c2r map 2.6x. +IF (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") + FILE(GLOB _fftw_neon_sources ${fftw_SOURCE_DIR}/dft/simd/neon/*.c ${fftw_SOURCE_DIR}/rdft/simd/neon/*.c) + TARGET_SOURCES(fftw3f PRIVATE ${_fftw_neon_sources}) + TARGET_COMPILE_DEFINITIONS(fftw3f PRIVATE HAVE_NEON=1) +ENDIF() ADD_COMPILE_DEFINITIONS(JFJOCH_USE_FFTW) # Eigen (header-only), consumed by the analysis libraries directly and by Ceres and ffbidx through