FFTW: build the NEON codelets on aarch64
Build Packages / Create release (push) Successful in 48s
Build Packages / build:viewer:macos-arm64:nocuda (push) Successful in 2m56s
Build Packages / build:rugnux:macos-arm64:nocuda (push) Successful in 2m26s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 23m45s
Build Packages / build:viewer:windows-x86_64:nocuda (push) Successful in 16m46s
Build Packages / build:viewer:windows-x86_64:cuda (push) Successful in 23m7s
Build Packages / build:rugnux:windows-x86_64:cuda (push) Successful in 17m4s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 6m30s
Build Packages / build:rugnux:linux-x86_64:cuda (push) Successful in 6m58s
Build Packages / build:viewer:linux-x86_64:nocuda (push) Successful in 7m11s
Build Packages / build:viewer:linux-x86_64:cuda (push) Successful in 8m19s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 10m27s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 15m34s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 16m17s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 16m26s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 16m14s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 15m48s
Build Packages / Generate python client (push) Successful in 14s
Build Packages / Build documentation (push) Successful in 48s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 15m22s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 15m37s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 14m39s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 16m28s
Build Packages / Unit tests (push) Successful in 1h47m0s

FFTW's CMake build knows only SSE/SSE2/AVX/AVX2; NEON exists only in its
autotools build (--enable-neon). The ENABLE_NEON this file set was silently
ignored, so on Apple Silicon and the Linux aarch64 build FFTW ran its scalar
codelets (config.h: HAVE_NEON undefined, no simd/neon objects). The NEON
sources are now added to fftw3f the way its CMakeLists adds the SSE2/AVX
ones, with HAVE_NEON as a target definition (the config.h template carries
it only as a comment). No compiler flag: NEON is part of every aarch64 CPU.
FFTW 3.3.11 would not help - its CMake build has no NEON either, and its
Apple ARM cycle counter only matters to FFTW_MEASURE planning, while every
plan here is FFTW_ESTIMATE.

FFTW's runtime NEON probe on unix/linux executes .long 0xf2000150; on
aarch64 that decodes as ands x16, x10, #0x100000001 and runs without
SIGILL (checked on Apple Silicon), so the codelets are used on Linux too.

Measured on Apple Silicon against the scalar build: batched 1D r2c 1.8x
(power-of-two length) and 1.3x (730), 2D r2c 1024^2 1.9x, 3D c2r 128^3
2.6x, spectra equal to 1.6e-8 relative. rugnux -X FFTW on 360 frames of
the rotation test set: merged .hkl byte-identical, report identical; CPU
time unchanged (300 s), so FFTs are a small share of that run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Filip LeonarskiandClaude Opus 5.5 committed 2026-09-26 19:35:07 +02:00
1 parent 48ce0dd570
commit 3c7efcd1e5
1 file changed
+15 -3
+15 -3
View File
@@ -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 $<BUILD_INTERFACE:${fftw_SOURCE_DIR}/api>)
# 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