From: Alexander Karsakov Date: Tue, 22 Jul 2014 07:24:19 +0000 (+0400) Subject: Added rest Elena's changes X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3095^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52f76a32838019b4eb8e3f889dd25623a5983c74;p=platform%2Fupstream%2Fopencv.git Added rest Elena's changes --- diff --git a/modules/core/perf/opencl/perf_dxt.cpp b/modules/core/perf/opencl/perf_dxt.cpp index f4b6b49..797b2c5 100644 --- a/modules/core/perf/opencl/perf_dxt.cpp +++ b/modules/core/perf/opencl/perf_dxt.cpp @@ -65,10 +65,10 @@ enum OCL_FFT_TYPE typedef tuple DftParams; typedef TestBaseWithParam DftFixture; -OCL_PERF_TEST_P(DftFixture, Dft, ::testing::Combine(Values(C2C/*, R2R, C2R, R2C*/), +OCL_PERF_TEST_P(DftFixture, Dft, ::testing::Combine(Values(C2C, R2R, C2R, R2C), Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3, Size(1024, 1024), Size(512, 512), Size(2048, 2048)), - Values((int) 0, (int)DFT_ROWS, (int)DFT_SCALE, (int)DFT_INVERSE, - /*(int)DFT_INVERSE | DFT_SCALE,*/ (int)DFT_ROWS | DFT_INVERSE))) + Values((int) 0, (int)DFT_ROWS, (int)DFT_SCALE/*, (int)DFT_INVERSE, + (int)DFT_INVERSE | DFT_SCALE, (int)DFT_ROWS | DFT_INVERSE*/))) { const DftParams params = GetParam(); const int dft_type = get<0>(params); diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index d5b1cb3..eaef53a 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -1791,14 +1791,6 @@ namespace cv { CV_Assert(s == CLFFT_SUCCESS); \ } -enum FftType -{ - R2R = 0, // real to real - C2R = 1, // opencl HERMITIAN_INTERLEAVED to real - R2C = 2, // real to opencl HERMITIAN_INTERLEAVED - C2C = 3 // complex to complex -}; - class PlanCache { struct FftPlan @@ -2034,6 +2026,14 @@ namespace cv #ifdef HAVE_OPENCL +enum FftType +{ + R2R = 0, + C2R = 1, + R2C = 2, + C2C = 3 +}; + static std::vector ocl_getRadixes(int cols, std::vector& radixes, std::vector& blocks, int& min_radix) { int factors[34]; @@ -2054,13 +2054,19 @@ static std::vector ocl_getRadixes(int cols, std::vector& radixes, std: else if (4*n <= factors[0]) { radix = 4; - if (cols % 8 == 0) + if (cols % 12 == 0) + block = 3; + else if (cols % 8 == 0) block = 2; } else { - if (cols % 8 == 0) + if (cols % 10 == 0) + block = 5; + else if (cols % 8 == 0) block = 4; + else if (cols % 6 == 0) + block = 3; else if (cols % 4 == 0) block = 2; } @@ -2081,6 +2087,8 @@ static std::vector ocl_getRadixes(int cols, std::vector& radixes, std: { if (cols % 12 == 0) block = 4; + else if (cols % 9 == 0) + block = 3; else if (cols % 6 == 0) block = 2; } @@ -2142,7 +2150,6 @@ struct OCL_FftPlan { int radix = radixes[i]; n *= radix; - for (int j=1; j planStorage; }; -static bool ocl_dft_C2C_rows(InputArray _src, OutputArray _dst, int nonzero_rows, int flags) +static bool ocl_dft_C2C_rows(InputArray _src, OutputArray _dst, int nonzero_rows, int flags, int fftType) { const OCL_FftPlan* plan = OCL_FftPlanCache::getInstance().getFftPlan(_src.cols(), flags); - return plan->enqueueTransform(_src, _dst, nonzero_rows, flags, true); + return plan->enqueueTransform(_src, _dst, nonzero_rows, flags, fftType, true); } -static bool ocl_dft_C2C_cols(InputArray _src, OutputArray _dst, int nonzero_cols, int flags) +static bool ocl_dft_C2C_cols(InputArray _src, OutputArray _dst, int nonzero_cols, int flags, int fftType) { const OCL_FftPlan* plan = OCL_FftPlanCache::getInstance().getFftPlan(_src.rows(), flags); - return plan->enqueueTransform(_src, _dst, nonzero_cols, flags, false); + return plan->enqueueTransform(_src, _dst, nonzero_cols, flags, fftType, false); } static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_rows) @@ -2298,29 +2318,26 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro complex_output = 1; } + FftType fftType = (FftType)(complex_input << 0 | complex_output << 1); + // Forward Complex to CCS not supported - if (complex_input && real_output && !inv) - { - flags ^= DFT_REAL_OUTPUT; - flags |= DFT_COMPLEX_OUTPUT; - real_output = 0; - complex_output = 1; - } + if (fftType == C2R && !inv) + fftType = C2C; + // Inverse CCS to Complex not supported - if (real_input && complex_output && inv) - { - complex_output = 0; - real_output = 1; - } + if (fftType == R2C && inv) + fftType = R2R; UMat output; - if (complex_output) + if (fftType == C2C || fftType == R2C) { + // complex output _dst.create(src.size(), CV_32FC2); output = _dst.getUMat(); - } + } else { + // real output if (is1d) { _dst.create(src.size(), CV_32FC1); @@ -2333,17 +2350,49 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro } } - if (!ocl_dft_C2C_rows(src, output, nonzero_rows, flags)) - return false; - - if (!is1d) + if (!inv) { - int nonzero_cols = real_input && real_output ? output.cols/2 + 1 : output.cols; - if (!ocl_dft_C2C_cols(output, _dst, nonzero_cols, flags)) + if (!ocl_dft_C2C_rows(src, output, nonzero_rows, flags, fftType)) return false; - } else + + if (!is1d) + { + int nonzero_cols = fftType == R2R ? output.cols/2 + 1 : output.cols; + if (!ocl_dft_C2C_cols(output, _dst, nonzero_cols, flags, fftType)) + return false; + } + } + else { - _dst.assign(output); + if (fftType == C2C) + { + // complex output + if (!ocl_dft_C2C_rows(src, output, nonzero_rows, flags, fftType)) + return false; + + if (!is1d) + { + if (!ocl_dft_C2C_cols(output, output, output.cols, flags, fftType)) + return false; + } + } + else + { + if (is1d) + { + if (!ocl_dft_C2C_rows(src, output, nonzero_rows, flags, fftType)) + return false; + } + else + { + int nonzero_cols = src.cols/2 + 1;// : src.cols; + if (!ocl_dft_C2C_cols(src, output, nonzero_cols, flags, fftType)) + return false; + + if (!ocl_dft_C2C_rows(output, _dst, nonzero_rows, flags, fftType)) + return false; + } + } } return true; } diff --git a/modules/core/src/opencl/fft.cl b/modules/core/src/opencl/fft.cl index fdbad19..dd8ff59 100644 --- a/modules/core/src/opencl/fft.cl +++ b/modules/core/src/opencl/fft.cl @@ -16,106 +16,224 @@ float2 twiddle(float2 a) { } __attribute__((always_inline)) -void fft_radix2(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void butterfly2(float2 a0, float2 a1, __local float2* smem, __constant const float2* twiddles, + const int x, const int block_size) +{ + const int k = x & (block_size - 1); + a1 = mul_float2(twiddles[k], a1); + const int dst_ind = (x << 1) - k; + + smem[dst_ind] = a0 + a1; + smem[dst_ind+block_size] = a0 - a1; +} + +__attribute__((always_inline)) +void butterfly4(float2 a0, float2 a1, float2 a2, float2 a3, __local float2* smem, __constant const float2* twiddles, + const int x, const int block_size) { const int k = x & (block_size - 1); + a1 = mul_float2(twiddles[k], a1); + a2 = mul_float2(twiddles[k + block_size], a2); + a3 = mul_float2(twiddles[k + 2*block_size], a3); + + const int dst_ind = ((x - k) << 2) + k; + + float2 b0 = a0 + a2; + a2 = a0 - a2; + float2 b1 = a1 + a3; + a3 = twiddle(a1 - a3); + + smem[dst_ind] = b0 + b1; + smem[dst_ind + block_size] = a2 + a3; + smem[dst_ind + 2*block_size] = b0 - b1; + smem[dst_ind + 3*block_size] = a2 - a3; +} + +__attribute__((always_inline)) +void butterfly3(float2 a0, float2 a1, float2 a2, __local float2* smem, __constant const float2* twiddles, + const int x, const int block_size) +{ + const int k = x & (block_size - 1); + a1 = mul_float2(twiddles[k], a1); + a2 = mul_float2(twiddles[k+block_size], a2); + const int dst_ind = ((x - k) * 3) + k; + + float2 b1 = a1 + a2; + a2 = twiddle(sin_120*(a1 - a2)); + float2 b0 = a0 - (float2)(0.5f)*b1; + + smem[dst_ind] = a0 + b1; + smem[dst_ind + block_size] = b0 + a2; + smem[dst_ind + 2*block_size] = b0 - a2; +} + +__attribute__((always_inline)) +void butterfly5(float2 a0, float2 a1, float2 a2, float2 a3, float2 a4, __local float2* smem, __constant const float2* twiddles, + const int x, const int block_size) +{ + const int k = x & (block_size - 1); + a1 = mul_float2(twiddles[k], a1); + a2 = mul_float2(twiddles[k + block_size], a2); + a3 = mul_float2(twiddles[k+2*block_size], a3); + a4 = mul_float2(twiddles[k+3*block_size], a4); + + const int dst_ind = ((x - k) * 5) + k; + __local float2* dst = smem + dst_ind; + + float2 b0, b1, b5; + + b1 = a1 + a4; + a1 -= a4; + + a4 = a3 + a2; + a3 -= a2; + + a2 = b1 + a4; + b0 = a0 - (float2)0.25f * a2; + + b1 = fft5_2 * (b1 - a4); + a4 = fft5_3 * (float2)(-a1.y - a3.y, a1.x + a3.x); + b5 = (float2)(a4.x - fft5_5 * a1.y, a4.y + fft5_5 * a1.x); + + a4.x += fft5_4 * a3.y; + a4.y -= fft5_4 * a3.x; + + a1 = b0 + b1; + b0 -= b1; + + dst[0] = a0 + a2; + dst[block_size] = a1 + a4; + dst[2 * block_size] = b0 + b5; + dst[3 * block_size] = b0 - b5; + dst[4 * block_size] = a1 - a4; +} + +__attribute__((always_inline)) +void fft_radix2(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +{ float2 a0, a1; if (x < t) { a0 = smem[x]; - a1 = mul_float2(twiddles[k],smem[x+t]); + a1 = smem[x+t]; } barrier(CLK_LOCAL_MEM_FENCE); if (x < t) - { - const int dst_ind = (x << 1) - k; - - smem[dst_ind] = a0 + a1; - smem[dst_ind+block_size] = a0 - a1; - } + butterfly2(a0, a1, smem, twiddles, x, block_size); barrier(CLK_LOCAL_MEM_FENCE); } __attribute__((always_inline)) -void fft_radix2_B2(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void fft_radix2_B2(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) { - const int k1 = x & (block_size - 1); - const int x2 = x + t/2; - const int k2 = x2 & (block_size - 1); + const int x2 = x1 + t/2; float2 a0, a1, a2, a3; - if (x < t/2) + if (x1 < t/2) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k1],smem[x+t]); - a2 = smem[x2]; - a3 = mul_float2(twiddles[k2],smem[x2+t]); + a0 = smem[x1]; a1 = smem[x1+t]; + a2 = smem[x2]; a3 = smem[x2+t]; } barrier(CLK_LOCAL_MEM_FENCE); - if (x < t/2) + if (x1 < t/2) { - int dst_ind = (x << 1) - k1; - smem[dst_ind] = a0 + a1; - smem[dst_ind+block_size] = a0 - a1; + butterfly2(a0, a1, smem, twiddles, x1, block_size); + butterfly2(a2, a3, smem, twiddles, x2, block_size); + } - dst_ind = (x2 << 1) - k2; - smem[dst_ind] = a2 + a3; - smem[dst_ind+block_size] = a2 - a3; + barrier(CLK_LOCAL_MEM_FENCE); +} + +__attribute__((always_inline)) +void fft_radix2_B3(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) +{ + const int x2 = x1 + t/3; + const int x3 = x1 + 2*t/3; + float2 a0, a1, a2, a3, a4, a5; + + if (x1 < t/3) + { + a0 = smem[x1]; a1 = smem[x1+t]; + a2 = smem[x2]; a3 = smem[x2+t]; + a4 = smem[x3]; a5 = smem[x3+t]; + } + + barrier(CLK_LOCAL_MEM_FENCE); + + if (x1 < t/3) + { + butterfly2(a0, a1, smem, twiddles, x1, block_size); + butterfly2(a2, a3, smem, twiddles, x2, block_size); + butterfly2(a4, a5, smem, twiddles, x3, block_size); } barrier(CLK_LOCAL_MEM_FENCE); } __attribute__((always_inline)) -void fft_radix2_B4(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void fft_radix2_B4(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) { const int thread_block = t/4; - const int k1 = x & (block_size - 1); - const int x2 = x + thread_block; - const int k2 = x2 & (block_size - 1); - const int x3 = x + 2*thread_block; - const int k3 = x3 & (block_size - 1); - const int x4 = x + 3*thread_block; - const int k4 = x4 & (block_size - 1); + const int x2 = x1 + thread_block; + const int x3 = x1 + 2*thread_block; + const int x4 = x1 + 3*thread_block; float2 a0, a1, a2, a3, a4, a5, a6, a7; - if (x < t/4) + if (x1 < t/4) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k1],smem[x+t]); - a2 = smem[x2]; - a3 = mul_float2(twiddles[k2],smem[x2+t]); - a4 = smem[x3]; - a5 = mul_float2(twiddles[k3],smem[x3+t]); - a6 = smem[x4]; - a7 = mul_float2(twiddles[k4],smem[x4+t]); + a0 = smem[x1]; a1 = smem[x1+t]; + a2 = smem[x2]; a3 = smem[x2+t]; + a4 = smem[x3]; a5 = smem[x3+t]; + a6 = smem[x4]; a7 = smem[x4+t]; } barrier(CLK_LOCAL_MEM_FENCE); - if (x < t/4) + if (x1 < t/4) { - int dst_ind = (x << 1) - k1; - smem[dst_ind] = a0 + a1; - smem[dst_ind+block_size] = a0 - a1; + butterfly2(a0, a1, smem, twiddles, x1, block_size); + butterfly2(a2, a3, smem, twiddles, x2, block_size); + butterfly2(a4, a5, smem, twiddles, x3, block_size); + butterfly2(a6, a7, smem, twiddles, x4, block_size); + } - dst_ind = (x2 << 1) - k2; - smem[dst_ind] = a2 + a3; - smem[dst_ind+block_size] = a2 - a3; + barrier(CLK_LOCAL_MEM_FENCE); +} - dst_ind = (x3 << 1) - k3; - smem[dst_ind] = a4 + a5; - smem[dst_ind+block_size] = a4 - a5; +__attribute__((always_inline)) +void fft_radix2_B5(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) +{ + const int thread_block = t/5; + const int x2 = x1 + thread_block; + const int x3 = x1 + 2*thread_block; + const int x4 = x1 + 3*thread_block; + const int x5 = x1 + 4*thread_block; + float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9; - dst_ind = (x4 << 1) - k4; - smem[dst_ind] = a6 + a7; - smem[dst_ind+block_size] = a6 - a7; + if (x1 < t/5) + { + a0 = smem[x1]; a1 = smem[x1+t]; + a2 = smem[x2]; a3 = smem[x2+t]; + a4 = smem[x3]; a5 = smem[x3+t]; + a6 = smem[x4]; a7 = smem[x4+t]; + a8 = smem[x5]; a9 = smem[x5+t]; + } + + barrier(CLK_LOCAL_MEM_FENCE); + + if (x1 < t/5) + { + butterfly2(a0, a1, smem, twiddles, x1, block_size); + butterfly2(a2, a3, smem, twiddles, x2, block_size); + butterfly2(a4, a5, smem, twiddles, x3, block_size); + butterfly2(a6, a7, smem, twiddles, x4, block_size); + butterfly2(a8, a9, smem, twiddles, x5, block_size); } barrier(CLK_LOCAL_MEM_FENCE); @@ -124,85 +242,65 @@ void fft_radix2_B4(__local float2* smem, __constant const float2* twiddles, cons __attribute__((always_inline)) void fft_radix4(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) { - const int k = x & (block_size - 1); float2 a0, a1, a2, a3; if (x < t) { - const int twiddle_block = block_size / 4; - a0 = smem[x]; - a1 = mul_float2(twiddles[k],smem[x+t]); - a2 = mul_float2(twiddles[k + block_size],smem[x+2*t]); - a3 = mul_float2(twiddles[k + 2*block_size],smem[x+3*t]); + a0 = smem[x]; a1 = smem[x+t]; a2 = smem[x+2*t]; a3 = smem[x+3*t]; } barrier(CLK_LOCAL_MEM_FENCE); if (x < t) + butterfly4(a0, a1, a2, a3, smem, twiddles, x, block_size); + + barrier(CLK_LOCAL_MEM_FENCE); +} + +__attribute__((always_inline)) +void fft_radix4_B2(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) +{ + const int x2 = x1 + t/2; + float2 a0, a1, a2, a3, a4, a5, a6, a7; + + if (x1 < t/2) { - const int dst_ind = ((x - k) << 2) + k; + a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; a3 = smem[x1+3*t]; + a4 = smem[x2]; a5 = smem[x2+t]; a6 = smem[x2+2*t]; a7 = smem[x2+3*t]; + } - float2 b0 = a0 + a2; - a2 = a0 - a2; - float2 b1 = a1 + a3; - a3 = twiddle(a1 - a3); + barrier(CLK_LOCAL_MEM_FENCE); - smem[dst_ind] = b0 + b1; - smem[dst_ind + block_size] = a2 + a3; - smem[dst_ind + 2*block_size] = b0 - b1; - smem[dst_ind + 3*block_size] = a2 - a3; + if (x1 < t/2) + { + butterfly4(a0, a1, a2, a3, smem, twiddles, x1, block_size); + butterfly4(a4, a5, a6, a7, smem, twiddles, x2, block_size); } barrier(CLK_LOCAL_MEM_FENCE); } __attribute__((always_inline)) -void fft_radix4_B2(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void fft_radix4_B3(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) { - const int k = x & (block_size - 1); - const int x2 = x + t/2; - const int k2 = x2 & (block_size - 1); - float2 a0, a1, a2, a3, a4, a5, a6, a7; + const int x2 = x1 + t/3; + const int x3 = x2 + t/3; + float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11; - if (x < t/2) + if (x1 < t/3) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k], smem[x+t]); - a2 = mul_float2(twiddles[k + block_size],smem[x+2*t]); - a3 = mul_float2(twiddles[k + 2*block_size],smem[x+3*t]); - - a4 = smem[x2]; - a5 = mul_float2(twiddles[k2], smem[x2+t]); - a6 = mul_float2(twiddles[k2 + block_size],smem[x2+2*t]); - a7 = mul_float2(twiddles[k2 + 2*block_size],smem[x2+3*t]); + a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; a3 = smem[x1+3*t]; + a4 = smem[x2]; a5 = smem[x2+t]; a6 = smem[x2+2*t]; a7 = smem[x2+3*t]; + a8 = smem[x3]; a9 = smem[x3+t]; a10 = smem[x3+2*t]; a11 = smem[x3+3*t]; } barrier(CLK_LOCAL_MEM_FENCE); - if (x < t/2) + if (x1 < t/3) { - int dst_ind = ((x - k) << 2) + k; - - float2 b0 = a0 + a2; - a2 = a0 - a2; - float2 b1 = a1 + a3; - a3 = twiddle(a1 - a3); - - smem[dst_ind] = b0 + b1; - smem[dst_ind + block_size] = a2 + a3; - smem[dst_ind + 2*block_size] = b0 - b1; - smem[dst_ind + 3*block_size] = a2 - a3; - - dst_ind = ((x2 - k2) << 2) + k2; - b0 = a4 + a6; - a6 = a4 - a6; - b1 = a5 + a7; - a7 = twiddle(a5 - a7); - - smem[dst_ind] = b0 + b1; - smem[dst_ind + block_size] = a6 + a7; - smem[dst_ind + 2*block_size] = b0 - b1; - smem[dst_ind + 3*block_size] = a6 - a7; + butterfly4(a0, a1, a2, a3, smem, twiddles, x1, block_size); + butterfly4(a4, a5, a6, a7, smem, twiddles, x2, block_size); + butterfly4(a8, a9, a10, a11, smem, twiddles, x3, block_size); } barrier(CLK_LOCAL_MEM_FENCE); @@ -274,156 +372,95 @@ void fft_radix8(__local float2* smem, __constant const float2* twiddles, const i __attribute__((always_inline)) void fft_radix3(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) { - const int k = x % block_size; float2 a0, a1, a2; if (x < t) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k], smem[x+t]); - a2 = mul_float2(twiddles[k+block_size], smem[x+2*t]); + a0 = smem[x]; a1 = smem[x+t]; a2 = smem[x+2*t]; } barrier(CLK_LOCAL_MEM_FENCE); if (x < t) - { - const int dst_ind = ((x - k) * 3) + k; - - float2 b1 = a1 + a2; - a2 = twiddle(sin_120*(a1 - a2)); - float2 b0 = a0 - (float2)(0.5f)*b1; - - smem[dst_ind] = a0 + b1; - smem[dst_ind + block_size] = b0 + a2; - smem[dst_ind + 2*block_size] = b0 - a2; - } + butterfly3(a0, a1, a2, smem, twiddles, x, block_size); barrier(CLK_LOCAL_MEM_FENCE); } __attribute__((always_inline)) -void fft_radix3_B2(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void fft_radix3_B2(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) { - const int k = x % block_size; - const int x2 = x + t/2; - const int k2 = x2 % block_size; + const int x2 = x1 + t/2; float2 a0, a1, a2, a3, a4, a5; - if (x < t/2) + if (x1 < t/2) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k], smem[x+t]); - a2 = mul_float2(twiddles[k+block_size], smem[x+2*t]); - - a3 = smem[x2]; - a4 = mul_float2(twiddles[k2], smem[x2+t]); - a5 = mul_float2(twiddles[k2+block_size], smem[x2+2*t]); + a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; + a3 = smem[x2]; a4 = smem[x2+t]; a5 = smem[x2+2*t]; } barrier(CLK_LOCAL_MEM_FENCE); - if (x < t/2) + if (x1 < t/2) { - int dst_ind = ((x - k) * 3) + k; + butterfly3(a0, a1, a2, smem, twiddles, x1, block_size); + butterfly3(a3, a4, a5, smem, twiddles, x2, block_size); + } - float2 b1 = a1 + a2; - a2 = twiddle(sin_120*(a1 - a2)); - float2 b0 = a0 - (float2)(0.5f)*b1; + barrier(CLK_LOCAL_MEM_FENCE); +} - smem[dst_ind] = a0 + b1; - smem[dst_ind + block_size] = b0 + a2; - smem[dst_ind + 2*block_size] = b0 - a2; +__attribute__((always_inline)) +void fft_radix3_B3(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) +{ + const int x2 = x1 + t/3; + const int x3 = x2 + t/3; + float2 a0, a1, a2, a3, a4, a5, a6, a7, a8; - dst_ind = ((x2 - k2) * 3) + k2; + if (x1 < t/2) + { + a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; + a3 = smem[x2]; a4 = smem[x2+t]; a5 = smem[x2+2*t]; + a6 = smem[x3]; a7 = smem[x3+t]; a8 = smem[x3+2*t]; + } - b1 = a4 + a5; - a5 = twiddle(sin_120*(a4 - a5)); - b0 = a3 - (float2)(0.5f)*b1; + barrier(CLK_LOCAL_MEM_FENCE); - smem[dst_ind] = a3 + b1; - smem[dst_ind + block_size] = b0 + a5; - smem[dst_ind + 2*block_size] = b0 - a5; + if (x1 < t/2) + { + butterfly3(a0, a1, a2, smem, twiddles, x1, block_size); + butterfly3(a3, a4, a5, smem, twiddles, x2, block_size); + butterfly3(a6, a7, a8, smem, twiddles, x3, block_size); } barrier(CLK_LOCAL_MEM_FENCE); } __attribute__((always_inline)) -void fft_radix3_B4(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void fft_radix3_B4(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) { const int thread_block = t/4; - const int k = x % block_size; - const int x2 = x + thread_block; - const int k2 = x2 % block_size; - const int x3 = x + 2*thread_block; - const int k3 = x3 % block_size; - const int x4 = x + 3*thread_block; - const int k4 = x4 % block_size; + const int x2 = x1 + thread_block; + const int x3 = x1 + 2*thread_block; + const int x4 = x1 + 3*thread_block; float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11; - if (x < t/4) + if (x1 < t/4) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k], smem[x+t]); - a2 = mul_float2(twiddles[k+block_size], smem[x+2*t]); - - a3 = smem[x2]; - a4 = mul_float2(twiddles[k2], smem[x2+t]); - a5 = mul_float2(twiddles[k2+block_size], smem[x2+2*t]); - - a6 = smem[x3]; - a7 = mul_float2(twiddles[k3], smem[x3+t]); - a8 = mul_float2(twiddles[k3+block_size], smem[x3+2*t]); - - a9 = smem[x4]; - a10 = mul_float2(twiddles[k4], smem[x4+t]); - a11 = mul_float2(twiddles[k4+block_size], smem[x4+2*t]); + a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; + a3 = smem[x2]; a4 = smem[x2+t]; a5 = smem[x2+2*t]; + a6 = smem[x3]; a7 = smem[x3+t]; a8 = smem[x3+2*t]; + a9 = smem[x4]; a10 = smem[x4+t]; a11 = smem[x4+2*t]; } barrier(CLK_LOCAL_MEM_FENCE); - if (x < t/4) + if (x1 < t/4) { - int dst_ind = ((x - k) * 3) + k; - - float2 b1 = a1 + a2; - a2 = twiddle(sin_120*(a1 - a2)); - float2 b0 = a0 - (float2)(0.5f)*b1; - - smem[dst_ind] = a0 + b1; - smem[dst_ind + block_size] = b0 + a2; - smem[dst_ind + 2*block_size] = b0 - a2; - - dst_ind = ((x2 - k2) * 3) + k2; - - b1 = a4 + a5; - a5 = twiddle(sin_120*(a4 - a5)); - b0 = a3 - (float2)(0.5f)*b1; - - smem[dst_ind] = a3 + b1; - smem[dst_ind + block_size] = b0 + a5; - smem[dst_ind + 2*block_size] = b0 - a5; - - dst_ind = ((x3 - k3) * 3) + k3; - - b1 = a7 + a8; - a8 = twiddle(sin_120*(a7 - a8)); - b0 = a6 - (float2)(0.5f)*b1; - - smem[dst_ind] = a6 + b1; - smem[dst_ind + block_size] = b0 + a8; - smem[dst_ind + 2*block_size] = b0 - a8; - - dst_ind = ((x4 - k4) * 3) + k4; - - b1 = a10 + a11; - a11 = twiddle(sin_120*(a10 - a11)); - b0 = a9 - (float2)(0.5f)*b1; - - smem[dst_ind] = a9 + b1; - smem[dst_ind + block_size] = b0 + a11; - smem[dst_ind + 2*block_size] = b0 - a11; + butterfly3(a0, a1, a2, smem, twiddles, x1, block_size); + butterfly3(a3, a4, a5, smem, twiddles, x2, block_size); + butterfly3(a6, a7, a8, smem, twiddles, x3, block_size); + butterfly3(a9, a10, a11, smem, twiddles, x4, block_size); } barrier(CLK_LOCAL_MEM_FENCE); @@ -437,135 +474,35 @@ void fft_radix5(__local float2* smem, __constant const float2* twiddles, const i if (x < t) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k], smem[x + t]); - a2 = mul_float2(twiddles[k + block_size],smem[x+2*t]); - a3 = mul_float2(twiddles[k+2*block_size],smem[x+3*t]); - a4 = mul_float2(twiddles[k+3*block_size],smem[x+4*t]); + a0 = smem[x]; a1 = smem[x + t]; a2 = smem[x+2*t]; a3 = smem[x+3*t]; a4 = smem[x+4*t]; } barrier(CLK_LOCAL_MEM_FENCE); if (x < t) - { - const int dst_ind = ((x - k) * 5) + k; - __local float2* dst = smem + dst_ind; - - float2 b0, b1, b5; - - b1 = a1 + a4; - a1 -= a4; - - a4 = a3 + a2; - a3 -= a2; - - a2 = b1 + a4; - b0 = a0 - (float2)0.25f * a2; - - b1 = fft5_2 * (b1 - a4); - a4 = fft5_3 * (float2)(-a1.y - a3.y, a1.x + a3.x); - b5 = (float2)(a4.x - fft5_5 * a1.y, a4.y + fft5_5 * a1.x); - - a4.x += fft5_4 * a3.y; - a4.y -= fft5_4 * a3.x; - - a1 = b0 + b1; - b0 -= b1; - - dst[0] = a0 + a2; - dst[block_size] = a1 + a4; - dst[2 * block_size] = b0 + b5; - dst[3 * block_size] = b0 - b5; - dst[4 * block_size] = a1 - a4; - } + butterfly5(a0, a1, a2, a3, a4, smem, twiddles, x, block_size); barrier(CLK_LOCAL_MEM_FENCE); } __attribute__((always_inline)) -void fft_radix5_B2(__local float2* smem, __constant const float2* twiddles, const int x, const int block_size, const int t) +void fft_radix5_B2(__local float2* smem, __constant const float2* twiddles, const int x1, const int block_size, const int t) { - const int k = x % block_size; - const int x2 = x+t/2; - const int k2 = x2 % block_size; + const int x2 = x1+t/2; float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9; - if (x < t/2) + if (x1 < t/2) { - a0 = smem[x]; - a1 = mul_float2(twiddles[k], smem[x + t]); - a2 = mul_float2(twiddles[k + block_size],smem[x+2*t]); - a3 = mul_float2(twiddles[k+2*block_size],smem[x+3*t]); - a4 = mul_float2(twiddles[k+3*block_size],smem[x+4*t]); - - a5 = smem[x2]; - a6 = mul_float2(twiddles[k2], smem[x2 + t]); - a7 = mul_float2(twiddles[k2 + block_size],smem[x2+2*t]); - a8 = mul_float2(twiddles[k2+2*block_size],smem[x2+3*t]); - a9 = mul_float2(twiddles[k2+3*block_size],smem[x2+4*t]); + a0 = smem[x1]; a1 = smem[x1 + t]; a2 = smem[x1+2*t]; a3 = smem[x1+3*t]; a4 = smem[x1+4*t]; + a5 = smem[x2]; a6 = smem[x2 + t]; a7 = smem[x2+2*t]; a8 = smem[x2+3*t]; a9 = smem[x2+4*t]; } barrier(CLK_LOCAL_MEM_FENCE); - if (x < t/2) + if (x1 < t/2) { - int dst_ind = ((x - k) * 5) + k; - __local float2* dst = smem + dst_ind; - - float2 b0, b1, b5; - - b1 = a1 + a4; - a1 -= a4; - - a4 = a3 + a2; - a3 -= a2; - - a2 = b1 + a4; - b0 = a0 - (float2)0.25f * a2; - - b1 = fft5_2 * (b1 - a4); - a4 = fft5_3 * (float2)(-a1.y - a3.y, a1.x + a3.x); - b5 = (float2)(a4.x - fft5_5 * a1.y, a4.y + fft5_5 * a1.x); - - a4.x += fft5_4 * a3.y; - a4.y -= fft5_4 * a3.x; - - a1 = b0 + b1; - b0 -= b1; - - dst[0] = a0 + a2; - dst[block_size] = a1 + a4; - dst[2 * block_size] = b0 + b5; - dst[3 * block_size] = b0 - b5; - dst[4 * block_size] = a1 - a4; - - dst_ind = ((x2 - k2) * 5) + k2; - dst = smem + dst_ind; - - b1 = a6 + a9; - a6 -= a9; - - a9 = a8 + a7; - a8 -= a7; - - a7 = b1 + a9; - b0 = a5 - (float2)0.25f * a7; - - b1 = fft5_2 * (b1 - a9); - a9 = fft5_3 * (float2)(-a6.y - a8.y, a6.x + a8.x); - b5 = (float2)(a9.x - fft5_5 * a6.y, a9.y + fft5_5 * a6.x); - - a9.x += fft5_4 * a8.y; - a9.y -= fft5_4 * a8.x; - - a6 = b0 + b1; - b0 -= b1; - - dst[0] = a5 + a7; - dst[block_size] = a6 + a9; - dst[2 * block_size] = b0 + b5; - dst[3 * block_size] = b0 - b5; - dst[4 * block_size] = a6 - a9; + butterfly5(a0, a1, a2, a3, a4, smem, twiddles, x1, block_size); + butterfly5(a5, a6, a7, a8, a9, smem, twiddles, x2, block_size); } barrier(CLK_LOCAL_MEM_FENCE); @@ -611,7 +548,7 @@ __kernel void fft_multi_radix_rows(__global const uchar* src_ptr, int src_step, RADIX_PROCESS; -#ifndef CCS_OUTPUT +#ifndef REAL_OUTPUT #ifdef NO_CONJUGATE // copy result without complex conjugate const int cols = dst_cols/2 + 1; @@ -659,7 +596,7 @@ __kernel void fft_multi_radix_cols(__global const uchar* src_ptr, int src_step, RADIX_PROCESS; -#ifndef CCS_OUTPUT +#ifndef REAL_OUTPUT __global uchar* dst = dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(float)*2), dst_offset)); #pragma unroll for (int i=0; i