Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to run find_package(Torch) on Windows with libtorch package #333

Closed
1 task done
jeongseok-meta opened this issue Jan 27, 2025 · 15 comments · Fixed by #339
Closed
1 task done

Fails to run find_package(Torch) on Windows with libtorch package #333

jeongseok-meta opened this issue Jan 27, 2025 · 15 comments · Fixed by #339
Labels
bug Something isn't working

Comments

@jeongseok-meta
Copy link
Contributor

Solution to issue cannot be found in the documentation.

  • I checked the documentation.

Issue

Description:

The libtorch package for Windows in CMake is currently not working as expected. When using find_package(Torch) in a CMakeLists.txt file, it returns an error due to missing .dll files:

-- Caffe2: Found protobuf with new-style protobuf targets.
-- Caffe2: Protobuf version 28.3.0
CMake Error at .pixi/envs/default/Library/share/cmake/Caffe2/Caffe2Targets.cmake:122 (message):
  The imported target "c10" references the file
     "<root>/test_libtorch/.pixi/envs/default/Library/lib/c10.dll"
  but this file does not exist.  Possible reasons include:
  * The file was deleted, renamed, or moved to another location.
  * An install or uninstall procedure did not complete successfully.
  * The installation package was faulty and contained
     "<root>/test_libtorch/.pixi/envs/default/Library/share/cmake/Caffe2/Caffe2Targets.cmake"
  but not all the files it references.
Call Stack (most recent call first):
  .pixi/envs/default/Library/share/cmake/Caffe2/Caffe2Config.cmake:114 (include)
  .pixi/envs/default/Library/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:5 (find_package)
  
-- Configuring incomplete, errors occurred!

Reproduction Steps:

  1. Create a new CMake project with the following CMakeLists.txt:

    cmake_minimum_required(VERSION 3.16.3)
    project(LibTorchExample)
    find_package(Torch CONFIG REQUIRED)
  2. Run cmake on the project and observe the error message.

Note: This issue only occurs on Windows, while macOS and Linux work fine.

The .dll files are located in <prefix>/Library/bin/*, but the configuration is set to find them in <prefix>/Library/lib/*. I'm unsure where to look into to resolve this issue. Any help would be appreciated!

Installed packages

Package             Version                Build                     Size       Kind   Source
cuda-cudart         12.6.77                he0c23c2_0                161.1 KiB  conda  cuda-cudart
cuda-cudart_win-64  12.6.77                he0c23c2_0                22.1 KiB   conda  cuda-cudart_win-64
cuda-cupti          12.6.80                he0c23c2_0                2.8 MiB    conda  cuda-cupti
cuda-nvrtc          12.6.85                he0c23c2_0                29.2 MiB   conda  cuda-nvrtc
cuda-version        12.6                   h7480c83_3                20.4 KiB   conda  cuda-version
cudnn               9.3.0.75               h1361d0a_2                374.8 MiB  conda  cudnn
cusparselt          0.6.3.2                hffc9a7f_1                55.1 MiB   conda  cusparselt
intel-openmp        2024.2.1               h57928b3_1083             1.8 MiB    conda  intel-openmp
libabseil           20240722.0             cxx17_h4eb7d71_4          1.7 MiB    conda  libabseil
libblas             3.9.0                  26_win64_mkl              3.6 MiB    conda  libblas
libcblas            3.9.0                  26_win64_mkl              3.6 MiB    conda  libcblas
libcublas           12.6.4.1               he0c23c2_0                287.2 MiB  conda  libcublas
libcudss0           0.4.0.2                hdb9b9d5_2                21.7 MiB   conda  libcudss0
libcufft            11.3.0.4               he0c23c2_0                155.9 MiB  conda  libcufft
libcurand           10.3.7.77              he0c23c2_0                41.7 MiB   conda  libcurand
libcusolver         11.7.1.2               he0c23c2_0                91.3 MiB   conda  libcusolver
libcusparse         12.5.4.2               he0c23c2_0                116.9 MiB  conda  libcusparse
libhwloc            2.11.2                 default_ha69328c_1001     2.3 MiB    conda  libhwloc
libiconv            1.17                   hcfcfb64_2                621.2 KiB  conda  libiconv
liblapack           3.9.0                  26_win64_mkl              3.6 MiB    conda  liblapack
libmagma            2.8.0                  h630bcb8_2                69.8 MiB   conda  libmagma
libnvjitlink        12.6.85                he0c23c2_0                12.5 MiB   conda  libnvjitlink
libprotobuf         5.28.3                 h8309712_1                5.9 MiB    conda  libprotobuf
libtorch            2.5.1                  cuda126_mkl_h5239056_310  382.3 MiB  conda  libtorch
libuv               1.50.0                 h2466b09_0                285.1 KiB  conda  libuv
libwinpthread       12.0.0.r4.gg4f2fc60ca  h57928b3_9                35 KiB     conda  libwinpthread
libxml2             2.13.5                 he286e8c_1                1.5 MiB    conda  libxml2
libzlib             1.3.1                  h2466b09_2                54.2 KiB   conda  libzlib
mkl                 2024.2.2               h66d3029_15               98.3 MiB   conda  mkl
sleef               3.7                    h7e360cc_2                2 MiB      conda  sleef
tbb                 2021.13.0              h62715c5_1                147.9 KiB  conda  tbb
ucrt                10.0.22621.0           h57928b3_1                546.6 KiB  conda  ucrt
vc                  14.3                   h5fd82a7_24               17.3 KiB   conda  vc
vc14_runtime        14.42.34433            h6356254_24               735.9 KiB  conda  vc14_runtime

Environment info

System
------------
       Pixi version: 0.40.3
           Platform: win-64
   Virtual packages: __win=0=0
                   : __cuda=12.5=0
                   : __archspec=1=x86_64_v3
          Cache dir: C:\Users\jeongseok\AppData\Local\rattler\cache
       Auth storage: C:\Users\jeongseok\.rattler\credentials.json
   Config locations: No config files found

Global
------------
            Bin dir: <root>\.pixi\bin
    Environment dir: <root>\.pixi\envs
       Manifest dir: <root>\.pixi\manifests\pixi-global.toml

Project
------------
               Name: test_libtorch
            Version: 0.1.0
      Manifest file: <root>\test_libtorch\pixi.toml
       Last updated: 27-01-2025 12:58:50

Environments
------------
        Environment: default
           Features: default
           Channels: conda-forge
   Dependency count: 1
       Dependencies: libtorch
   Target platforms: win-64
              Tasks: config
@jeongseok-meta jeongseok-meta added the bug Something isn't working label Jan 27, 2025
@h-vetinari
Copy link
Member

h-vetinari commented Jan 27, 2025

Yeah, I just noticed this in conda-forge/torchaudio-feedstock#14. The issue is that we move c10.dll from %SP_DIR%\torch\lib to %PREFIX%\Library\bin (note the switch from lib to bin), and so it looks in the wrong place (relative to a Torch_Root directory, which I think changes successfully to LIBRARY_PREFIX):

 │ │   CMake Error at %PREFIX%/Library/share/cmake/Caffe2/Caffe2Targets.cmake:122 (message):
 │ │     The imported target "c10" references the file
 │ │        "%PREFIX%/Library/lib/c10.dll"
 │ │     but this file does not exist.  Possible reasons include:

In this way, this is a follow-up to of #327 & #328.

I think the easiest might be to patch the CMake metadata here? Otherwise we'd have to patch the build system itself to ensure DLLs get installed into ...\bin.

Thoughts @mgorny @hmaarrfk @isuruf @danpetry?

@h-vetinari
Copy link
Member

@traversaro
Copy link

I think (but did not test) that to install the c10 DLLs in bin it should be sufficient to remove the DESTINATION lib from https://github.com/pytorch/pytorch/blob/7d01f6e6f25835f67f564414b2f66953fd9af67a/c10/CMakeLists.txt#L166 and similar invocation of the install( command, as the default installation prefix for RUNTIME libraries is bin. If that does not work, I guess we need to explicitly add RUNTIME DESTINATION bin to the install( invocation.

@jeongseok-meta
Copy link
Contributor Author

As a note, c10 is not the only issue; other targets' DLLs should also be set to bin, such as torch_cpu, torch, and so on. It seems we have two options: either update this line to copy files to lib (if I'm correct), which is the simplest solution, or update upstream (or adding a patch) for all targets, a more long-term approach suggested by @traversaro.

@h-vetinari
Copy link
Member

I'm working on a patch + test.

@h-vetinari
Copy link
Member

If that does not work, I guess we need to explicitly add RUNTIME DESTINATION bin to the install( invocation.

Indeed, simply removing the destination does not work:

  CMake Error at caffe2/CMakeLists.txt:1501 (install):
    install FILES given no DESTINATION!

@traversaro
Copy link

If that does not work, I guess we need to explicitly add RUNTIME DESTINATION bin to the install( invocation.

Indeed, simply removing the destination does not work:

  CMake Error at caffe2/CMakeLists.txt:1501 (install):
    install FILES given no DESTINATION!

Default DESTINATION argument is available for install(TARGETS, not for install(FILES like the command use there, so for those indeed we manually need to change the install dir to bin (related cmake issue: https://gitlab.kitware.com/cmake/cmake/-/issues/18393).

@h-vetinari
Copy link
Member

h-vetinari commented Jan 28, 2025

@traversaro, I've switched things to (only for TARGETS)

-install(TARGETS torch_python DESTINATION "${TORCH_INSTALL_LIB_DIR}")
+install(TARGETS torch_python
+        LIBRARY DESTINATION lib
+        RUNTIME DESTINATION bin)

(and so on) but looking at the logs, it seems that the import libraries do not get installed anymore.

You're right though, before I made the mistake of also changing some install(FILES directives, so perhaps I should just go back to deleting DESTINATION from install(TARGETS...?

@traversaro
Copy link

Either we delete DESTINATION from install(TARGETS, or add ARCHIVE DESTINATION for installing import libraries.

@h-vetinari
Copy link
Member

or add ARCHIVE DESTINATION for installing import libraries.

gah, why would import libraries be handled by ARCHIVE DESTINATION, it would make much more sense under LIBRARY DESTINATION IMO. In any case, I've deleted DESTINATION from targets in 46d06c1

@traversaro
Copy link

or add ARCHIVE DESTINATION for installing import libraries.

gah, why would import libraries be handled by ARCHIVE DESTINATION, it would make much more sense under LIBRARY DESTINATION IMO. In any case, I've deleted DESTINATION from targets in 46d06c1

I get your pain, but just for reference the related docs is in https://cmake.org/cmake/help/latest/command/install.html#signatures .

@h-vetinari
Copy link
Member

Even with the fixes from #318, there's still a problem with CMake, in that the CUDA-enabled builds (at least on linux), insist on finding actual CUDA drivers(?):

Caffe2: Found protobuf with new-style protobuf targets.
Caffe2: Protobuf version 28.3.0
CUDA_TOOLKIT_ROOT_DIR not found or specified
Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) 
CMake Warning at $PREFIX/share/cmake/Caffe2/public/cuda.cmake:31 (message):
  Caffe2: CUDA cannot be found.  Depending on whether you are building Caffe2
  or a Caffe2 dependent library, the next warning / error will give you more
  info.

This will obviously affect all feedstocks that want to build on top of a cuda-enabled pytorch. Someone else raised this in conda-forge/cuda-feedstock#59 already; the issue is that the Caffe2 CMake files still use the long-deprecated find_package(CUDA), see pytorch/pytorch#76082

@h-vetinari
Copy link
Member

@danpetry, thanks for the offer to help. Here's my draft of replacing find_package(CUDA). However, this sets a large amount of CUDA_* variables, and it's not at all clear which ones remain set, need to be changed to CUDAToolkit_*, or rewritten completely (CUDA_NVRTC_SHORTHASH?)

diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index b51c7cc637b..6e107b5b02a 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -906,25 +906,25 @@ if(USE_ROCM)
         "$<$<COMPILE_LANGUAGE:CXX>:ATen/core/ATen_pch.h>")
   endif()
 elseif(USE_CUDA)
-  set(CUDA_LINK_LIBRARIES_KEYWORD PRIVATE)
+  set(CUDAToolkit_LINK_LIBRARIES_KEYWORD PRIVATE)
   list(APPEND Caffe2_GPU_SRCS ${GENERATED_CXX_TORCH_CUDA})
-  if(CUDA_SEPARABLE_COMPILATION)
+  if(CUDAToolkit_SEPARABLE_COMPILATION)
     # Separate compilation fails when kernels using `thrust::sort_by_key`
     # are linked with the rest of CUDA code. Workaround by linking them separately.
     add_library(torch_cuda ${Caffe2_GPU_SRCS} ${Caffe2_GPU_CU_SRCS})
-    set_property(TARGET torch_cuda PROPERTY CUDA_SEPARABLE_COMPILATION ON)
+    set_property(TARGET torch_cuda PROPERTY CUDAToolkit_SEPARABLE_COMPILATION ON)
 
     add_library(torch_cuda_w_sort_by_key OBJECT
         ${Caffe2_GPU_SRCS_W_SORT_BY_KEY}
         ${Caffe2_GPU_CU_SRCS_W_SORT_BY_KEY})
-    set_property(TARGET torch_cuda_w_sort_by_key PROPERTY CUDA_SEPARABLE_COMPILATION OFF)
+    set_property(TARGET torch_cuda_w_sort_by_key PROPERTY CUDAToolkit_SEPARABLE_COMPILATION OFF)
     target_link_libraries(torch_cuda PRIVATE torch_cuda_w_sort_by_key)
   else()
     add_library(torch_cuda
         ${Caffe2_GPU_SRCS} ${Caffe2_GPU_SRCS_W_SORT_BY_KEY}
         ${Caffe2_GPU_CU_SRCS} ${Caffe2_GPU_CU_SRCS_W_SORT_BY_KEY})
   endif()
-  set(CUDA_LINK_LIBRARIES_KEYWORD)
+  set(CUDAToolkit_LINK_LIBRARIES_KEYWORD)
   torch_compile_options(torch_cuda)  # see cmake/public/utils.cmake
   target_compile_definitions(torch_cuda PRIVATE USE_CUDA)
 
@@ -973,12 +973,12 @@ elseif(USE_CUDA)
         torch_cuda
     )
     if($ENV{ATEN_STATIC_CUDA})
-      if(CUDA_VERSION_MAJOR LESS_EQUAL 11)
+      if(CUDAToolkit_VERSION_MAJOR LESS_EQUAL 11)
         target_link_libraries(torch_cuda_linalg PRIVATE
             CUDA::cusolver_static
             ${CUDAToolkit_LIBRARY_DIR}/liblapack_static.a     # needed for libcusolver_static
         )
-      elseif(CUDA_VERSION_MAJOR GREATER_EQUAL 12)
+      elseif(CUDAToolkit_VERSION_MAJOR GREATER_EQUAL 12)
         target_link_libraries(torch_cuda_linalg PRIVATE
             CUDA::cusolver_static
             ${CUDAToolkit_LIBRARY_DIR}/libcusolver_lapack_static.a     # needed for libcusolver_static
diff --git a/cmake/Summary.cmake b/cmake/Summary.cmake
index d51c451589c..154f04a89dd 100644
--- a/cmake/Summary.cmake
+++ b/cmake/Summary.cmake
@@ -76,7 +76,7 @@ function(caffe2_print_configuration_summary)
     message(STATUS "    USE_CUSPARSELT      : ${USE_CUSPARSELT}")
     message(STATUS "    USE_CUDSS           : ${USE_CUDSS}")
     message(STATUS "    USE_CUFILE          : ${USE_CUFILE}")
-    message(STATUS "    CUDA version        : ${CUDA_VERSION}")
+    message(STATUS "    CUDA version        : ${CUDAToolkit_VERSION}")
     message(STATUS "    USE_FLASH_ATTENTION : ${USE_FLASH_ATTENTION}")
     message(STATUS "    USE_MEM_EFF_ATTENTION : ${USE_MEM_EFF_ATTENTION}")
     if(${USE_CUDNN})
@@ -88,7 +88,7 @@ function(caffe2_print_configuration_summary)
     if(${USE_CUFILE})
       message(STATUS "    cufile library    : ${CUDA_cuFile_LIBRARY}")
     endif()
-    message(STATUS "    CUDA root directory : ${CUDA_TOOLKIT_ROOT_DIR}")
+    message(STATUS "    CUDA root directory : ${CUDAToolkit_ROOT}")
     message(STATUS "    CUDA library        : ${CUDA_cuda_driver_LIBRARY}")
     message(STATUS "    cudart library      : ${CUDA_cudart_LIBRARY}")
     message(STATUS "    cublas library      : ${CUDA_cublas_LIBRARY}")
@@ -108,12 +108,12 @@ function(caffe2_print_configuration_summary)
       message(STATUS "    cuDSS library       : ${__tmp}")
     endif()
     message(STATUS "    nvrtc               : ${CUDA_nvrtc_LIBRARY}")
-    message(STATUS "    CUDA include path   : ${CUDA_INCLUDE_DIRS}")
-    message(STATUS "    NVCC executable     : ${CUDA_NVCC_EXECUTABLE}")
+    message(STATUS "    CUDA include path   : ${CUDATookit_INCLUDE_DIRS}")
+    message(STATUS "    NVCC executable     : ${CUDATookit_NVCC_EXECUTABLE}")
     message(STATUS "    CUDA compiler       : ${CMAKE_CUDA_COMPILER}")
     message(STATUS "    CUDA flags          : ${CMAKE_CUDA_FLAGS}")
     message(STATUS "    CUDA host compiler  : ${CMAKE_CUDA_HOST_COMPILER}")
-    message(STATUS "    CUDA --device-c     : ${CUDA_SEPARABLE_COMPILATION}")
+    message(STATUS "    CUDA --device-c     : ${CUDATookit_SEPARABLE_COMPILATION}")
     message(STATUS "    USE_TENSORRT        : ${USE_TENSORRT}")
     if(${USE_TENSORRT})
       message(STATUS "      TensorRT runtime library: ${TENSORRT_LIBRARY}")
diff --git a/cmake/TorchConfig.cmake.in b/cmake/TorchConfig.cmake.in
index cba4d929855..da904fc6a18 100644
--- a/cmake/TorchConfig.cmake.in
+++ b/cmake/TorchConfig.cmake.in
@@ -125,7 +125,7 @@ if(@USE_CUDA@)
     find_library(CAFFE2_NVRTC_LIBRARY caffe2_nvrtc PATHS "${TORCH_INSTALL_PREFIX}/lib")
     list(APPEND TORCH_CUDA_LIBRARIES ${CAFFE2_NVRTC_LIBRARY})
   else()
-    set(TORCH_CUDA_LIBRARIES ${CUDA_NVRTC_LIB})
+    set(TORCH_CUDA_LIBRARIES CUDA::nvrtc)
   endif()
   if(TARGET torch::nvtoolsext)
     list(APPEND TORCH_CUDA_LIBRARIES torch::nvtoolsext)
diff --git a/cmake/public/cuda.cmake b/cmake/public/cuda.cmake
index 152fbdbe6dd..13bae9b6227 100644
--- a/cmake/public/cuda.cmake
+++ b/cmake/public/cuda.cmake
@@ -26,8 +26,8 @@ if(NOT MSVC)
 endif()
 
 # Find CUDA.
-find_package(CUDA)
-if(NOT CUDA_FOUND)
+find_package(CUDAToolkit)
+if(NOT CUDAToolkit_FOUND)
   message(WARNING
     "Caffe2: CUDA cannot be found. Depending on whether you are building "
     "Caffe2 or a Caffe2 dependent library, the next warning / error will "
@@ -36,8 +36,6 @@ if(NOT CUDA_FOUND)
   return()
 endif()
 
-# Enable CUDA language support
-set(CUDAToolkit_ROOT "${CUDA_TOOLKIT_ROOT_DIR}")
 # Pass clang as host compiler, which according to the docs
 # Must be done before CUDA language is enabled, see
 # https://cmake.org/cmake/help/v3.15/variable/CMAKE_CUDA_HOST_COMPILER.html
@@ -56,24 +54,18 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
   cmake_policy(SET CMP0074 NEW)
 endif()
 
-find_package(CUDAToolkit REQUIRED)
+find_package(CUDAToolkit REQUIRED COMPONENTS cudart nvrtc REQUIRED)
 
 cmake_policy(POP)
 
-if(NOT CMAKE_CUDA_COMPILER_VERSION VERSION_EQUAL CUDAToolkit_VERSION)
-  message(FATAL_ERROR "Found two conflicting CUDA versions:\n"
-                      "V${CMAKE_CUDA_COMPILER_VERSION} in '${CUDA_INCLUDE_DIRS}' and\n"
-                      "V${CUDAToolkit_VERSION} in '${CUDAToolkit_INCLUDE_DIRS}'")
-endif()
-
-message(STATUS "Caffe2: CUDA detected: " ${CUDA_VERSION})
-message(STATUS "Caffe2: CUDA nvcc is: " ${CUDA_NVCC_EXECUTABLE})
-message(STATUS "Caffe2: CUDA toolkit directory: " ${CUDA_TOOLKIT_ROOT_DIR})
-if(CUDA_VERSION VERSION_LESS 11.0)
+message(STATUS "Caffe2: CUDA detected: " ${CUDAToolkit_VERSION})
+message(STATUS "Caffe2: CUDA nvcc is: " ${CUDAToolkit_NVCC_EXECUTABLE})
+message(STATUS "Caffe2: CUDA toolkit directory: " ${CUDAToolkit_ROOT})
+if(CUDAToolkit_VERSION VERSION_LESS 11.0)
   message(FATAL_ERROR "PyTorch requires CUDA 11.0 or above.")
 endif()
 
-if(CUDA_FOUND)
+if(CUDAToolkit_FOUND)
   # Sometimes, we may mismatch nvcc with the CUDA headers we are
   # compiling with, e.g., if a ccache nvcc is fed to us by CUDA_NVCC_EXECUTABLE
   # but the PATH is not consistent with CUDA_HOME.  It's better safe
@@ -97,8 +89,8 @@ if(CUDA_FOUND)
     )
   if(NOT CMAKE_CROSSCOMPILING)
     try_run(run_result compile_result ${PROJECT_RANDOM_BINARY_DIR} ${file}
-      CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}"
-      LINK_LIBRARIES ${CUDA_LIBRARIES}
+      CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDAToolkit_INCLUDE_DIRS}"
+      LINK_LIBRARIES ${CUDAToolkit_LIBRARIES}
       RUN_OUTPUT_VARIABLE cuda_version_from_header
       COMPILE_OUTPUT_VARIABLE output_var
       )
@@ -106,20 +98,20 @@ if(CUDA_FOUND)
       message(FATAL_ERROR "Caffe2: Couldn't determine version from header: " ${output_var})
     endif()
     message(STATUS "Caffe2: Header version is: " ${cuda_version_from_header})
-    if(NOT cuda_version_from_header STREQUAL ${CUDA_VERSION_STRING})
+    if(NOT cuda_version_from_header STREQUAL ${CUDAToolkit_VERSION_STRING})
       # Force CUDA to be processed for again next time
       # TODO: I'm not sure if this counts as an implementation detail of
       # FindCUDA
-      set(${cuda_version_from_findcuda} ${CUDA_VERSION_STRING})
+      set(${cuda_version_from_findcuda} ${CUDAToolkit_VERSION_STRING})
       unset(CUDA_TOOLKIT_ROOT_DIR_INTERNAL CACHE)
       # Not strictly necessary, but for good luck.
-      unset(CUDA_VERSION CACHE)
+      unset(CUDAToolkit_VERSION CACHE)
       # Error out
       message(FATAL_ERROR "FindCUDA says CUDA version is ${cuda_version_from_findcuda} (usually determined by nvcc), "
         "but the CUDA headers say the version is ${cuda_version_from_header}.  This often occurs "
         "when you set both CUDA_HOME and CUDA_NVCC_EXECUTABLE to "
         "non-standard locations, without also setting PATH to point to the correct nvcc.  "
-        "Perhaps, try re-running this command again with PATH=${CUDA_TOOLKIT_ROOT_DIR}/bin:$PATH.  "
+        "Perhaps, try re-running this command again with PATH=${CUDAToolkit_ROOT}/bin:$PATH.  "
         "See above log messages for more diagnostics, and see https://github.com/pytorch/pytorch/issues/8092 for more details.")
     endif()
   endif()
@@ -128,8 +120,8 @@ endif()
 # ---[ CUDA libraries wrapper
 
 # find lbnvrtc.so
-set(CUDA_NVRTC_LIB "${CUDA_nvrtc_LIBRARY}" CACHE FILEPATH "")
-if(CUDA_NVRTC_LIB AND NOT CUDA_NVRTC_SHORTHASH)
+get_target_property(CUDA_NVRTC_LIB cuda::nvrtc INTERFACE_LINK_LIBRARIES)
+if(NOT CUDA_NVRTC_SHORTHASH)
   find_package(Python COMPONENTS Interpreter)
   execute_process(
     COMMAND Python::Interpreter -c

@danpetry
Copy link
Contributor

looks like you've removed set(CUDAToolkit_ROOT "${CUDA_TOOLKIT_ROOT_DIR}") completely, is that intentional or should it be before the old find_package(CUDA)?

@h-vetinari
Copy link
Member

looks like you've removed set(CUDAToolkit_ROOT "${CUDA_TOOLKIT_ROOT_DIR}") completely,

That should be set by find_package(CUDAToolkit) AFAIU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants