forked from pytorch/TensorRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
157 lines (130 loc) · 4.23 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
set(lib_name "torch_tensorrt")
add_library(${lib_name} OBJECT)
set(CXX_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/src/compile_spec.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/logging.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ptq.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/torch_tensorrt.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/types.cpp"
)
set(HEADER_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/include/torch_tensorrt/logging.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/torch_tensorrt/macros.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/torch_tensorrt/ptq.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/torch_tensorrt/torch_tensorrt.h"
)
target_sources(${lib_name}
PRIVATE
${CXX_SRCS}
$<TARGET_OBJECTS:core>
)
target_link_libraries(${lib_name}
PUBLIC
"${TORCH_LIBRARIES}"
TensorRT::nvinfer
core
)
target_compile_definitions(${lib_name} PUBLIC "USE_CMAKE_GENERATED_EXPORT_HEADER")
include("GenerateExportHeader")
generate_export_header(${lib_name}
EXPORT_MACRO_NAME TORCHTRT_API
NO_EXPORT_MACRO_NAME TORCHTRT_HIDDEN
)
target_include_directories(${lib_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" # _export.h
PRIVATE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_export.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
########################
# API library torchtrt #
########################
set(CMAKE_INSTALL_RPATH "$ORIGIN")
set(torchtrt_lib_name "torchtrt")
add_library(${torchtrt_lib_name} SHARED)
if(NOT MSVC)
set_target_properties(
${torchtrt_lib_name}
PROPERTIES INSTALL_RPATH_USE_LINK_PATH FALSE #
LINK_FLAGS "-Wl,--disable-new-dtags")
endif()
target_sources(${torchtrt_lib_name}
PRIVATE
$<TARGET_OBJECTS:torch_tensorrt>
)
target_link_libraries(${torchtrt_lib_name}
PUBLIC
TensorRT::TensorRT
"${TORCH_LIBRARIES}"
PRIVATE
torch_tensorrt
core
)
target_include_directories(${torchtrt_lib_name}
PUBLIC
# enable include from core from the tests
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
# API headers
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" # _export.h
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
install(FILES ${HEADER_FILES} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/torch_tensorrt/")
################################
# API library torchtrt_runtime #
################################
set(runtime_lib_name "torchtrt_runtime")
add_library(${runtime_lib_name} SHARED)
if(NOT MSVC)
set_target_properties(
${runtime_lib_name}
PROPERTIES INSTALL_RPATH_USE_LINK_PATH FALSE #
LINK_FLAGS "-Wl,--disable-new-dtags")
endif()
target_sources(${runtime_lib_name}
PRIVATE
$<TARGET_OBJECTS:core_runtime>
$<TARGET_OBJECTS:core_plugins>
)
target_link_libraries(${runtime_lib_name}
PUBLIC
TensorRT::TensorRT
"${TORCH_LIBRARIES}"
PRIVATE
core_runtime
core_plugins
)
################################
# API library torchtrt_plugins #
################################
set(plugins_lib_name "torchtrt_plugins")
add_library(${plugins_lib_name} SHARED)
if(NOT MSVC)
set_target_properties(
${plugins_lib_name}
PROPERTIES INSTALL_RPATH_USE_LINK_PATH FALSE #
LINK_FLAGS "-Wl,--disable-new-dtags")
endif()
target_sources(${plugins_lib_name}
PRIVATE
$<TARGET_OBJECTS:core_plugins>
)
target_link_libraries(${plugins_lib_name}
PUBLIC
TensorRT::TensorRT
PRIVATE
core_plugins
)
install(
TARGETS ${torchtrt_lib_name} ${runtime_lib_name} ${plugins_lib_name} torch_tensorrt core core_runtime core_plugins core_util core_util_logging core_lowering core_partitioning core_ir core_conversion
EXPORT ${torchtrt_lib_name}Targets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(
EXPORT ${torchtrt_lib_name}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/torchtrt
COMPONENT ${torchtrt_lib_name}Targets)
add_subdirectory(bin)