fixed GPU samples and MultiGpuMgr
This commit is contained in:
		@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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<int> gpu_id_stack_;
 | 
			
		||||
    vector<CUcontext> 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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user