forked from prabhuomkar/pytorch-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
123 lines (97 loc) · 3.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(pytorch-cpp VERSION 1.0.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(DOWNLOAD_DATASETS "Automatically download required datasets at build-time." ON)
option(CREATE_SCRIPTMODULES "Automatically create all required scriptmodule files at build-time (requires python3)." OFF)
set(PYTORCH_VERSION "1.9.0")
find_package(Torch ${PYTORCH_VERSION} EXACT QUIET PATHS "${CMAKE_SOURCE_DIR}/libtorch")
if(NOT Torch_FOUND)
unset(Torch_FOUND)
include(fetch_libtorch)
endif()
if(CREATE_SCRIPTMODULES)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
endif()
set(EXECUTABLE_NAME pytorch-cpp)
add_executable(${EXECUTABLE_NAME})
target_sources(${EXECUTABLE_NAME} PRIVATE main.cpp)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
)
target_link_libraries(${EXECUTABLE_NAME} ${TORCH_LIBRARIES})
# External dependencies
add_subdirectory("extern")
# Utils
add_subdirectory("utils/image_io")
# Dataset fetching
if(DOWNLOAD_DATASETS)
set(DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data CACHE PATH "Dataset download directory")
file(MAKE_DIRECTORY ${DATA_DIR})
add_custom_target(mnist COMMAND ${CMAKE_COMMAND}
-D DATA_DIR=${DATA_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_mnist.cmake)
add_custom_target(cifar10 COMMAND ${CMAKE_COMMAND}
-D DATA_DIR=${DATA_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_cifar10.cmake)
add_custom_target(penntreebank COMMAND ${CMAKE_COMMAND}
-D DATA_DIR=${DATA_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_penntreebank.cmake)
add_custom_target(neural_style_transfer_images COMMAND ${CMAKE_COMMAND}
-D DATA_DIR=${DATA_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_neural_style_transfer_images.cmake)
add_custom_target(flickr8k COMMAND ${CMAKE_COMMAND}
-D DATA_DIR=${DATA_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fetch_flickr8k.cmake)
endif()
# Add tutorial sub-projects:
# Basics
add_subdirectory("tutorials/basics/feedforward_neural_network")
add_subdirectory("tutorials/basics/linear_regression")
add_subdirectory("tutorials/basics/logistic_regression")
add_subdirectory("tutorials/basics/pytorch_basics")
add_custom_target(basics)
add_dependencies(basics
feedforward-neural-network
linear-regression
logistic-regression
pytorch-basics)
# Intermediate
add_subdirectory("tutorials/intermediate/convolutional_neural_network")
add_subdirectory("tutorials/intermediate/deep_residual_network")
add_subdirectory("tutorials/intermediate/recurrent_neural_network")
add_subdirectory("tutorials/intermediate/bidirectional_recurrent_neural_network")
add_subdirectory("tutorials/intermediate/language_model")
add_custom_target(intermediate)
add_dependencies(intermediate
convolutional-neural-network
deep-residual-network
recurrent-neural-network
bidirectional-recurrent-neural-network
language-model)
# Advanced
add_subdirectory("tutorials/advanced/generative_adversarial_network")
add_subdirectory("tutorials/advanced/variational_autoencoder")
add_subdirectory("tutorials/advanced/neural_style_transfer")
add_subdirectory("tutorials/advanced/image_captioning")
add_custom_target(advanced)
add_dependencies(advanced
generative-adversarial-network
variational-autoencoder
neural-style-transfer
image-captioning)
# Popular
add_subdirectory("tutorials/popular/blitz/tensors")
add_subdirectory("tutorials/popular/blitz/autograd")
add_subdirectory("tutorials/popular/blitz/neural_networks")
add_subdirectory("tutorials/popular/blitz/training_a_classifier")
add_custom_target(popular)
add_dependencies(popular
tensors
autograd
neural-networks
training-a-classifier)
if(MSVC)
include(copy_torch_dlls)
copy_torch_dlls(${EXECUTABLE_NAME})
endif()