From 575fd1fe4c7ef44fa49d35d071c2235f9c2d595c Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Fri, 28 Jan 2011 11:59:26 +0000 Subject: [PATCH] reafactoring: replaced query device props functions with the DeviceInfo class --- modules/gpu/include/opencv2/gpu/gpu.hpp | 34 ++++-- modules/gpu/src/brute_force_matcher.cpp | 2 +- modules/gpu/src/imgproc_gpu.cpp | 5 +- modules/gpu/src/initialization.cpp | 135 ++++++++++++------------ modules/gpu/src/matrix_reductions.cpp | 20 ++-- modules/gpu/src/split_merge.cpp | 4 +- modules/gpu/src/stereobm.cpp | 8 +- modules/gpu/src/surf.cpp | 2 +- tests/gpu/src/arithm.cpp | 6 +- tests/gpu/src/bitwise_oper.cpp | 2 +- tests/gpu/src/match_template.cpp | 4 +- tests/gpu/src/meanshift.cpp | 12 +-- tests/gpu/src/mssegmentation.cpp | 6 +- tests/gpu/src/split_merge.cpp | 10 +- 14 files changed, 127 insertions(+), 123 deletions(-) diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index ea07a74c82..967b81328b 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -60,7 +60,7 @@ namespace cv CV_EXPORTS int getCudaEnabledDeviceCount(); //! Functions below throw cv::Expception if the library is compiled without Cuda. - CV_EXPORTS string getDeviceName(int device); + CV_EXPORTS void setDevice(int device); CV_EXPORTS int getDevice(); @@ -85,15 +85,35 @@ namespace cv TargetArchs(); }; - CV_EXPORTS void getComputeCapability(int device, int& major, int& minor); - CV_EXPORTS int getNumberOfSMs(int device); + class CV_EXPORTS DeviceInfo + { + public: + DeviceInfo() : device_id_(getDevice()) { query(); } + DeviceInfo(int device_id) : device_id_(device_id) { query(); } - CV_EXPORTS void getGpuMemInfo(size_t& free, size_t& total); + string name() const { return name_; } - CV_EXPORTS bool hasNativeDoubleSupport(int device); - CV_EXPORTS bool hasAtomicsSupport(int device); + int major() const { return major_; } + int minor() const { return minor_; } - CV_EXPORTS bool isCompatibleWith(int device); + int multiProcessorCount() const { return multi_processor_count_; } + + size_t freeMemory() const; + size_t totalMemory() const; + + bool has(GpuFeature feature) const; + bool isCompatible() const; + + private: + void query(); + void queryMemory(size_t& free_memory, size_t& total_memory) const; + + int device_id_; + + string name_; + int multi_processor_count_; + int major_, minor_; + }; //////////////////////////////// Error handling //////////////////////// diff --git a/modules/gpu/src/brute_force_matcher.cpp b/modules/gpu/src/brute_force_matcher.cpp index e0025a57a6..344712125c 100644 --- a/modules/gpu/src/brute_force_matcher.cpp +++ b/modules/gpu/src/brute_force_matcher.cpp @@ -531,7 +531,7 @@ void cv::gpu::BruteForceMatcher_GPU_base::radiusMatch(const GpuMat& queryDescs, } }; - CV_Assert(hasAtomicsSupport(getDevice())); + CV_Assert(DeviceInfo().has(ATOMICS)); const int nQuery = queryDescs.rows; const int nTrain = trainDescs.rows; diff --git a/modules/gpu/src/imgproc_gpu.cpp b/modules/gpu/src/imgproc_gpu.cpp index 43ece0c62d..4c24684efe 100644 --- a/modules/gpu/src/imgproc_gpu.cpp +++ b/modules/gpu/src/imgproc_gpu.cpp @@ -1246,14 +1246,11 @@ void cv::gpu::ConvolveBuf::create(Size image_size, Size templ_size) Size cv::gpu::ConvolveBuf::estimateBlockSize(Size result_size, Size templ_size) { - int major, minor; - getComputeCapability(getDevice(), major, minor); - int scale = 40; Size bsize_min(1024, 1024); // Check whether we use Fermi generation or newer GPU - if (major >= 2) + if (DeviceInfo().major() >= 2) { bsize_min.width = 2048; bsize_min.height = 2048; diff --git a/modules/gpu/src/initialization.cpp b/modules/gpu/src/initialization.cpp index cab5f626c0..b3e3ba036e 100644 --- a/modules/gpu/src/initialization.cpp +++ b/modules/gpu/src/initialization.cpp @@ -49,18 +49,18 @@ using namespace cv::gpu; namespace { template - bool compare(const std::string& str, int x, Comparer cmp) + bool compareToSet(const std::string& set_as_str, int value, Comparer cmp) { - if (str.find_first_not_of(" ") == string::npos) + if (set_as_str.find_first_not_of(" ") == string::npos) return false; - std::stringstream stream(str); - int val; + std::stringstream stream(set_as_str); + int cur_value; while (!stream.eof()) { - stream >> val; - if (cmp(val, x)) + stream >> cur_value; + if (cmp(cur_value, value)) return true; } @@ -87,19 +87,19 @@ CV_EXPORTS bool cv::gpu::TargetArchs::has(int major, int minor) CV_EXPORTS bool cv::gpu::TargetArchs::hasPtx(int major, int minor) { - return ::compare(CUDA_ARCH_PTX, major * 10 + minor, std::equal_to()); + return ::compareToSet(CUDA_ARCH_PTX, major * 10 + minor, std::equal_to()); } CV_EXPORTS bool cv::gpu::TargetArchs::hasBin(int major, int minor) { - return ::compare(CUDA_ARCH_BIN, major * 10 + minor, std::equal_to()); + return ::compareToSet(CUDA_ARCH_BIN, major * 10 + minor, std::equal_to()); } CV_EXPORTS bool cv::gpu::TargetArchs::hasEqualOrLessPtx(int major, int minor) { - return ::compare(CUDA_ARCH_PTX, major * 10 + minor, + return ::compareToSet(CUDA_ARCH_PTX, major * 10 + minor, std::less_equal()); } @@ -113,14 +113,14 @@ CV_EXPORTS bool cv::gpu::TargetArchs::hasEqualOrGreater(int major, int minor) CV_EXPORTS bool cv::gpu::TargetArchs::hasEqualOrGreaterPtx(int major, int minor) { - return ::compare(CUDA_ARCH_PTX, major * 10 + minor, + return ::compareToSet(CUDA_ARCH_PTX, major * 10 + minor, std::greater_equal()); } CV_EXPORTS bool cv::gpu::TargetArchs::hasEqualOrGreaterBin(int major, int minor) { - return ::compare(CUDA_ARCH_BIN, major * 10 + minor, + return ::compareToSet(CUDA_ARCH_BIN, major * 10 + minor, std::greater_equal()); } @@ -128,16 +128,20 @@ CV_EXPORTS bool cv::gpu::TargetArchs::hasEqualOrGreaterBin(int major, int minor) #if !defined (HAVE_CUDA) CV_EXPORTS int cv::gpu::getCudaEnabledDeviceCount() { return 0; } -CV_EXPORTS string cv::gpu::getDeviceName(int /*device*/) { throw_nogpu(); return 0; } -CV_EXPORTS void cv::gpu::setDevice(int /*device*/) { throw_nogpu(); } +CV_EXPORTS void cv::gpu::setDevice(int) { throw_nogpu(); } CV_EXPORTS int cv::gpu::getDevice() { throw_nogpu(); return 0; } -CV_EXPORTS void cv::gpu::getComputeCapability(int /*device*/, int& /*major*/, int& /*minor*/) { throw_nogpu(); } -CV_EXPORTS int cv::gpu::getNumberOfSMs(int /*device*/) { throw_nogpu(); return 0; } -CV_EXPORTS void cv::gpu::getGpuMemInfo(size_t& /*free*/, size_t& /*total*/) { throw_nogpu(); } -CV_EXPORTS bool cv::gpu::hasNativeDoubleSupport(int /*device*/) { throw_nogpu(); return false; } -CV_EXPORTS bool cv::gpu::hasAtomicsSupport(int /*device*/) { throw_nogpu(); return false; } -CV_EXPORTS bool cv::gpu::isCompatibleWith(int device) { throw_nogpu(); return false; } - +cv::gpu::DeviceInfo::DeviceInfo() { throw_nogpu(); } +cv::gpu::DeviceInfo::DeviceInfo(int) { throw_nogpu(); } +string cv::gpu::DeviceInfo::name() const { throw_nogpu(); return ""; } +int cv::gpu::DeviceInfo::major() const { throw_nogpu(); return 0; } +int cv::gpu::DeviceInfo::minor() const { throw_nogpu(); return 0; } +int cv::gpu::DeviceInfo::multiProcessorCount() const { throw_nogpu(); return 0; } +size_t cv::gpu::DeviceInfo::freeMemory() const { throw_nogpu(); return 0; } +size_t cv::gpu::DeviceInfo::totalMemory() const { throw_nogpu(); return 0; } +bool cv::gpu::DeviceInfo::has(cv::gpu::GpuFeature) const { throw_nogpu(); return false; } +bool cv::gpu::DeviceInfo::isCompatible() const { throw_nogpu(); return false; } +void cv::gpu::DeviceInfo::query() const { throw_nogpu(); } +void cv::gpu::DeviceInfo::queryMemory(size_t, size_t) const { throw_nogpu(); } #else /* !defined (HAVE_CUDA) */ @@ -149,14 +153,6 @@ CV_EXPORTS int cv::gpu::getCudaEnabledDeviceCount() } -CV_EXPORTS string cv::gpu::getDeviceName(int device) -{ - cudaDeviceProp prop; - cudaSafeCall( cudaGetDeviceProperties( &prop, device) ); - return prop.name; -} - - CV_EXPORTS void cv::gpu::setDevice(int device) { cudaSafeCall( cudaSetDevice( device ) ); @@ -171,66 +167,69 @@ CV_EXPORTS int cv::gpu::getDevice() } -CV_EXPORTS void cv::gpu::getComputeCapability(int device, int& major, int& minor) +size_t cv::gpu::DeviceInfo::freeMemory() const { - cudaDeviceProp prop; - cudaSafeCall( cudaGetDeviceProperties( &prop, device) ); - - major = prop.major; - minor = prop.minor; + size_t free_memory, total_memory; + queryMemory(free_memory, total_memory); + return free_memory; } -CV_EXPORTS int cv::gpu::getNumberOfSMs(int device) +size_t cv::gpu::DeviceInfo::totalMemory() const { - cudaDeviceProp prop; - cudaSafeCall( cudaGetDeviceProperties( &prop, device ) ); - return prop.multiProcessorCount; + size_t free_memory, total_memory; + queryMemory(free_memory, total_memory); + return total_memory; } -CV_EXPORTS void cv::gpu::getGpuMemInfo(size_t& free, size_t& total) +bool cv::gpu::DeviceInfo::has(cv::gpu::GpuFeature feature) const { - cudaSafeCall( cudaMemGetInfo( &free, &total ) ); + if (feature == NATIVE_DOUBLE) + return major() > 1 || (major() == 1 && minor() >= 3); + if (feature == ATOMICS) + return major() > 1 || (major() == 1 && minor() >= 1); + return false; } -CV_EXPORTS bool cv::gpu::hasNativeDoubleSupport(int device) +bool cv::gpu::DeviceInfo::isCompatible() const { - int major, minor; - getComputeCapability(device, major, minor); - return major > 1 || (major == 1 && minor >= 3); -} - - -CV_EXPORTS bool cv::gpu::hasAtomicsSupport(int device) -{ - int major, minor; - getComputeCapability(device, major, minor); - return major > 1 || (major == 1 && minor >= 1); -} - - -CV_EXPORTS bool cv::gpu::isCompatibleWith(int device) -{ - // According to the CUDA C Programming Guide Version 3.2: "PTX code - // produced for some specific compute capability can always be compiled to - // binary code of greater or equal compute capability". - - int major, minor; - getComputeCapability(device, major, minor); - // Check PTX compatibility - if (TargetArchs::hasEqualOrLessPtx(major, minor)) + if (TargetArchs::hasEqualOrLessPtx(major(), minor())) return true; - // Check CUBIN compatibility - for (int i = minor; i >= 0; --i) - if (TargetArchs::hasBin(major, i)) + // Check BIN compatibility + for (int i = minor(); i >= 0; --i) + if (TargetArchs::hasBin(major(), i)) return true; return false; } + +void cv::gpu::DeviceInfo::query() +{ + cudaDeviceProp prop; + cudaSafeCall(cudaGetDeviceProperties(&prop, device_id_)); + name_ = prop.name; + multi_processor_count_ = prop.multiProcessorCount; + major_ = prop.major; + minor_ = prop.minor; +} + + +void cv::gpu::DeviceInfo::queryMemory(size_t& free_memory, size_t& total_memory) const +{ + int prev_device_id = getDevice(); + if (prev_device_id != device_id_) + setDevice(device_id_); + + cudaSafeCall(cudaMemGetInfo(&free_memory, &total_memory)); + + if (prev_device_id != device_id_) + setDevice(prev_device_id); +} + #endif diff --git a/modules/gpu/src/matrix_reductions.cpp b/modules/gpu/src/matrix_reductions.cpp index 32467850a0..8f4fb95d6c 100644 --- a/modules/gpu/src/matrix_reductions.cpp +++ b/modules/gpu/src/matrix_reductions.cpp @@ -170,7 +170,7 @@ Scalar cv::gpu::sum(const GpuMat& src, GpuMat& buf) ensureSizeIsEnough(buf_size, CV_8U, buf); Caller* callers = multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = singlepass_callers; Caller caller = callers[src.depth()]; @@ -206,7 +206,7 @@ Scalar cv::gpu::sqrSum(const GpuMat& src, GpuMat& buf) sqrSumCaller, sqrSumCaller, 0 }; Caller* callers = multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = singlepass_callers; Size buf_size; @@ -284,7 +284,7 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp CV_Assert(mask.empty() || (mask.type() == CV_8U && src.size() == mask.size())); CV_Assert(src.type() != CV_64F || (TargetArchs::builtWith(NATIVE_DOUBLE) && - hasNativeDoubleSupport(getDevice()))); + DeviceInfo().has(NATIVE_DOUBLE))); double minVal_; if (!minVal) minVal = &minVal_; double maxVal_; if (!maxVal) maxVal = &maxVal_; @@ -296,7 +296,7 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp if (mask.empty()) { Caller* callers = multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = singlepass_callers; Caller caller = callers[src.type()]; @@ -306,7 +306,7 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp else { MaskedCaller* callers = masked_multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = masked_singlepass_callers; MaskedCaller caller = callers[src.type()]; @@ -383,7 +383,7 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point CV_Assert(mask.empty() || (mask.type() == CV_8U && src.size() == mask.size())); CV_Assert(src.type() != CV_64F || (TargetArchs::builtWith(NATIVE_DOUBLE) && - hasNativeDoubleSupport(getDevice()))); + DeviceInfo().has(NATIVE_DOUBLE))); double minVal_; if (!minVal) minVal = &minVal_; double maxVal_; if (!maxVal) maxVal = &maxVal_; @@ -399,7 +399,7 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point if (mask.empty()) { Caller* callers = multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = singlepass_callers; Caller caller = callers[src.type()]; @@ -409,7 +409,7 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point else { MaskedCaller* callers = masked_multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = masked_singlepass_callers; MaskedCaller caller = callers[src.type()]; @@ -464,14 +464,14 @@ int cv::gpu::countNonZero(const GpuMat& src, GpuMat& buf) CV_Assert(src.channels() == 1); CV_Assert(src.type() != CV_64F || (TargetArchs::builtWith(NATIVE_DOUBLE) && - hasNativeDoubleSupport(getDevice()))); + DeviceInfo().has(NATIVE_DOUBLE))); Size buf_size; getBufSizeRequired(src.cols, src.rows, buf_size.width, buf_size.height); ensureSizeIsEnough(buf_size, CV_8U, buf); Caller* callers = multipass_callers; - if (TargetArchs::builtWith(ATOMICS) && hasAtomicsSupport(getDevice())) + if (TargetArchs::builtWith(ATOMICS) && DeviceInfo().has(ATOMICS)) callers = singlepass_callers; Caller caller = callers[src.type()]; diff --git a/modules/gpu/src/split_merge.cpp b/modules/gpu/src/split_merge.cpp index b3b2fa4b69..6f6b95ec06 100644 --- a/modules/gpu/src/split_merge.cpp +++ b/modules/gpu/src/split_merge.cpp @@ -74,7 +74,7 @@ namespace cv { namespace gpu { namespace split_merge CV_Assert(n > 0); bool double_ok = TargetArchs::builtWith(NATIVE_DOUBLE) && - hasNativeDoubleSupport(getDevice()); + DeviceInfo().has(NATIVE_DOUBLE); CV_Assert(src[0].depth() != CV_64F || double_ok); int depth = src[0].depth(); @@ -117,7 +117,7 @@ namespace cv { namespace gpu { namespace split_merge CV_Assert(dst); bool double_ok = TargetArchs::builtWith(NATIVE_DOUBLE) && - hasNativeDoubleSupport(getDevice()); + DeviceInfo().has(NATIVE_DOUBLE); CV_Assert(src.depth() != CV_64F || double_ok); int depth = src.depth(); diff --git a/modules/gpu/src/stereobm.cpp b/modules/gpu/src/stereobm.cpp index fb8f7515b6..5c82fa117b 100644 --- a/modules/gpu/src/stereobm.cpp +++ b/modules/gpu/src/stereobm.cpp @@ -86,13 +86,9 @@ bool cv::gpu::StereoBM_GPU::checkIfGpuCallReasonable() if (0 == getCudaEnabledDeviceCount()) return false; - int device = getDevice(); + DeviceInfo device_info; - int minor, major; - getComputeCapability(device, major, minor); - int numSM = getNumberOfSMs(device); - - if (major > 1 || numSM > 16) + if (device_info.major() > 1 || device_info.multiProcessorCount() > 16) return true; return false; diff --git a/modules/gpu/src/surf.cpp b/modules/gpu/src/surf.cpp index 58f346332c..fc2313f24c 100644 --- a/modules/gpu/src/surf.cpp +++ b/modules/gpu/src/surf.cpp @@ -104,7 +104,7 @@ namespace CV_Assert(img.type() == CV_8UC1); CV_Assert(mask.empty() || (mask.size() == img.size() && mask.type() == CV_8UC1)); CV_Assert(nOctaves > 0 && nIntervals > 2); - CV_Assert(hasAtomicsSupport(getDevice())); + CV_Assert(DeviceInfo().has(ATOMICS)); max_features = static_cast(img.size().area() * featuresRatio); max_candidates = static_cast(1.5 * max_features); diff --git a/tests/gpu/src/arithm.cpp b/tests/gpu/src/arithm.cpp index 338b8e3f3d..fe2385a518 100644 --- a/tests/gpu/src/arithm.cpp +++ b/tests/gpu/src/arithm.cpp @@ -660,7 +660,7 @@ struct CV_GpuMinMaxTest: public CvTest try { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); int depth_end = double_ok ? CV_64F : CV_32F; for (int depth = CV_8U; depth <= depth_end; ++depth) @@ -794,7 +794,7 @@ struct CV_GpuMinMaxLocTest: public CvTest try { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); int depth_end = double_ok ? CV_64F : CV_32F; for (int depth = CV_8U; depth <= depth_end; ++depth) @@ -875,7 +875,7 @@ struct CV_GpuCountNonZeroTest: CvTest try { int depth_end; - if (cv::gpu::hasNativeDoubleSupport(cv::gpu::getDevice())) + if (cv::gpu::DeviceInfo().has(cv::gpu::NATIVE_DOUBLE)) depth_end = CV_64F; else depth_end = CV_32F; diff --git a/tests/gpu/src/bitwise_oper.cpp b/tests/gpu/src/bitwise_oper.cpp index a3379b3e90..9cd0d5b4f6 100644 --- a/tests/gpu/src/bitwise_oper.cpp +++ b/tests/gpu/src/bitwise_oper.cpp @@ -60,7 +60,7 @@ struct CV_GpuBitwiseTest: public CvTest int rows, cols; bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); int depth_end = double_ok ? CV_64F : CV_32F; for (int depth = CV_8U; depth <= depth_end; ++depth) diff --git a/tests/gpu/src/match_template.cpp b/tests/gpu/src/match_template.cpp index 431d547cc9..479ea09fa8 100644 --- a/tests/gpu/src/match_template.cpp +++ b/tests/gpu/src/match_template.cpp @@ -65,7 +65,7 @@ struct CV_GpuMatchTemplateTest: CvTest try { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); if (!double_ok) { // For sqrIntegral @@ -245,7 +245,7 @@ struct CV_GpuMatchTemplateFindPatternInBlackTest: CvTest try { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); if (!double_ok) { // For sqrIntegral diff --git a/tests/gpu/src/meanshift.cpp b/tests/gpu/src/meanshift.cpp index 7e19a3762a..dc3942306c 100644 --- a/tests/gpu/src/meanshift.cpp +++ b/tests/gpu/src/meanshift.cpp @@ -54,12 +54,9 @@ struct CV_GpuMeanShiftTest : public CvTest int colorRad = 30; cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "meanshift/cones.png"); - cv::Mat img_template; + cv::Mat img_template; - int major, minor; - cv::gpu::getComputeCapability(cv::gpu::getDevice(), major, minor); - - if (cv::gpu::TargetArchs::hasEqualOrGreater(2, 0) && major >= 2) + if (cv::gpu::TargetArchs::hasEqualOrGreater(2, 0) && cv::gpu::DeviceInfo().major() >= 2) img_template = cv::imread(std::string(ts->get_data_path()) + "meanshift/con_result.png"); else img_template = cv::imread(std::string(ts->get_data_path()) + "meanshift/con_result_CC1X.png"); @@ -202,10 +199,7 @@ struct CV_GpuMeanShiftProcTest : public CvTest cv::Mat spmap_template; cv::FileStorage fs; - int major, minor; - cv::gpu::getComputeCapability(cv::gpu::getDevice(), major, minor); - - if (cv::gpu::TargetArchs::hasEqualOrGreater(2, 0) && major >= 2) + if (cv::gpu::TargetArchs::hasEqualOrGreater(2, 0) && cv::gpu::DeviceInfo().major() >= 2) fs.open(std::string(ts->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ); else fs.open(std::string(ts->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ); diff --git a/tests/gpu/src/mssegmentation.cpp b/tests/gpu/src/mssegmentation.cpp index 268cdb1937..ea09b0101a 100644 --- a/tests/gpu/src/mssegmentation.cpp +++ b/tests/gpu/src/mssegmentation.cpp @@ -63,15 +63,13 @@ struct CV_GpuMeanShiftSegmentationTest : public CvTest { Mat img; cvtColor(img_rgb, img, CV_BGR2BGRA); - - int major, minor; - cv::gpu::getComputeCapability(cv::gpu::getDevice(), major, minor); + for (int minsize = 0; minsize < 2000; minsize = (minsize + 1) * 4) { stringstream path; path << ts->get_data_path() << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize; - if (TargetArchs::hasEqualOrGreater(2, 0) && major >= 2) + if (TargetArchs::hasEqualOrGreater(2, 0) && DeviceInfo().major() >= 2) path << ".png"; else path << "_CC1X.png"; diff --git a/tests/gpu/src/split_merge.cpp b/tests/gpu/src/split_merge.cpp index 6a09dffff9..e96e7d8986 100644 --- a/tests/gpu/src/split_merge.cpp +++ b/tests/gpu/src/split_merge.cpp @@ -64,7 +64,7 @@ struct CV_MergeTest : public CvTest void CV_MergeTest::can_merge(size_t rows, size_t cols) { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); size_t depth_end = double_ok ? CV_64F : CV_32F; for (size_t num_channels = 1; num_channels <= 4; ++num_channels) @@ -106,7 +106,7 @@ 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::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); size_t depth_end = double_ok ? CV_64F : CV_32F; for (size_t num_channels = 1; num_channels <= 4; ++num_channels) @@ -180,7 +180,7 @@ struct CV_SplitTest : public CvTest void CV_SplitTest::can_split(size_t rows, size_t cols) { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); size_t depth_end = double_ok ? CV_64F : CV_32F; for (size_t num_channels = 1; num_channels <= 4; ++num_channels) @@ -222,7 +222,7 @@ 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::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); size_t depth_end = double_ok ? CV_64F : CV_32F; for (size_t num_channels = 1; num_channels <= 4; ++num_channels) @@ -293,7 +293,7 @@ struct CV_SplitMergeTest : public CvTest void CV_SplitMergeTest::can_split_merge(size_t rows, size_t cols) { bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) && - gpu::hasNativeDoubleSupport(gpu::getDevice()); + gpu::DeviceInfo().has(gpu::NATIVE_DOUBLE); size_t depth_end = double_ok ? CV_64F : CV_32F; for (size_t num_channels = 1; num_channels <= 4; ++num_channels)