Issues setting up LibTorch on Windows 11

46 Views Asked by At

Hello and thanks in advance!

When following the official LibTorch installation guide, I ran across a four separate errors when building the project. I have not found solutions to the last two errors anywhere in PyTorch forums or stackoverflow.

To be as clear as possible, I'll recall what each of the errors and solutions were. Only the two CMake commands found in the guide result in errors.

Issue 1 (resolved):

I learned from one thread that I had to specify the Torch_DIR to the TorchConfig.cmake and torch-config.cmake files. This effectively replaced the command

cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..

with

cmake -DCMAKE_PREFIX_PATH=C:/Users/evana/Documents/MyPrograms/C++/Chess2/libtorch-win-shared-with-deps-2.2.1+cu121 -DTorch_DIR=C:\Users\evana\Documents\MyPrograms\C++\Chess2\libtorch-win-shared-with-deps-2.2.1+cu121\libtorch\share\cmake\Torch ..

Issue 2 (resolved):

Even after including Torch_DIR in the command, I received the same error found in this post. I could be completely misunderstanding this, but I think that one of CUDA's 12.1 libraries' new header-only format was conflicting with LibTorch or one of its dependencies. The post helped me realize I had to use part of the CUDA 11.8 library.

Issue 3:

Finally, I could enter the first CMake command of the guide without errors:

PS C:\Users\evana\Documents\MyPrograms\C++\Chess2\build> cmake -DCMAKE_PREFIX_PATH=C:/Users/evana/Documents/MyPrograms/C++/Chess2/libtorch-win-shared-with-deps-2.2.1+cu121 -DTorch_DIR=C:\Users\evana\Documents\MyPrograms\C++\Chess2\libtorch-win-shared-with-deps-2.2.1+cu121\libtorch\share\cmake\Torch ..
>>
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.29.30153.0
-- The CXX compiler identification is MSVC 19.29.30153.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/v12.1 (found version "12.1") 
-- The CUDA compiler identification is NVIDIA 12.1.66
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/include (found version "12.1.66") 
-- Caffe2: CUDA detected: 12.1
-- Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/bin/nvcc.exe
-- Caffe2: CUDA toolkit directory: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1
-- Caffe2: Header version is: 12.1
-- C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64/nvrtc.lib shorthash is bac8224f
-- USE_CUDNN is set to 0. Compiling without cuDNN support
-- USE_CUSPARSELT is set to 0. Compiling without cuSPARSELt support
-- Autodetected CUDA architecture(s):  8.6
-- Added CUDA NVCC flags for: -gencode;arch=compute_86,code=sm_86
-- Found Torch: C:/Users/evana/Documents/MyPrograms/C++/Chess2/libtorch-win-shared-with-deps-2.2.1+cu121/libtorch/lib/torch.lib  
-- Configuring done (23.9s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/evana/Documents/MyPrograms/C++/Chess2/build

However, there was a problem with the second CMake command:

PS C:\Users\evana\Documents\MyPrograms\C++\Chess2\build> cmake --build . --config Release                                                                                                                                                    
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  1>Checking Build System
  Building Custom Rule C:/Users/evana/Documents/MyPrograms/C++/Chess2/CMakeLists.txt
  example-app.cpp
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\glog/log_severity.h(57,1): fatal error C1189: #error:  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document
 for detail. [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]

Issue 4:

When I threw in a #define GLOG_NO_ABBREVIATED_SEVERITIES in logging.h to arbitrarily define the variable, I recieved over 100 syntax errors across multiple of LibTorch's dependencies:

PS C:\Users\evana\Documents\MyPrograms\C++\Chess2\build> cmake --build . --config Release                                                                                                                                                    
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

 1>Checking Build System
 Building Custom Rule C:/Users/evana/Documents/MyPrograms/C++/Chess2/CMakeLists.txt
 example-app.cpp
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\c10/core/TensorImpl.h(2065,1): error C2589: '(': illegal token on right side of '::' [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\c10/core/TensorImpl.h(2065): error C2062: type 'unknown-type' unexpected [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\c10/core/TensorImpl.h(2065,1): error C2059: syntax error: ')' [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-app.vcxproj]
... many more syntax errors later ...
C:\Users\evana\Documents\OtherPrograms\vcpkg\installed\x64-windows\include\ATen/core/jit_type_base.h(87,1): fatal error C1003: error count exceeds 100; stopping compilation [C:\Users\evana\Documents\MyPrograms\C++\Chess2\build\example-a 
pp.vcxproj]

Code and other information:

I'm certain I'm overcomplicating things, but I've tried to stay as close as possible to the original guide for installing LibTorch on Windows 11. The code for CMakeLists.txt and example-app.cpp can be seen in the guide.

Here's the code for the first syntax error from issue 4:

TensorImpl.h(2065,1) error C2589: '(': illegal token on right side of '::'

  int64_t safe_compute_numel() const {
    uint64_t n = 1;
    bool overflows = c10::safe_multiplies_u64(sizes(), &n);
    constexpr auto numel_max = std::min( // line 2065
        static_cast<uint64_t>(std::numeric_limits<int64_t>::max()),
        static_cast<uint64_t>(std::numeric_limits<size_t>::max()));

    overflows |= (n > numel_max);
    TORCH_CHECK(!overflows, "numel: integer multiplication overflow");
    return static_cast<int64_t>(n);
  }

As of March 17, 2024, I am using the most recent GPU, CUDA 12.1, Windows, C++ API combination: libtorch-win-shared-with-deps-2.2.1+cu121.zip. I greatly appreciate any help with issues 3 and 4! Apologies for the long post and can provide any more information as necessary.

0

There are 0 best solutions below