1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

updated main CMakeLists.txt gpu module section, now user can manage binary and intermediate code versions of the gpu module image

added more functions to check version of gpu code in runtime
This commit is contained in:
Alexey Spizhevoy
2011-01-20 09:22:05 +00:00
parent 1e1a139270
commit 8779306800
6 changed files with 216 additions and 95 deletions
+9 -4
View File
@@ -72,11 +72,16 @@ namespace cv
CV_EXPORTS bool hasNativeDoubleSupport(int device);
CV_EXPORTS bool hasAtomicsSupport(int device);
CV_EXPORTS bool ptxVersionIs(int major, int minor);
CV_EXPORTS bool ptxVersionIsLessOrEqual(int major, int minor);
CV_EXPORTS bool ptxVersionIsGreaterOrEqual(int major, int minor);
CV_EXPORTS bool hasPtxVersion(int major, int minor);
CV_EXPORTS bool hasLessOrEqualPtxVersion(int major, int minor);
CV_EXPORTS bool hasGreaterOrEqualPtxVersion(int major, int minor);
CV_EXPORTS bool hasCubinVersion(int major, int minor);
CV_EXPORTS bool hasGreaterOrEqualCubinVersion(int major, int minor);
CV_EXPORTS bool hasVersion(int major, int minor);
CV_EXPORTS bool hasGreaterOrEqualVersion(int major, int minor);
//! Checks if the GPU module is PTX compatible with the given NVIDIA device
CV_EXPORTS bool isCompatibleWith(int device);
//////////////////////////////// Error handling ////////////////////////
+94 -23
View File
@@ -57,9 +57,13 @@ 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::ptxVersionIs(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::ptxVersionIsLessOrEqual(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::ptxVersionIsGreaterOrEqual(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasPtxVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasLessOrEqualPtxVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasGreaterOrEqualPtxVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasCubinVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasGreaterOrEqualCubinVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::hasGreaterOrEqualVersion(int major, int minor) { throw_nogpu(); return false; }
CV_EXPORTS bool cv::gpu::isCompatibleWith(int device) { throw_nogpu(); return false; }
@@ -140,37 +144,63 @@ namespace
template <typename Comparer>
bool checkPtxVersion(int major, int minor, Comparer cmp)
{
#ifdef OPENCV_GPU_CUDA_ARCH_10
#ifdef OPENCV_ARCH_PTX_10
if (cmp(1, 0, major, minor)) return true;
#endif
#ifdef OPENCV_GPU_CUDA_ARCH_11
#ifdef OPENCV_ARCH_PTX_11
if (cmp(1, 1, major, minor)) return true;
#endif
#ifdef OPENCV_GPU_CUDA_ARCH_12
#ifdef OPENCV_ARCH_PTX_12
if (cmp(1, 2, major, minor)) return true;
#endif
#ifdef OPENCV_GPU_CUDA_ARCH_13
#ifdef OPENCV_ARCH_PTX_13
if (cmp(1, 3, major, minor)) return true;
#endif
#ifdef OPENCV_GPU_CUDA_ARCH_20
#ifdef OPENCV_ARCH_PTX_20
if (cmp(2, 0, major, minor)) return true;
#endif
#ifdef OPENCV_GPU_CUDA_ARCH_21
#ifdef OPENCV_ARCH_PTX_21
if (cmp(2, 1, major, minor)) return true;
#endif
return false;
}
}
template <typename Comparer>
bool checkCubinVersion(int major, int minor, Comparer cmp)
{
#ifdef OPENCV_ARCH_GPU_10
if (cmp(1, 0, major, minor)) return true;
#endif
#ifdef OPENCV_ARCH_GPU_11
if (cmp(1, 1, major, minor)) return true;
#endif
#ifdef OPENCV_ARCH_GPU_12
if (cmp(1, 2, major, minor)) return true;
#endif
#ifdef OPENCV_ARCH_GPU_13
if (cmp(1, 3, major, minor)) return true;
#endif
#ifdef OPENCV_ARCH_GPU_20
if (cmp(2, 0, major, minor)) return true;
#endif
#ifdef OPENCV_ARCH_GPU_21
if (cmp(2, 1, major, minor)) return true;
#endif
return false;
}
CV_EXPORTS bool cv::gpu::ptxVersionIs(int major, int minor)
{
struct ComparerEqual
{
bool operator()(int lhs1, int lhs2, int rhs1, int rhs2) const
@@ -178,12 +208,7 @@ CV_EXPORTS bool cv::gpu::ptxVersionIs(int major, int minor)
return lhs1 == rhs1 && lhs2 == rhs2;
}
};
return checkPtxVersion(major, minor, ComparerEqual());
}
CV_EXPORTS bool cv::gpu::ptxVersionIsLessOrEqual(int major, int minor)
{
struct ComparerLessOrEqual
{
bool operator()(int lhs1, int lhs2, int rhs1, int rhs2) const
@@ -191,12 +216,7 @@ CV_EXPORTS bool cv::gpu::ptxVersionIsLessOrEqual(int major, int minor)
return lhs1 < rhs1 || (lhs1 == rhs1 && lhs2 <= rhs2);
}
};
return checkPtxVersion(major, minor, ComparerLessOrEqual());
}
CV_EXPORTS bool cv::gpu::ptxVersionIsGreaterOrEqual(int major, int minor)
{
struct ComparerGreaterOrEqual
{
bool operator()(int lhs1, int lhs2, int rhs1, int rhs2) const
@@ -204,10 +224,52 @@ CV_EXPORTS bool cv::gpu::ptxVersionIsGreaterOrEqual(int major, int minor)
return lhs1 > rhs1 || (lhs1 == rhs1 && lhs2 >= rhs2);
}
};
}
CV_EXPORTS bool cv::gpu::hasPtxVersion(int major, int minor)
{
return checkPtxVersion(major, minor, ComparerEqual());
}
CV_EXPORTS bool cv::gpu::hasLessOrEqualPtxVersion(int major, int minor)
{
return checkPtxVersion(major, minor, ComparerLessOrEqual());
}
CV_EXPORTS bool cv::gpu::hasGreaterOrEqualPtxVersion(int major, int minor)
{
return checkPtxVersion(major, minor, ComparerGreaterOrEqual());
}
CV_EXPORTS bool cv::gpu::hasCubinVersion(int major, int minor)
{
return checkCubinVersion(major, minor, ComparerEqual());
}
CV_EXPORTS bool cv::gpu::hasGreaterOrEqualCubinVersion(int major, int minor)
{
return checkCubinVersion(major, minor, ComparerGreaterOrEqual());
}
CV_EXPORTS bool cv::gpu::hasVersion(int major, int minor)
{
return hasPtxVersion(major, minor) || hasCubinVersion(major, minor);
}
CV_EXPORTS bool cv::gpu::hasGreaterOrEqualVersion(int major, int minor)
{
return hasGreaterOrEqualPtxVersion(major, minor) ||
hasGreaterOrEqualCubinVersion(major, minor);
}
CV_EXPORTS bool cv::gpu::isCompatibleWith(int device)
{
// According to the CUDA C Programming Guide Version 3.2: "PTX code
@@ -217,7 +279,16 @@ CV_EXPORTS bool cv::gpu::isCompatibleWith(int device)
int major, minor;
getComputeCapability(device, major, minor);
return ptxVersionIsLessOrEqual(major, minor);
// Check PTX compatibility
if (hasLessOrEqualPtxVersion(major, minor))
return true;
// Check CUBIN compatibilty
for (int i = 0; i <= minor; ++i)
if (hasCubinVersion(major, i))
return true;
return false;
}
#endif
+7 -7
View File
@@ -166,7 +166,7 @@ Scalar cv::gpu::sum(const GpuMat& src, GpuMat& buf)
ensureSizeIsEnough(buf_size, CV_8U, buf);
Caller* callers = multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = singlepass_callers;
Caller caller = callers[src.depth()];
@@ -202,7 +202,7 @@ Scalar cv::gpu::sqrSum(const GpuMat& src, GpuMat& buf)
sqrSumCaller<int>, sqrSumCaller<float>, 0 };
Caller* callers = multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = singlepass_callers;
Size buf_size;
@@ -289,7 +289,7 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp
if (mask.empty())
{
Caller* callers = multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = singlepass_callers;
Caller caller = callers[src.type()];
@@ -299,7 +299,7 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp
else
{
MaskedCaller* callers = masked_multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = masked_singlepass_callers;
MaskedCaller caller = callers[src.type()];
@@ -389,7 +389,7 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point
if (mask.empty())
{
Caller* callers = multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = singlepass_callers;
Caller caller = callers[src.type()];
@@ -399,7 +399,7 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point
else
{
MaskedCaller* callers = masked_multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = masked_singlepass_callers;
MaskedCaller caller = callers[src.type()];
@@ -459,7 +459,7 @@ int cv::gpu::countNonZero(const GpuMat& src, GpuMat& buf)
ensureSizeIsEnough(buf_size, CV_8U, buf);
Caller* callers = multipass_callers;
if (ptxVersionIsGreaterOrEqual(1, 1) && hasAtomicsSupport(getDevice()))
if (hasGreaterOrEqualVersion(1, 1) && hasAtomicsSupport(getDevice()))
callers = singlepass_callers;
Caller caller = callers[src.type()];