|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CV_DbgAssert( deviceId >= 0 && deviceId < static_cast<int>(streams_.size()) ); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < deviceCount; ++i) |
|
|
|
if (streams_[deviceId].empty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cudaStream_t stream = NULL; |
|
|
|
cudaStream_t stream = NULL; |
|
|
|
Ptr<Stream::Impl> impl = makePtr<Stream::Impl>(stream); |
|
|
|
Ptr<Stream::Impl> impl = makePtr<Stream::Impl>(stream); |
|
|
|
streams_[i] = Ptr<Stream>(new Stream(impl)); |
|
|
|
streams_[deviceId] = Ptr<Stream>(new Stream(impl)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
streams_initialized_ = true; |
|
|
|
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; |
|
|
|