-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
179 lines (149 loc) · 5.71 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
# cmake file to build the project and tests
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
# ----------------------------------------------------------------------------------------
# ===== Project Setup =====
project(SCAMP LANGUAGES CXX CUDA)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 1)
add_subdirectory(gflags)
find_program(
CLANG_TIDY_EXE
NAMES clang-tidy-6.0 clang-tidy-5.0 clang-tidy
DOC "Path to clang-tidy executable (v5+)"
)
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-fuchsia-default-arguments,-hicpp-vararg,-cppcoreguidelines-pro-type-vararg" "-warnings-as-errors=*")
endif()
find_program(
CLANG_FORMAT_EXE
NAMES clang-format-6.0 clang-format-5.0 clang-format
DOC "Path to clang-format executable (v5+)"
)
if(NOT CLANG_FORMAT_EXE)
message(STATUS "clang-format not found.")
else()
message(STATUS "clang-format found: ${CLANG_FORMAT_EXE}")
set(DO_CLANG_FORMAT "${CLANG_FORMAT}" "-i -style=file")
endif()
add_subdirectory(proto)
set(
PROJECT_SOURCE_FILES
src/*.h
src/*.cpp
src/*.cu
# src/common.h
# src/kernels.h
# src/utils.h
# src/tile.h
# src/SCAMP.h
# src/fft_helper.h
# src/fft_kernels.h
# src/kernels.cu
# src/utils.cu
# src/tile.cpp
# src/SCAMP.cpp
# src/fft_helper.cpp
# src/fft_kernels.cu
# src/main.cpp
# src/common.cpp
src/cpu/solvers/*
src/cpu/utils/*
)
# ----------------------------------------------------------------------------------------
# ===== Compiler Configuration =====
set(CXX_STD, "-std=c++11")
message(STATUS "CUDA Root Directory is ${CUDA_TOOLKIT_ROOT_DIR}")
include_directories("${CUDA_TOOLKIT_ROOT_DIR}/include" "proto")
set(CUDA_SEPARABLE_COMPILATION ON)
#set(CUDA_COMPILATION_FLAGS "--std=c++14 -O0 -g")
set(CUDA_COMPILATION_FLAGS "--std=c++14 -lineinfo --expt-relaxed-constexpr -use_fast_math")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_60,code=sm_70")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_61,code=sm_61")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_60,code=sm_60")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_50,code=sm_50")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_37,code=sm_37")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_35,code=sm_35")
set(CUDA_GENCODE_FLAGS "${CUDA_GENCODE_FLAGS} -gencode arch=compute_30,code=sm_30")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STD}")
# optimize in release
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -funroll-loops")
# build debug with sanitizer
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
if(${COMPILER_ID} MATCHES "GNU") # gcc specific flags
add_definitions("-Wextra -Wpedantic")
elseif(${COMPILER_ID} MATCHES "clang") # clang specific flags
add_definitions("-Weverything")
endif()
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
# ----------------------------------------------------------------------------------------
# ===== Build targets =====
set(DLS_COMPILE_FLAGS "-fPIC -fopenmp -I$(DLS_DIR) -DDLS_STATS -DOPENCL")
add_library(common src/common.cpp)
target_link_libraries(common messages -lcudart_static)
add_library(fft_kernels src/fft_kernels.cu)
add_library(fft src/fft_helper.cpp)
target_link_libraries(fft -lcufft fft_kernels common)
add_library(utils src/utils.cu)
target_link_libraries(utils messages common -fPIC -fopenmp -I$(DLS_DIR) -DDLS_STATS -DOPENCL)
add_library(kernels src/kernels.cu)
target_link_libraries(kernels messages common)
add_library(tile src/tile.cpp)
target_link_libraries(tile messages common kernels fft)
# add cpu code
# add_library(cpu_code src/cpu/utils/alloc.cpp src/cpu/utils/cov.cpp src/cpu/utils/primitive_print_funcs.cpp src/cpu/solvers/pearson.cpp)
# target_link_libraries(cpu_code)
add_library(scamp src/SCAMP.cpp)
target_link_libraries(scamp messages utils tile common fft)
set_target_properties(kernels PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
COMPILE_FLAGS "${CUDA_COMPILATION_FLAGS} ${CUDA_GENCODE_FLAGS}"
)
set_target_properties(utils PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
COMPILE_FLAGS "${CUDA_COMPILATION_FLAGS} ${CUDA_GENCODE_FLAGS}"
)
if(CLANG_TIDY_EXE)
set_target_properties(
common PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
set_target_properties(
scamp PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
set_target_properties(
tile PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
set_target_properties(
fft PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
endif()
function(prepend var prefix)
set(listVar "")
foreach(f ${ARGN})
list(APPEND listVar "${prefix}/${f}")
endforeach()
set(${var} "${listVar}" PARENT_SCOPE)
endfunction()
if(CLANG_FORMAT_EXE)
prepend(FILES_TO_FORMAT ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_FILES})
add_custom_target(
clang-format
COMMAND ${CLANG_FORMAT_EXE} -i -style=file ${FILES_TO_FORMAT}
)
endif()
set(DLS_LINK_FLAGS "-L$(DLS_DIR)/lib/ -L. -ldls -lm -fopenmp -lstdc++ -L/usr/local/cuda-10.1/lib64 -lOpenCL -rdynamic")
add_executable(SCAMP src/main.cpp)
target_link_libraries(SCAMP -lcudart_static gflags messages common scamp utils -L$(DLS_DIR)/lib/ -L. -ldls -lm -fopenmp -lstdc++ -L/usr/local/cuda-10.1/lib64 -lOpenCL -rdynamic)