yum/gpu_fft

A GPU-friendly FFT

git clone https://git.yummers.dev/yum/gpu_fft

yumNaive DFT now respects workgroup sized144a07

master
841 B33 linesraw
1[[vk::binding(0, 0)]]
2StructuredBuffer<float2> input;
3
4[[vk::binding(1, 0)]]
5RWStructuredBuffer<float2> output;
6
7#define PI 3.1415926535897932384626433832795028841971f
8#define TAU 6.283185307179586476925286766559005768394f
9
10[shader("compute")]
11[numthreads(256, 1, 1)]
12void brute_force_dft(uint3 globalId : SV_DispatchThreadID)
13{
14
15    uint input_len, input_stride;
16    input.GetDimensions(input_len, input_stride);
17
18    const float k = globalId.x;
19    const float N = input_len;
20
21    float phase_base = -TAU * k / N;
22    float2 result = float2(0, 0);
23    for (uint n = 0; n < input_len; n++)
24    {
25        float phase = phase_base * n;
26        float re, im;
27        sincos(phase, im, re);
28        float2 x_n = input[n];
29        result += float2(x_n[0] * re - x_n[1] * im, x_n[0] * im + x_n[1] * re);
30    }
31
32    output[globalId.x] = result;
33}