forked from alibaba/hiactor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
524 lines (444 loc) · 16.1 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# Copyright 2021 Alibaba Group Holding Limited. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required (VERSION 3.13)
project (Hiactor
VERSION 1.0
LANGUAGES CXX)
option (Hiactor_DEBUG
"Enable debug mode"
OFF)
option (Hiactor_TESTING
"Enable hiactor tests"
ON)
option (Hiactor_DEMOS
"Enable hiactor demos"
ON)
option (Hiactor_INSTALL
"Install targets."
ON)
option (Hiactor_DPDK
"Enable DPDK support."
OFF)
option (Hiactor_GPU_ENABLE
"Enable gpu device for hiactor, cuda environments required!"
OFF)
option (Hiactor_CPU_STALL_REPORT
"Enable reporting at cpu stall."
OFF)
option (Hiactor_UNUSED_RESULT_ERROR
"Make [[nodiscard]] violations an error (instead of a warning)."
OFF)
set (Hiactor_CXX_DIALECT
"gnu++17"
CACHE
STRING
"Compile Hiactor according to the named C++ standard.")
set (Hiactor_CXX_FLAGS
""
CACHE
STRING
"Semicolon-separated list of extra compilation flags for Hiactor itself.")
option (Hiactor_COOK_DEPENDENCIES
"Download and build all dependencies by Hiactor."
OFF)
option (Hiactor_COOK_DEPENDENCIES_ALL_STATIC
"Cook all dependencies as static libraries."
OFF)
set (Hiactor_COOK_EXCLUDES
""
CACHE
STRING
"Semicolon-separated list of dependency names to exclude from cooking.")
option (Hiactor_FIFO_NETWORK_MESSAGE
"Ensure actor message cross network to be FIFO, which may cause unbalanced network load between shards."
ON)
# When Hiactor is embedded with `add_subdirectory`, disable the non-library targets.
if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
set (Hiactor_DEMOS OFF)
set (Hiactor_TESTING OFF)
set (Hiactor_INSTALL OFF)
endif ()
set (Hiactor_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set (Hiactor_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
## Override seastar options
set (Seastar_CXX_DIALECT
${Hiactor_CXX_DIALECT}
CACHE
STRING
"Compile Seastar according to the named C++ standard.")
set (Seastar_DPDK
${Hiactor_DPDK}
CACHE
BOOL
"Enable Seastar DPDK support.")
set (Seastar_DPDK_MACHINE
"native"
CACHE
STRING
"Configure Seastar DPDK with native machine.")
## Set seastar dirs
set (Hiactor_BUILD_SEASTAR_SOURCE_DIR ${Hiactor_BINARY_DIR}/seastar)
set (Hiactor_BUILD_SEASTAR_BINARY_DIR ${Hiactor_BINARY_DIR}/seastar_build)
## Copy seastar repo and apply patch
if (NOT EXISTS ${Hiactor_BUILD_SEASTAR_SOURCE_DIR})
message ("-- Copying Seastar code source into build dir ...")
execute_process (
COMMAND git clone -c advice.detachedHead=false -q ${Hiactor_SOURCE_DIR}/seastar/seastar
WORKING_DIRECTORY ${Hiactor_BINARY_DIR})
message ("-- Applying Seastar patch from Hiactor ...")
execute_process (
COMMAND git config --local user.name hiactor
COMMAND git config --local user.email [email protected]
COMMAND git am -q ${Hiactor_SOURCE_DIR}/seastar/patch/hiactor-hackings.patch
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR})
if (Hiactor_COOK_DEPENDENCIES_ALL_STATIC)
execute_process (
COMMAND git config --local user.name hiactor
COMMAND git config --local user.email [email protected]
COMMAND git am -q ${Hiactor_SOURCE_DIR}/seastar/patch/cooking-deps-all-static.patch
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR})
endif ()
endif ()
if (Hiactor_DPDK)
if (NOT EXISTS ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/dpdk/kernel)
message ("-- Copying dpdk code source into build dir ...")
execute_process (
COMMAND git clone -c advice.detachedHead=false -q ${Hiactor_SOURCE_DIR}/seastar/seastar/dpdk
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR})
endif ()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set (dpdk_quadruple arm64-armv8a-linuxapp-gcc)
else()
set (dpdk_quadruple ${CMAKE_SYSTEM_PROCESSOR}-native-linuxapp-gcc)
endif()
set (dpdk_args
# gcc 10 defaults to -fno-common, which dpdk is not prepared for
"EXTRA_CFLAGS=-Wno-error -fcommon"
O=${Hiactor_BINARY_DIR}/dpdk_build
DESTDIR=${Hiactor_BINARY_DIR}/dpdk_installed
T=${dpdk_quadruple})
if (NOT EXISTS ${Hiactor_BINARY_DIR}/dpdk_installed)
message ("-- Building DPDK ...")
cmake_host_system_information (
RESULT build_concurrency_factor
QUERY NUMBER_OF_LOGICAL_CORES)
execute_process (
COMMAND make ${dpdk_args} config
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/dpdk)
execute_process (
COMMAND
${CMAKE_COMMAND}
-DSeastar_DPDK_MACHINE=${Seastar_DPDK_MACHINE}
-DSeastar_DPDK_CONFIG_FILE_IN=${Hiactor_BINARY_DIR}/dpdk_build/.config
-DSeastar_DPDK_CONFIG_FILE_CHANGES=${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/dpdk_config
-DSeastar_DPDK_CONFIG_FILE_OUT=${Hiactor_BINARY_DIR}/dpdk_build/${dpdk_quadruple}/.config
-P ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/dpdk_configure.cmake
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/dpdk)
execute_process (
COMMAND make -j ${build_concurrency_factor} ${dpdk_args} install
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/dpdk)
endif ()
list (APPEND CMAKE_PREFIX_PATH ${Hiactor_BINARY_DIR}/dpdk_installed)
endif ()
if (Hiactor_COOK_DEPENDENCIES)
set (Hiactor_COOKING_BUILD_DIR ${Hiactor_BINARY_DIR}/cooking_build)
set (Hiactor_COOKING_INSTALL_DIR ${Hiactor_BINARY_DIR}/cooking_install)
if (NOT EXISTS ${Hiactor_COOKING_INSTALL_DIR})
set (cooking_excludes)
if (Hiactor_COOK_EXCLUDES)
foreach (EXCLUDE_DEP ${Hiactor_COOK_EXCLUDES})
list (APPEND cooking_excludes "-e ${EXCLUDE_DEP}")
endforeach ()
endif ()
if (NOT Hiactor_DPDK)
list (APPEND cooking_excludes "-e dpdk")
endif ()
string (REPLACE ";" " " exclude_args "${cooking_excludes}")
message ("-- Downloading and cooking dependencies ...")
execute_process (
COMMAND ./cooking.sh -d ${Hiactor_COOKING_BUILD_DIR} -f ${Hiactor_COOKING_INSTALL_DIR} ${exclude_args}
WORKING_DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR})
if (Hiactor_COOK_DEPENDENCIES_ALL_STATIC)
execute_process (
COMMAND bash -c "rm -f lib*.so*"
WORKING_DIRECTORY ${Hiactor_COOKING_INSTALL_DIR}/lib)
endif ()
endif ()
set (CMAKE_PREFIX_PATH ${Hiactor_COOKING_INSTALL_DIR})
endif ()
add_subdirectory (${Hiactor_BUILD_SEASTAR_SOURCE_DIR} ${Hiactor_BUILD_SEASTAR_BINARY_DIR})
if (Hiactor_GPU_ENABLE)
# add compiling source files
set (Hiactor_GPU_POOL_SOURCES
include/hiactor/core/gpu_resource_pool.hh
src/core/gpu_resource_pool.cc)
add_definitions (-DHIACTOR_GPU_ENABLE)
# build cuda kernels
find_package (CUDA 9.0 REQUIRED)
set (CUDA_NVCC_FLAGS "-std=c++14 --compiler-options -fPIC") # nvcc flags
if (Hiactor_DEBUG)
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -O1; -G; -g; -line-info)
else ()
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -O2)
endif ()
cuda_add_library (cuda_kernels STATIC
include/hiactor/cuda/device.h
src/cuda/device.cu)
endif ()
if (Hiactor_CPU_STALL_REPORT)
add_definitions (-DHIACTOR_CPU_STALL_REPORT)
endif ()
add_library (hiactor STATIC
${Hiactor_GPU_POOL_SOURCES}
include/hiactor/core/actor-app.hh
include/hiactor/core/actor-template.hh
include/hiactor/core/actor_client.hh
include/hiactor/core/actor_core.hh
include/hiactor/core/actor_factory.hh
include/hiactor/core/actor_message.hh
include/hiactor/core/actor_pollfn.hh
include/hiactor/core/actor_scheduling.hh
include/hiactor/core/actor_timer.hh
include/hiactor/core/alien_thread_pool.hh
include/hiactor/core/cb_table.hh
include/hiactor/core/column_batch.hh
include/hiactor/core/continuation.hh
include/hiactor/core/coordinator.hh
include/hiactor/core/coordinator_worker.hh
include/hiactor/core/dynamic-queue.hh
include/hiactor/core/exception.hh
include/hiactor/core/local_channel.hh
include/hiactor/core/message_reclaimer.hh
include/hiactor/core/message_tag.hh
include/hiactor/core/promise_manager.hh
include/hiactor/core/reference_base.hh
include/hiactor/core/root_actor_group.hh
include/hiactor/core/shard-config.hh
include/hiactor/core/thread_resource_pool.hh
include/hiactor/net/connection.hh
include/hiactor/net/defs.hh
include/hiactor/net/entry.hh
include/hiactor/net/lba_policy.hh
include/hiactor/net/network_channel.hh
include/hiactor/net/network_config.hh
include/hiactor/net/network_io.hh
include/hiactor/net/serializable_queue.hh
include/hiactor/util/common-utils.hh
include/hiactor/util/data_type.hh
include/hiactor/util/machine_info.hh
include/hiactor/util/unaligned_int.hh
include/hiactor/testing/test_case.hh
src/core/actor-app.cc
src/core/actor_core.cc
src/core/actor_factory.cc
src/core/actor-template.cc
src/core/actor_message.cc
src/core/actor_timer.cc
src/core/alien_thread_pool.cc
src/core/coordinator.cc
src/core/coordinator_worker.cc
src/core/local_channel.cc
src/core/root_actor_group.cc
src/core/thread_resource_pool.cc
src/net/connection.cc
src/net/network_channel.cc
src/net/network_io.cc)
add_library (Hiactor::hiactor ALIAS hiactor)
target_include_directories (hiactor
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${Hiactor_SOURCE_DIR}/include>
PRIVATE
${Hiactor_SOURCE_DIR}/src)
set (Hiactor_PRIVATE_CXX_FLAGS
-fvisibility=hidden
-UNDEBUG
-Wall
-Werror
-Wno-array-bounds
-Wno-error=deprecated-declarations
-Wno-attributes)
if (Hiactor_CXX_FLAGS)
list (APPEND Hiactor_PRIVATE_CXX_FLAGS ${Hiactor_CXX_FLAGS})
endif ()
target_compile_options (hiactor
PRIVATE ${Hiactor_PRIVATE_CXX_FLAGS})
if (Hiactor_UNUSED_RESULT_ERROR)
target_compile_options (hiactor
PUBLIC
-Werror=unused-result
-Werror=unused-variable)
else ()
target_compile_options (hiactor
PUBLIC
-Wno-unused-result
-Wno-unused-variable)
endif ()
if (Hiactor_DEBUG)
target_compile_definitions (hiactor
PRIVATE HIACTOR_DEBUG)
set (Hiactor_MODE_FLAGS -DDEBUG -g)
else ()
set (Hiactor_MODE_FLAGS -DNDEBUG -O3)
endif ()
target_compile_options (hiactor
PUBLIC
-std=${Hiactor_CXX_DIALECT}
${Hiactor_MODE_FLAGS})
target_link_libraries (hiactor PUBLIC seastar)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
target_link_libraries (hiactor PRIVATE stdc++fs)
endif ()
if (Hiactor_GPU_ENABLE)
target_link_libraries (hiactor PUBLIC cuda_kernels)
endif ()
if (NOT Hiactor_FIFO_NETWORK_MESSAGE)
target_compile_definitions (hiactor
PRIVATE HIACTOR_ROUND_ROUBIN_NETWORK_PROXY)
endif ()
## hiactor private interface
add_library (hiactor_private INTERFACE)
target_compile_options (hiactor_private
INTERFACE ${Hiactor_PRIVATE_CXX_FLAGS})
target_link_libraries (hiactor_private
INTERFACE hiactor)
include (${Hiactor_SOURCE_DIR}/codegen/ActorAutoGen.cmake)
## hiactor demos
if (Hiactor_DEMOS)
add_subdirectory (demos)
endif ()
## hiactor tests
if (Hiactor_TESTING)
add_subdirectory (tests)
enable_testing ()
add_test (actor_test tests/actor_test -- -c4)
add_test (alien_pool_test tests/alien_pool_test -- -c4)
add_test (thread_pool_test tests/thread_pool_test -- --open-thread-resource-pool=true)
add_test (column_batch_test tests/column_batch_test)
endif ()
## install targets
if (Hiactor_INSTALL)
include (GNUInstallDirs)
include (CMakePackageConfigHelpers)
set (install_cmake_dir ${CMAKE_INSTALL_LIBDIR}/cmake/Hiactor)
# install cooked dependenices
if (Hiactor_COOK_DEPENDENCIES)
install (
DIRECTORY ${Hiactor_COOKING_INSTALL_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install (
DIRECTORY ${Hiactor_COOKING_INSTALL_DIR}/bin/
DESTINATION ${CMAKE_INSTALL_BINDIR})
install (
DIRECTORY ${Hiactor_COOKING_INSTALL_DIR}/sbin/
DESTINATION ${CMAKE_INSTALL_SBINDIR})
install (
DIRECTORY ${Hiactor_COOKING_INSTALL_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (
DIRECTORY ${Hiactor_COOKING_INSTALL_DIR}/share/
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/)
endif()
# install include files
install (
DIRECTORY ${Hiactor_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install (
DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set (Hiactor_BUILD_SEASTAR_GEN_BINARY_DIR ${Hiactor_BUILD_SEASTAR_BINARY_DIR}/gen)
install (
DIRECTORY ${Hiactor_BUILD_SEASTAR_GEN_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# install actor codegen tool
install (
FILES
${Hiactor_SOURCE_DIR}/codegen/__init__.py
${Hiactor_SOURCE_DIR}/codegen/actor_codegen.py
${Hiactor_SOURCE_DIR}/codegen/generator.py
${Hiactor_SOURCE_DIR}/codegen/traverse.py
${Hiactor_SOURCE_DIR}/codegen/typedef.py
${Hiactor_SOURCE_DIR}/codegen/utility.py
${Hiactor_SOURCE_DIR}/codegen/ActorAutoGen.cmake
DESTINATION ${CMAKE_INSTALL_BINDIR}/hiactor_codegen)
# install seastar binaries
install (
PROGRAMS ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/scripts/seastar-json2code.py
DESTINATION ${CMAKE_INSTALL_BINDIR})
# install targets
install (
TARGETS
hiactor
seastar
EXPORT hiactor-export
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (Hiactor_GPU_ENABLE)
install (
TARGETS cuda_kernels
EXPORT hiactor-export
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif ()
install (
EXPORT hiactor-export
FILE HiactorTargets.cmake
NAMESPACE Hiactor::
DESTINATION ${install_cmake_dir})
write_basic_package_version_file (
${Hiactor_BINARY_DIR}/HiactorConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)
configure_package_config_file (
${Hiactor_SOURCE_DIR}/cmake/HiactorConfig.cmake.in
${Hiactor_BINARY_DIR}/HiactorConfig.cmake
INSTALL_DESTINATION ${install_cmake_dir})
install (
FILES
${Hiactor_BINARY_DIR}/HiactorConfig.cmake
${Hiactor_BINARY_DIR}/HiactorConfigVersion.cmake
DESTINATION ${install_cmake_dir})
install (
FILES
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/FindConcepts.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/FindGnuTLS.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/FindLinuxMembarrier.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/FindPthreadSetName.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/FindSanitizers.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/FindStdAtomic.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findc-ares.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findcryptopp.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Finddpdk.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findhwloc.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findlksctp-tools.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findlz4.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findnumactl.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findragel.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findrt.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/Findyaml-cpp.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/SeastarDependencies.cmake
${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/dpdk_configure.cmake
DESTINATION ${install_cmake_dir})
install (
DIRECTORY ${Hiactor_BUILD_SEASTAR_SOURCE_DIR}/cmake/code_tests
DESTINATION ${install_cmake_dir})
# Export targets from the build tree for the user package registry.
export (
EXPORT hiactor-export
FILE ${Hiactor_BINARY_DIR}/HiactorTargets.cmake
NAMESPACE Hiactor::)
export (PACKAGE Hiactor)
# Packaging.
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
include (CPack)
endif ()