CMake: cuFFT linked statically wherever the toolkit has the static library

The server build linked libcufft.so, so any executable copied to another
machine needed the CUDA toolkit library beside it; only the portable builds
linked libcufft_static.a. Now every build does where CUDA::cufft_static
exists (Linux); Windows, which has none, keeps the DLL as before.

libcufft_static.a needs a device-link step in every executable that links
it. The four per-target CUDA_RESOLVE_DEVICE_SYMBOLS settings (rugnux,
jfjoch_viewer, jfjoch_portable_test, rugnux_refine_test) become one pass at
the end of the top-level CMakeLists over the executables and shared
libraries of the source tree (fetched dependencies left alone).

Executables grow by about 290 MB (rugnux 193 -> 486 MB, jfjoch_broker 488
MB, jfjoch_fpga_stills_test 484 MB); ldd no longer lists libcufft.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdHHZ4cogS1mrGUtfN7
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-18 10:09:53 +01:00
1 parent 9f38cffdda
commit 3ac1fd657f
7 files changed
+31 -29

No files matched your search

+26
View File
@@ -656,6 +656,32 @@ IF (NOT JFJOCH_WRITER_ONLY AND NOT JFJOCH_PORTABLE_ONLY)
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/frontend/dist/ DESTINATION share/jfjoch/frontend COMPONENT jfjoch )
ENDIF()
# libcufft_static.a carries a relocatable-device-code object (separate_callback.o), so an executable
# linking it needs a CUDA device-link step -- without it the host link fails on an undefined
# __cudaRegisterLinkedBinary_* symbol. CUDA 13 no longer ships libcufft_static_nocallback.a, which
# used to be the way around it. CUDA_RESOLVE_DEVICE_SYMBOLS makes CMake emit that step while leaving
# the host link driver alone, so the -march/-flto flags CI passes still apply. Set on every executable
# and shared library of this source tree, as nearly all of them link the image analysis.
FUNCTION(JFJOCH_RESOLVE_DEVICE_SYMBOLS dir)
GET_PROPERTY(_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
FOREACH(_target IN LISTS _targets)
GET_TARGET_PROPERTY(_type ${_target} TYPE)
IF (_type MATCHES "EXECUTABLE|SHARED_LIBRARY|MODULE_LIBRARY")
SET_TARGET_PROPERTIES(${_target} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
ENDIF()
ENDFOREACH()
GET_PROPERTY(_subdirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
FOREACH(_subdir IN LISTS _subdirs)
STRING(FIND "${_subdir}" "${CMAKE_SOURCE_DIR}/" _position)
IF (_position EQUAL 0) # not the fetched dependencies
JFJOCH_RESOLVE_DEVICE_SYMBOLS(${_subdir})
ENDIF()
ENDFOREACH()
ENDFUNCTION()
IF (JFJOCH_CUDA_AVAILABLE AND TARGET CUDA::cufft_static)
JFJOCH_RESOLVE_DEVICE_SYMBOLS(${CMAKE_SOURCE_DIR})
ENDIF()
# Windows has no static cuFFT (the toolkit ships no cufft_static.lib), so there the indexer links
# the import library and the self-contained products must carry the DLL beside the executable --
# the same idea the Linux builds no longer need, since they link libcufft_static.a. CUDA 13 keeps
@@ -47,7 +47,7 @@ IF (JFJOCH_CUDA_AVAILABLE)
BeamCenterBackgroundGPU.cu BeamCenterBackgroundGPU.h)
# Same static/dynamic cuFFT choice as the FFT indexer, and for the same reasons - see the long
# note in image_analysis/indexing/CMakeLists.txt.
IF (JFJOCH_PORTABLE_ONLY AND TARGET CUDA::cufft_static)
IF (TARGET CUDA::cufft_static)
TARGET_LINK_LIBRARIES(JFJochGeomRefinement CUDA::cufft_static)
ELSE()
TARGET_LINK_LIBRARIES(JFJochGeomRefinement CUDA::cufft)
+4 -4
View File
@@ -51,10 +51,10 @@ IF (JFJOCH_CUDA_AVAILABLE)
# and the dynamic library is the only option; the top-level CMakeLists installs the DLL beside
# the executable for the self-contained builds. Test the target rather than the platform, so a
# toolkit that gains or loses the static library is handled without another special case.
# Both halves matter: the server build keeps the shared library (its .deb/.rpm take CUDA from the
# distro, and every executable there -- broker, tests, tools -- would otherwise need the device
# link below), and Windows has no static cuFFT to link even for the portable products.
IF (JFJOCH_PORTABLE_ONLY AND TARGET CUDA::cufft_static)
# The server build links it statically too, so its executables (broker, tools copied to another
# machine) need no CUDA toolkit library; the top-level CMakeLists gives every executable the device
# link this needs.
IF (TARGET CUDA::cufft_static)
TARGET_LINK_LIBRARIES(JFJochIndexing fast_indexer_static CUDA::cufft_static)
ELSE()
TARGET_LINK_LIBRARIES(JFJochIndexing fast_indexer_static CUDA::cufft)
-8
View File
@@ -66,14 +66,6 @@ IF(APPLE AND JFJOCH_MACOS_SIGNING_IDENTITY)
COMPONENT rugnux)
ENDIF()
# libcufft_static.a carries a relocatable-device-code object (separate_callback.o), so an executable
# linking it needs a CUDA device-link step -- without it the host link fails on an undefined
# __cudaRegisterLinkedBinary_* symbol. CUDA 13 no longer ships libcufft_static_nocallback.a, which
# used to be the way around it. CUDA_RESOLVE_DEVICE_SYMBOLS makes CMake emit that step while leaving
# the host link driver alone, so the -march/-flto flags CI passes still apply.
IF (JFJOCH_PORTABLE_ONLY AND JFJOCH_CUDA_AVAILABLE AND TARGET CUDA::cufft_static)
SET_TARGET_PROPERTIES(rugnux PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
ENDIF()
# On Windows this CLI gets getopt/getopt_long from the vendored wingetopt shim (libc has none).
-4
View File
@@ -47,10 +47,6 @@ ADD_EXECUTABLE(jfjoch_portable_test EXCLUDE_FROM_ALL
target_link_libraries(jfjoch_portable_test Catch2WithMain JFJochRugnux JFJochReader JFJochImageAnalysis
JFJochWriter JFJochAPIConvert JFJochCommon)
target_include_directories(jfjoch_portable_test PRIVATE .)
# Same device-link step as rugnux (see rugnux/CMakeLists.txt): a portable CUDA build links cuFFT statically.
IF (JFJOCH_PORTABLE_ONLY AND JFJOCH_CUDA_AVAILABLE AND TARGET CUDA::cufft_static)
SET_TARGET_PROPERTIES(jfjoch_portable_test PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
ENDIF()
# The CPU vs GPU test of the fast-feedback indexer reads the library's own test spot lists
IF (JFJOCH_CUDA_AVAILABLE)
-4
View File
@@ -18,10 +18,6 @@ TARGET_LINK_LIBRARIES(jfjoch_extract_hkl JFJochReader)
# measuring the refinement on battery outputs without processing anything again.
ADD_EXECUTABLE(rugnux_refine_test rugnux_refine_test.cpp)
TARGET_LINK_LIBRARIES(rugnux_refine_test JFJochStructureRefinement JFJochCommon gemmi)
# Same device-link step as rugnux (see rugnux/CMakeLists.txt): a portable CUDA build links cuFFT statically.
IF (JFJOCH_PORTABLE_ONLY AND JFJOCH_CUDA_AVAILABLE AND TARGET CUDA::cufft_static)
SET_TARGET_PROPERTIES(rugnux_refine_test PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
ENDIF()
# In-place re-compress /entry/data/data of a _data file from bitshuffle/LZ4 to bitshuffle/zstd.
ADD_EXECUTABLE(jfjoch_recompress jfjoch_recompress.cpp)
-8
View File
@@ -184,14 +184,6 @@ IF(APPLE)
PATTERN "COLLECT.sh" EXCLUDE)
ENDIF()
# libcufft_static.a carries a relocatable-device-code object (separate_callback.o), so an executable
# linking it needs a CUDA device-link step -- without it the host link fails on an undefined
# __cudaRegisterLinkedBinary_* symbol. CUDA 13 no longer ships libcufft_static_nocallback.a, which
# used to be the way around it. CUDA_RESOLVE_DEVICE_SYMBOLS makes CMake emit that step while leaving
# the host link driver alone, so the -march/-flto flags CI passes still apply.
IF (JFJOCH_PORTABLE_ONLY AND JFJOCH_CUDA_AVAILABLE AND TARGET CUDA::cufft_static)
SET_TARGET_PROPERTIES(jfjoch_viewer PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
ENDIF()
IF(JFJOCH_VIEWER_DBUS)