Fail to compile cmake cuda project while using nvhpc

Hi,
I am trying to switch from regular cuda to nvhpc cuda.
In order to manage my prokject I am using cmake which based on the next tutorial

after the line " project(cmake_and_cuda LANGUAGES CXX CUDA)"

Which gives me the following errors:

/opt/clion-2022.2.1/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/opt/clion-2022.2.1/bin/ninja/linux/ninja -DNVHPC_ENABLE=ON -G Ninja -S /home/Yehonatans/work/nlircloud/src -B /home/Yehonatans/work/nlircloud/src/cmake-build-debug
Cmake version 3.23.2
NVHPC_ENABLE is active
-- The CUDA compiler identification is NVIDIA 11.7.64
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - broken
CMake Error at /opt/clion-2022.2.1/bin/cmake/linux/share/cmake-3.23/Modules/CMakeTestCUDACompiler.cmake:56 (message):
  The CUDA compiler

    "/usr/local/cuda/bin/nvcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/Yehonatans/work/nlircloud/src/cmake-build-debug/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/opt/clion-2022.2.1/bin/ninja/linux/ninja cmTC_77f8c && [1/2] Building CUDA object CMakeFiles/cmTC_77f8c.dir/main.cu.o
    [2/2] Linking CUDA executable cmTC_77f8c
    FAILED: cmTC_77f8c 
    : && /bin/g++  CMakeFiles/cmTC_77f8c.dir/main.cu.o -o cmTC_77f8c  -lcudadevrt  -lcudart_static  -lrt  -lpthread  -ldl -L"/usr/local/cuda/targets/x86_64-linux/lib/stubs" -L"/usr/local/cuda/targets/x86_64-linux/lib" && :
    /bin/ld: cannot find -lcudadevrt
    /bin/ld: cannot find -lcudart_static
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.

In order to use CUDA property I relink the cuda at
/usr/local to :
While in order to find the cuda lib I just linked :
cuda → /opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda

  1. What I am doing wrong and how to solve it?
    2.How to use Cmake + cuda + nvhppc while keep compatibility with regullar cuda?
    3.How to use cmake with nvhpc?

Regards Yehonatan

Hi yehonatans68sw4,

Unfortunately I don’t know CMake enough to help with your errors, but will do my best.

Since the NVHPC SDK package can ship with multiple CUDA versions, you need to add the CUDA version to the directory. For example: “/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/”.

Though creating the link may not be the best strategy. In the Blog you linked, they use the CMAKE_CUDA_COMPILER variable to set where nvcc is located. Did you try changing this variable to something like “/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/bin/nvcc”?

I’m not sure if CMake uses the CUDA_HOME environment variable, but if it does set it to “/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/”.

-Mat

Sorry but after the modification the issue still seems to be appears

Hi
After set(CMAKE_CUDA_COMPILER_FORCED TRUE) I was able to compile the project bu then I faced an issue that I recived linler issue :

/bin/ld: cannot find -lcudadevrt
/bin/ld: cannot find -lcudart_static
while at TARGET_LINK_LIBRARIES I am add follwing options
NVHPC::MPI_CXX NVHPC::NCCL NVHPC::CUDA NVHPC::MATH NVHPC::CUDA

What directories are being using with the “-L” flag? “-L” sets the path to the libraries.

These libraries are located in “/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/targets/x86_64-linux/lib”.

Alternatively, “/opt/nvidia/hpc_sdk/Linux_x86_64/22.7/cuda/11.7/lib64” can be used since its a link to the target directory.

Hi

I am able to use target_link_directories(XX PUBLIC ${NVHPC_CUDA_LIBRARY_DIR}) (and its working)
but NVHPC::CUDA should not resolve it automatically?