Repository: pytorch
Issue: LibTorch build error on Windows for CUDA version (debug/release)
Labels: module: build,module: windows,module: cpp,module: cuda,triaged

### 🐛 Describe the bug

I downloaded versions of LibTorch supporting computations on both CPU and CUDA 12.4.   
I created a C++ project in Visual Studio 2022, which is built using CMake. The project includes presets for building the code in CPU (debug/release) and CUDA (debug/release) versions. Each preset set points to a different path to the directory with the unpacked binary version of LibTorch.

Building and running the sample C++ code for LibTorch in debug/release mode for CPU works as expected without any issues. However, when I choose to build the code with CUDA support (e.g., for debug), I receive error messages related to Caffe2 build failures. I see nvTools header files on my machine but no any lib, dlls and so on (maybe it's just in a form of a header file only now).


I've attached the build log  generated by CMake below.

```txt
1> CMake generation started for configuration: 'win-cuda-debug'.
1> Environment settings: // A few elems
...
1>     DevEnvDir=C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\
1>     ExtensionSdkDir=C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs
1>     is_x64_arch=true
1>     VSCMD_ARG_app_plat=Desktop
1>     VSCMD_ARG_HOST_ARCH=x64
1>     VSCMD_ARG_no_logo=1
1>     VSCMD_ARG_TGT_ARCH=x64
1>     VSCMD_DEBUG=5 
1>     VSCMD_VER=17.11.5
1>     VS_Perf_Session_GCHeapCount=2
1>     OS=Windows_NT
1>     NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\
1>     CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
1>     LibTorch=D:\_ML\libTorch\2.5.0
1>     CUDA_ROOT=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
1>     CUDA_PATH_V12_5=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5
1>     CUDA_PATH_V12_4=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
1>     PROCESSOR_ARCHITECTURE=AMD64
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_TOOLCHAIN_FILE:STRING="D:\Vcpkg/scripts/buildsystems/vcpkg.cmake" -DCMAKE_C_COMPILER:STRING="cl.exe" -DCMAKE_CXX_COMPILER:STRING="cl.exe" -DVCPKG_TARGET_TRIPLET:STRING="x64-windows" -DCMAKE_BUILD_TYPE:STRING="Debug" -DTorch_DIR:STRING="D:\_ML\libTorch\2.5.0/cuda/debug/libtorch/share/cmake/Torch" -DFORCE_LINK_SYMBOL:STRING="?ignore_this_library_placeholder@@YAHXZ" -DCMAKE_INSTALL_PREFIX:PATH="D:/Projects/TorchTrade/out/install/win-cuda-debug"   -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\Projects\TorchTrade" 2>&1"
...
1> Working directory: D:/Projects/TorchTrade/out/build/win-cuda-debug
1> [CMake] -- Running vcpkg install
1> [CMake] Detecting compiler hash for triplet x64-windows...
1> [CMake] Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe
1> [CMake] All requested packages are currently installed.
1> [CMake] Total install time: 400 ns
1> [CMake] The package fmt provides CMake targets:
1> [CMake] 
1> [CMake]     find_package(fmt CONFIG REQUIRED)
1> [CMake]     target_link_libraries(main PRIVATE fmt::fmt)
1> [CMake] 
1> [CMake]     # Or use the header-only version
1> [CMake]     find_package(fmt CONFIG REQUIRED)
1> [CMake]     target_link_libraries(main PRIVATE fmt::fmt-header-only)
1> [CMake] 
1> [CMake] The package gtest is compatible with built-in CMake targets:
1> [CMake] 
1> [CMake]     enable_testing()
1> [CMake]     
1> [CMake]     find_package(GTest CONFIG REQUIRED)
1> [CMake]     target_link_libraries(main PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)
1> [CMake]     
1> [CMake]     add_test(AllTestsInMain main)
1> [CMake] 
1> [CMake] The package nlohmann-json provides CMake targets:
1> [CMake] 
1> [CMake]     find_package(nlohmann_json CONFIG REQUIRED)
1> [CMake]     target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)
1> [CMake] 
1> [CMake] The package nlohmann-json can be configured to not provide implicit conversions via a custom triplet file:
1> [CMake] 
1> [CMake]     set(nlohmann-json_IMPLICIT_CONVERSIONS OFF)
1> [CMake] 
1> [CMake] For more information, see the docs here:
1> [CMake]     
1> [CMake]     https://json.nlohmann.me/api/macros/json_use_implicit_conversions/
1> [CMake] 
1> [CMake] The package spdlog provides CMake targets:
1> [CMake] 
1> [CMake]     find_package(spdlog CONFIG REQUIRED)
1> [CMake]     target_link_libraries(main PRIVATE spdlog::spdlog)
1> [CMake] 
1> [CMake]     # Or use the header-only version
1> [CMake]     find_package(spdlog CONFIG REQUIRED)
1> [CMake]     target_link_libraries(main PRIVATE spdlog::spdlog_header_only)
1> [CMake] 
1> [CMake] -- Running vcpkg install - done
1> [CMake] -- Caffe2: CUDA detected: 12.4
1> [CMake] -- Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/nvcc.exe
1> [CMake] -- Caffe2: CUDA toolkit directory: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4
1> [CMake] -- Caffe2: Header version is: 12.4
1> [CMake] CMake Warning at D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/public/cuda.cmake:140 (message):
1> [CMake]   Failed to compute shorthash for libnvrtc.so
1> [CMake] Call Stack (most recent call first):
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:86 (include)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   TorchTrade/CMakeLists.txt:5 (find_package)
1> [CMake] 
1> [CMake] 
1> [CMake] CMake Warning (dev) at C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
1> [CMake]   The package name passed to `find_package_handle_standard_args` (nvtx3) does
1> [CMake]   not match the name of the calling package (Caffe2).  This can lead to
1> [CMake]   problems in calling code that expects `find_package` result variables
1> [CMake]   (e.g., `_FOUND`) to follow a certain pattern.
1> [CMake] Call Stack (most recent call first):
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/public/cuda.cmake:174 (find_package_handle_standard_args)
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:86 (include)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   TorchTrade/CMakeLists.txt:5 (find_package)
1> [CMake] This warning is for project developers.  Use -Wno-dev to suppress it.
1> [CMake] 
1> [CMake] -- Could NOT find nvtx3 (missing: nvtx3_dir) 
1> [CMake] CMake Warning at D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/public/cuda.cmake:180 (message):
1> [CMake]   Cannot find NVTX3, find old NVTX instead
1> [CMake] Call Stack (most recent call first):
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:86 (include)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   TorchTrade/CMakeLists.txt:5 (find_package)
1> [CMake] 
1> [CMake] 
1> [CMake] -- USE_CUDNN is set to 0. Compiling without cuDNN support
1> [CMake] -- USE_CUSPARSELT is set to 0. Compiling without cuSPARSELt support
1> [CMake] -- USE_CUDSS is set to 0. Compiling without cuDSS support
1> [CMake] -- USE_CUFILE is set to 0. Compiling without cuFile support
1> [CMake] -- Autodetected CUDA architecture(s):  7.5
1> [CMake] -- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
1> [CMake] -- Configuring done (24.7s)
1> [CMake] CMake Error at D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/public/cuda.cmake:182 (set_property):
1> [CMake]   The link interface of target "torch::nvtoolsext" contains:
1> [CMake] 
1> [CMake]     CUDA::nvToolsExt
1> [CMake] 
1> [CMake]   but the target was not found.  Possible reasons include:
1> [CMake] 
1> [CMake]     * There is a typo in the target name.
1> [CMake]     * A find_package call is missing for an IMPORTED target.
1> [CMake]     * An ALIAS target is missing.
1> [CMake] 
1> [CMake] Call Stack (most recent call first):
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:86 (include)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   D:/_ML/libTorch/2.5.0/cuda/debug/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
1> [CMake]   D:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
1> [CMake]   TorchTrade/CMakeLists.txt:5 (find_package)
1> [CMake] -- Generating done (0.0s)
1> [CMake] CMake Warning:
1> [CMake]   Manually-specified variables were not used by the project:
1> [CMake] 
1> [CMake]     CMAKE_TOOLCHAIN_FILE
1> [CMake] 
1> [CMake] 
1> [CMake] CMake Generate step failed.  Build files cannot be regenerated correctly.
1> 'C:\WINDOWS\system32\cmd.exe' '/c ... ninja.exe" "D:\Projects\TorchTrade" 2>&1"' returned with exit code: 1'.

```

### Versions

Libtorch 2.5.0, cuda 12.4 for Windows
https://download.pytorch.org/libtorch/cu124/libtorch-win-shared-with-deps-debug-2.5.0%2Bcu124.zip

I have CUDA 12.4 Toolkit installed.



cc @malfet @seemethere @peterjc123 @mszhanyi @skyline75489 @nbcsm @iremyux @Blackhex @jbschlosser @ptrblck @msaroufim