Can't build libtorch following offical tutorial

username: Wesley_Neill
cooked: <p>I am attempting to follow this tutorial: <a href="https://pytorch.org/cppdocs/installing.html" class="inline-onebox" rel="noopener nofollow ugc">Installing C++ Distributions of PyTorch — PyTorch main documentation</a></p>
<p>I have followed it exactly besides changing the name of my project, and of course filling out the actual location of libtorch in place of the dummy location.</p>
<p>However, the prescribed steps fail.</p>
<pre><code class="lang-auto">$ cmake -DCMAKE_PREFIX_PATH=/c/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch ..
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.29.30148.0
-- The CXX compiler identification is MSVC 19.29.30148.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6 (found version "11.6") 
CMake Warning (dev) at C:/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/public/cuda.cmake:44 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  C:/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  C:/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:4 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeDetermineCompilerId.cmake:501 (message):
  No CUDA toolset found.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test)
  C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeDetermineCUDACompiler.cmake:307 (CMAKE_DETERMINE_COMPILER_ID)
  C:/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/public/cuda.cmake:47 (enable_language)
  C:/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  C:/Users/wesle/source/libtorch-win-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!
</code></pre>
<p>Note that just before the warnings about using quotations, I am notified that CUDA was found.</p>
<h2>
<a name="what-i-tried-1" class="anchor" href="#what-i-tried-1"></a>What I tried</h2>
<p>Searching around I tried a couple of things that did not work:</p>
<ul>
<li>
<p>Set the CMAKE_CUDA_COMPILER env variable to the location of nvcc. I tried it with and without .exe on the end. Neither changed the outcome.</p>
</li>
<li>
<p>set the same variable in CMakeLists.txt</p>
</li>
<li>
<p>Finally, the only other thing I find odd is that one line of the output you see mention of two different versions of MSVC:</p>
</li>
</ul>
<pre><code class="lang-auto">-- The CXX compiler identification is MSVC 19.29.30148.0
</code></pre>
<p>And on another, you see</p>
<pre><code class="lang-auto">-- Check for working CXX compiler: C:/.../MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
</code></pre>
<p>I know nothing about cmake or compiler commands, so have no idea how to troubleshoot this. Any help is appreciated.</p>

username: Wesley_Neill
cooked: <p>I found this thread solved my problem:</p>
<aside class="onebox githubissue" data-onebox-src="https://github.com/NVlabs/tiny-cuda-nn/issues/164">
  <header class="source">

      <a href="https://github.com/NVlabs/tiny-cuda-nn/issues/164" target="_blank" rel="noopener nofollow ugc">github.com/NVlabs/tiny-cuda-nn</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewbox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/NVlabs/tiny-cuda-nn/issues/164" target="_blank" rel="noopener nofollow ugc">Can't build on Windows - No CUDA toolset found error</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2022-10-07" data-time="13:20:44" data-timezone="UTC">01:20PM - 07 Oct 22 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/dokluch" target="_blank" rel="noopener nofollow ugc">
          <img alt="dokluch" src="https://avatars.githubusercontent.com/u/135181?v=4" class="onebox-avatar-inline" width="20" height="20">
          dokluch
        </a>
      </div>
    </div>

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">I can't install tiny-cuda-nn neither with pip, nor building it with Cmake.
Howe<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">ver, Cmake produces at least a readable error:

```
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The CXX compiler identification is MSVC 19.29.30139.0
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCompilerId.cmake:491 (message):
  No CUDA toolset found.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCompilerId.cmake:6 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCompilerId.cmake:48 (__determine_compiler_id_test)
  C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCUDACompiler.cmake:307 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:25 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Code/tiny-cuda-nn/build/CMakeFiles/CMakeOutput.log".

C:\Code\tiny-cuda-nn&gt;cmake . -B build
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCompilerId.cmake:491 (message):
  No CUDA toolset found.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCompilerId.cmake:6 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCompilerId.cmake:48 (__determine_compiler_id_test)
  C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeDetermineCUDACompiler.cmake:307 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:25 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Code/tiny-cuda-nn/build/CMakeFiles/CMakeOutput.log".
```

I have CUDA 11.8 installed, CUDA_PATH is set properly.
Microsoft Visual Studio 2019, Community Edition
Nvidia A6000</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>There are 4 files located at <code>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\extras\visual_studio_integration\MSBuildExtensions</code></p>
<p>Copy and paste those files to either:</p>
<ul>
<li>If you are just using build tools, but don’t have the Visual Studio IDE installed: <code>C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\BuildCustomizations</code>
</li>
<li>If you are using Visual Studio IDE: <code>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\BuildCustomizations</code>
</li>
</ul>
<p>Note that the year and edition of the IDE might be different for you.</p>
<p>This requirement should probably be added to the tutorial. But I sometimes think the devs and tut writers don’t care about providing good directions for those of us using Windows. I could be wrong but I think we are an afterthought.</p>