From 0da71a01ffbaf350c91a9be57ab674524463ae83 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Thu, 20 Jan 2011 15:08:48 +0000 Subject: [PATCH] fixed some GPU tests failing when compiled for 1.1(no doubles) and run on 1.3(with doubles) --- modules/gpu/src/initialization.cpp | 2 +- modules/gpu/src/matrix_reductions.cpp | 15 ++++++-- modules/gpu/src/split_merge.cpp | 8 +++++ tests/gpu/src/arithm.cpp | 18 +++++----- tests/gpu/src/bitwise_oper.cpp | 7 +++- tests/gpu/src/match_template.cpp | 20 +++++++++++ tests/gpu/src/split_merge.cpp | 50 +++++++++++++++++++-------- 7 files changed, 90 insertions(+), 30 deletions(-) diff --git a/modules/gpu/src/initialization.cpp b/modules/gpu/src/initialization.cpp index 514292350f..bee31e5c13 100644 --- a/modules/gpu/src/initialization.cpp +++ b/modules/gpu/src/initialization.cpp @@ -222,7 +222,7 @@ CV_EXPORTS bool cv::gpu::isCompatibleWith(int device) if (hasLessOrEqualPtxVersion(major, minor)) return true; - // Check CUBIN compatibilty + // Check CUBIN compatibility for (int i = minor; i >= 0; --i) if (hasCubinVersion(major, i)) return true; diff --git a/modules/gpu/src/matrix_reductions.cpp b/modules/gpu/src/matrix_reductions.cpp index b37b20404e..732d36b8d0 100644 --- a/modules/gpu/src/matrix_reductions.cpp +++ b/modules/gpu/src/matrix_reductions.cpp @@ -277,7 +277,10 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp CV_Assert(src.channels() == 1); CV_Assert(mask.empty() || (mask.type() == CV_8U && src.size() == mask.size())); - CV_Assert(src.type() != CV_64F || hasNativeDoubleSupport(getDevice())); + + bool double_ok = hasGreaterOrEqualVersion(1, 3) && + hasNativeDoubleSupport(getDevice()); + CV_Assert(src.type() != CV_64F || double_ok); double minVal_; if (!minVal) minVal = &minVal_; double maxVal_; if (!maxVal) maxVal = &maxVal_; @@ -373,7 +376,10 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point CV_Assert(src.channels() == 1); CV_Assert(mask.empty() || (mask.type() == CV_8U && src.size() == mask.size())); - CV_Assert(src.type() != CV_64F || hasNativeDoubleSupport(getDevice())); + + bool double_ok = hasGreaterOrEqualVersion(1, 3) && + hasNativeDoubleSupport(getDevice()); + CV_Assert(src.type() != CV_64F || double_ok); double minVal_; if (!minVal) minVal = &minVal_; double maxVal_; if (!maxVal) maxVal = &maxVal_; @@ -452,7 +458,10 @@ int cv::gpu::countNonZero(const GpuMat& src, GpuMat& buf) countNonZeroCaller }; CV_Assert(src.channels() == 1); - CV_Assert(src.type() != CV_64F || hasNativeDoubleSupport(getDevice())); + + bool double_ok = hasGreaterOrEqualVersion(1, 3) && + hasNativeDoubleSupport(getDevice()); + CV_Assert(src.type() != CV_64F || double_ok); Size buf_size; getBufSizeRequired(src.cols, src.rows, buf_size.width, buf_size.height); diff --git a/modules/gpu/src/split_merge.cpp b/modules/gpu/src/split_merge.cpp index 7dcc44652a..9a2120053a 100644 --- a/modules/gpu/src/split_merge.cpp +++ b/modules/gpu/src/split_merge.cpp @@ -73,6 +73,10 @@ namespace cv { namespace gpu { namespace split_merge CV_Assert(src); CV_Assert(n > 0); + bool double_ok = hasGreaterOrEqualVersion(1, 3) && + hasNativeDoubleSupport(getDevice()); + CV_Assert(src[0].depth() != CV_64F || double_ok); + int depth = src[0].depth(); Size size = src[0].size(); @@ -112,6 +116,10 @@ namespace cv { namespace gpu { namespace split_merge { CV_Assert(dst); + bool double_ok = hasGreaterOrEqualVersion(1, 3) && + hasNativeDoubleSupport(getDevice()); + CV_Assert(src.depth() != CV_64F || double_ok); + int depth = src.depth(); int num_channels = src.channels(); Size size = src.size(); diff --git a/tests/gpu/src/arithm.cpp b/tests/gpu/src/arithm.cpp index 5b4230c15c..8fea5401bb 100644 --- a/tests/gpu/src/arithm.cpp +++ b/tests/gpu/src/arithm.cpp @@ -659,11 +659,10 @@ struct CV_GpuMinMaxTest: public CvTest { try { - int depth_end; - if (cv::gpu::hasNativeDoubleSupport(cv::gpu::getDevice())) - depth_end = CV_64F; - else - depth_end = CV_32F; + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + int depth_end = double_ok ? CV_64F : CV_32F; + for (int depth = CV_8U; depth <= depth_end; ++depth) { for (int i = 0; i < 3; ++i) @@ -794,11 +793,10 @@ struct CV_GpuMinMaxLocTest: public CvTest { try { - int depth_end; - if (cv::gpu::hasNativeDoubleSupport(cv::gpu::getDevice())) - depth_end = CV_64F; - else - depth_end = CV_32F; + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + int depth_end = double_ok ? CV_64F : CV_32F; + for (int depth = CV_8U; depth <= depth_end; ++depth) { int rows = 1, cols = 3; diff --git a/tests/gpu/src/bitwise_oper.cpp b/tests/gpu/src/bitwise_oper.cpp index d391ff9d20..788b84aa88 100644 --- a/tests/gpu/src/bitwise_oper.cpp +++ b/tests/gpu/src/bitwise_oper.cpp @@ -58,7 +58,12 @@ struct CV_GpuBitwiseTest: public CvTest void run(int) { int rows, cols; - for (int depth = CV_8U; depth <= CV_64F; ++depth) + + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + int depth_end = double_ok ? CV_64F : CV_32F; + + for (int depth = CV_8U; depth <= CV_32F; ++depth) for (int cn = 1; cn <= 4; ++cn) for (int attempt = 0; attempt < 3; ++attempt) { diff --git a/tests/gpu/src/match_template.cpp b/tests/gpu/src/match_template.cpp index eb9116bc6d..b5dd9e410f 100644 --- a/tests/gpu/src/match_template.cpp +++ b/tests/gpu/src/match_template.cpp @@ -64,6 +64,16 @@ struct CV_GpuMatchTemplateTest: CvTest { try { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + if (!double_ok) + { + // For sqrIntegral + ts->printf(CvTS::CONSOLE, "\nCode and device double support is required (CC >= 1.3)"); + ts->set_failed_test_info(CvTS::FAIL_GENERIC); + return; + } + Mat image, templ; Mat dst_gold; gpu::GpuMat dst; @@ -234,6 +244,16 @@ struct CV_GpuMatchTemplateFindPatternInBlackTest: CvTest { try { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + if (!double_ok) + { + // For sqrIntegral + ts->printf(CvTS::CONSOLE, "\nCode and device double support is required (CC >= 1.3)"); + ts->set_failed_test_info(CvTS::FAIL_GENERIC); + return; + } + Mat image = imread(std::string(ts->get_data_path()) + "matchtemplate/black.png"); if (image.empty()) { diff --git a/tests/gpu/src/split_merge.cpp b/tests/gpu/src/split_merge.cpp index 12f922e845..2a929f66e8 100644 --- a/tests/gpu/src/split_merge.cpp +++ b/tests/gpu/src/split_merge.cpp @@ -49,7 +49,7 @@ using namespace std; using namespace cv; -//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // Merge struct CV_MergeTest : public CvTest @@ -63,8 +63,12 @@ struct CV_MergeTest : public CvTest void CV_MergeTest::can_merge(size_t rows, size_t cols) { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + size_t depth_end = double_ok ? CV_64F : CV_32F; + for (size_t num_channels = 1; num_channels <= 4; ++num_channels) - for (size_t depth = CV_8U; depth <= CV_64F; ++depth) + for (size_t depth = CV_8U; depth <= depth_end; ++depth) { vector src; for (size_t i = 0; i < num_channels; ++i) @@ -101,8 +105,12 @@ void CV_MergeTest::can_merge(size_t rows, size_t cols) void CV_MergeTest::can_merge_submatrixes(size_t rows, size_t cols) { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + size_t depth_end = double_ok ? CV_64F : CV_32F; + for (size_t num_channels = 1; num_channels <= 4; ++num_channels) - for (size_t depth = CV_8U; depth <= CV_64F; ++depth) + for (size_t depth = CV_8U; depth <= depth_end; ++depth) { vector src; for (size_t i = 0; i < num_channels; ++i) @@ -158,7 +166,7 @@ void CV_MergeTest::run(int) } -//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // Split struct CV_SplitTest : public CvTest @@ -171,8 +179,12 @@ struct CV_SplitTest : public CvTest void CV_SplitTest::can_split(size_t rows, size_t cols) { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + size_t depth_end = double_ok ? CV_64F : CV_32F; + for (size_t num_channels = 1; num_channels <= 4; ++num_channels) - for (size_t depth = CV_8U; depth <= CV_64F; ++depth) + for (size_t depth = CV_8U; depth <= depth_end; ++depth) { Mat src(rows, cols, CV_MAKETYPE(depth, num_channels), Scalar(1.0, 2.0, 3.0, 4.0)); vector dst; @@ -209,8 +221,12 @@ void CV_SplitTest::can_split(size_t rows, size_t cols) void CV_SplitTest::can_split_submatrix(size_t rows, size_t cols) { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + size_t depth_end = double_ok ? CV_64F : CV_32F; + for (size_t num_channels = 1; num_channels <= 4; ++num_channels) - for (size_t depth = CV_8U; depth <= CV_64F; ++depth) + for (size_t depth = CV_8U; depth <= depth_end; ++depth) { Mat src_data(rows * 2, cols * 2, CV_MAKETYPE(depth, num_channels), Scalar(1.0, 2.0, 3.0, 4.0)); Mat src(src_data(Range(rows / 2, rows / 2 + rows), Range(cols / 2, cols / 2 + cols))); @@ -264,8 +280,8 @@ void CV_SplitTest::run(int) } } - -//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// // Split and merge struct CV_SplitMergeTest : public CvTest @@ -276,8 +292,12 @@ struct CV_SplitMergeTest : public CvTest }; void CV_SplitMergeTest::can_split_merge(size_t rows, size_t cols) { + bool double_ok = gpu::hasGreaterOrEqualVersion(1, 3) && + gpu::hasNativeDoubleSupport(gpu::getDevice()); + size_t depth_end = double_ok ? CV_64F : CV_32F; + for (size_t num_channels = 1; num_channels <= 4; ++num_channels) - for (size_t depth = CV_8U; depth <= CV_64F; ++depth) + for (size_t depth = CV_8U; depth <= depth_end; ++depth) { Mat orig(rows, cols, CV_MAKETYPE(depth, num_channels), Scalar(1.0, 2.0, 3.0, 4.0)); gpu::GpuMat dev_orig(orig); @@ -318,12 +338,12 @@ void CV_SplitMergeTest::run(int) } -///////////////////////////////////////////////////////////////////////////// -/////////////////// tests registration ///////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -// If we comment some tests, we may foget/miss to uncomment it after. -// Placing all test definitions in one place +///////////////////////////////////////////////////////////////////////////// +/////////////////// tests registration ///////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// + +// If we comment some tests, we may foget/miss to uncomment it after. +// Placing all test definitions in one place // makes us know about what tests are commented.