-
Notifications
You must be signed in to change notification settings - Fork 355
/
CMakeLists.txt
300 lines (278 loc) · 14.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
cmake_minimum_required(VERSION 3.18.0)
# cuFFTDxExamples project
project(cuFFTDxExamples LANGUAGES CXX CUDA)
# Find CUDA Toolkit packaged, required for NVRTC sample
find_package(CUDAToolkit)
# Project options
option(USE_MATHDX_PACKAGE "Use mathDx package to find cuFFTDx" ON)
option(USE_CUFFTDX_PACKAGE "Use cuFFTDx package to find cuFFTDx" OFF)
if(DEFINED cufftdx_ROOT OR DEFINED ENV{cufftdx_ROOT})
SET(USE_CUFFTDX_PACKAGE ON CACHE BOOL "Use cuFFTDx package to find cuFFTDx" FORCE)
SET(USE_MATHDX_PACKAGE OFF CACHE BOOL "Use mathDx package to find cuFFTDx" FORCE)
endif()
if(DEFINED mathdx_ROOT OR DEFINED ENV{mathdx_ROOT})
SET(USE_CUFFTDX_PACKAGE OFF CACHE BOOL "Use cuFFTDx package to find cuFFTDx" FORCE)
SET(USE_MATHDX_PACKAGE ON CACHE BOOL "Use mathDx package to find cuFFTDx" FORCE)
endif()
if(NOT TARGET cufftdx)
if(USE_MATHDX_PACKAGE)
message(STATUS "Using mathDx package to find cuFFTDx")
# Find mathDx and cuFFTDx (mathDx's component)
# Default path: "/opt/nvidia/mathdx/24.08", path to mathDx can be passed cmake in mathdx_ROOT variable
find_package(mathdx REQUIRED COMPONENTS cufftdx CONFIG
PATHS
"${PROJECT_SOURCE_DIR}/../.." # example/cufftdx
"${PROJECT_SOURCE_DIR}/../../.." # include/cufftdx/example
"/opt/nvidia/mathdx/24.08"
)
elseif(USE_CUFFTDX_PACKAGE)
message(STATUS "Using cuFFTDx package to find cuFFTDx")
# Find cuFFTDx
# Default path: "/opt/nvidia/mathdx/24.08/include/cufftdx", path to cuFFTDx can be passed cmake in cufftdx_ROOT variable
find_package(cufftdx REQUIRED CONFIG PATHS "/opt/nvidia/mathdx/24.08/include/cufftdx" "${PROJECT_SOURCE_DIR}/../../cufftdx")
else()
message(FATAL_ERROR "No cuFFTDx package found")
endif()
endif()
if((NOT TARGET cufftdx) AND (NOT CUFFTDX_TEST_RELEASED_PACKAGE) AND (NOT MATHDX_TEST_RELEASED_PACKAGE))
# Targeted CUDA Architectures, see https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html#prop_tgt:CUDA_ARCHITECTURES
if(CUFFTDX_TARGET_ARCHS)
set(CUFFTDX_TARGET_ARCHS 70;75;80 CACHE
STRING "[LEGACY] List of targeted cuFFTDx Example CUDA architectures (compute capabilities), for example \"70;75\". Can't be older than 70."
)
list(SORT CUFFTDX_TARGET_ARCHS)
# Remove unsupported architectures
list(REMOVE_ITEM CUFFTDX_TARGET_ARCHS 30;32;35;37;50;52;53;60;61;62)
# Translate legacy option CUFFTDX_TARGET_ARCHS into CUFFTDX_CUDA_ARCHITECTURES
set(CUFFTDX_TARGET_ARCHS_TRANSLATED)
foreach(ARCH ${CUFFTDX_TARGET_ARCHS})
list(APPEND CUFFTDX_TARGET_ARCHS_TRANSLATED ${ARCH}-real)
endforeach()
set(CUFFTDX_CUDA_ARCHITECTURES ${CUFFTDX_TARGET_ARCHS_TRANSLATED} CACHE
STRING "List of targeted cuFFTDx CUDA architectures, for example \"70-real;75-real;80\""
)
else()
set(CUFFTDX_CUDA_ARCHITECTURES 70-real;75-real;80-real CACHE
STRING "List of targeted cuFFTDX CUDA architectures, for example \"70-real;75-real;80\""
)
# Remove unsupported architectures
list(REMOVE_ITEM CUFFTDX_CUDA_ARCHITECTURES 30;32;35;37;50;52;53;60;61;62)
list(REMOVE_ITEM CUFFTDX_CUDA_ARCHITECTURES 30-real;32-real;35-real;37-real;50-real;52-real;53-real;60-real;61-real;62-real)
list(REMOVE_ITEM CUFFTDX_CUDA_ARCHITECTURES 30-virtual;32-virtual;35-virtual;37-virtual;50-virtual;52-virtual;53-virtual;60-virtual;61-virtual;62-virtual)
endif()
message(STATUS "Targeted cuFFTDx Examples CUDA Architectures: ${CUFFTDX_CUDA_ARCHITECTURES}")
# Global CXX/CUDA flags
if(NOT MSVC)
set(CUFFTDX_CUDA_CXX_FLAGS "${CUFFTDX_CUDA_CXX_FLAGS} -Wall -Wextra")
else()
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-DNOMINMAX)
set(CUFFTDX_CUDA_CXX_FLAGS "${CUFFTDX_CUDA_CXX_FLAGS} /W3") # Warning level
set(CUFFTDX_CUDA_CXX_FLAGS "${CUFFTDX_CUDA_CXX_FLAGS} /WX") # All warnings are errors
set(CUFFTDX_CUDA_CXX_FLAGS "${CUFFTDX_CUDA_CXX_FLAGS} /Zc:__cplusplus") # Enable __cplusplus macro
endif()
# Global CXX flags/options
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUFFTDX_CUDA_CXX_FLAGS}")
# Global CUDA CXX flags/options
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_EXTENSIONS OFF)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler \"${CUFFTDX_CUDA_CXX_FLAGS}\"")
# Clang
if(BUILD_CUFFTDX)
if(CMAKE_CUDA_HOST_COMPILER MATCHES ".*clang.*")
# clang complains about unused function in CUDA system headers
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-unused-function")
endif()
endif()
# CUDA Architectures
set(CMAKE_CUDA_ARCHITECTURES OFF)
# Enable testing (ctest)
enable_testing()
endif()
# ###############################################################
# add_cufftdx_example
# ###############################################################
function(add_cufftdx_example GROUP_TARGET EXAMPLE_NAME EXAMPLE_SOURCES)
list(GET EXAMPLE_SOURCES 0 EXAMPLE_MAIN_SOURCE)
get_filename_component(EXAMPLE_TARGET ${EXAMPLE_MAIN_SOURCE} NAME_WE)
set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES LANGUAGE CUDA)
add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCES})
target_link_libraries(${EXAMPLE_TARGET}
PRIVATE
$<IF:$<TARGET_EXISTS:mathdx::cufftdx>,mathdx::cufftdx,cufftdx::cufftdx>
)
if(NOT TARGET cufftdx)
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/example/cufftdx"
)
endif()
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
CUDA_ARCHITECTURES "${CUFFTDX_CUDA_ARCHITECTURES}"
)
target_compile_options(${EXAMPLE_TARGET}
PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xfatbin -compress-all>"
)
add_test(NAME ${EXAMPLE_NAME} COMMAND ${EXAMPLE_TARGET})
set_tests_properties(${EXAMPLE_NAME}
PROPERTIES
LABELS "CUFFTDX_EXAMPLE"
)
if(CUFFTDX_SANTIZERS_BUILD)
# See https://github.com/google/sanitizers/issues/629 for why
set_tests_properties(${EXAMPLE_NAME} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=protect_shadow_gap=0")
endif()
add_dependencies(${GROUP_TARGET} ${EXAMPLE_TARGET})
endfunction()
# ###############################################################
# add_cufft_and_cufftdx_example
# ###############################################################
function(add_cufft_and_cufftdx_example GROUP_TARGET EXAMPLE_NAME EXAMPLE_SOURCES)
list(GET EXAMPLE_SOURCES 0 EXAMPLE_MAIN_SOURCE)
get_filename_component(EXAMPLE_TARGET ${EXAMPLE_MAIN_SOURCE} NAME_WE)
set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES LANGUAGE CUDA)
add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCES})
target_link_libraries(${EXAMPLE_TARGET}
PRIVATE
$<IF:$<TARGET_EXISTS:mathdx::cufftdx>,mathdx::cufftdx,cufftdx::cufftdx>
)
if(CUFFTDX_EXAMPLES_CUFFT_CALLBACK)
if(TARGET cufft)
target_link_libraries(${EXAMPLE_TARGET} PRIVATE cufft_static)
else()
target_link_libraries(${EXAMPLE_TARGET} PRIVATE CUDA::cufft_static)
endif()
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
)
target_compile_definitions(${EXAMPLE_TARGET} PRIVATE CUFFTDX_EXAMPLES_CUFFT_CALLBACK)
else()
if(TARGET cufft)
target_link_libraries(${EXAMPLE_TARGET} PRIVATE cufft)
else()
target_link_libraries(${EXAMPLE_TARGET} PRIVATE CUDA::cufft)
endif()
endif()
if(NOT TARGET cufftdx)
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/example/cufftdx"
)
endif()
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
CUDA_ARCHITECTURES "${CUFFTDX_CUDA_ARCHITECTURES}"
)
target_compile_options(${EXAMPLE_TARGET}
PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xfatbin -compress-all>"
)
add_test(NAME ${EXAMPLE_NAME} COMMAND ${EXAMPLE_TARGET})
set_tests_properties(${EXAMPLE_NAME}
PROPERTIES
LABELS "CUFFTDX_EXAMPLE"
)
if(CUFFTDX_SANTIZERS_BUILD)
# See https://github.com/google/sanitizers/issues/629 for why
set_tests_properties(${EXAMPLE_NAME} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=protect_shadow_gap=0")
endif()
add_dependencies(${GROUP_TARGET} ${EXAMPLE_TARGET})
endfunction()
# ###############################################################
# add_cufftdx_nvrtc_example
# ###############################################################
function(add_cufftdx_nvrtc_example GROUP_TARGET EXAMPLE_NAME EXAMPLE_SOURCES)
list(GET EXAMPLE_SOURCES 0 EXAMPLE_MAIN_SOURCE)
get_filename_component(EXAMPLE_TARGET ${EXAMPLE_MAIN_SOURCE} NAME_WE)
set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES LANGUAGE CUDA)
add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCES})
target_link_libraries(${EXAMPLE_TARGET}
PRIVATE
$<IF:$<TARGET_EXISTS:mathdx::cufftdx>,mathdx::cufftdx,cufftdx::cufftdx>
CUDA::cudart
CUDA::cuda_driver
CUDA::nvrtc
)
if(NOT TARGET cufftdx)
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/example/cufftdx"
)
target_compile_definitions(${EXAMPLE_TARGET}
PRIVATE
CUDA_INCLUDE_DIR="${CUDAToolkit_INCLUDE_DIRS}"
COMMONDX_INCLUDE_DIR="${cufftdx_commondx_INCLUDE_DIR}"
CUFFTDX_INCLUDE_DIRS="${cufftdx_INCLUDE_DIRS}"
)
else()
target_compile_definitions(${EXAMPLE_TARGET}
PRIVATE
CUDA_INCLUDE_DIR="${CUDAToolkit_INCLUDE_DIRS}"
COMMONDX_INCLUDE_DIR="${CMAKE_SOURCE_DIR}/external/commondx/include"
CUFFTDX_INCLUDE_DIRS="${CMAKE_SOURCE_DIR}/libcufftdx/include\\\;${CMAKE_BINARY_DIR}/libcufftdx/include"
)
endif()
set_target_properties(${EXAMPLE_TARGET}
PROPERTIES
CUDA_ARCHITECTURES "${CUFFTDX_CUDA_ARCHITECTURES}"
)
add_test(NAME ${EXAMPLE_NAME} COMMAND ${EXAMPLE_TARGET})
set_tests_properties(${EXAMPLE_NAME}
PROPERTIES
LABELS "CUFFTDX_EXAMPLE"
)
if(CUFFTDX_SANTIZERS_BUILD)
# See https://github.com/google/sanitizers/issues/629 for why
set_tests_properties(${EXAMPLE_NAME} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=protect_shadow_gap=0")
endif()
add_dependencies(${GROUP_TARGET} ${EXAMPLE_TARGET})
endfunction()
# Enable testing only for selected architectures
add_compile_definitions(CUFFTDX_EXAMPLE_CMAKE)
foreach(CUDA_ARCH ${CUFFTDX_CUDA_ARCHITECTURES})
# Extract SM from SM-real/SM-virtual
string(REPLACE "-" ";" CUDA_ARCH_LIST ${CUDA_ARCH})
list(GET CUDA_ARCH_LIST 0 ARCH)
add_compile_definitions(CUFFTDX_EXAMPLE_ENABLE_SM_${ARCH})
endforeach()
# ###############################################################
# cuFFTDx Examples
# ###############################################################
add_custom_target(cufftdx_examples)
# CUFFTDX_EXAMPLES_CUFFT_CALLBACK
option(CUFFTDX_EXAMPLES_CUFFT_CALLBACK "Build cuFFTDx convolution_performance example with cuFFT callback" OFF)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.introduction_example" introduction_example.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_thread" simple_fft_thread.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_thread_fp16" simple_fft_thread_fp16.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block" simple_fft_block.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_half2" simple_fft_block_half2.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_fp16" simple_fft_block_fp16.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_r2c" simple_fft_block_r2c.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_r2c_fp16" simple_fft_block_r2c_fp16.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_c2r" simple_fft_block_c2r.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_c2r_fp16" simple_fft_block_c2r_fp16.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_shared" simple_fft_block_shared.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_std_complex" simple_fft_block_std_complex.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.simple_fft_block_cub_io" simple_fft_block_cub_io.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.convolution" convolution.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.convolution_r2c_c2r" convolution_r2c_c2r.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.block_fft_performance" block_fft_performance.cu)
add_cufftdx_example(cufftdx_examples "cuFFTDx.example.block_fft_performance_many" block_fft_performance_many.cu)
add_cufft_and_cufftdx_example(cufftdx_examples "cuFFTDx.example.convolution_performance" convolution_performance.cu)
add_cufftdx_nvrtc_example(cufftdx_examples "cuFFTDx.example.nvrtc_fft_thread" nvrtc_fft_thread.cu)
add_cufftdx_nvrtc_example(cufftdx_examples "cuFFTDx.example.nvrtc_fft_block" nvrtc_fft_block.cu)
add_cufft_and_cufftdx_example(cufftdx_examples "cuFFTDx.example.fft_3d_cube_single_block" fft_3d_cube_single_block.cu)
add_cufft_and_cufftdx_example(cufftdx_examples "cuFFTDx.example.fft_3d_box_single_block" fft_3d_box_single_block.cu)
add_cufft_and_cufftdx_example(cufftdx_examples "cuFFTDx.example.fft_2d" fft_2d.cu)
add_cufft_and_cufftdx_example(cufftdx_examples "cuFFTDx.example.fft_2d_single_kernel" fft_2d_single_kernel.cu)
add_cufft_and_cufftdx_example(cufftdx_examples "cuFFTDx.example.fft_2d_r2c_c2r" fft_2d_r2c_c2r.cu)