An error in building package KOKKOS with cmake

Hi, everyone.
When I want to build package KOKKOS with cmake, lammps tells me “cannot find -lcufft: No such file or directory” like below

And I find the file “-lcufft” is a package file in nvidia-cuda toolkit. In fact I already find this file “libcufft.so” is in cuda’s package directory and in the package file “lib64” “libcufft.so” is linked to right package file.


I don’t know why I’m told “cannot find -lcufft: No such file or directory”, is this error relationship with the versions of lammps and cuda?

By the way, here is my some version:
UBUNTU: 22.04(in wsl)
CUDA-TOOLKIT: 12.3
LAMMPS: lammps stable release(2 AUG 2023)

THANKS in advance!

BTW, the package GPU can run normally.

I’ve run into this as well, my workaround was switching FFT libraries from FFTW3 to KISS.

I’m sure there’s a way to fix the -lcufft issue, but I couldn’t get any to work

@Paradx_G @tjbarrett

Please apply the following change and try to run CMake again and recompile.
This will move a check for whether the cuFFT library can be found by the linker to the CMake configuration step and then will allow to provide an explicit path from the command line, if needed.

  diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake
  index ce55c83b08..fa2201c595 100644
  --- a/cmake/Modules/Packages/KOKKOS.cmake
  +++ b/cmake/Modules/Packages/KOKKOS.cmake
  @@ -139,8 +139,9 @@ if(PKG_KSPACE)
         message(WARNING "Using KISS FFT with the CUDA backend of Kokkos may be sub-optimal.")
         target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_KISS)
       elseif(FFT_KOKKOS STREQUAL "CUFFT")
  +      find_library(CUFFT_LIBRARY cufft)
         target_compile_definitions(lammps PRIVATE -DFFT_KOKKOS_CUFFT)
  -      target_link_libraries(lammps PRIVATE cufft)
  +      target_link_libraries(lammps PRIVATE ${CUFFT_LIBRARY})
       endif()
     elseif(Kokkos_ENABLE_HIP)
       if(NOT ((FFT_KOKKOS STREQUAL "KISS") OR (FFT_KOKKOS STREQUAL "HIPFFT")))
1 Like

@akohlmey
Thanks Dr. Kohlmeyer, worked perfectly.

So for future reference, for LAMMPS Stable, 2Aug2023:

in KOKKOS.cmake, changing

if(Kokkos_ENABLE_CUDA)
    if(NOT (FFT STREQUAL "KISS"))
      target_compile_definitions(lammps PRIVATE -DFFT_CUFFT)
      target_link_libraries(lammps PRIVATE cufft)
    endif()
  elseif(Kokkos_ENABLE_HIP)
    if(NOT (FFT STREQUAL "KISS"))
      include(DetectHIPInstallation)
      find_package(hipfft REQUIRED)
      target_compile_definitions(lammps PRIVATE -DFFT_HIPFFT)
      target_link_libraries(lammps PRIVATE hip::hipfft)
    endif()
  endif()

to:

if(Kokkos_ENABLE_CUDA)
    if(NOT (FFT STREQUAL "KISS"))
      find_library(CUFFT_LIBRARY cufft)
      target_compile_definitions(lammps PRIVATE -DFFT_CUFFT)
      target_link_libraries(lammps PRIVATE ${CUFFT_LIBRARY})
    endif()
  elseif(Kokkos_ENABLE_HIP)
    if(NOT (FFT STREQUAL "KISS"))
      include(DetectHIPInstallation)
      find_package(hipfft REQUIRED)
      target_compile_definitions(lammps PRIVATE -DFFT_HIPFFT)
      target_link_libraries(lammps PRIVATE hip::hipfft)
    endif()
  endif()

and pointing the ungrouped entry CUFFT_LIBRARY in cmake to libcufft.so fixes the -lcufft error
KOKKOS.cmake (9.9 KB)

Yes, the stable version requires a different patch. My diff was for the latest feature release from 7 Feb 2024. We have improved and expanded the FFT handling since the stable release, so the CMake script code is different.

The corresponding change is already in the maintenance branch here: Third Set of Collected Bug Fixes and Maintenance Updates for 2 August 2023 Stable release by akohlmey · Pull Request #4044 · lammps/lammps · GitHub
and will eventually be released as Update 3 for the stable version.

1 Like

I follow your method to fix KOKKOS.cmake file, but the error changes into below:

“-lCUFFT_LIBRARY” is still not found.

This means that CMake could not find it when it ran its configuration and there should be a warning about it. This usually means that your environment setup for the CUDA toolkit is not complete so that the library you are looking for is not found in one of the folders that CMake is searching. You will either have to figure out which settings to change for CMake to find it (check out its documentation here) or use -D CUFFT_LIBRARY=/full/path/to/libcufft.so when running cmake where you replace /full/path/to with the actual path to the library in your installation.