refactoring of GPU module

pull/13383/head
Alexey Spizhevoy 14 years ago
parent 6b6a63ba38
commit 04709a2793
  1. 15
      modules/gpu/include/opencv2/gpu/gpu.hpp
  2. 32
      modules/gpu/src/multi_gpu_manager.cpp
  3. 2
      samples/gpu/multi.cpp
  4. 2
      samples/gpu/stereo_multi.cpp

@ -76,6 +76,8 @@ namespace cv
NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13 NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13
}; };
// Gives information about what GPU archs this OpenCV GPU module was
// compiled for
class CV_EXPORTS TargetArchs class CV_EXPORTS TargetArchs
{ {
public: public:
@ -91,6 +93,7 @@ namespace cv
TargetArchs(); TargetArchs();
}; };
// Gives information about the given GPU
class CV_EXPORTS DeviceInfo class CV_EXPORTS DeviceInfo
{ {
public: public:
@ -132,11 +135,11 @@ namespace cv
/////////////////////////// Multi GPU Manager ////////////////////////////// /////////////////////////// Multi GPU Manager //////////////////////////////
// Provides functionality for working with many GPUs // Provides functionality for working with many GPUs
class CV_EXPORTS MultiGpuMgr class CV_EXPORTS MultiGpuManager
{ {
public: public:
MultiGpuMgr(); MultiGpuManager();
~MultiGpuMgr(); ~MultiGpuManager();
// Must be called before any other GPU calls // Must be called before any other GPU calls
void init(); void init();
@ -144,14 +147,14 @@ namespace cv
// Makes the given GPU active // Makes the given GPU active
void gpuOn(int gpu_id); void gpuOn(int gpu_id);
// Finishes the piece of work with the current GPU // Finishes the piece of work on the current GPU
void gpuOff(); void gpuOff();
static const int BAD_GPU_ID = -1; static const int BAD_GPU_ID = -1;
private: private:
void operator=(const MultiGpuMgr&); void operator=(const MultiGpuManager&);
MultiGpuMgr(const MultiGpuMgr&); MultiGpuManager(const MultiGpuManager&);
class Impl; class Impl;
Ptr<Impl> impl_; Ptr<Impl> impl_;

@ -46,17 +46,17 @@
namespace cv { namespace gpu { namespace cv { namespace gpu {
class MultiGpuMgr::Impl {}; class MultiGpuManager::Impl {};
MultiGpuMgr::MultiGpuMgr() { throw_nogpu(); } MultiGpuManager::MultiGpuManager() { throw_nogpu(); }
void MultiGpuMgr::init() { throw_nogpu(); } MultiGpuManager::~MultiGpuManager() { throw_nogpu(); }
void MultiGpuMgr::gpuOn(int) { throw_nogpu(); } void MultiGpuManager::init() { throw_nogpu(); }
void MultiGpuMgr::gpuOff() { throw_nogpu(); } void MultiGpuManager::gpuOn(int) { throw_nogpu(); }
void MultiGpuManager::gpuOff() { throw_nogpu(); }
}} }}
#else #else
#include <stack>
#include <vector> #include <vector>
#include <cuda.h> #include <cuda.h>
@ -67,7 +67,7 @@ using namespace std;
namespace cv { namespace gpu { namespace cv { namespace gpu {
class MultiGpuMgr::Impl class MultiGpuManager::Impl
{ {
public: public:
Impl(); Impl();
@ -81,7 +81,7 @@ public:
void gpuOn(int gpu_id) void gpuOn(int gpu_id)
{ {
if (gpu_id < 0 || gpu_id >= num_devices_) if (gpu_id < 0 || gpu_id >= num_devices_)
CV_Error(CV_StsBadArg, "MultiGpuMgr::gpuOn: GPU ID is out of range"); CV_Error(CV_StsBadArg, "MultiGpuManager::gpuOn: GPU ID is out of range");
cuSafeCall(cuCtxPushCurrent(contexts_[gpu_id])); cuSafeCall(cuCtxPushCurrent(contexts_[gpu_id]));
} }
@ -103,7 +103,7 @@ private:
}; };
MultiGpuMgr::Impl::Impl(): num_devices_(0) MultiGpuManager::Impl::Impl(): num_devices_(0)
{ {
num_devices_ = getCudaEnabledDeviceCount(); num_devices_ = getCudaEnabledDeviceCount();
contexts_.resize(num_devices_); contexts_.resize(num_devices_);
@ -121,28 +121,28 @@ MultiGpuMgr::Impl::Impl(): num_devices_(0)
} }
MultiGpuMgr::MultiGpuMgr() {} MultiGpuManager::MultiGpuManager() {}
MultiGpuMgr::~MultiGpuMgr() {} MultiGpuManager::~MultiGpuManager() {}
void MultiGpuMgr::init() void MultiGpuManager::init()
{ {
impl_ = Ptr<Impl>(new Impl()); impl_ = Ptr<Impl>(new Impl());
} }
void MultiGpuMgr::gpuOn(int gpu_id) void MultiGpuManager::gpuOn(int gpu_id)
{ {
if (impl_.empty()) if (impl_.empty())
CV_Error(CV_StsNullPtr, "MultiGpuMgr::gpuOn: must be initialized before any calls"); CV_Error(CV_StsNullPtr, "MultiGpuManager::gpuOn: must be initialized before any calls");
impl_->gpuOn(gpu_id); impl_->gpuOn(gpu_id);
} }
void MultiGpuMgr::gpuOff() void MultiGpuManager::gpuOff()
{ {
if (impl_.empty()) if (impl_.empty())
CV_Error(CV_StsNullPtr, "MultiGpuMgr::gpuOff: must be initialized before any calls"); CV_Error(CV_StsNullPtr, "MultiGpuManager::gpuOff: must be initialized before any calls");
impl_->gpuOff(); impl_->gpuOff();
} }

@ -36,7 +36,7 @@ using namespace cv::gpu;
struct Worker { void operator()(int device_id) const; }; struct Worker { void operator()(int device_id) const; };
MultiGpuMgr multi_gpu_mgr; MultiGpuManager multi_gpu_mgr;
int main() int main()
{ {

@ -38,7 +38,7 @@ using namespace cv::gpu;
struct Worker { void operator()(int device_id) const; }; struct Worker { void operator()(int device_id) const; };
MultiGpuMgr multi_gpu_mgr; MultiGpuManager multi_gpu_mgr;
// GPUs data // GPUs data
GpuMat d_left[2]; GpuMat d_left[2];

Loading…
Cancel
Save