Compiling libtorch example: Visual Studio/CUDA integration problem

Tricky to get CUDA/CUDNN working
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.

e.g.
cmake -DCMAKE_PREFIX_PATH=c:\libtorch
-DCUDA_TOOLKIT_ROOT_DIR=“c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0”
-DCMAKE_GENERATOR_PLATFORM=x64
-DCMAKE_BUILD_TYPE=Release …

– Caffe2: CUDA detected: 9.0
– Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe
– Caffe2: CUDA toolkit directory: c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0
CMake Error at C:/libtorch/share/cmake/Caffe2/public/cuda.cmake:53 (message):
Caffe2: Couldn’t determine version from header: Change Dir:
C:/Users/t/ktorch/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual
Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe cmTC_853c8.vcxproj
/p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=15.0 /v:m

Microsoft ® Build Engine version 15.9.21+g9802d43bc3 for .NET Framework

Copyright © Microsoft Corporation. All rights reserved.
Microsoft ® C/C++ Optimizing Compiler Version 19.16.27027.1 for x64
Copyright © Microsoft Corporation. All rights reserved.

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

cmTC_853c8.dir\Debug\detect_cuda_version.obj : fatal error LNK1112: module
machine type ‘x64’ conflicts with target machine type ‘x86’
[C:\Users\t\ktorch\build\CMakeFiles\CMakeTmp\cmTC_853c8.vcxproj]

Call Stack (most recent call first):
C:/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
C:/libtorch/share/cmake/Torch/TorchConfig.cmake:39 (find_package)
CMakeLists.txt:4 (find_package)

– Configuring incomplete, errors occurred!
See also “C:/Users/t/ktorch/build/CMakeFiles/CMakeOutput.log”.
See also “C:/Users/t/ktorch/build/CMakeFiles/CMakeError.log”.

Please pass CMake generator directly, that is -GVisual Studio 15 2017 Win64.

Thanks
passing -G"Visual Studio 15 2017 Win64"
gave me problems, but
-G"Visual Studio 15 2017"
helped things go a little further, until a problem with NVTX not installed.

I think my Visual Studio setup is likely wrong,
but not sure what the best setup is.

I don’t need Visual Studio or any IDE, is it possible to make without it?


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:

-G “Visual Studio 15 2017” -A x64

so the full line would be:

cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch … -G “Visual Studio 15 2017” -A x64

source, from the CMake documentations