microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.8k stars 6.3k forks source link

[CUDA] find_package(CUDA 10.1 EXACT) only finds latest installed version #12448

Open PhilLab opened 4 years ago

PhilLab commented 4 years ago

Is your feature request related to a problem? Please describe. We have an exact version requirement for NVIDIA CUDA:

find_package(CUDA 10.1 EXACT REQUIRED)

However, the current port file only reports the latest version, even if older versions are installed:

Could NOT find CUDA: Found unsuitable version "11.0", but required is exact version "10.1" (found C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0)

I have available on my system:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\

Proposed solution The port file should not only find the latest version but if an exact one was requested, return it

Describe alternatives you've considered

Additional context

MVoz commented 4 years ago

del or comment str set(CUDA_REQUIRED_VERSION "10.1.0")

PhilLab commented 4 years ago

@Voskrese Thanks for the lightning-fast response. However, I am unsure if this is the actual problem here, as the "10.1.0" would actually be the version I need. In the portfile, this just seems to be the minor version vcpkg is working with.

The cmake error about mismatching versions does not fail in the port file - then, the message would be:

CUDA ${CUDA_VERSION} found, but v${CUDA_REQUIRED_VERSION} is required. Please download and install a more recent version...

but rather when I use find_package(CUDA 10.1 EXACT REQUIRED) in my own script. It then says

Could NOT find CUDA: Found unsuitable version "11.0", but required is exact version "10.1" (found C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0)

JackBoosY commented 4 years ago

@Neumann-A Could you please take a look?

Thanks.

Neumann-A commented 4 years ago

The CUDA port just verifies that CUDA exists nothing more.

find_package(CUDA 10.1 EXACT REQUIRED)

For that somebody as to dig down into the CUDA module and check weather or not it supports searching for other versions. It could be that it only uses CUDA_PATH. Thus you just need to set CUDA_PATH to the correct toolset path for the CUDA version you want to use.

MVoz commented 4 years ago

in port file

vcpkg_add_to_path(PREPEND $ENV{CUDA_PATH}/bin) or vcpkg_add_to_path(PREPEND $ENV{CUDA_PATH_V10_0}/bin) or ...

...
set(CMAKE_CUDA_COMPILER_WORKS TRUE)
vcpkg_add_to_path(PREPEND $ENV{CUDA_PATH}/bin)

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
...