yum-mirror/VkFFT

git clone https://git.yummers.dev/yum-mirror/VkFFT

Tolmachev DmitriiMerge pull request #76 from mabraham/patch-16dfb3fc

v1.2.26
14.2 KiB276 linesraw
1cmake_minimum_required(VERSION 3.11)
2project(Vulkan_FFT)
3set(CMAKE_CONFIGURATION_TYPES "Release" CACHE STRING "" FORCE)
4set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
5include(FetchContent)
6set(VKFFT_BACKEND 0 CACHE STRING "0 - Vulkan, 1 - CUDA, 2 - HIP, 3 - OpenCL, 4 - Level Zero")
7
8if(${VKFFT_BACKEND} EQUAL 1)
9	option(build_VkFFT_cuFFT_benchmark "Build VkFFT cuFFT benchmark" ON)
10else()
11	option(build_VkFFT_cuFFT_benchmark "Build VkFFT cuFFT benchmark" OFF)
12endif()
13
14if(${VKFFT_BACKEND} EQUAL 2)
15	option(build_VkFFT_rocFFT_benchmark "Build VkFFT rocFFT benchmark" ON)
16else()
17	option(build_VkFFT_rocFFT_benchmark "Build VkFFT rocFFT benchmark" OFF)
18endif()
19
20option(build_VkFFT_FFTW_precision "Build VkFFT FFTW precision comparison" OFF)
21if (MSVC)
22	set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
23	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
24endif()
25if(build_VkFFT_FFTW_precision)
26	add_executable(${PROJECT_NAME} Vulkan_FFT.cpp
27		benchmark_scripts/vkFFT_scripts/src/utils_VkFFT.cpp
28		benchmark_scripts/vkFFT_scripts/src/user_benchmark_VkFFT.cpp
29		benchmark_scripts/vkFFT_scripts/src/sample_0_benchmark_VkFFT_single.cpp
30		benchmark_scripts/vkFFT_scripts/src/sample_1_benchmark_VkFFT_double.cpp
31		benchmark_scripts/vkFFT_scripts/src/sample_2_benchmark_VkFFT_half.cpp
32		benchmark_scripts/vkFFT_scripts/src/sample_3_benchmark_VkFFT_single_3d.cpp
33		benchmark_scripts/vkFFT_scripts/src/sample_4_benchmark_VkFFT_single_3d_zeropadding.cpp
34		benchmark_scripts/vkFFT_scripts/src/sample_5_benchmark_VkFFT_single_disableReorderFourStep.cpp
35		benchmark_scripts/vkFFT_scripts/src/sample_6_benchmark_VkFFT_single_r2c.cpp
36		benchmark_scripts/vkFFT_scripts/src/sample_7_benchmark_VkFFT_single_Bluestein.cpp
37		benchmark_scripts/vkFFT_scripts/src/sample_8_benchmark_VkFFT_double_Bluestein.cpp
38		benchmark_scripts/vkFFT_scripts/src/sample_10_benchmark_VkFFT_single_multipleBuffers.cpp
39		benchmark_scripts/vkFFT_scripts/src/sample_11_precision_VkFFT_single.cpp
40		benchmark_scripts/vkFFT_scripts/src/sample_12_precision_VkFFT_double.cpp
41		benchmark_scripts/vkFFT_scripts/src/sample_13_precision_VkFFT_half.cpp
42		benchmark_scripts/vkFFT_scripts/src/sample_14_precision_VkFFT_single_nonPow2.cpp
43		benchmark_scripts/vkFFT_scripts/src/sample_15_precision_VkFFT_single_r2c.cpp
44		benchmark_scripts/vkFFT_scripts/src/sample_16_precision_VkFFT_single_dct.cpp
45		benchmark_scripts/vkFFT_scripts/src/sample_17_precision_VkFFT_double_dct.cpp
46		benchmark_scripts/vkFFT_scripts/src/sample_18_precision_VkFFT_double_nonPow2.cpp
47		benchmark_scripts/vkFFT_scripts/src/sample_50_convolution_VkFFT_single_1d_matrix.cpp
48		benchmark_scripts/vkFFT_scripts/src/sample_51_convolution_VkFFT_single_3d_matrix_zeropadding_r2c.cpp
49		benchmark_scripts/vkFFT_scripts/src/sample_52_convolution_VkFFT_single_2d_batched_r2c.cpp
50		benchmark_scripts/vkFFT_scripts/src/sample_100_benchmark_VkFFT_single_nd_dct.cpp
51		benchmark_scripts/vkFFT_scripts/src/sample_101_benchmark_VkFFT_double_nd_dct.cpp
52		benchmark_scripts/vkFFT_scripts/src/sample_1000_VkFFT_single_2_4096.cpp
53		benchmark_scripts/vkFFT_scripts/src/sample_1001_benchmark_VkFFT_double_2_4096.cpp
54		benchmark_scripts/vkFFT_scripts/src/sample_1003_benchmark_VkFFT_single_3d_2_512.cpp)
55else()		
56	add_executable(${PROJECT_NAME} Vulkan_FFT.cpp
57		benchmark_scripts/vkFFT_scripts/src/utils_VkFFT.cpp
58		benchmark_scripts/vkFFT_scripts/src/user_benchmark_VkFFT.cpp
59		benchmark_scripts/vkFFT_scripts/src/sample_0_benchmark_VkFFT_single.cpp
60		benchmark_scripts/vkFFT_scripts/src/sample_1_benchmark_VkFFT_double.cpp
61		benchmark_scripts/vkFFT_scripts/src/sample_2_benchmark_VkFFT_half.cpp
62		benchmark_scripts/vkFFT_scripts/src/sample_3_benchmark_VkFFT_single_3d.cpp
63		benchmark_scripts/vkFFT_scripts/src/sample_4_benchmark_VkFFT_single_3d_zeropadding.cpp
64		benchmark_scripts/vkFFT_scripts/src/sample_5_benchmark_VkFFT_single_disableReorderFourStep.cpp
65		benchmark_scripts/vkFFT_scripts/src/sample_6_benchmark_VkFFT_single_r2c.cpp
66		benchmark_scripts/vkFFT_scripts/src/sample_7_benchmark_VkFFT_single_Bluestein.cpp
67		benchmark_scripts/vkFFT_scripts/src/sample_8_benchmark_VkFFT_double_Bluestein.cpp
68		benchmark_scripts/vkFFT_scripts/src/sample_10_benchmark_VkFFT_single_multipleBuffers.cpp
69		benchmark_scripts/vkFFT_scripts/src/sample_50_convolution_VkFFT_single_1d_matrix.cpp
70		benchmark_scripts/vkFFT_scripts/src/sample_51_convolution_VkFFT_single_3d_matrix_zeropadding_r2c.cpp
71		benchmark_scripts/vkFFT_scripts/src/sample_52_convolution_VkFFT_single_2d_batched_r2c.cpp
72		benchmark_scripts/vkFFT_scripts/src/sample_100_benchmark_VkFFT_single_nd_dct.cpp
73		benchmark_scripts/vkFFT_scripts/src/sample_101_benchmark_VkFFT_double_nd_dct.cpp
74		benchmark_scripts/vkFFT_scripts/src/sample_1000_VkFFT_single_2_4096.cpp
75		benchmark_scripts/vkFFT_scripts/src/sample_1001_benchmark_VkFFT_double_2_4096.cpp
76		benchmark_scripts/vkFFT_scripts/src/sample_1003_benchmark_VkFFT_single_3d_2_512.cpp)
77endif()
78target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
79add_definitions(-DVKFFT_BACKEND=${VKFFT_BACKEND})
80if(${VKFFT_BACKEND} EQUAL 0)
81	find_package(Vulkan REQUIRED)
82elseif(${VKFFT_BACKEND} EQUAL 1)
83	find_package(CUDA 9.0 REQUIRED)
84	enable_language(CUDA)
85if (MSVC)
86else()
87		set_source_files_properties(Vulkan_FFT.cpp PROPERTIES LANGUAGE CUDA)
88endif()
89	set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 35 60 70 75 80 86)
90	target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:
91	-std=c++11
92	-DVKFFT_BACKEND=${VKFFT_BACKEND}
93	-gencode arch=compute_35,code=compute_35
94	-gencode arch=compute_60,code=compute_60
95	-gencode arch=compute_70,code=compute_70 
96	-gencode arch=compute_75,code=compute_75 
97	-gencode arch=compute_80,code=compute_80 
98	-gencode arch=compute_86,code=compute_86>")
99	set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
100	set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
101elseif(${VKFFT_BACKEND} EQUAL 2)
102	list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
103	find_package(hip)
104	#target_compile_definitions(${PROJECT_NAME} PUBLIC -DVKFFT_OLD_ROCM) #ROCm versions before 4.5 needed kernel include of hiprtc
105elseif(${VKFFT_BACKEND} EQUAL 3)
106	find_package(OpenCL REQUIRED)
107elseif(${VKFFT_BACKEND} EQUAL 4)
108	set(LevelZero_LIBRARY "/usr/lib/x86_64-linux-gnu/")
109	set(LevelZero_INCLUDE_DIR "/usr/include/")
110	find_library(
111		LevelZero_LIB
112		NAMES "ze_loader"
113		PATHS ${LevelZero_LIBRARY}
114		PATH_SUFFIXES "lib" "lib64"
115		NO_DEFAULT_PATH
116	  )
117	find_path(
118		LevelZero_INCLUDES
119		NAMES "ze_api.h"
120		PATHS ${LevelZero_INCLUDE_DIR}
121		PATH_SUFFIXES "include" 
122		NO_DEFAULT_PATH
123	  )
124	target_include_directories(${PROJECT_NAME} PUBLIC ${LevelZero_INCLUDES})
125endif()
126
127target_compile_definitions(${PROJECT_NAME} PUBLIC -DVK_API_VERSION=11)#10 - Vulkan 1.0, 11 - Vulkan 1.1, 12 - Vulkan 1.2 
128if(${VKFFT_BACKEND} EQUAL 0)
129	FetchContent_Declare(
130		glslang-master
131		GIT_REPOSITORY https://github.com/KhronosGroup/glslang
132		SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glslang-master
133	)
134	FetchContent_GetProperties(glslang-master)
135	if(NOT glslang-master_POPULATED)
136		FetchContent_Populate(glslang-master)
137	endif()
138	target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/glslang-master/glslang/Include/)
139	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glslang-master)
140endif()
141
142target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vkFFT/)
143add_library(VkFFT INTERFACE)
144target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=${VKFFT_BACKEND})
145
146target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/half_lib/)
147add_library(half INTERFACE)
148
149target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_scripts/vkFFT_scripts/include/)
150
151if(${VKFFT_BACKEND} EQUAL 0)
152	target_link_libraries(${PROJECT_NAME} PUBLIC SPIRV glslang Vulkan::Vulkan VkFFT half)
153elseif(${VKFFT_BACKEND} EQUAL 1)
154	find_library(CUDA_NVRTC_LIB libnvrtc nvrtc HINTS "${CUDA_TOOLKIT_ROOT_DIR}/lib64" "${LIBNVRTC_LIBRARY_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" /usr/lib64 /usr/local/cuda/lib64)
155	target_link_libraries(${PROJECT_NAME} PUBLIC ${CUDA_LIBRARIES} cuda ${CUDA_NVRTC_LIB} VkFFT half)
156elseif(${VKFFT_BACKEND} EQUAL 2)
157	target_link_libraries(${PROJECT_NAME} PUBLIC hip::host VkFFT half)
158elseif(${VKFFT_BACKEND} EQUAL 3)
159	target_link_libraries(${PROJECT_NAME} PUBLIC OpenCL::OpenCL VkFFT half)
160elseif(${VKFFT_BACKEND} EQUAL 4)
161	target_link_libraries(${PROJECT_NAME} PUBLIC ze_loader VkFFT half)
162endif()
163
164if(build_VkFFT_FFTW_precision)
165	add_definitions(-DUSE_FFTW)
166	set(FFTW3_LIB_DIR "/usr/lib/x86_64-linux-gnu/")
167	set(FFTW3_INCLUDE_DIR "/usr/include/")
168	find_library(
169		FFTW_LIB
170		NAMES "libfftw3-3" "fftw3"
171		PATHS ${FFTW3_LIB_DIR}
172		PATH_SUFFIXES "lib" "lib64"
173		NO_DEFAULT_PATH
174	  )
175	find_path(
176		FFTW_INCLUDES
177		NAMES "fftw3.h"
178		PATHS ${FFTW3_INCLUDE_DIR}
179		PATH_SUFFIXES "include"
180		NO_DEFAULT_PATH
181	  )
182	
183	target_link_libraries (${PROJECT_NAME} PUBLIC ${FFTW_LIB})
184	target_include_directories(${PROJECT_NAME} PUBLIC ${FFTW_INCLUDES})
185endif()
186
187if(build_VkFFT_cuFFT_benchmark)
188	add_definitions(-DUSE_cuFFT)
189	find_package(CUDA 9.0 REQUIRED)
190	enable_language(CUDA)	
191	if(build_VkFFT_FFTW_precision)
192		add_library(cuFFT_scripts STATIC
193		benchmark_scripts/cuFFT_scripts/src/user_benchmark_cuFFT.cu
194		benchmark_scripts/cuFFT_scripts/src/sample_0_benchmark_cuFFT_single.cu
195		benchmark_scripts/cuFFT_scripts/src/sample_1_benchmark_cuFFT_double.cu
196		benchmark_scripts/cuFFT_scripts/src/sample_2_benchmark_cuFFT_half.cu
197		benchmark_scripts/cuFFT_scripts/src/sample_3_benchmark_cuFFT_single_3d.cu
198		benchmark_scripts/cuFFT_scripts/src/sample_6_benchmark_cuFFT_single_r2c.cu
199		benchmark_scripts/cuFFT_scripts/src/sample_7_benchmark_cuFFT_single_Bluestein.cu
200		benchmark_scripts/cuFFT_scripts/src/sample_8_benchmark_cuFFT_double_Bluestein.cu
201		benchmark_scripts/cuFFT_scripts/src/sample_1000_benchmark_cuFFT_single_2_4096.cu
202		benchmark_scripts/cuFFT_scripts/src/sample_1001_benchmark_cuFFT_double_2_4096.cu
203		benchmark_scripts/cuFFT_scripts/src/sample_1003_benchmark_cuFFT_single_3d_2_512.cu
204		benchmark_scripts/cuFFT_scripts/src/precision_cuFFT_single.cu
205		benchmark_scripts/cuFFT_scripts/src/precision_cuFFT_r2c.cu
206		benchmark_scripts/cuFFT_scripts/src/precision_cuFFT_double.cu
207		benchmark_scripts/cuFFT_scripts/src/precision_cuFFT_half.cu)
208	else()
209		add_library(cuFFT_scripts STATIC
210		benchmark_scripts/cuFFT_scripts/src/user_benchmark_cuFFT.cu
211		benchmark_scripts/cuFFT_scripts/src/sample_0_benchmark_cuFFT_single.cu
212		benchmark_scripts/cuFFT_scripts/src/sample_1_benchmark_cuFFT_double.cu
213		benchmark_scripts/cuFFT_scripts/src/sample_2_benchmark_cuFFT_half.cu
214		benchmark_scripts/cuFFT_scripts/src/sample_3_benchmark_cuFFT_single_3d.cu
215		benchmark_scripts/cuFFT_scripts/src/sample_6_benchmark_cuFFT_single_r2c.cu
216		benchmark_scripts/cuFFT_scripts/src/sample_7_benchmark_cuFFT_single_Bluestein.cu
217		benchmark_scripts/cuFFT_scripts/src/sample_8_benchmark_cuFFT_double_Bluestein.cu
218		benchmark_scripts/cuFFT_scripts/src/sample_1000_benchmark_cuFFT_single_2_4096.cu
219		benchmark_scripts/cuFFT_scripts/src/sample_1001_benchmark_cuFFT_double_2_4096.cu
220		benchmark_scripts/cuFFT_scripts/src/sample_1003_benchmark_cuFFT_single_3d_2_512.cu)
221	endif()
222	set_property(TARGET cuFFT_scripts PROPERTY CUDA_ARCHITECTURES 35 60 70 75 80 86)
223	CUDA_ADD_CUFFT_TO_TARGET(cuFFT_scripts)
224	target_compile_options(cuFFT_scripts PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:
225	-std=c++11
226	-gencode arch=compute_35,code=compute_35
227	-gencode arch=compute_60,code=compute_60
228	-gencode arch=compute_70,code=compute_70 
229	-gencode arch=compute_75,code=compute_75 
230	-gencode arch=compute_80,code=compute_80 
231	-gencode arch=compute_86,code=compute_86>")
232	target_include_directories(cuFFT_scripts PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_scripts/cuFFT_scripts/include)
233	set_target_properties(cuFFT_scripts PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
234	set_target_properties(cuFFT_scripts PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
235	target_link_libraries(${PROJECT_NAME} PUBLIC cuFFT_scripts)
236endif()
237if(build_VkFFT_rocFFT_benchmark)
238	add_definitions(-DUSE_rocFFT)
239	list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm)
240	find_package(hip)
241    find_package(hipfft)
242
243	if(build_VkFFT_FFTW_precision)
244		add_library(rocFFT_scripts STATIC
245		benchmark_scripts/rocFFT_scripts/src/user_benchmark_rocFFT.cpp
246		benchmark_scripts/rocFFT_scripts/src/sample_0_benchmark_rocFFT_single.cpp
247		benchmark_scripts/rocFFT_scripts/src/sample_1_benchmark_rocFFT_double.cpp
248		benchmark_scripts/rocFFT_scripts/src/sample_3_benchmark_rocFFT_single_3d.cpp
249		benchmark_scripts/rocFFT_scripts/src/sample_6_benchmark_rocFFT_single_r2c.cpp
250		benchmark_scripts/rocFFT_scripts/src/sample_7_benchmark_rocFFT_single_Bluestein.cpp
251		benchmark_scripts/rocFFT_scripts/src/sample_8_benchmark_rocFFT_double_Bluestein.cpp
252		benchmark_scripts/rocFFT_scripts/src/sample_1000_benchmark_rocFFT_single_2_4096.cpp
253		benchmark_scripts/rocFFT_scripts/src/sample_1001_benchmark_rocFFT_double_2_4096.cpp
254		benchmark_scripts/rocFFT_scripts/src/sample_1003_benchmark_rocFFT_single_3d_2_512.cpp
255		benchmark_scripts/rocFFT_scripts/src/precision_rocFFT_single.cpp
256		benchmark_scripts/rocFFT_scripts/src/precision_rocFFT_r2c.cpp
257		benchmark_scripts/rocFFT_scripts/src/precision_rocFFT_double.cpp)
258	else()
259		add_library(rocFFT_scripts STATIC
260		benchmark_scripts/rocFFT_scripts/src/user_benchmark_rocFFT.cpp
261		benchmark_scripts/rocFFT_scripts/src/sample_0_benchmark_rocFFT_single.cpp
262		benchmark_scripts/rocFFT_scripts/src/sample_1_benchmark_rocFFT_double.cpp
263		benchmark_scripts/rocFFT_scripts/src/sample_3_benchmark_rocFFT_single_3d.cpp
264		benchmark_scripts/rocFFT_scripts/src/sample_6_benchmark_rocFFT_single_r2c.cpp
265		benchmark_scripts/rocFFT_scripts/src/sample_7_benchmark_rocFFT_single_Bluestein.cpp
266		benchmark_scripts/rocFFT_scripts/src/sample_8_benchmark_rocFFT_double_Bluestein.cpp
267		benchmark_scripts/rocFFT_scripts/src/sample_1000_benchmark_rocFFT_single_2_4096.cpp
268		benchmark_scripts/rocFFT_scripts/src/sample_1001_benchmark_rocFFT_double_2_4096.cpp
269		benchmark_scripts/rocFFT_scripts/src/sample_1003_benchmark_rocFFT_single_3d_2_512.cpp)
270	endif()
271	target_include_directories(rocFFT_scripts PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_scripts/rocFFT_scripts/include)
272	target_link_libraries(rocFFT_scripts PRIVATE hip::host hip::hipfft)
273	target_link_libraries(${PROJECT_NAME} PUBLIC rocFFT_scripts)
274endif()
275install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/vkFFT/vkFFT.h" DESTINATION include)
276install(TARGETS ${PROJECT_NAME} DESTINATION bin)