Commit a42a4285 authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

fixed GPU samples and MultiGpuMgr

parent 6ce1c0e2
...@@ -139,9 +139,6 @@ namespace cv ...@@ -139,9 +139,6 @@ namespace cv
public: public:
MultiGpuMgr(); MultiGpuMgr();
// Returns the current GPU id (or BAD_GPU_ID if no GPU is active)
int currentGpuId() const;
// Makes the given GPU active // Makes the given GPU active
void gpuOn(int gpu_id); void gpuOn(int gpu_id);
......
...@@ -48,7 +48,6 @@ namespace cv { namespace gpu { ...@@ -48,7 +48,6 @@ namespace cv { namespace gpu {
class MultiGpuMgr::Impl {}; class MultiGpuMgr::Impl {};
MultiGpuMgr::MultiGpuMgr() { throw_nogpu(); } MultiGpuMgr::MultiGpuMgr() { throw_nogpu(); }
int MultiGpuMgr::currentGpuId() const { throw_nogpu(); return 0; }
void MultiGpuMgr::gpuOn(int) { throw_nogpu(); } void MultiGpuMgr::gpuOn(int) { throw_nogpu(); }
void MultiGpuMgr::gpuOff() { throw_nogpu(); } void MultiGpuMgr::gpuOff() { throw_nogpu(); }
...@@ -78,31 +77,15 @@ public: ...@@ -78,31 +77,15 @@ public:
cuSafeCall(cuCtxDestroy(contexts_[i])); 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) void gpuOn(int gpu_id)
{ {
if (gpu_id != currentGpuId()) cuSafeCall(cuCtxPushCurrent(contexts_[gpu_id]));
{
cuSafeCall(cuCtxPushCurrent(contexts_[gpu_id]));
gpu_id_stack_.push(gpu_id);
}
} }
void gpuOff() void gpuOff()
{ {
if (gpu_id_stack_.empty())
return;
CUcontext prev_context; CUcontext prev_context;
cuSafeCall(cuCtxPopCurrent(&prev_context)); cuSafeCall(cuCtxPopCurrent(&prev_context));
gpu_id_stack_.pop();
} }
private: private:
...@@ -113,7 +96,6 @@ private: ...@@ -113,7 +96,6 @@ private:
} }
int num_devices_; int num_devices_;
stack<int> gpu_id_stack_;
vector<CUcontext> contexts_; vector<CUcontext> contexts_;
}; };
...@@ -134,16 +116,9 @@ MultiGpuMgr::Impl::Impl(): num_devices_(0) ...@@ -134,16 +116,9 @@ MultiGpuMgr::Impl::Impl(): num_devices_(0)
} }
MultiGpuMgr::MultiGpuMgr(): impl_(new Impl()) {} MultiGpuMgr::MultiGpuMgr(): impl_(new Impl()) {}
int MultiGpuMgr::currentGpuId() const
{
return impl_->currentGpuId();
}
void MultiGpuMgr::gpuOn(int gpu_id) void MultiGpuMgr::gpuOn(int gpu_id)
{ {
impl_->gpuOn(gpu_id); impl_->gpuOn(gpu_id);
......
...@@ -39,11 +39,13 @@ using namespace cv::gpu; ...@@ -39,11 +39,13 @@ using namespace cv::gpu;
struct Worker { void operator()(int device_id) const; }; struct Worker { void operator()(int device_id) const; };
void destroyContexts(); void destroyContexts();
#define safeCall(code) if (code != CUDA_SUCCESS) { \ #define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
cout << "CUDA driver API error: code " << code \ inline void safeCall_(int code, const char* expr, const char* file, int line)
<< ", file " << __FILE__ << ", line " << __LINE__ << endl; \ {
destroyContexts(); \ cout << "CUDA driver API error: code " << code << ", expr " << expr
exit(-1); \ << ", file " << file << ", line " << line << endl;
destroyContexts();
exit(-1);
} }
// Each GPU is associated with its own context // Each GPU is associated with its own context
......
...@@ -41,11 +41,13 @@ using namespace cv::gpu; ...@@ -41,11 +41,13 @@ using namespace cv::gpu;
struct Worker { void operator()(int device_id) const; }; struct Worker { void operator()(int device_id) const; };
void destroyContexts(); void destroyContexts();
#define safeCall(code) if (code != CUDA_SUCCESS) { \ #define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
cout << "CUDA driver API error: code " << code \ inline void safeCall_(int code, const char* expr, const char* file, int line)
<< ", file " << __FILE__ << ", line " << __LINE__ << endl; \ {
destroyContexts(); \ cout << "CUDA driver API error: code " << code << ", expr " << expr
exit(-1); \ << ", file " << file << ", line " << line << endl;
destroyContexts();
exit(-1);
} }
// Each GPU is associated with its own context // Each GPU is associated with its own context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment