This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
222 lines (196 loc) · 9.58 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
cmake_minimum_required (VERSION 3.17 FATAL_ERROR)
#-------------------------------------------------------------------------------
# Turn on precompiled headers support.
#-------------------------------------------------------------------------------
option (USE_PCH "Use precompiled headers." OFF)
#-------------------------------------------------------------------------------
# Setup languages to use. Only enable CUDA if GPU's are in use.
#-------------------------------------------------------------------------------
project (kronmult LANGUAGES CXX)
option (USE_GPU "Use CUDA for gpu support" OFF)
if (USE_GPU)
enable_language (CUDA)
endif ()
#-------------------------------------------------------------------------------
# Setup a menu of build types.
#-------------------------------------------------------------------------------
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
Debug
Release
MinSizeRel
RelWithDebInfo
Sanitized
)
#-------------------------------------------------------------------------------
# Sanitizer options
#-------------------------------------------------------------------------------
set (CMAKE_CXX_FLAGS_SANITIZED -fno-omit-frame-pointer)
set (CMAKE_CUDA_FLAGS_SANITIZED -fno-omit-frame-pointer)
set (CMAKE_EXE_LINKER_FLAGS_SANITIZED "")
set (CMAKE_SHARED_LINKER_FLAGS_SANITIZED "")
macro (register_sanitizer_option name default)
string (TOUPPER ${name} upper_name)
option (SANITIZE_${upper_name} "Enable the ${name} sanitizer" ${default})
if (${SANITIZE_${upper_name}})
set (CMAKE_CXX_FLAGS_SANITIZED "${CMAKE_CXX_FLAGS_SANITIZED} -fsanitize=${name}")
set (CMAKE_CUDA_FLAGS_SANITIZED "${CMAKE_CUDA_FLAGS_SANITIZED} -fsanitize=${name}")
set (CMAKE_EXE_LINKER_FLAGS_SANITIZED "${CMAKE_EXE_LINKER_FLAGS_SANITIZED} -fsanitize=${name}")
set (CMAKE_SHARED_LINKER_FLAGS_SANITIZED "${CMAKE_SHARED_LINKER_FLAGS_SANITIZED} -fsanitize=${name}")
endif ()
endmacro ()
register_sanitizer_option (address ON)
register_sanitizer_option (leak OFF)
register_sanitizer_option (memory OFF)
register_sanitizer_option (thread OFF)
register_sanitizer_option (undefined ON)
#-------------------------------------------------------------------------------
# Define a macro function to set a targets source files to the CUDA language.
#
# Can't use $<$<COMPILE_LANGUAGE:LANG>:foo> generator expressions for
# target_compile_features
#
# Need to handle this with an explicit if statement.
#-------------------------------------------------------------------------------
macro (target_set_cuda target)
if (USE_GPU)
target_compile_features (${target} PUBLIC cuda_std_14)
get_target_property (SOURCES ${target} SOURCES)
set_source_files_properties (${SOURCES} PROPERTIES LANGUAGE CUDA)
set_target_properties (${target} PROPERTIES CUDA_ARCHITECTURES 60)
endif ()
endmacro ()
#-------------------------------------------------------------------------------
# Find 3rd party libraries.
#-------------------------------------------------------------------------------
find_package (OpenMP)
#-------------------------------------------------------------------------------
# Configure kron target.
#-------------------------------------------------------------------------------
add_library (kron SHARED)
# Note can't use generator expressions on the source files since it interfers
# with setting the source property to target CUDA.
target_sources (kron
PRIVATE
kgemm_nn_batched.cpp
kgemm_nn.cpp
kgemm_nt_batched.cpp
kgemm_nt.cpp
kronmult1_batched.cpp
kronmult1_pbatched.cpp
kronmult1_xbatched.cpp
kronmult2_batched.cpp
kronmult2_pbatched.cpp
kronmult2_xbatched.cpp
kronmult3_batched.cpp
kronmult3_pbatched.cpp
kronmult3_xbatched.cpp
kronmult4_batched.cpp
kronmult4_pbatched.cpp
kronmult4_xbatched.cpp
kronmult5_batched.cpp
kronmult5_pbatched.cpp
kronmult5_xbatched.cpp
kronmult6_batched.cpp
kronmult6_pbatched.cpp
kronmult6_xbatched.cpp
)
target_precompile_headers (kron
PUBLIC
$<$<BOOL:${USE_PCH}>:kgemm_nn.hpp>
$<$<BOOL:${USE_PCH}>:kgemm_nn_batched.hpp>
$<$<BOOL:${USE_PCH}>:kgemm_nt.hpp>
$<$<BOOL:${USE_PCH}>:kgemm_nt_batched.hpp>
$<$<BOOL:${USE_PCH}>:kroncommon.hpp>
$<$<BOOL:${USE_PCH}>:kronmult1.hpp>
$<$<BOOL:${USE_PCH}>:kronmult1_batched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult1_pbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult1_xbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult2.hpp>
$<$<BOOL:${USE_PCH}>:kronmult2_batched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult2_pbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult2_xbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult3.hpp>
$<$<BOOL:${USE_PCH}>:kronmult3_batched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult3_pbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult3_xbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult4.hpp>
$<$<BOOL:${USE_PCH}>:kronmult4_batched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult4_pbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult4_xbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult5.hpp>
$<$<BOOL:${USE_PCH}>:kronmult5_batched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult5_pbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult5_xbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult6.hpp>
$<$<BOOL:${USE_PCH}>:kronmult6_batched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult6_pbatched.hpp>
$<$<BOOL:${USE_PCH}>:kronmult6_xbatched.hpp>
)
target_include_directories (kron
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_features (kron PUBLIC cxx_std_17)
target_set_cuda (kron)
if (ASGARD_RECOMMENDED_DEFAULTS)
if (NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
target_compile_options (kron
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:-Wall>
)
endif()
if (NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")
target_compile_options (kron
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:-Wextra>
)
endif()
if (NOT CMAKE_CXX_FLAGS MATCHES "-Wpedantic")
target_compile_options (kron
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:-Wpedantic>
)
endif()
endif()
target_compile_options (kron
PUBLIC
$<$<COMPILE_LANGUAGE:CUDA>:--compiler-options -fPIC --keep-device-functions>
)
target_compile_definitions (kron
PUBLIC
$<$<COMPILE_LANGUAGE:CUDA>:USE_GPU>
)
target_link_libraries (kron
PUBLIC
$<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>
)
#-------------------------------------------------------------------------------
# Setup testing
#-------------------------------------------------------------------------------
enable_testing ()
#-------------------------------------------------------------------------------
# Define a macro function to regester tests.
#-------------------------------------------------------------------------------
macro (add_test_target target source)
add_executable (${target})
target_sources (${target}
PRIVATE
${source}
)
target_set_cuda (${target})
target_link_libraries (${target} PUBLIC kron)
if (${USE_PCH})
target_precompile_headers (${target} REUSE_FROM kron)
endif ()
add_test (NAME ${target}
COMMAND ${target})
set_tests_properties (${target} PROPERTIES PROCESSORS 2 ENVIRONMENT OMP_NUM_THREADS=2)
endmacro ()
#-------------------------------------------------------------------------------
# Configure test targets.
#-------------------------------------------------------------------------------
add_test_target (kgemm_nn_test test_kgemm_nn_batched.cpp)
add_test_target (kgemm_nt_test test_kgemm_nt_batched.cpp)
add_test_target (test_kronmult6_batched test_kronmult6_batched.cpp)
add_test_target (test_kronmult6_pbatched test_kronmult6_pbatched.cpp)
add_test_target (test_kronmult6_xbatched test_kronmult6_xbatched.cpp)