Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU FFT and simple profiler #1779

Merged
merged 4 commits into from
Aug 15, 2023
Merged

GPU FFT and simple profiler #1779

merged 4 commits into from
Aug 15, 2023

Conversation

srcejon
Copy link
Collaborator

@srcejon srcejon commented Aug 14, 2023

This PR adds support for running FFT on GPU using the VkFFT library, with either Vulkan or CUDA backend, as per #1166

To allow easier performance comparisons, I have updated the FFTEngine and FFTFactory class to support multiple simultaneous FFTEngines, so a user can switch between FFTW, Kiss and VkFFT at run-time via a GUI option (Preferences > FFT). Also, different bits of SDRangel can request different FFTEngines. So FFTW could be used generally, but a specific plugin could request VkFFT if it thinks it will benefit from it.

I have also added a simple profiler, that displays average execution time in a dialog (View > Profile Data...). Profiling is enabled via the cmake -DENABLE_PROFILER=ON option. It is disabled by default, and when disabled, there should be no performance impact as the profiling code is not included in the executable. It can also be used to easily profile other parts of SDRangel - here showing GL spectrum draw time, as well as FFT. To profille some code, you just need to stick the PROFILE_START() and PROFILE_STOP("name") macros around the code.

image

Whether VkFFT uses Vulkan or CUDA is a cmake option, -DVKFFT_BACKEND=0 for Vulkan and -DVKFFT_BACKEND=1 for CUDA. The code should compile without VkFFT if neither the Vulkan or CUDA SDKs are available.

On Windows, VkFFT is automatically downloaded as an external project. If external project is off, then it can be downloaded with:

cd /opt/build
git clone https://github.com/DTolm/VkFFT.git
cd VkFFT
git checkout v1.3.1

It's a header only library, so doesn't need to be built.

Either the Vulkan or CUDA SDKs need to be installed to compile it:

Linux Vulkan Setup

cd /opt/install
mkdir -p vulkansdk
cd vulkansdk
wget https://vulkan.lunarg.com/sdk/download/1.3.250.1/linux/vulkansdk-linux-x86_64-1.3.250.1.tar.gz
tar xf vulkansdk-linux-x86_64-1.3.250.1.tar.gz
source /opt/install/vulkansdk/1.3.250.1/setup-env.sh
...
cmake -DVKFFT_INCLUDE_DIR=/opt/build/VkFFT/vkFFT/ -DVKFFT_BACKEND=0 ..

Linux CUDA setup

Install CUDA toolkit from https://developer.nvidia.com/cuda-downloads
export PATH=/usr/local/cuda/bin:%PATH
...
cmake -DVKFFT_INCLUDE_DIR=/opt/build/VkFFT/vkFFT/ -DVKFFT_BACKEND=1 ..

Windows Vulkan Setup

Install Vulkan SDK (With optional 64-bit Debug libraries) from https://vulkan.lunarg.com/sdk/home#windows
Copy include\glslang\Include\glslang_c_interface. and include\glslang\Include\glslang_c_shader_types.h from Linux SDK as they are missing (See https://vulkan.lunarg.com/issue/view/63d158a85df11200d569b2ab)
set VULKAN_SDK=C:\VulkanSDK\1.3.250.1  (or where ever you installed it)
cmake -DVKFFT_BACKEND=0 ..

Windows CUDA Setup

Install CUDA toolkit from https://developer.nvidia.com/cuda-downloads (This creates CUDA_PATH environment variable)
cmake -DVKFFT_BACKEND=1 ..

Unfortunately, on my PCs, using the GPU (via either Vulkan or CUDA) is much slower than using FFTW, due to the overhead of getting the data from the CPU to the GPU. It may be more beneficial on embedded SoCs that have unified memory and relatively slower CPUs, but haven't tried. To get better performance, we'd probably need to submit FFTs in batches, rather than one at a time (or do additional processing on the GPU). So there's no reason to try to enable this in the release builds now, but it's the first step towards GPU support.

@f4exb
Copy link
Owner

f4exb commented Aug 15, 2023

To get better performance, we'd probably need to submit FFTs in batches, rather than one at a time (or do additional processing on the GPU)

The problem in this case is that the rendering will probably be sketchy. It may be more beneficial to processes using FFT heavily in the background.

@f4exb f4exb merged commit 21b24c8 into f4exb:master Aug 15, 2023
1 check passed
@RobRich999
Copy link

RobRich999 commented Aug 16, 2023

Just rolled an updated local build. I will probably look into profiling actual performance later, but for now according to mesa debugging info, VkFFT Vulkan under SDRangel appears to be working okay on my Kubuntu 23.04 system with AMDPU and RADV.

AMD 5700u processor here, so AMD Vega GPU with 8 CUs.

Thanks to the project devs for the feature and support. :)

@savagesmc
Copy link

Thank you for adding this feature!

@srcejon
Copy link
Collaborator Author

srcejon commented Aug 17, 2023

I wouldn't get too excited - it seems to be much slower than using the CPU!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants