I build Gromacs from source, I get a message that Could NOT find CUDA (missing: CUDA_INCLUDE_DIR)

GROMACS version:2024.3
GROMACS modification: no

My cuda-toolkit is installed in the conda environment

(MD_Gromacs_mpi_plumed)gst@DESKTOP-H4HHN9K:~/groinstall/gromacs-2024.3/build$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Wed_Aug_14_10:10:22_PDT_2024
Cuda compilation tools, release 12.6, V12.6.68
Build cuda_12.6.r12.6/compiler.34714021_0

When I compile Gromacs with GPU acceleration from source code, I get a message “missing: $CUDA_INCLUDE_DIRS” when running the Cmake command. Here is the specific error message:

CMake Error at /home/gst/miniconda3/envs/MD_Gromacs_mpi_plumed/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS) (found suitable version
  "12.6", minimum required is "11.0")
Call Stack (most recent call first):
  /home/gst/miniconda3/envs/MD_Gromacs_mpi_plumed/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  /home/gst/miniconda3/envs/MD_Gromacs_mpi_plumed/share/cmake-3.30/Modules/FindCUDA.cmake:1294 (find_package_handle_standard_args)
  cmake/gmxManageCuda.cmake:45 (find_package)
  CMakeLists.txt:697 (include)

Here is the Cmake command:

cmake .. -DGMX_BUILD_OWN_FFTW=OFF \
         -DREGRESSIONTEST_DOWNLOAD=ON \
         -DGMX_GPU=CUDA \
         -DGMX_MPI=ON \
         -DCMAKE_C_COMPILER=mpicc \
         -DCMAKE_CXX_COMPILER=mpicxx \
         -DGMX_EXTERNAL_BLAS=OFF \
         -DGMX_EXTERNAL_LAPACK=OFF \
         -DCUDA_TOOLKIT_ROOT_DIR=$CONDA_PREFIX \
         -DGMX_SIMD=AVX2_256 \ 
         -DCMAKE_BUILD_TYPE=Debug \
	 -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX

My cmake is also installed in conda

(MD_Gromacs_mpi_plumed)gst@DESKTOP-H4HHN9K:~/groinstall/gromacs-2024.3/build$ cmake --version
cmake version 3.30.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

I have added the following variables before running the Cmake command, but Cmake still doesn’t work

export LD_LIBRARY_PATH=:$CONDA_PREFIX/lib
export CUDA_HOME=:$CONDA_PREFIX
export PATH=$PATH:$CONDA_PREFIX/bin
export CUDA_INCLUDE_DIRS=:$CONDA_PREFIX/include
export CUDA_BIN_PATH=$CONDA_PREFIX/bin

But I tried to download and install cuda-toolkit from Nvidia official website
to the default path: /usr/local/cuda12.6, and then replace -DCUDA_TOOLKIT_ROOT_DIR=$CONDA_PREFIX to -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda12.6 ,Compilation can run normally.

I would like to ask if I have missed adding some variables, or the Cmake file of Gromacs cannot be compiled with the CUDA-toolkit in conda.What should I do if I want to compile with CUDA-toolkit in conda

I don’t think there has been that much testing compiling GROMACS in a conda environment. The message that it is missing CUDA_INCLUDE_DIRS indicates that the development headers are not installed in the conda cuda package, only the cuda library.

Thank you for your reply.
I compared the directory structure of the cuda-toolkit which installed on NVIDIA’s official website or installed by conda. There are indeed some differences. For example, the /lib64 directory does not exist in the cuda-toolkit installed by conda, but the corresponding header files such as cuda.h are all there. I am not sure whether this is a problem with the cuda-toolkit installed by conda or a problem with the cmake file of Gromacs, because the nvcc can be detected. I cannot get sudo permissions so conda is best choice.

Just in case somebody else is also struggling with this one still:

I had the exact same problem which was caused by different versions of cuda packages installed by anaconda3. Check via “conda list” that all your CUDA-packages match (for example, anaconda3 had installed different versions of cuda-toolkit and cuda-compiler for me).

I had to explicitly list all those cuda package versions to get the version I wanted to work (12.4):

mamba install -c nvidia cuda=12.4 cuda-toolkit=12.4 cuda-libraries=12.4 cuda-compiler=12.4 cuda-libraries-dev=12.4 cuda-visual-tools=12.4 cuda-cupti-dev=12.4 cuda-libraries-static=12.4 cuda-command-line-tools=12.4 cuda-tools=12.4

The same question. Have you solved this Problem?
I’m using cudatoolkit=11.8 cuda-nvcc=11.8 now