Created
May 24, 2023 13:55
-
-
Save firejox/138dfc70085334ad5e7b0c16573d5a79 to your computer and use it in GitHub Desktop.
LibTorch integrated with CMake on Windows Subsystem Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.21) | |
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) | |
set(CMAKE_CUDA_ARCHITECTURES "75") | |
endif() | |
set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc") | |
project(example-app) | |
set(CMAKE_CXX_STANDARD 14) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
enable_language(CUDA) | |
find_package(PythonInterp REQUIRED) | |
set(CAFFE2_USE_CUDNN ON) | |
include(FetchContent) | |
FetchContent_Declare( | |
torch | |
URL https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcu117.zip | |
) | |
FetchContent_MakeAvailable(torch) | |
find_package(Torch REQUIRED PATHS "${torch_SOURCE_DIR}") | |
add_library(torch-lib INTERFACE) | |
target_link_libraries(torch-lib INTERFACE "${TORCH_LIBRARIES}") | |
target_include_directories(torch-lib INTERFACE "${TORCH_INCLUDE_DIRS}") | |
target_compile_options(torch-lib INTERFACE "${TORCH_CXX_FLAGS}") | |
add_executable(example-app example-app.cpp) | |
target_link_libraries(example-app torch-lib) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment