Hi, I am trying this tutorial but having a difficulties building the C++ file. Installing C++ Distributions of PyTorch β PyTorch main documentation
- I downloaded LibTorch from PyTorch website.
- I wrote a simple C++ file (CNN_Cpp.cpp)
#include <torch/torch.h>
#include <iostream>
int main() {
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
}
- Wrote a CMakeLists.txt and saved in the same directory where CNN_Cpp.cpp is saved.
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET example-app
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:example-app>)
endif (MSVC)
- Now, my directory looks like below
CNN_Cpp/
CMakeLists.txt
CNN_Cpp.cpp
build/
CMakeLists.txt
- Opened Windows cmd and went to the build/ directory above and executed a command below.
C:\Users\eugene.roh\Desktop\CNN_Cpp\build>cmake -DCMAKE_PREFIX_PATH=βC:\Users\eugene.roh\Downloads\libtorch-win-shared-with-deps-latest\libtorchβ
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.β Building for: Visual Studio 16 2019
β Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
β The C compiler identification is MSVC 19.29.30136.0
β The CXX compiler identification is MSVC 19.29.30136.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/Community/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/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
β Detecting CXX compile features
β Detecting CXX compile features - done
β Looking for pthread.h
β Looking for pthread.h - not found
β Found Threads: TRUE
β Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5 (found version β11.5β)
β Caffe2: CUDA detected: 11.5
β Caffe2: CUDA nvcc is: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5/bin/nvcc.exe
β Caffe2: CUDA toolkit directory: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5
β Caffe2: Header version is: 11.5
β Could NOT find CUDNN (missing: CUDNN_LIBRARY_PATH CUDNN_INCLUDE_PATH)
CMake Warning at C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/public/cuda.cmake:111 (message):
Caffe2: Cannot find cuDNN library. Turning the option off
Call Stack (most recent call first):
C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:4 (find_package)Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
CMake Warning at C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/public/cuda.cmake:205 (message):
Failed to compute shorthash for libnvrtc.so
Call Stack (most recent call first):
C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:4 (find_package)β Autodetected CUDA architecture(s): 7.5
β Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
CMake Warning (dev) at C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/public/cuda.cmake:467 (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/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/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:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:96 (message):
Your installed Caffe2 version uses cuDNN but I cannot find the cuDNN
libraries. Please set the proper cuDNN prefixes and / or install cuDNN.
Call Stack (most recent call first):
C:/Users/eugene.roh/Downloads/libtorch-win-shared-with-deps-latest/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:4 (find_package)β Configuring incomplete, errors occurred!
See also βC:/Users/eugene.roh/Desktop/CNN_Cpp/build/CMakeFiles/CMakeOutput.logβ.
See also βC:/Users/eugene.roh/Desktop/CNN_Cpp/build/CMakeFiles/CMakeError.logβ.
Question.
It seems like I need cuDNN. I downloaded a .zip file from NVidia website. Now what should I do to make it work? Or, is there any way that I can do cuDNN with anaconda?
cudnn-10.2-windows10-x64-v8.2.4.15.zip/
cuda/
bin/
include/
lib/
NVIDIA_SLA_cuDNN_Support/