Compiling libtorch example: Visual Studio/CUDA integration problem

meganset: <p>Tricky to get CUDA/CUDNN working<br>
I found I had to include more on the command line for 64-bit, but was unable to get past some Visual Studio/CUDA integration.</p>
<p>e.g.<br>
cmake -DCMAKE_PREFIX_PATH=c:\libtorch<br>
-DCUDA_TOOLKIT_ROOT_DIR=“c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0”<br>
-DCMAKE_GENERATOR_PLATFORM=x64<br>
-DCMAKE_BUILD_TYPE=Release …</p>
<p>– Caffe2: CUDA detected: 9.0<br>
– Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe<br>
– Caffe2: CUDA toolkit directory: c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0<br>
CMake Error at C:/libtorch/share/cmake/Caffe2/public/cuda.cmake:53 (message):<br>
Caffe2: Couldn’t determine version from header: Change Dir:<br>
C:/Users/t/ktorch/build/CMakeFiles/CMakeTmp</p>
<p>Run Build Command(s):C:/Program Files (x86)/Microsoft Visual<br>
Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe cmTC_853c8.vcxproj<br>
/p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=15.0 /v:m</p>
<p>Microsoft ® Build Engine version 15.9.21+g9802d43bc3 for .NET Framework</p>
<p>Copyright © Microsoft Corporation.  All rights reserved.<br>
Microsoft ® C/C++ Optimizing Compiler Version 19.16.27027.1 for x64<br>
Copyright © Microsoft Corporation.  All rights reserved.</p>
<pre><code>detect_cuda_version.cc
cl /c /I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include" /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_853c8.dir\Debug\\" /Fd"cmTC_853c8.dir\Debug\vc141.pdb" /Gd /TP /errorReport:queue C:\Users\t\ktorch\build\detect_cuda_version.cc
</code></pre>
<p>cmTC_853c8.dir\Debug\detect_cuda_version.obj : fatal error LNK1112: module<br>
machine type ‘x64’ conflicts with target machine type ‘x86’<br>
[C:\Users\t\ktorch\build\CMakeFiles\CMakeTmp\cmTC_853c8.vcxproj]</p>
<p>Call Stack (most recent call first):<br>
C:/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)<br>
C:/libtorch/share/cmake/Torch/TorchConfig.cmake:39 (find_package)<br>
CMakeLists.txt:4 (find_package)</p>
<p>– Configuring incomplete, errors occurred!<br>
See also “C:/Users/t/ktorch/build/CMakeFiles/CMakeOutput.log”.<br>
See also “C:/Users/t/ktorch/build/CMakeFiles/CMakeError.log”.</p>

peterjc123: <p>Please pass CMake generator directly, that is <code>-GVisual Studio 15 2017 Win64</code>.</p>

meganset: <p>Thanks<br>
passing -G"Visual Studio 15 2017 Win64"<br>
gave me problems, but<br>
-G"Visual Studio 15 2017"<br>
helped things go a little further, until a problem with NVTX not installed.</p>
<p>I think my Visual Studio setup is likely wrong,<br>
but not sure what the best setup is.</p>
<p>I don’t need Visual Studio or any IDE, is it possible to make without it?</p>

peterjc123: <p><aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/pytorch/pytorch#install-pytorch" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars2.githubusercontent.com/u/21003710?s=400&amp;amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/pytorch/pytorch#install-pytorch" target="_blank" rel="nofollow noopener">pytorch/pytorch</a></h3>

<p>Tensors and Dynamic neural networks in Python  with strong GPU acceleration - pytorch/pytorch</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
<aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/peterjc123/pytorch-scripts/issues/23" target="_blank" rel="nofollow noopener">github.com/peterjc123/pytorch-scripts</a>
  </header>
  <article class="onebox-body">
    <a href="https://github.com/Baddest-Juju" rel="nofollow noopener">
<img src="https://avatars1.githubusercontent.com/u/33403660?v=2&amp;s=96" class="thumbnail onebox-avatar" width="60" height="60">
</a>

<h4><a href="https://github.com/peterjc123/pytorch-scripts/issues/23" target="_blank" rel="nofollow noopener">Issue: Fixes</a></h4>

<div class="date" style="margin-top:10px;">
	<div class="user" style="margin-top:10px;">
	opened by <a href="https://github.com/Baddest-Juju" target="_blank" rel="nofollow noopener">Baddest-Juju</a>
	on <a href="https://github.com/peterjc123/pytorch-scripts/issues/23" target="_blank" rel="nofollow noopener">2018-03-16</a>
	</div>
	<div class="user">
	closed by <a href="https://github.com/peterjc123" target="_blank" rel="nofollow noopener">peterjc123</a>
	on <a href="https://github.com/peterjc123/pytorch-scripts/issues/23" target="_blank" rel="nofollow noopener">2018-03-16</a>
	</div>
</div>

<pre class="content" style="white-space: pre-wrap;">Script changes needed in this repo
PATH variable of cuda bat files not correctly stated, leading to errors when it hits parantheses
set...</pre>

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

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>

joaovbs96: <p>Hi! I just had this issue myself, and I’m aware this is an old topic, but adding the following flags solved it for me:</p>
<p>-G “Visual Studio 15 2017” -A x64</p>
<p>so the full line would be:</p>
<p>cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch … -G “Visual Studio 15 2017” -A x64</p>
<p><a href="https://cmake.org/cmake/help/v3.15/generator/Visual%20Studio%2015%202017.html" rel="nofollow noopener">source, from the CMake documentations</a></p>