Commit 52f76a32 authored by Alexander Karsakov's avatar Alexander Karsakov

Added rest Elena's changes

parent 77912645
...@@ -65,10 +65,10 @@ enum OCL_FFT_TYPE ...@@ -65,10 +65,10 @@ enum OCL_FFT_TYPE
typedef tuple<OCL_FFT_TYPE, Size, int> DftParams; typedef tuple<OCL_FFT_TYPE, Size, int> DftParams;
typedef TestBaseWithParam<DftParams> DftFixture; typedef TestBaseWithParam<DftParams> 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(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, Values((int) 0, (int)DFT_ROWS, (int)DFT_SCALE/*, (int)DFT_INVERSE,
/*(int)DFT_INVERSE | DFT_SCALE,*/ (int)DFT_ROWS | DFT_INVERSE))) (int)DFT_INVERSE | DFT_SCALE, (int)DFT_ROWS | DFT_INVERSE*/)))
{ {
const DftParams params = GetParam(); const DftParams params = GetParam();
const int dft_type = get<0>(params); const int dft_type = get<0>(params);
......
...@@ -1791,14 +1791,6 @@ namespace cv { ...@@ -1791,14 +1791,6 @@ namespace cv {
CV_Assert(s == CLFFT_SUCCESS); \ 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 class PlanCache
{ {
struct FftPlan struct FftPlan
...@@ -2034,6 +2026,14 @@ namespace cv ...@@ -2034,6 +2026,14 @@ namespace cv
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
enum FftType
{
R2R = 0,
C2R = 1,
R2C = 2,
C2C = 3
};
static std::vector<int> ocl_getRadixes(int cols, std::vector<int>& radixes, std::vector<int>& blocks, int& min_radix) static std::vector<int> ocl_getRadixes(int cols, std::vector<int>& radixes, std::vector<int>& blocks, int& min_radix)
{ {
int factors[34]; int factors[34];
...@@ -2054,13 +2054,19 @@ static std::vector<int> ocl_getRadixes(int cols, std::vector<int>& radixes, std: ...@@ -2054,13 +2054,19 @@ static std::vector<int> ocl_getRadixes(int cols, std::vector<int>& radixes, std:
else if (4*n <= factors[0]) else if (4*n <= factors[0])
{ {
radix = 4; radix = 4;
if (cols % 8 == 0) if (cols % 12 == 0)
block = 3;
else if (cols % 8 == 0)
block = 2; block = 2;
} }
else else
{ {
if (cols % 8 == 0) if (cols % 10 == 0)
block = 5;
else if (cols % 8 == 0)
block = 4; block = 4;
else if (cols % 6 == 0)
block = 3;
else if (cols % 4 == 0) else if (cols % 4 == 0)
block = 2; block = 2;
} }
...@@ -2081,6 +2087,8 @@ static std::vector<int> ocl_getRadixes(int cols, std::vector<int>& radixes, std: ...@@ -2081,6 +2087,8 @@ static std::vector<int> ocl_getRadixes(int cols, std::vector<int>& radixes, std:
{ {
if (cols % 12 == 0) if (cols % 12 == 0)
block = 4; block = 4;
else if (cols % 9 == 0)
block = 3;
else if (cols % 6 == 0) else if (cols % 6 == 0)
block = 2; block = 2;
} }
...@@ -2142,7 +2150,6 @@ struct OCL_FftPlan ...@@ -2142,7 +2150,6 @@ struct OCL_FftPlan
{ {
int radix = radixes[i]; int radix = radixes[i];
n *= radix; n *= radix;
for (int j=1; j<radix; j++) for (int j=1; j<radix; j++)
{ {
...@@ -2160,7 +2167,7 @@ struct OCL_FftPlan ...@@ -2160,7 +2167,7 @@ struct OCL_FftPlan
dft_size, dft_size/thread_count, radix_processing.c_str()); dft_size, dft_size/thread_count, radix_processing.c_str());
} }
bool enqueueTransform(InputArray _src, OutputArray _dst, int dft_size, int flags, bool rows = true) const bool enqueueTransform(InputArray _src, OutputArray _dst, int dft_size, int flags, int fftType, bool rows = true) const
{ {
if (!status) if (!status)
return false; return false;
...@@ -2195,12 +2202,25 @@ struct OCL_FftPlan ...@@ -2195,12 +2202,25 @@ struct OCL_FftPlan
if (src.channels() == 1) if (src.channels() == 1)
options += " -D REAL_INPUT"; options += " -D REAL_INPUT";
else
options += " -D COMPLEX_INPUT";
if (dst.channels() == 1) if (dst.channels() == 1)
options += " -D CCS_OUTPUT"; options += " -D REAL_OUTPUT";
if ((is1d && src.channels() == 1) || (rows && (flags & DFT_REAL_OUTPUT)))
options += " -D NO_CONJUGATE";
if (is1d) if (is1d)
options += " -D IS_1D"; options += " -D IS_1D";
if (!inv)
{
if ((is1d && src.channels() == 1) || (rows && (fftType == R2R)))
options += " -D NO_CONJUGATE";
}
else
{
if (is1d && fftType == C2R || (rows && fftType == R2R))
options += " -D NO_CONJUGATE";
if (dst.cols % 2 == 0)
options += " -D EVEN";
}
ocl::Kernel k(kernel_name.c_str(), ocl::core::fft_oclsrc, options); ocl::Kernel k(kernel_name.c_str(), ocl::core::fft_oclsrc, options);
if (k.empty()) if (k.empty())
...@@ -2253,16 +2273,16 @@ protected: ...@@ -2253,16 +2273,16 @@ protected:
std::vector<OCL_FftPlan*> planStorage; std::vector<OCL_FftPlan*> 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); 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); 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) 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 ...@@ -2298,29 +2318,26 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro
complex_output = 1; complex_output = 1;
} }
FftType fftType = (FftType)(complex_input << 0 | complex_output << 1);
// Forward Complex to CCS not supported // Forward Complex to CCS not supported
if (complex_input && real_output && !inv) if (fftType == C2R && !inv)
{ fftType = C2C;
flags ^= DFT_REAL_OUTPUT;
flags |= DFT_COMPLEX_OUTPUT;
real_output = 0;
complex_output = 1;
}
// Inverse CCS to Complex not supported // Inverse CCS to Complex not supported
if (real_input && complex_output && inv) if (fftType == R2C && inv)
{ fftType = R2R;
complex_output = 0;
real_output = 1;
}
UMat output; UMat output;
if (complex_output) if (fftType == C2C || fftType == R2C)
{ {
// complex output
_dst.create(src.size(), CV_32FC2); _dst.create(src.size(), CV_32FC2);
output = _dst.getUMat(); output = _dst.getUMat();
} }
else else
{ {
// real output
if (is1d) if (is1d)
{ {
_dst.create(src.size(), CV_32FC1); _dst.create(src.size(), CV_32FC1);
...@@ -2333,17 +2350,49 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro ...@@ -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)) if (!inv)
return false;
if (!is1d)
{ {
int nonzero_cols = real_input && real_output ? output.cols/2 + 1 : output.cols; if (!ocl_dft_C2C_rows(src, output, nonzero_rows, flags, fftType))
if (!ocl_dft_C2C_cols(output, _dst, nonzero_cols, flags))
return false; 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; return true;
} }
......
This diff is collapsed.
...@@ -50,10 +50,10 @@ ...@@ -50,10 +50,10 @@
enum OCL_FFT_TYPE enum OCL_FFT_TYPE
{ {
R2R = 0, // real to real (CCS) R2R = 0,
C2R = 1, // complex to real (CCS) C2R = 1,
R2C = 2, // real (CCS) to complex R2C = 2,
C2C = 3 // complex to complex C2C = 3
}; };
namespace cvtest { namespace cvtest {
...@@ -62,7 +62,7 @@ namespace ocl { ...@@ -62,7 +62,7 @@ namespace ocl {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dft // Dft
PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, bool, bool, bool) PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, bool, bool, bool, bool)
{ {
cv::Size dft_size; cv::Size dft_size;
int dft_flags, depth, cn, dft_type; int dft_flags, depth, cn, dft_type;
...@@ -88,12 +88,12 @@ PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, bool, bool, bool) ...@@ -88,12 +88,12 @@ PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, bool, bool, bool)
} }
if (GET_PARAM(2)) if (GET_PARAM(2))
dft_flags |= cv::DFT_ROWS; dft_flags |= cv::DFT_INVERSE;
if (GET_PARAM(3)) if (GET_PARAM(3))
dft_flags |= cv::DFT_ROWS;
if (GET_PARAM(4))
dft_flags |= cv::DFT_SCALE; dft_flags |= cv::DFT_SCALE;
/*if (GET_PARAM(4)) inplace = GET_PARAM(5);
dft_flags |= cv::DFT_INVERSE;*/
inplace = GET_PARAM(4);
is1d = (dft_flags & DFT_ROWS) != 0 || dft_size.height == 1; is1d = (dft_flags & DFT_ROWS) != 0 || dft_size.height == 1;
...@@ -116,16 +116,16 @@ OCL_TEST_P(Dft, Mat) ...@@ -116,16 +116,16 @@ OCL_TEST_P(Dft, Mat)
OCL_OFF(cv::dft(src, dst, dft_flags)); OCL_OFF(cv::dft(src, dst, dft_flags));
OCL_ON(cv::dft(usrc, udst, dft_flags)); OCL_ON(cv::dft(usrc, udst, dft_flags));
if (dft_type == R2C && is1d) if (dft_type == R2C && is1d && (dft_flags & cv::DFT_INVERSE) == 0)
{ {
dst = dst(cv::Range(0, dst.rows), cv::Range(0, dst.cols/2 + 1)); dst = dst(cv::Range(0, dst.rows), cv::Range(0, dst.cols/2 + 1));
udst = udst(cv::Range(0, udst.rows), cv::Range(0, udst.cols/2 + 1)); udst = udst(cv::Range(0, udst.rows), cv::Range(0, udst.cols/2 + 1));
} }
//Mat gpu = udst.getMat(ACCESS_READ); Mat gpu = udst.getMat(ACCESS_READ);
//std::cout << src << std::endl; std::cout << src << std::endl;
//std::cout << dst << std::endl; std::cout << dst << std::endl;
//std::cout << gpu << std::endl; std::cout << gpu << std::endl;
//int cn = udst.channels(); //int cn = udst.channels();
// //
...@@ -188,12 +188,12 @@ OCL_TEST_P(MulSpectrums, Mat) ...@@ -188,12 +188,12 @@ OCL_TEST_P(MulSpectrums, Mat)
OCL_INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MulSpectrums, testing::Combine(Bool(), Bool())); OCL_INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MulSpectrums, testing::Combine(Bool(), Bool()));
OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(16, 4), cv::Size(5, 8), cv::Size(6, 6), OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(4, 1), cv::Size(5, 8), cv::Size(6, 6),
cv::Size(512, 1), cv::Size(1280, 768)), cv::Size(512, 1), cv::Size(1280, 768)),
Values((OCL_FFT_TYPE) R2C, (OCL_FFT_TYPE) C2C, (OCL_FFT_TYPE) R2R, (OCL_FFT_TYPE) C2R), Values((OCL_FFT_TYPE) R2C, (OCL_FFT_TYPE) C2C, (OCL_FFT_TYPE) R2R, (OCL_FFT_TYPE) C2R),
Bool(), // DFT_INVERSE
Bool(), // DFT_ROWS Bool(), // DFT_ROWS
Bool(), // DFT_SCALE Bool(), // DFT_SCALE
//Bool(), // DFT_INVERSE
Bool() // inplace Bool() // inplace
) )
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment