Commit 68e08bbe authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

fix null stream initialization for multi-gpu systems

parent 05d40946
...@@ -330,14 +330,11 @@ namespace cv { namespace cuda ...@@ -330,14 +330,11 @@ namespace cv { namespace cuda
void initStreams(); void initStreams();
void initPools(); void initPools();
std::vector<Ptr<Stream> > streams_;
Mutex streams_mtx_; Mutex streams_mtx_;
volatile bool streams_initialized_;
Mutex pools_mtx_;
volatile bool pools_initialized_;
std::vector<Ptr<Stream> > streams_;
std::vector<MemoryPool> pools_; std::vector<MemoryPool> pools_;
Mutex pools_mtx_;
}; };
DefaultDeviceInitializer::DefaultDeviceInitializer() DefaultDeviceInitializer::DefaultDeviceInitializer()
...@@ -358,60 +355,44 @@ namespace cv { namespace cuda ...@@ -358,60 +355,44 @@ namespace cv { namespace cuda
} }
Stream& DefaultDeviceInitializer::getNullStream(int deviceId) Stream& DefaultDeviceInitializer::getNullStream(int deviceId)
{
initStreams();
CV_DbgAssert( deviceId >= 0 && deviceId < static_cast<int>(streams_.size()) );
return *streams_[deviceId];
}
MemoryPool* DefaultDeviceInitializer::getMemoryPool(int deviceId)
{
initPools();
CV_DbgAssert( deviceId >= 0 && deviceId < static_cast<int>(pools_.size()) );
return &pools_[deviceId];
}
void DefaultDeviceInitializer::initStreams()
{ {
AutoLock lock(streams_mtx_); AutoLock lock(streams_mtx_);
if (!streams_initialized_) if (streams_.empty())
{ {
int deviceCount = getCudaEnabledDeviceCount(); int deviceCount = getCudaEnabledDeviceCount();
if (deviceCount > 0) if (deviceCount > 0)
{
streams_.resize(deviceCount); streams_.resize(deviceCount);
}
for (int i = 0; i < deviceCount; ++i) CV_DbgAssert( deviceId >= 0 && deviceId < static_cast<int>(streams_.size()) );
{
cudaStream_t stream = NULL;
Ptr<Stream::Impl> impl = makePtr<Stream::Impl>(stream);
streams_[i] = Ptr<Stream>(new Stream(impl));
}
}
streams_initialized_ = true; if (streams_[deviceId].empty())
{
cudaStream_t stream = NULL;
Ptr<Stream::Impl> impl = makePtr<Stream::Impl>(stream);
streams_[deviceId] = Ptr<Stream>(new Stream(impl));
} }
return *streams_[deviceId];
} }
void DefaultDeviceInitializer::initPools() MemoryPool* DefaultDeviceInitializer::getMemoryPool(int deviceId)
{ {
AutoLock lock(pools_mtx_); AutoLock lock(pools_mtx_);
if (!pools_initialized_) if (pools_.empty())
{ {
int deviceCount = getCudaEnabledDeviceCount(); int deviceCount = getCudaEnabledDeviceCount();
if (deviceCount > 0) if (deviceCount > 0)
pools_.resize(deviceCount); pools_.resize(deviceCount);
pools_initialized_ = true;
} }
CV_DbgAssert( deviceId >= 0 && deviceId < static_cast<int>(pools_.size()) );
return &pools_[deviceId];
} }
DefaultDeviceInitializer initializer; DefaultDeviceInitializer initializer;
......
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