Skip to content

Commit 8abd163

Browse files
committed
Merge pull request opencv#8404 from khnaba:stream-with-custom-allocator
2 parents e5dbd2c + 2968010 commit 8abd163

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

modules/core/include/opencv2/core/cuda.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ class CV_EXPORTS Stream
507507
//! creates a new asynchronous stream
508508
Stream();
509509

510+
//! creates a new asynchronous stream with custom allocator
511+
Stream(const Ptr<GpuMat::Allocator>& allocator);
512+
510513
/** @brief Returns true if the current stream queue is finished. Otherwise, it returns false.
511514
*/
512515
bool queryIfComplete() const;

modules/core/src/cuda_stream.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ class cv::cuda::Stream::Impl
282282
cudaStream_t stream;
283283
bool ownStream;
284284

285-
Ptr<StackAllocator> stackAllocator;
285+
Ptr<GpuMat::Allocator> allocator;
286286

287287
Impl();
288+
Impl(const Ptr<GpuMat::Allocator>& allocator);
288289
explicit Impl(cudaStream_t stream);
289290

290291
~Impl();
@@ -295,17 +296,23 @@ cv::cuda::Stream::Impl::Impl() : stream(0), ownStream(false)
295296
cudaSafeCall( cudaStreamCreate(&stream) );
296297
ownStream = true;
297298

298-
stackAllocator = makePtr<StackAllocator>(stream);
299+
allocator = makePtr<StackAllocator>(stream);
300+
}
301+
302+
cv::cuda::Stream::Impl::Impl(const Ptr<GpuMat::Allocator>& allocator) : stream(0), ownStream(false), allocator(allocator)
303+
{
304+
cudaSafeCall( cudaStreamCreate(&stream) );
305+
ownStream = true;
299306
}
300307

301308
cv::cuda::Stream::Impl::Impl(cudaStream_t stream_) : stream(stream_), ownStream(false)
302309
{
303-
stackAllocator = makePtr<StackAllocator>(stream);
310+
allocator = makePtr<StackAllocator>(stream);
304311
}
305312

306313
cv::cuda::Stream::Impl::~Impl()
307314
{
308-
stackAllocator.release();
315+
allocator.release();
309316

310317
if (stream && ownStream)
311318
{
@@ -417,6 +424,16 @@ cv::cuda::Stream::Stream()
417424
#endif
418425
}
419426

427+
cv::cuda::Stream::Stream(const Ptr<GpuMat::Allocator>& allocator)
428+
{
429+
#ifndef HAVE_CUDA
430+
(void) allocator;
431+
throw_no_cuda();
432+
#else
433+
impl_ = makePtr<Impl>(allocator);
434+
#endif
435+
}
436+
420437
bool cv::cuda::Stream::queryIfComplete() const
421438
{
422439
#ifndef HAVE_CUDA
@@ -675,7 +692,7 @@ cv::cuda::BufferPool::BufferPool(Stream& stream)
675692
throw_no_cuda();
676693
}
677694
#else
678-
cv::cuda::BufferPool::BufferPool(Stream& stream) : allocator_(stream.impl_->stackAllocator)
695+
cv::cuda::BufferPool::BufferPool(Stream& stream) : allocator_(stream.impl_->allocator)
679696
{
680697
}
681698
#endif

0 commit comments

Comments
 (0)