-
Notifications
You must be signed in to change notification settings - Fork 39
/
CMakeLists.txt
322 lines (277 loc) · 11.9 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(MIRAGE LANGUAGES C CXX CUDA)
message(STATUS "CMake Version: ${CMAKE_VERSION}")
if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
include (${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
endif()
endif()
#include directories
include_directories(${CMAKE_INCLUDE_PATH})
include_directories(${CMAKE_BINARY_DIR}) # to include protobuf headeer files
include_directories("include")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake)
#add_subdirectory(deps/cutlass)
set(CMAKE_CUDA_ARCHITECTURES "70;75;80;86;89;90")
#set(CUTLASS_NVCC_ARCHS "80;86")
file(GLOB_RECURSE MIRAGE_SRCS
src/*.cc
)
file(GLOB_RECURSE MIRAGE_CUDA_SRCS
src/*.cu
)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++17" SUPPORT_CXX17)
#set CUDA version
include(deps/cutlass/CUDA.cmake)
string(REPLACE "." ";" CUDA_VERSION_PARTS ${CUDA_VERSION})
list(GET CUDA_VERSION_PARTS 0 CUDA_VERSION_MAJOR)
list(GET CUDA_VERSION_PARTS 1 CUDA_VERSION_MINOR)
list(APPEND CMAKE_CUDA_FLAGS "-D__CUDACC_VER_MAJOR__=${CUDA_VERSION_MAJOR} -D__CUDACC_VER_MINOR__=${CUDA_VERSION_MINOR}")
# TODO: Currently disable CUTLASS_ARCH_MMA_SM80_ENABLED flag
# since we target Triton to perform codegen
#list(APPEND CMAKE_CUDA_FLAGS "-DCUTLASS_ARCH_MMA_SM80_ENABLED")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message("Build in Debug mode")
set(CMAKE_CUDA_FLAGS "-O0 -g -Xcompiler=-fPIC ${CMAKE_CUDA_FLAGS}")
set(CMAKE_CXX_FLAGS "-fopenmp -O0 -g -Wall -fPIC ${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CUDA_FLAGS "-O2 -Xcompiler=-fPIC ${CMAKE_CUDA_FLAGS}")
set(CMAKE_CXX_FLAGS "-fopenmp -O2 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
endif()
#set CUDA
if (NOT "${USE_CUDA}" STREQUAL "OFF")
include(cmake/cuda.cmake)
find_cuda(${USE_CUDA})
if (CUDA_FOUND)
list(APPEND MIRAGE_SRCS ${MIRAGE_CUDA_SRCS})
include_directories(${CUDA_INCLUDE_DIRS})
message(STATUS "CUDA_INCLUDE_DIR=" ${CUDA_INCLUDE_DIRS})
list(APPEND MIRAGE_LINK_LIBS ${CUDA_CUDART_LIBRARY})
list(APPEND MIRAGE_LINK_LIBS ${CUDA_CUDA_LIBRARY})
list(APPEND MIRAGE_LINK_LIBS ${CUDA_CUDNN_LIBRARY})
list(APPEND MIRAGE_LINK_LIBS ${CUDA_CUBLAS_LIBRARY})
else()
message(FATAL_ERROR "Cannot find CUDA, USE_CUDA=" ${USE_CUDA})
endif(CUDA_FOUND)
endif()
#set CUTLASS
set(CUTLASS_DIR ${PROJECT_SOURCE_DIR}/deps/cutlass)
include_directories(deps/cutlass/include)
include_directories(deps/cutlass/tools/util/include)
#include_directories(${MIRAGE_INCLUDE_DIRS})
#set Z3
if(Z3_CXX_INCLUDE_DIRS AND Z3_LIBRARIES)
message(STATUS "Z3_CXX_INCLUDE_DIRS: ${Z3_CXX_INCLUDE_DIRS}")
message(STATUS "Z3_LIBRARIES: ${Z3_LIBRARIES}")
else()
find_package(Z3 REQUIRED)
message(STATUS "Z3_FOUND: ${Z3_FOUND}")
message(STATUS "Found Z3 ${Z3_VERSION_STRING}")
message(STATUS "Z3_DIR: ${Z3_DIR}")
endif()
include_directories(${Z3_CXX_INCLUDE_DIRS})
#target_link_libraries(mirage_runtime PUBLIC ${Z3_LIBRARIES})
list(APPEND MIRAGE_LINK_LIBS ${Z3_LIBRARIES})
add_subdirectory(deps/json)
list(APPEND MIRAGE_LINK_LIBS nlohmann_json::nlohmann_json)
#add_subdirectory(deps/z3 z3 EXCLUDE_FROM_ALL)
#include_directories(deps/z3/src/api/c++)
#include_directories(deps/z3/src/api)
#list(APPEND MIRAGE_LINK_LIBS z3)
add_library(mirage_runtime ${MIRAGE_SRCS})
# Note(zhihao): CUDA_SEPARABLE_COMPILATION is non-compatible with
# cython's installation, since enabling separable compilation
# will let cmake generate a seperate object file called
# cmake_device_link.o, and cython's installation cannot
# automatically link to that file, resulting in:
# undefined symbol: __cudaRegisterLinkedBinary_...
#set_target_properties(mirage_runtime
# PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(mirage_runtime PROPERTIES CUDA_ARCHITECTURES "70;75;80;86;89;90")
target_compile_features(mirage_runtime PUBLIC cxx_std_17)
target_link_libraries(mirage_runtime ${MIRAGE_LINK_LIBS})
target_include_directories(mirage_runtime
PUBLIC ${PROJECT_SOURCE_DIR}/include)
install(TARGETS mirage_runtime
LIBRARY DESTINATION lib)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include
DESTINATION .)
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN dnn)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Multi-Query Attention Incremental Decoding
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN multi_query_attn_inc_decode)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Multi-Query Attention Speculative Decoding
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN multi_query_attn_spec_decode)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Multi-Query Attention Prefilling
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN multi_query_attn_prefill)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Group-Query Attention Incremental Decoding
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN group_query_attn_inc_decode)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Group-Query Attention Spec Decoding
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN group_query_attn_spec_decode)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Group-Query Attention Prefilling
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN group_query_attn_prefill)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Multi-Head Attention Incremental Decoding
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN multi_head_attn_inc_decode)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Multi-Head Attention Speculative Decoding
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN multi_head_attn_spec_decode)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Multi-Head Attention Prefilling
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN multi_head_attn_prefill)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# LoRA
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN lora)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# MLP
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN mlp)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# MoE
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN moe)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# RMS
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN rms)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# GatedMLP
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN gated_mlp)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
# Chameleon
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN chameleon)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
if ("${BUILD_CPP_EXAMPLES}" STREQUAL "ON")
set(CPP_EXAMPLES_DIR cpp_examples)
set(CPP_EXAMPLES_BIN profile)
file(GLOB CPP_EXAMPLES_SRCS ${CPP_EXAMPLES_DIR}/${CPP_EXAMPLES_BIN}.cc)
add_executable(${CPP_EXAMPLES_BIN} ${CPP_EXAMPLES_SRCS})
set_target_properties(${CPP_EXAMPLES_BIN}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP_EXAMPLES_DIR})
target_link_libraries(${CPP_EXAMPLES_BIN} mirage_runtime)
endif()
option(MIRAGE_BUILD_UNIT_TEST "build unit tests" OFF)
if (MIRAGE_BUILD_UNIT_TEST)
enable_testing()
add_subdirectory(tests)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
target_link_libraries(mirage_runtime stdc++fs)
endif()
endif()