Skip to content

ENH: Modernize CUDA wiring and auto-detect default VKFFT backend#77

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:enh/vkfft-modernize-cuda-autodetect
Jun 8, 2026
Merged

ENH: Modernize CUDA wiring and auto-detect default VKFFT backend#77
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:enh/vkfft-modernize-cuda-autodetect

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Modernize CUDA wiring and add auto-detection of a sensible default VKFFT backend (CUDA → Metal → OpenCL). Verified locally with VKFFT_BACKEND=1 against ITK main on Linux + CUDA 13.2 (RTX 6000 Ada).

What changed
  • itk-module-init.cmake

    • Replace the removed find_package(CUDA) (legacy module dropped in CMake 4.0+) with enable_language(CUDA) + find_package(CUDAToolkit). CUDA_LIBRARIES now resolves to CUDA::cudart; CUDA_NVRTC_LIB is searched under CUDAToolkit_LIBRARY_DIR.
    • Auto-pick a default VKFFT_BACKEND when the user has not set one: CUDA (1) if check_language(CUDA) finds a working compiler, Metal (5) on Apple if the Metal / Foundation / QuartzCore frameworks probe successfully, otherwise OpenCL (3).
    • Handle VKFFT_BACKEND=5 (Metal): error out cleanly on non-Apple platforms; find the Metal/Foundation/QuartzCore frameworks here so they are available before the consumer-facing CMakeLists runs.
  • src/CMakeLists.txt

    • Link CUDA::cuda_driver instead of bare cuda. The bare name expands to -lcuda, which conda / cross toolchains using a private sysroot do not find (their linker does not search /usr/lib/x86_64-linux-gnu). The imported target carries the absolute path.
  • CMakeLists.txt

    • Replace FetchContent_MakeAvailable(vkfft_lib) with manual FetchContent_Populate + add_subdirectory(... EXCLUDE_FROM_ALL). This keeps the VkFFT / half interface targets that VkFFTBackend links against, but excludes the upstream VkFFT_TestSuite benchmark executable — which hard-requires CL/cl.h and vulkan/vulkan.h even when only the CUDA path is being built.
Local validation

Built against ITK main on Linux x86_64 with CUDA 13.2:

CUDACXX=/usr/local/cuda/bin/nvcc cmake -DVKFFT_BACKEND=1 \
    -DCMAKE_CUDA_ARCHITECTURES=89 ...
cmake --build .
# [420/422] Linking CXX executable bin/VkFFTBackendTestDriver

Tested:

  • VKFFT_BACKEND=1 (CUDA) — explicit, builds and links.
  • No -DVKFFT_BACKEND — auto-detect picks CUDA on this host.

Not tested locally:

  • VKFFT_BACKEND=5 (Metal) — no Apple hardware in this session.
  • VKFFT_BACKEND=3 (OpenCL) — unchanged path, regression risk low.

Assisted-by: Claude Code (claude-opus-4-7) -- CMake modernization and Metal auto-detect branch.

@hjmjohnson hjmjohnson marked this pull request as ready for review June 7, 2026 17:19
@hjmjohnson hjmjohnson force-pushed the enh/vkfft-modernize-cuda-autodetect branch 5 times, most recently from 432a074 to d85fd0a Compare June 8, 2026 00:44
* itk-module-init.cmake: replace removed find_package(CUDA) with
  enable_language(CUDA) + find_package(CUDAToolkit). Auto-pick a
  default VKFFT_BACKEND when not set: CUDA if a CUDA compiler is
  found, Metal if the Apple Metal/Foundation/QuartzCore frameworks
  probe successfully, otherwise OpenCL.
* itk-module-init.cmake: handle VKFFT_BACKEND=5 (Metal) by locating
  the required Apple frameworks early.
* src/CMakeLists.txt: link CUDA::cuda_driver instead of the bare
  'cuda' name so conda/cross toolchains that do not search
  /usr/lib/x86_64-linux-gnu resolve libcuda.
* CMakeLists.txt: pull the vendored VkFFT sources with
  EXCLUDE_FROM_ALL so the upstream VkFFT_TestSuite benchmark (which
  hard-requires CL/cl.h and vulkan/vulkan.h) is not built unless
  explicitly requested.

Assisted-by: Claude Code (claude-opus-4-7) -- CMake modernization and Metal auto-detect branch.
@hjmjohnson hjmjohnson force-pushed the enh/vkfft-modernize-cuda-autodetect branch from d85fd0a to d9a6036 Compare June 8, 2026 13:14
@hjmjohnson hjmjohnson requested a review from dzenanz June 8, 2026 13:44

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good on a glance.

Comment thread CMakeLists.txt
@hjmjohnson hjmjohnson merged commit fe65a73 into InsightSoftwareConsortium:main Jun 8, 2026
14 checks passed
hjmjohnson added a commit that referenced this pull request Jun 8, 2026
COMP: Simplify CUDA backend wiring and adopt ITK-conformant formatting (follow-up to #77)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants