From 65b9f3bc108850722a3be1e165e9ddeda4cab0d9 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Thu, 27 Jan 2011 12:17:56 +0000 Subject: [PATCH] fixed TargetArchs implementation in case when HAVE_CUDA=false, added initial structure for multi_gpu sample --- modules/gpu/src/initialization.cpp | 179 ++++++++++++++--------------- samples/gpu/CMakeLists.txt | 4 + samples/gpu/multi_gpu.cpp | 34 ++++++ 3 files changed, 124 insertions(+), 93 deletions(-) create mode 100644 samples/gpu/multi_gpu.cpp diff --git a/modules/gpu/src/initialization.cpp b/modules/gpu/src/initialization.cpp index a1b7fcd76..cab5f626c 100644 --- a/modules/gpu/src/initialization.cpp +++ b/modules/gpu/src/initialization.cpp @@ -46,99 +46,6 @@ using namespace cv; using namespace cv::gpu; -#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 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::hasPtxVersion(int major, int minor) { throw_nogpu(); return false; } -CV_EXPORTS bool cv::gpu::hasLessOrEqualPtxVersion(int major, int minor) { return false; } -CV_EXPORTS bool cv::gpu::hasGreaterOrEqualPtxVersion(int major, int minor) { return false; } -CV_EXPORTS bool cv::gpu::hasCubinVersion(int major, int minor) { return false; } -CV_EXPORTS bool cv::gpu::hasGreaterOrEqualCubinVersion(int major, int minor) { return false; } -CV_EXPORTS bool cv::gpu::hasVersion(int major, int minor) { return false; } -CV_EXPORTS bool cv::gpu::hasGreaterOrEqualVersion(int major, int minor) { return false; } -CV_EXPORTS bool cv::gpu::isCompatibleWith(int device) { throw_nogpu(); return false; } - - -#else /* !defined (HAVE_CUDA) */ - -CV_EXPORTS int cv::gpu::getCudaEnabledDeviceCount() -{ - int count; - cudaSafeCall( cudaGetDeviceCount( &count ) ); - return count; -} - - -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 ) ); -} - - -CV_EXPORTS int cv::gpu::getDevice() -{ - int device; - cudaSafeCall( cudaGetDevice( &device ) ); - return device; -} - - -CV_EXPORTS void cv::gpu::getComputeCapability(int device, int& major, int& minor) -{ - cudaDeviceProp prop; - cudaSafeCall( cudaGetDeviceProperties( &prop, device) ); - - major = prop.major; - minor = prop.minor; -} - - -CV_EXPORTS int cv::gpu::getNumberOfSMs(int device) -{ - cudaDeviceProp prop; - cudaSafeCall( cudaGetDeviceProperties( &prop, device ) ); - return prop.multiProcessorCount; -} - - -CV_EXPORTS void cv::gpu::getGpuMemInfo(size_t& free, size_t& total) -{ - cudaSafeCall( cudaMemGetInfo( &free, &total ) ); -} - - -CV_EXPORTS bool cv::gpu::hasNativeDoubleSupport(int device) -{ - 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); -} - - namespace { template @@ -218,6 +125,92 @@ 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 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; } + + +#else /* !defined (HAVE_CUDA) */ + +CV_EXPORTS int cv::gpu::getCudaEnabledDeviceCount() +{ + int count; + cudaSafeCall( cudaGetDeviceCount( &count ) ); + return count; +} + + +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 ) ); +} + + +CV_EXPORTS int cv::gpu::getDevice() +{ + int device; + cudaSafeCall( cudaGetDevice( &device ) ); + return device; +} + + +CV_EXPORTS void cv::gpu::getComputeCapability(int device, int& major, int& minor) +{ + cudaDeviceProp prop; + cudaSafeCall( cudaGetDeviceProperties( &prop, device) ); + + major = prop.major; + minor = prop.minor; +} + + +CV_EXPORTS int cv::gpu::getNumberOfSMs(int device) +{ + cudaDeviceProp prop; + cudaSafeCall( cudaGetDeviceProperties( &prop, device ) ); + return prop.multiProcessorCount; +} + + +CV_EXPORTS void cv::gpu::getGpuMemInfo(size_t& free, size_t& total) +{ + cudaSafeCall( cudaMemGetInfo( &free, &total ) ); +} + + +CV_EXPORTS bool cv::gpu::hasNativeDoubleSupport(int device) +{ + 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 diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index c65c2e60b..de9fe6ef8 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -15,6 +15,10 @@ if (BUILD_EXAMPLES) "${CMAKE_SOURCE_DIR}/modules/contrib/include" "${CMAKE_SOURCE_DIR}/modules/gpu/include" ) + + if(HAVE_CUDA) + include_directories(${CUDA_INCLUDE_DIRS}) + endif() if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") diff --git a/samples/gpu/multi_gpu.cpp b/samples/gpu/multi_gpu.cpp new file mode 100644 index 000000000..262f6e03f --- /dev/null +++ b/samples/gpu/multi_gpu.cpp @@ -0,0 +1,34 @@ +// Disable some warnings which are caused with CUDA headers +#pragma warning(disable: 4201 4408 4100) + +#include +#include +#include +#include + +#ifdef HAVE_CUDA +#include +#endif + +using namespace std; +using namespace cv; + +int main() +{ + bool can_run = true; + +#if !defined(HAVE_CUDA) + cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n"; + can_run = false; +#endif + +#if !defined(HAVE_TBB) + cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n"; + can_run = false; +#endif + + if (!can_run) + return -1; + + return 0; +} \ No newline at end of file