fixed TargetArchs implementation in case when HAVE_CUDA=false, added initial structure for multi_gpu sample

This commit is contained in:
Alexey Spizhevoy 2011-01-27 12:17:56 +00:00
parent 85e5de67e4
commit 65b9f3bc10
3 changed files with 124 additions and 93 deletions

View File

@ -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 <typename Comparer>
@ -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

View File

@ -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")

34
samples/gpu/multi_gpu.cpp Normal file
View File

@ -0,0 +1,34 @@
// Disable some warnings which are caused with CUDA headers
#pragma warning(disable: 4201 4408 4100)
#include <iostream>
#include <cvconfig.h>
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/highgui/highgui.hpp>
#ifdef HAVE_CUDA
#include <cuda_runtime.h>
#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;
}