-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
226 lines (197 loc) · 5.14 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
cmake_minimum_required(VERSION 3.20.0)
project(
NSFemSolver
VERSION 0.1.0
DESCRIPTION "Finite element method solver for the Navier-Stokes equations."
LANGUAGES CXX CUDA
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Path to where <package>-confng.cmake files generated by conan cmake_find_package are located
if(NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
endif()
find_package(nlohmann_json REQUIRED CONFIG)
find_package(TBB REQUIRED CONFIG)
find_package(OpenCV REQUIRED CONFIG)
find_package(CUDAToolkit REQUIRED)
set(WITH_ADDRESS_SANITIZER
OFF CACHE BOOL
"If ON the project will be compiled with address sanitizer (it will run slow). For now it's clang only")
set(WITH_CPU_PROFILER
OFF CACHE BOOL
"If ON additional compiler flags will be set so that the executable could be profiled with perf")
set(WITH_GPU_PROFILER
OFF CACHE BOOL
"If ON additional compiler flags will be set for the CUDA project so that profiler can be run")
set(WITH_PROFILING_SCOPED_TIMERS
OFF CACHE BOOL
"If ON all scoped timers will be enabled and will print their result on the console")
option(WITH_GPU_SOLVER
"If true the solution of the NS equations (advection, diffusion and pressure projection) will be performend on the GPU"
OFF)
set(PTX_SOURCE_FOLDER "${PROJECT_BINARY_DIR}/ptx")
if(${WITH_ADDRESS_SANITIZER})
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(_sanitizer_flags "-g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_sanitizer_flags}")
set(CMAKE_CXX_EXE_LINKER_FLAGS "${CMAKE_CXX_EXE_LINKER_FLAGS} ${_sanitizer_flags}")
unset(_sanitizer_flags)
else()
message(FATAL_ERROR "Address sanitizing is supported only for Clang and GCC")
endif()
endif()
set(CPP
cpp/main.cpp
cpp/grid.cpp
cpp/expression.cpp
cpp/error_code.cpp
cpp/assembly.cpp
cpp/cmd_line_parser.cpp
cpp/gpu_host_common.cpp
cpp/gpu_simulation_device.cpp
cpp/kd_tree_builder.cpp
cpp/gpu_sparse_matrix.cpp
)
set(HEADERS
include/grid.h
include/assembly.h
include/static_matrix.h
include/expression.h
include/error_code.h
include/timer.h
include/cmd_line_parser.h
include/gpu_host_common.h
include/gpu_simulation_device.h
include/kd_tree_builder.h
include/gpu_sparse_matrix.h
sparse_matrix_math/include/sparse_matrix_math.h
# shared between gpu and cpu
gpu_cpu_shared/kd_tree_common.cuh
gpu_cpu_shared/misc_common.cuh
gpu_cpu_shared/defines_common.cuh
gpu_cpu_shared/kd_tree.cuh
gpu_cpu_shared/gpu_grid.cuh
gpu_cpu_shared/small_vector.cuh
gpu_cpu_shared/matrix_math_common.cuh
)
add_executable(${PROJECT_NAME} ${CPP} ${HEADERS})
target_include_directories(${PROJECT_NAME}
PRIVATE
include
vendor
gpu_cpu_shared
sparse_matrix_math/include)
target_link_libraries(${PROJECT_NAME}
PRIVATE
TBB::tbb
nlohmann_json::nlohmann_json
opencv::opencv
CUDA::cuda_driver)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
-D_USE_MATH_DEFINES
-DPTX_SOURCE_FOLDER="${PTX_SOURCE_FOLDER}/"
-DSMM_MULTITHREADING_TBB
-DCUDA_API_PER_THREAD_DEFAULT_STREAM)
if(NOT MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-pedantic
$<$<CONFIG:DEBUG>:-fno-limit-debug-info>
-fno-exceptions
-fno-rtti
-ffast-math
-Wreturn-type
)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE
/fp:fast
/GR-
/EHsc
)
endif()
if(${WITH_GBENCH})
find_package(benchmark REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark)
endif()
if(${WITH_CPU_PROFILER})
if(NOT MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE -fno-omit-frame-pointer -g)
else()
target_compile_options(${PROJECT_NAME} PRIVATE /Oy- /Zi)
endif()
endif()
if(${WITH_PROFILING_SCOPED_TIMERS})
target_compile_definitions(${PROJECT_NAME} PRIVATE WITH_PROFILING_SCOPED_TIMERS)
endif()
if(${WITH_GPU_SOLVER})
target_compile_definitions(
${PROJECT_NAME}
PRIVATE
-DGPU_SETUP
-DGPU_ADVECTION
-DGPU_CONJUGATE_GRADIENT
)
endif()
add_subdirectory(sparse_matrix_math)
target_precompile_headers(${PROJECT_NAME}
PRIVATE
# containers
<vector>
<map>
<unordered_set>
<unordered_map>
<string>
<set>
# i/o
<fstream>
<cstdio>
<iostream>
<filesystem>
<iomanip>
# utils
<cstring>
<memory>
<cinttypes>
<chrono>
<limits>
<cassert>
<cstdarg>
<cctype>
<cmath>
<numeric>
<iterator>
<utility>
<algorithm>
# non STL
<nlohmann/json.hpp>
<opencv2/imgproc.hpp>
<opencv2/imgcodecs.hpp>
# From the project
[[include/error_code.h]]
)
add_library(gpu_sim
OBJECT
gpu/advection.cu
gpu/matrix_math.cu)
target_include_directories(gpu_sim
PRIVATE
gpu_cpu_shared)
set_target_properties(gpu_sim
PROPERTIES
CUDA_PTX_COMPILATION ON
CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}-virtual)
if(${WITH_GPU_PROFILER})
target_compile_options(gpu_sim
PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:
-g>)
endif()
add_dependencies(${PROJECT_NAME} gpu_sim)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PTX_SOURCE_FOLDER}
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_OBJECTS:gpu_sim>" ${PTX_SOURCE_FOLDER}
COMMAND_EXPAND_LISTS)