From a42a42858c0bbbb620575b99ac72c6f3cf3b21c9 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Mon, 14 Feb 2011 15:09:45 +0000 Subject: [PATCH] fixed GPU samples and MultiGpuMgr --- modules/gpu/include/opencv2/gpu/gpu.hpp | 3 --- modules/gpu/src/multi_gpu_mgr.cpp | 27 +------------------------ samples/gpu/multi.cpp | 12 ++++++----- samples/gpu/stereo_multi.cpp | 12 ++++++----- 4 files changed, 15 insertions(+), 39 deletions(-) diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index 95657cb78..a18e88bac 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -139,9 +139,6 @@ namespace cv public: MultiGpuMgr(); - // Returns the current GPU id (or BAD_GPU_ID if no GPU is active) - int currentGpuId() const; - // Makes the given GPU active void gpuOn(int gpu_id); diff --git a/modules/gpu/src/multi_gpu_mgr.cpp b/modules/gpu/src/multi_gpu_mgr.cpp index fd31f2193..51fc5c426 100644 --- a/modules/gpu/src/multi_gpu_mgr.cpp +++ b/modules/gpu/src/multi_gpu_mgr.cpp @@ -48,7 +48,6 @@ namespace cv { namespace gpu { class MultiGpuMgr::Impl {}; MultiGpuMgr::MultiGpuMgr() { throw_nogpu(); } -int MultiGpuMgr::currentGpuId() const { throw_nogpu(); return 0; } void MultiGpuMgr::gpuOn(int) { throw_nogpu(); } void MultiGpuMgr::gpuOff() { throw_nogpu(); } @@ -78,31 +77,15 @@ public: cuSafeCall(cuCtxDestroy(contexts_[i])); } - int currentGpuId() const - { - if (gpu_id_stack_.empty()) - return MultiGpuMgr::BAD_GPU_ID; - return gpu_id_stack_.top(); - } - void gpuOn(int gpu_id) { - if (gpu_id != currentGpuId()) - { - cuSafeCall(cuCtxPushCurrent(contexts_[gpu_id])); - gpu_id_stack_.push(gpu_id); - } + cuSafeCall(cuCtxPushCurrent(contexts_[gpu_id])); } void gpuOff() { - if (gpu_id_stack_.empty()) - return; - CUcontext prev_context; cuSafeCall(cuCtxPopCurrent(&prev_context)); - - gpu_id_stack_.pop(); } private: @@ -113,7 +96,6 @@ private: } int num_devices_; - stack gpu_id_stack_; vector contexts_; }; @@ -134,16 +116,9 @@ MultiGpuMgr::Impl::Impl(): num_devices_(0) } - MultiGpuMgr::MultiGpuMgr(): impl_(new Impl()) {} -int MultiGpuMgr::currentGpuId() const -{ - return impl_->currentGpuId(); -} - - void MultiGpuMgr::gpuOn(int gpu_id) { impl_->gpuOn(gpu_id); diff --git a/samples/gpu/multi.cpp b/samples/gpu/multi.cpp index 7c42b3cd8..e2d1f2cf4 100644 --- a/samples/gpu/multi.cpp +++ b/samples/gpu/multi.cpp @@ -39,11 +39,13 @@ using namespace cv::gpu; struct Worker { void operator()(int device_id) const; }; void destroyContexts(); -#define safeCall(code) if (code != CUDA_SUCCESS) { \ - cout << "CUDA driver API error: code " << code \ - << ", file " << __FILE__ << ", line " << __LINE__ << endl; \ - destroyContexts(); \ - exit(-1); \ +#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__) +inline void safeCall_(int code, const char* expr, const char* file, int line) +{ + cout << "CUDA driver API error: code " << code << ", expr " << expr + << ", file " << file << ", line " << line << endl; + destroyContexts(); + exit(-1); } // Each GPU is associated with its own context diff --git a/samples/gpu/stereo_multi.cpp b/samples/gpu/stereo_multi.cpp index 8a57f4949..a25ac0219 100644 --- a/samples/gpu/stereo_multi.cpp +++ b/samples/gpu/stereo_multi.cpp @@ -41,11 +41,13 @@ using namespace cv::gpu; struct Worker { void operator()(int device_id) const; }; void destroyContexts(); -#define safeCall(code) if (code != CUDA_SUCCESS) { \ - cout << "CUDA driver API error: code " << code \ - << ", file " << __FILE__ << ", line " << __LINE__ << endl; \ - destroyContexts(); \ - exit(-1); \ +#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__) +inline void safeCall_(int code, const char* expr, const char* file, int line) +{ + cout << "CUDA driver API error: code " << code << ", expr " << expr + << ", file " << file << ", line " << line << endl; + destroyContexts(); + exit(-1); } // Each GPU is associated with its own context