MemoryStack* MemoryPool::getFreeMemStack()
{
AutoLock lock(mtx_);
-
if (!initialized_)
initilizeImpl();
namespace
{
+ Mutex mtx_;
+ bool memory_pool_manager_initialized;
+
class MemoryPoolManager
{
public:
MemoryPoolManager();
~MemoryPoolManager();
+ void Init();
MemoryPool* getPool(int deviceId);
private:
std::vector<MemoryPool> pools_;
- };
+ } manager;
+
+ //MemoryPoolManager ;
MemoryPoolManager::MemoryPoolManager()
{
- int deviceCount = getCudaEnabledDeviceCount();
+ }
+ void MemoryPoolManager::Init()
+ {
+ int deviceCount = getCudaEnabledDeviceCount();
if (deviceCount > 0)
pools_.resize(deviceCount);
}
{
for (size_t i = 0; i < pools_.size(); ++i)
{
- cudaSetDevice(i);
+ cudaSetDevice(static_cast<int>(i));
pools_[i].release();
}
}
MemoryPool* memPool(int deviceId)
{
- static MemoryPoolManager manager;
+ {
+ AutoLock lock(mtx_);
+ if (!memory_pool_manager_initialized)
+ {
+ memory_pool_manager_initialized = true;
+ manager.Init();
+ }
+ }
return manager.getPool(deviceId);
}
}
if (enableMemoryPool)
{
const int deviceId = getDevice();
- memStack_ = memPool(deviceId)->getFreeMemStack();
-
+ {
+ AutoLock lock(mtx_);
+ memStack_ = memPool(deviceId)->getFreeMemStack();
+ }
DeviceInfo devInfo(deviceId);
alignment_ = devInfo.textureAlignment();
}
#endif
}
+namespace
+{
+ bool default_stream_is_initialized;
+ Mutex mtx;
+ Ptr<Stream> default_stream;
+}
+
Stream& cv::cuda::Stream::Null()
{
- static Stream s(Ptr<Impl>(new Impl(0)));
- return s;
+ AutoLock lock(mtx);
+ if (!default_stream_is_initialized)
+ {
+ default_stream = Ptr<Stream>(new Stream(Ptr<Impl>(new Impl(0))));
+ default_stream_is_initialized = true;
+ }
+ return *default_stream;
}
cv::cuda::Stream::operator bool_type() const
namespace
{
+ Mutex mtx;
+
int calcSize(int octave, int layer)
{
/* Wavelet size at first layer of first octave. */
{
const int layer_rows = img_rows >> octave;
const int layer_cols = img_cols >> octave;
-
loadOctaveConstants(octave, layer_rows, layer_cols);
icvCalcLayerDetAndTrace_gpu(surf_.det, surf_.trace, img_rows, img_cols, octave, surf_.nOctaveLayers);
void cv::cuda::SURF_CUDA::operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints)
{
+ AutoLock lock(mtx);
if (!img.empty())
{
SURF_CUDA_Invoker surf(*this, img, mask);
void cv::cuda::SURF_CUDA::operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors,
bool useProvidedKeypoints)
{
+ AutoLock lock(mtx);
if (!img.empty())
{
SURF_CUDA_Invoker surf(*this, img, mask);
void cv::cuda::SURF_CUDA::operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints)
{
+ AutoLock lock(mtx);
GpuMat keypointsGPU;
(*this)(img, mask, keypointsGPU);
void cv::cuda::SURF_CUDA::operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints,
GpuMat& descriptors, bool useProvidedKeypoints)
{
+ AutoLock lock(mtx);
GpuMat keypointsGPU;
if (useProvidedKeypoints)
void cv::cuda::SURF_CUDA::operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints,
std::vector<float>& descriptors, bool useProvidedKeypoints)
{
+ AutoLock lock(mtx);
GpuMat descriptorsGPU;
(*this)(img, mask, keypoints, descriptorsGPU, useProvidedKeypoints);