Skip to content

Commit

Permalink
Merge pull request #1779 from srcejon/fix_1166
Browse files Browse the repository at this point in the history
GPU FFT and simple profiler
  • Loading branch information
f4exb authored Aug 15, 2023
2 parents b7de8b8 + d5268ec commit 21b24c8
Show file tree
Hide file tree
Showing 38 changed files with 2,454 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ option(BUNDLE "Enable distribution bundle" OFF)
set(ARCH_OPT "native" CACHE STRING "Specify instruction set to use. Will be passed directly as `-march` or `/arch:` argument on supported compilers. \
'native' option will figure out host machine compatibilities and set flags accordingly (even with MSVC).")
option(ENABLE_QT6 "Build with Qt6 rather than Qt5" OFF)
option(ENABLE_PROFILER "Enable runtime profiler" OFF)
set(VKFFT_BACKEND 1 CACHE STRING "vkFFT Backend: 0 - Vulkan, 1 - CUDA")

# Sampling devices enablers
option(ENABLE_AIRSPY "Enable AirSpy support" ON)
Expand Down Expand Up @@ -574,6 +576,10 @@ else()
message(STATUS "Compiling for 16 bit Rx DSP chain")
endif()

if (ENABLE_PROFILER)
add_compile_definitions(ENABLE_PROFILER)
endif()

# Set compiler options based on target architecture and selected extensions
include(CompilerOptions)

Expand Down
19 changes: 18 additions & 1 deletion cmake/cpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ elseif(WIN32 OR MINGW)
)
endforeach(libsigmf_dll)

if(${VKFFT_BACKEND} EQUAL 1)
find_package(CUDA)
if(CUDA_FOUND)
file(GLOB CUDA_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvrtc*${CMAKE_SHARED_LIBRARY_SUFFIX}")
foreach(cuda_dll ${CUDA_DLLS})
get_filename_component(cuda_dll_name "${cuda_dll}" NAME)
add_custom_target(copy_cuda_${cuda_dll_name} ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${cuda_dll}" "${SDRANGEL_BINARY_BIN_DIR}/"
)
endforeach(cuda_dll)
endif()
endif()

# TODO we need a way to fixup_bundle() on the build bin/ directory without call install
if(BUILD_GUI)
install(CODE "
Expand Down Expand Up @@ -295,7 +308,11 @@ elseif(WIN32 OR MINGW)
# libsigmf
install(DIRECTORY "${LIBSIGMF_DLL_DIR}/" DESTINATION "${INSTALL_LIB_DIR}"
FILES_MATCHING PATTERN "*${CMAKE_SHARED_LIBRARY_SUFFIX}")

# CUDA runtime
if((${VKFFT_BACKEND} EQUAL 1) AND CUDA_FOUND)
install(DIRECTORY "${CUDA_TOOLKIT_ROOT_DIR}/bin/" DESTINATION "${INSTALL_LIB_DIR}"
FILES_MATCHING PATTERN "nvrtc*${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()

install(CODE "
# remove *.lib files
Expand Down
14 changes: 14 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,20 @@ if(ENABLE_FEATURE_SATELLITETRACKER OR ENABLE_CHANNELRX_DEMODAPT)
endif ()
endif ()

# VkFFT (header only library)
ExternalProject_Add(vkfft
GIT_REPOSITORY https://github.com/DTolm/VkFFT.git
GIT_TAG v1.3.1
PREFIX "${EXTERNAL_BUILD_LIBRARIES}/vkfft"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
BUILD_BYPRODUCTS ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
ExternalProject_Get_Property(vkfft source_dir)
set(VKFFT_INCLUDE_DIR "${source_dir}/vkFFT" CACHE INTERNAL "")

# requirements needed by many packages on windows
if (WIN32)
ExternalProject_Add(pthreads4w
Expand Down
148 changes: 139 additions & 9 deletions sdrbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,61 @@ if(FFTW3F_FOUND)
add_definitions(-DUSE_FFTW)
include_directories(${FFTW3F_INCLUDE_DIRS})
set(sdrbase_FFTW3F_LIB ${FFTW3F_LIBRARIES})
else(FFTW3F_FOUND)
endif(FFTW3F_FOUND)

# Kiss FFT is always available
set(sdrbase_SOURCES
${sdrbase_SOURCES}
dsp/kissengine.cpp
dsp/kissfft.h
)
set(sdrbase_HEADERS
${sdrbase_HEADERS}
dsp/kissengine.h
)
add_definitions(-DUSE_KISSFFT)

# Vulkan SDK: https://vulkan.lunarg.com/
# Windows Vulkan SDK is missing glslang_c_interface.h
# See bug: https://vulkan.lunarg.com/issue/view/63d158a85df11200d569b2ab
# Copy it from Linux SDK
if (${VKFFT_BACKEND} EQUAL 0)
find_package(Vulkan)
if(Vulkan_FOUND)
set(sdrbase_SOURCES
${sdrbase_SOURCES}
dsp/vulkanvkfftengine.cpp
dsp/vulkanvkfftengine.h
)
endif()
endif()

# CUDA Toolkit: https://developer.nvidia.com/cuda-downloads
if (${VKFFT_BACKEND} EQUAL 1)
find_package(CUDA 9.0)
if(CUDA_FOUND)
enable_language(CUDA)
set(sdrbase_SOURCES
${sdrbase_SOURCES}
dsp/cudavkfftengine.cpp
dsp/cudavkfftengine.h
)
endif()
if(WIN32)
set(WINDOWS_FIXUP_BUNDLE_LIB_DIRS ${WINDOWS_FIXUP_BUNDLE_LIB_DIRS} ${CUDA_TOOLKIT_ROOT_DIR}/bin PARENT_SCOPE)
endif()
endif()

if((Vulkan_FOUND AND (${VKFFT_BACKEND} EQUAL 0)) OR (CUDA_FOUND AND (${VKFFT_BACKEND} EQUAL 1)))
set(sdrbase_SOURCES
${sdrbase_SOURCES}
dsp/kissengine.cpp
dsp/kissfft.h
)
set(sdrbase_HEADERS
${sdrbase_HEADERS}
dsp/kissengine.h
dsp/vkfftengine.cpp
dsp/vkfftengine.h
dsp/vkfftutils.cpp
dsp/vkfftutils.h
)
add_definitions(-DUSE_KISSFFT)
endif(FFTW3F_FOUND)
include_directories(${VKFFT_INCLUDE_DIR})
endif()

if (LIBSIGMF_FOUND)
set(sdrbase_SOURCES
Expand Down Expand Up @@ -207,6 +250,7 @@ set(sdrbase_SOURCES
util/planespotters.cpp
util/png.cpp
util/prettyprint.cpp
util/profiler.cpp
util/radiosonde.cpp
util/rtpsink.cpp
util/syncmessenger.cpp
Expand Down Expand Up @@ -442,6 +486,7 @@ set(sdrbase_HEADERS
util/planespotters.h
util/png.h
util/prettyprint.h
util/profiler.h
util/radiosonde.h
util/rtpsink.h
util/syncmessenger.h
Expand Down Expand Up @@ -507,6 +552,91 @@ if(DEFINED LIBSIGMF_DEPENDS)
add_dependencies(sdrbase "${LIBSIGMF_DEPENDS}")
endif()

if(Vulkan_FOUND AND (${VKFFT_BACKEND} EQUAL 0))
target_compile_definitions(sdrbase PUBLIC -DVK_API_VERSION=11)
target_include_directories(sdrbase PUBLIC ${Vulkan_INCLUDE_DIR} ${Vulkan_INCLUDE_DIR}/glslang/Include)
add_compile_definitions(sdrbase VKFFT_BACKEND=0)

find_library(VULKAN_SPIRV_LIB SPIRV HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPVREMAPPER_LIB SPVRemapper HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPIRV_TOOLS_LIB SPIRV-Tools HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPIRV_TOOLS_OPT_LIB SPIRV-Tools-opt HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPIRV_TOOLS_SHARED_LIB SPIRV-Tools-shared HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_HLSL_LIB HLSL HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_OGLCOMPILER_LIB OGLCompiler HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_OSDEPENDENT_LIB OSDependent HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_GLSLANG_LIB glslang HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_GLSLANG_RES_LIB glslang-default-resource-limits HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_MACHINEINDEPENDENT_LIB MachineIndependent HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_GENERICCODEGEN_LIB GenericCodeGen HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)

if(MSVC)
set(VULKAN_DEBUG_POSTFIX "d")
else()
set(VULKAN_DEBUG_POSTFIX "")
endif()
find_library(VULKAN_SPIRVD_LIB SPIRV${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPVREMAPPERD_LIB SPVRemapper${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPIRV_TOOLSD_LIB SPIRV-Tools${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPIRV_TOOLS_OPTD_LIB SPIRV-Tools-opt${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_SPIRV_TOOLS_SHAREDD_LIB SPIRV-Tools-shared${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_HLSLD_LIB HLSL${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_OGLCOMPILERD_LIB OGLCompiler${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_OSDEPENDENTD_LIB OSDependent${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_GLSLANGD_LIB glslang${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_GLSLANG_RESD_LIB glslang-default-resource-limits${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_MACHINEINDEPENDENTD_LIB MachineIndependent${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
find_library(VULKAN_GENERICCODEGEND_LIB GenericCodeGen${VULKAN_DEBUG_POSTFIX} HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)

target_link_libraries(sdrbase
optimized ${VULKAN_SPIRV_LIB}
optimized ${VULKAN_SPVREMAPPER_LIB}
optimized ${VULKAN_SPIRV_TOOLS_LIB}
optimized ${VULKAN_SPIRV_TOOLS_OPT_LIB}
optimized ${VULKAN_SPIRV_TOOLS_SHARED_LIB}
optimized ${VULKAN_HLSL_LIB}
optimized ${VULKAN_OGLCOMPILER_LIB}
optimized ${VULKAN_OSDEPENDENT_LIB}
optimized ${VULKAN_GLSLANG_LIB}
optimized ${VULKAN_GLSLANG_RES_LIB}
optimized ${VULKAN_MACHINEINDEPENDENT_LIB}
optimized ${VULKAN_GENERICCODEGEN_LIB}
optimized Vulkan::Vulkan
debug ${VULKAN_SPIRVD_LIB}
debug ${VULKAN_SPVREMAPPERD_LIB}
debug ${VULKAN_SPIRV_TOOLSD_LIB}
debug ${VULKAN_SPIRV_TOOLS_OPTD_LIB}
debug ${VULKAN_SPIRV_TOOLS_SHAREDD_LIB}
debug ${VULKAN_HLSLD_LIB}
debug ${VULKAN_OGLCOMPILERD_LIB}
debug ${VULKAN_OSDEPENDENTD_LIB}
debug ${VULKAN_GLSLANGD_LIB}
debug ${VULKAN_GLSLANG_RESD_LIB}
debug ${VULKAN_MACHINEINDEPENDENTD_LIB}
debug ${VULKAN_GENERICCODEGEND_LIB}
debug Vulkan::Vulkan
)
endif()

if(CUDA_FOUND AND (${VKFFT_BACKEND} EQUAL 1))
set_property(TARGET sdrbase PROPERTY CUDA_ARCHITECTURES 60 70 75 80 86)
add_compile_definitions(sdrbase VKFFT_BACKEND=1)
target_compile_options(sdrbase PUBLIC
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:
-DVKFFT_BACKEND=1
-gencode arch=compute_60,code=compute_60
-gencode arch=compute_70,code=compute_70
-gencode arch=compute_75,code=compute_75
-gencode arch=compute_80,code=compute_80
-gencode arch=compute_86,code=compute_86>")
set_target_properties(sdrbase PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(sdrbase PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
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 REQUIRED)
find_library(CUDA_LIB cuda HINTS "${CUDA_TOOLKIT_ROOT_DIR}/lib64" "${LIBNVRTC_LIBRARY_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" /usr/lib64 /usr/local/cuda/lib64 REQUIRED)
target_link_libraries(sdrbase ${CUDA_LIBRARIES} ${CUDA_LIB} ${CUDA_NVRTC_LIB})
target_include_directories(sdrbase PUBLIC ${CUDA_INCLUDE_DIRS})
endif()

target_link_libraries(sdrbase
${OPUS_LIBRARIES}
${sdrbase_FFTW3F_LIB}
Expand Down
Loading

0 comments on commit 21b24c8

Please sign in to comment.