fft.cl 952 Bytes
Newer Older
Peter Eastman's avatar
Peter Eastman committed
1
2
3
4
5
6
7
8
float2 multiplyComplex(float2 c1, float2 c2) {
    return (float2) (c1.x*c2.x-c1.y*c2.y, c1.x*c2.y+c1.y*c2.x);
}

/**
 * Perform a 1D FFT on each row along one axis.
 */

Peter Eastman's avatar
Peter Eastman committed
9
10
11
__kernel void execFFT(__global float2* in, __global float2* out, float sign, __local float2* w, __local float2* data0, __local float2* data1) {
    for (int i = get_local_id(0); i < ZSIZE; i += get_local_size(0))
        w[i] = (float2) (cos(-sign*i*2*M_PI/ZSIZE), sin(-sign*i*2*M_PI/ZSIZE));
12
    barrier(CLK_LOCAL_MEM_FENCE);
Peter Eastman's avatar
Peter Eastman committed
13
14
15
16
17
18
19
20
21
    for (int index = get_group_id(0); index < XSIZE*YSIZE; index += get_num_groups(0)) {
        int x = index/YSIZE;
        int y = index-x*YSIZE;
#ifdef LOOP_REQUIRED
        for (int z = get_local_id(0); z < ZSIZE; z += get_local_size(0))
            data0[z] = in[x*(YSIZE*ZSIZE)+y*ZSIZE+z];
#else
        data0[get_local_id(0)] = in[x*(YSIZE*ZSIZE)+y*ZSIZE+get_local_id(0)];
#endif
Peter Eastman's avatar
Peter Eastman committed
22
23
24
        barrier(CLK_LOCAL_MEM_FENCE);
        COMPUTE_FFT
    }
Peter Eastman's avatar
Peter Eastman committed
25
}