-
Notifications
You must be signed in to change notification settings - Fork 1
/
libs.cmake
205 lines (189 loc) · 8.99 KB
/
libs.cmake
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#
# Enable/disable building different libraries/executables.
#
option(RLS_DEBUG_ENABLE_GPU_UTIL_EXPERIMENT
"Build gpu_util_experiment experiment for investigating GPU utilization varies with multiple processes/threadsfor building tests"
OFF)
option(RLS_DEBUG_ENABLE_ACHIEVED_OCCUPANCY_EXPERIMENT
"Build achieved_occupancy_range_profiling* experiment for trying out new CUDA Profiling API for collecting GPU hardware metrics"
OFF)
option(RLS_DEBUG_ENABLE_DEVICE_QUERY
"Build deviceQuery CUDA sample program"
OFF)
option(RLS_DEBUG_ENABLE_TENSORRT_EXPERIMENT
"Build trtexec7 experiment for trying out CUDA TensorRT to measure throughput/latency of using TensorRT with different numbers of threads"
OFF)
option(RLS_DEBUG_ENABLE_LEGACY_DQN_CPP
"[Deprecated] build legacy DQN implementation in C++ (was exploring how it might compare to pure-Python implementation"
OFF)
option(RLS_DEBUG_ENABLE_CUPTI_API_EXPERIMENT
"Build CUDA CUPTI sample program for using CUPTI API to collect GPU kernel execution times"
OFF)
# Recursively gather source files in current directory.
macro(GlobProtobufSources VAR)
# message("GlobProtobufSources: VAR = ${VAR}")
file(GLOB_RECURSE ${VAR}
*.proto
)
# message("GlobProtobufSources: ${VAR} = ${${VAR}}")
# message("${VAR} = ${${VAR}}")
endmacro()
# Recursively gather source files in current directory.
macro(GlobSources VAR)
# message("GlobSources: VAR = ${VAR}")
file(GLOB_RECURSE ${VAR}
*.cu
*.cpp
*.cc
*.c)
# message("${VAR} = ${${VAR}}")
endmacro()
macro(_GatherTargetSources TARGET_VAR SOURCE_FILES_VAR PROTO_SRCS_VAR PROTO_HDRS_VAR)
GlobSources(${SOURCE_FILES_VAR})
GlobProtobufSources(PROTO_BUF_SOURCE_FILES)
get_filename_component(DIRNAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# message("DIRNAME = ${DIRNAME}")
set(${TARGET_VAR} ${DIRNAME})
# message("TARGET_VAR (${TARGET_VAR}) = ${${TARGET_VAR}}")
set(${PROTO_SRCS_VAR})
set(${PROTO_HDRS_VAR})
list(LENGTH PROTO_BUF_SOURCE_FILES PROTO_BUF_SOURCE_FILES_LENGTH)
if (PROTO_BUF_SOURCE_FILES_LENGTH GREATER 0)
# message("> PROTOBUF: ${${TARGET_VAR}}: PROTO_BUF_SOURCE_FILES_LENGTH = ${PROTO_BUF_SOURCE_FILES_LENGTH}")
# message("> PROTOBUF: ${${TARGET_VAR}}: protobuf_generate_cpp")
# message(" ${PROTO_SRCS_VAR}")
# message(" ${PROTO_HDRS_VAR}")
# message(" ${PROTO_BUF_SOURCE_FILES}")
protobuf_generate_cpp(${PROTO_SRCS_VAR} ${PROTO_HDRS_VAR}
${PROTO_BUF_SOURCE_FILES})
set(PY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/python3/dist-packages/${${TARGET_VAR}})
file(MAKE_DIRECTORY ${PY_INSTALL_DIR})
file(WRITE ${PY_INSTALL_DIR}/__init__.py "# DON'T MODIFY! AUTO-GENERATED BY CMAKE\n")
protobuf_generate_python(PROTO_PY_SRCS ${PROTO_BUF_SOURCE_FILES}
PROTOC_OUT_DIR ${PY_INSTALL_DIR})
# message(" PROTO_PY_SRCS: ${PROTO_PY_SRCS}")
# NOTE: This doesn't work... says file doesn't exist.
# install(TARGETS ${PROTO_PY_SRCS}
# CONFIGURATIONS Debug Release
# RUNTIME DESTINATION lib/python3/dist-packages/${TARGET_VAR})
# include_directories(
# ${CMAKE_CURRENT_BINARY_DIR}/src/libs
# )
# message("> PROTOBUF: ${${TARGET_VAR}}: ${PROTO_SRCS_VAR} = ${${PROTO_SRCS_VAR}}")
# message("> PROTOBUF: ${${TARGET_VAR}}: ${PROTO_HDRS_VAR} = ${${PROTO_HDRS_VAR}}")
# Glob for source files again in case pb.h / pb.cc files have been generated.
# GlobSources(${SOURCE_FILES_VAR})
list(APPEND ${SOURCE_FILES_VAR} ${${PROTO_SRCS_VAR}} ${${PROTO_HDRS_VAR}} ${PROTO_PY_SRCS})
# message("> PROTOBUF: ${${TARGET_VAR}}: append sources: ${${PROTO_SRCS_VAR}} ${${PROTO_HDRS_VAR}}")
endif()
RmGTestSources(${SOURCE_FILES_VAR})
endmacro()
function(_AddTargetDependencies TARGET)
# message("TARGET = ${TARGET}")
AddCUDA(${TARGET})
add_backward(${TARGET})
AddLoggingDeps(${TARGET})
AddGFlagsDeps(${TARGET})
# find_package(MySpdlog REQUIRED)
# target_link_libraries(${TARGET} PRIVATE ${MySpdlog_LIBRARIES})
# target_include_directories(${TARGET} PRIVATE ${MySpdlog_INCLUDE_DIRS})
# # message("> MySpdlog_LIBRARIES = ${MySpdlog_LIBRARIES}")
# # message("> MySpdlog_INCLUDE_DIRS = ${MySpdlog_INCLUDE_DIRS}")
#
# target_link_libraries(${TARGET} PRIVATE nlohmann_json::nlohmann_json)
#
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# get_target_property(CUR_FLAG ${TARGET} COMPILE_DEFINITIONS)
# set_target_properties(${TARGET} PROPERTIES COMPILE_DEFINITIONS "${CUR_FLAG};SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG")
# get_target_property(CUR_FLAG ${TARGET} COMPILE_DEFINITIONS)
# else()
# get_target_property(CUR_FLAG ${TARGET} COMPILE_DEFINITIONS)
# set_target_properties(${TARGET} PROPERTIES COMPILE_DEFINITIONS "${CUR_FLAG};SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_OFF")
# get_target_property(CUR_FLAG ${TARGET} COMPILE_DEFINITIONS)
# endif()
endfunction()
function(_AddProtoDeps TARGET PROTO_SRCS PROTO_HDRS)
# message("> _AddProtoDeps : PROTO_SRCS = ${PROTO_SRCS}")
AddProtobufDeps(${TARGET})
# Magical incantation to FORCE protobuf sources to be generated BEFORE people that depend
# on range_sampling library (librlscope.so) are built.
# OTHERWISE, first cmake build fails every time.
#
# Long story short: protobuf uses add_custom_command to output generated files, but cmake sucks
# at letting you depend on those files directly, so we need to add an extra level of indirection
# (add_custom_target) to depend on the generated proto srcs.
add_custom_target(${TARGET}_cpp_proto_srcs
DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
add_dependencies(${TARGET} ${TARGET}_cpp_proto_srcs)
endfunction()
# Build CUDA library from recursively discovered source files.
macro(MakeCudaLibraryFromDir LIBNAME_VAR SOURCE_FILES)
_GatherTargetSources(${LIBNAME_VAR} ${SOURCE_FILES} PROTO_SRCS PROTO_HDRS)
# message("> PROTOBUF: ${${LIBNAME_VAR}}: SOURCE_FILES (${SOURCE_FILES}) = ${${SOURCE_FILES}}")
# message("> PROTOBUF: ${${LIBNAME_VAR}}: LIBNAME_VAR (${LIBNAME_VAR}) = ${${LIBNAME_VAR}}")
cuda_add_library(${${LIBNAME_VAR}}
${${SOURCE_FILES}}
STATIC)
_AddTargetDependencies(${${LIBNAME_VAR}})
# Third party: protobuf
if (PROTO_SRCS OR PROTO_HDRS)
message("> PROTO_SRCS = ${PROTO_SRCS}")
_AddProtoDeps(${${LIBNAME_VAR}} ${PROTO_SRCS} ${PROTO_HDRS})
# AddProtobufDeps(${${LIBNAME_VAR}})
# # Magical incantation to FORCE protobuf sources to be generated BEFORE people that depend
# # on range_sampling library (librlscope.so) are built.
# # OTHERWISE, first cmake build fails every time.
# #
# # Long story short: protobuf uses add_custom_command to output generated files, but cmake sucks
# # at letting you depend on those files directly, so we need to add an extra level of indirection
# # (add_custom_target) to depend on the generated proto srcs.
# add_custom_target(${${LIBNAME_VAR}}_cpp_proto_srcs
# DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
# add_dependencies(${${LIBNAME_VAR}} ${${LIBNAME_VAR}}_cpp_proto_srcs)
endif()
# install(
# TARGETS ${${LIBNAME_VAR}}
# DESTINATION lib
# CONFIGURATIONS Debug)
# install(
# TARGETS ${${LIBNAME_VAR}}
# DESTINATION lib
# CONFIGURATIONS Release)
endmacro()
# Buld CUDA executable from recursively discovered source files.
macro(MakeCudaExecutableFromDir EXEC_NAME_VAR SOURCE_FILES)
set(PROTO_SRCS)
set(PROTO_HDRS)
_GatherTargetSources(${EXEC_NAME_VAR} ${SOURCE_FILES} PROTO_SRCS PROTO_HDRS)
# message("SOURCE_FILES = ${SOURCE_FILES}")
# message("EXEC_NAME_VAR (${EXEC_NAME_VAR}) = ${${EXEC_NAME_VAR}}")
cuda_add_executable(${${EXEC_NAME_VAR}}
${${SOURCE_FILES}})
_AddTargetDependencies(${${EXEC_NAME_VAR}})
# Third party: protobuf
if (PROTO_SRCS OR PROTO_HDRS)
_AddProtoDeps(${${EXEC_NAME_VAR}} PROTO_SRCS PROTO_HDRS)
endif()
# if (PROTO_SRCS OR PROTO_HDRS)
# AddProtobufDeps(${${LIBNAME_VAR}})
# endif()
message("> INSTALL: ${${EXEC_NAME_VAR}}")
install(
TARGETS ${${EXEC_NAME_VAR}}
DESTINATION bin
CONFIGURATIONS Debug)
install(
TARGETS ${${EXEC_NAME_VAR}}
DESTINATION bin
CONFIGURATIONS Release)
endmacro()
#find_package(CUDAProfilingAPI REQUIRED)
#include_directories(${CUDAProfilingAPI_INCLUDE_DIR})
# Gets included by libraries that require it (e.g., profilerhost_util)
#link_libraries(${CUDAProfilingAPI_LIBRARY})
# Include directories containing generated *.pb.h protobuf header files.
#message(" >> PROTOBUF: include_directories: ${CMAKE_CURRENT_BINARY_DIR}/src/libs")
include_directories(
${CMAKE_CURRENT_BINARY_DIR}/src/libs
)
add_subdirectory(./src/libs)