Build with cp2k and CUDA support fails

GROMACS version: 2024.2
GROMACS modification: No

I’m trying to build GROMACS with both CUDA and cp2k support but get errors in the building step. I’m trying to find out whether the issue is related to GROMACS or cp2k.

Steps to reproduce

mkdir gromacs
cd gromacs

# downloading, compiling and installing cp2k
git clone https://github.com/cp2k/cp2k.git
cd cp2k/tools/toolchain/
./install_cp2k_toolchain.sh \
    --install-all \
    --enable-cuda \
    --gpu-ver=V100 \
    --with-gcc \
    --with-cmake \
    --with-ninja \
    --with-openmpi \
    --with-libxc \
    --with-libint \
    --with-libgrpp \
    --with-fftw \
    --with-openblas \
    --with-scalapack \
    --with-libxsmm \
    --with-elpa \
    --with-cusolvermp \
    --with-pexsi \
    --with-ptscotch \
    --with-superlu \
    --with-quip \
    --with-deepmd \
    --with-plumed \
    --with-sirius \
    --with-gsl \
    --with-libvdwxc \
    --with-spglib \
    --with-hdf5 \
    --with-spfft \
    --with-spla \
    --with-cosma \
    --with-libvori \
    --with-libtorch \
    --with-dftd4
cp install/arch/* ../../arch/
cd ../..
source tools/toolchain/install/setup
make -j 12 ARCH=local VERSION=psmp
# make as a library
make -j 12 ARCH=local VERSION=psmp libcp2k

# Downloading, compiling, and installing gromacs
cd ..
wget https://ftp.gromacs.org/gromacs/gromacs-2024.2.tar.gz
tar xfz gromacs-2024.2.tar.gz
cd gromacs-2024.2
mkdir build
cd build
cmake .. -DGMX_BUILD_OWN_FFTW=ON \
        -DGMX_GPU=CUDA \
        -DCUDA_TOOLKIT_ROOT_DIR=/usr/lib/cuda \
        -DGMX_DOUBLE=OFF \
        -DGMX_SIMD=AVX2_256 \
        -DGMX_CP2K=ON \
        -DCP2K_DIR="../../cp2k/lib/local/psmp/" \
        -DBUILD_SHARED_LIBS=OFF \
        -DGMXAPI=OFF \
        -DGMX_INSTALL_NBLIB_API=OFF \
        -DCMAKE_C_COMPILER=gcc-11
make -j $(nproc)

What is the current bug behavior?

Looks like the libsirius dependency of the cp2k can’t find CUBLAS and libdeepmd dependency of the cp2k can’t find libtensorflow_framework. I’m unsure why this happens. Should I supply DCP2K_LINKER_FLAGS? Any ideas regarding the source of this behaviour (if it’s related to GROMACS or cp2k) is appreciated.

[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/testmatchers.cpp.o
/usr/bin/ld: /home/user/gromacs/cp2k/tools/toolchain/install/sirius-7.5.2/lib/cuda/libsirius.a(sirius_api.cpp.o): undefined reference to symbol 'cublasCreate_v2'
/usr/bin/ld: /home/user/gromacs/cp2k/tools/toolchain/install/libdeepmd_c-2.2.7/lib/../lib/../lib/libtensorflow_framework.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [src/programs/CMakeFiles/gmx.dir/build.make:98: bin/gmx] Error 1
make[1]: *** [CMakeFiles/Makefile2:6088: src/programs/CMakeFiles/gmx.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/testoptions.cpp.o
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/textblockmatchers.cpp.o
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/topologyhelpers.cpp.o
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/tprfilegenerator.cpp.o
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/trajectoryreader.cpp.o
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/xvgtest.cpp.o
[100%] Building CXX object src/testutils/CMakeFiles/testutils.dir/__/external/tinyxml2/tinyxml2.cpp.o
[100%] Linking CXX static library ../../lib/libtestutils.a
[100%] Built target testutils
make: *** [Makefile:166: all] Error 2