FindCUDAToolkit unable to find cudart library

First, a big thank you to the developers and community. My understanding of the fundamentals of cmake is lacking, so I greatly appreciate your time and patience.

I am trying to compile a program that comes with a CMakeLists.txt used for compilation. I’m using Ubuntu 20.04 and cmake 3.22.1. When I try to compile as is, I get this error:

CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find NVML (missing: NVML_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  CMakeModules/FindNVML.cmake:66 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:60 (find_package)

As I understand, the solution to this error should be to use the FindCUDAToolkit package, which is included in CMake 3.17.0 onwards (described on Stack Overflow).

Thus, I have attempted to use the approach described at the above link. This involves adding the below code to CMakeLists.txt:

find_package(CUDAToolkit)
add_executable(
    binary_linking_to_cudart 
    my_cpp_file_using_cudart.cpp
)
target_link_libraries(binary_linking_to_cudart PRIVATE CUDA::cudart)

However, this leads me to a new error that I’ve been unable to figure out:

-- Unable to find cudart library.
CMake Error at /home/gmobot/anaconda3/envs/snpint/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find CUDAToolkit (missing: CUDA_CUDART) (found version
  "10.1.243")
Call Stack (most recent call first):
  /home/gmobot/anaconda3/envs/snpint/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /home/gmobot/anaconda3/envs/snpint/share/cmake-3.22/Modules/FindCUDAToolkit.cmake:814 (find_package_handle_standard_args)
  CMakeLists.txt:54 (find_package)

I’m most confused by the line where it says it can NOT find CUDAToolkit, yet finds version 10.1.243. I would appreciate a remedial lesson on what exactly this means, because as little as I know about cmake, this sounds like a contradiction to me.

I do appear to have CUDA runtime (cudart) installed. Do I need to set some flag for cmake to find it?

(snpint) gmobot@forestry-rda-p5820-ubuntu:~/snpint-gpu$ sudo find / -name libcudart.*
/home/gmobot/anaconda3/pkgs/cudatoolkit-11.0.221-h6bb024c_0/lib/libcudart.so.11.0.221
/home/gmobot/anaconda3/pkgs/cudatoolkit-11.0.221-h6bb024c_0/lib/libcudart.so.11.0
/home/gmobot/anaconda3/pkgs/cudatoolkit-11.0.221-h6bb024c_0/lib/libcudart.so
/usr/lib/x86_64-linux-gnu/libcudart.so.10.1.243
/usr/lib/x86_64-linux-gnu/libcudart.so.10.1
/usr/lib/x86_64-linux-gnu/libcudart.so
/usr/share/man/man7/libcudart.7.gz
/usr/share/man/man7/libcudart.so.7.gz

Thanks for your time and help!

@robert.maynard

The cudatoolkit conda package needs to be enabled/installed in your conda enviornment for CMake to find it, since you are building within a conda env.