File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -656,6 +656,18 @@ class CV_EXPORTS_W Stream
656
656
// ! creates a new asynchronous stream with custom allocator
657
657
CV_WRAP Stream (const Ptr<GpuMat::Allocator>& allocator);
658
658
659
+ /* * @brief creates a new Stream using the cudaFlags argument to determine the behaviors of the stream
660
+
661
+ @note The cudaFlags parameter is passed to the underlying api cudaStreamCreateWithFlags() and
662
+ supports the same parameter values.
663
+ @code
664
+ // creates an OpenCV cuda::Stream that manages an asynchronous, non-blocking,
665
+ // non-default CUDA stream
666
+ cv::cuda::Stream cvStream(cudaStreamNonBlocking);
667
+ @endcode
668
+ */
669
+ CV_WRAP Stream (const size_t cudaFlags);
670
+
659
671
/* * @brief Returns true if the current stream queue is finished. Otherwise, it returns false.
660
672
*/
661
673
CV_WRAP bool queryIfComplete () const ;
Original file line number Diff line number Diff line change 41
41
//M*/
42
42
43
43
#include " precomp.hpp"
44
+ #include < cstdint>
44
45
45
46
using namespace cv ;
46
47
using namespace cv ::cuda;
@@ -293,6 +294,7 @@ class cv::cuda::Stream::Impl
293
294
294
295
Impl ();
295
296
Impl (const Ptr<GpuMat::Allocator>& allocator);
297
+ Impl (const unsigned int cudaFlags);
296
298
explicit Impl (cudaStream_t stream);
297
299
298
300
~Impl ();
@@ -312,6 +314,13 @@ cv::cuda::Stream::Impl::Impl(const Ptr<GpuMat::Allocator>& allocator) : stream(0
312
314
ownStream = true ;
313
315
}
314
316
317
+ cv::cuda::Stream::Impl::Impl (const unsigned int cudaFlags) : stream(0 ), ownStream(false )
318
+ {
319
+ cudaSafeCall (cudaStreamCreateWithFlags (&stream, cudaFlags));
320
+ ownStream = true ;
321
+ allocator = makePtr<StackAllocator>(stream);
322
+ }
323
+
315
324
cv::cuda::Stream::Impl::Impl (cudaStream_t stream_) : stream(stream_), ownStream(false )
316
325
{
317
326
allocator = makePtr<StackAllocator>(stream);
@@ -450,6 +459,16 @@ cv::cuda::Stream::Stream(const Ptr<GpuMat::Allocator>& allocator)
450
459
#endif
451
460
}
452
461
462
+ cv::cuda::Stream::Stream (const size_t cudaFlags)
463
+ {
464
+ #ifndef HAVE_CUDA
465
+ CV_UNUSED (cudaFlags);
466
+ throw_no_cuda ();
467
+ #else
468
+ impl_ = makePtr<Impl>(cudaFlags & UINT_MAX);
469
+ #endif
470
+ }
471
+
453
472
bool cv::cuda::Stream::queryIfComplete () const
454
473
{
455
474
#ifndef HAVE_CUDA
Original file line number Diff line number Diff line change
1
+ // This file is part of OpenCV project.
2
+ // It is subject to the license terms in the LICENSE file found in the top-level directory
3
+ // of this distribution and at http://opencv.org/license.html.
4
+
5
+ #if defined(HAVE_CUDA)
6
+
7
+ #include " test_precomp.hpp"
8
+ #include < cuda_runtime.h>
9
+ #include " opencv2/core/cuda.hpp"
10
+
11
+ namespace opencv_test { namespace {
12
+
13
+ TEST (CUDA_Stream, construct_cudaFlags)
14
+ {
15
+ cv::cuda::Stream stream (cudaStreamNonBlocking);
16
+ EXPECT_NE (stream.cudaPtr (), nullptr );
17
+ }
18
+
19
+ }} // namespace
20
+
21
+ #endif
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ def test_cuda_interop(self):
33
33
self .assertTrue (cuMat .cudaPtr () != 0 )
34
34
stream = cv .cuda_Stream ()
35
35
self .assertTrue (stream .cudaPtr () != 0 )
36
+ asyncstream = cv .cuda_Stream (1 ) # cudaStreamNonBlocking
37
+ self .assertTrue (asyncstream .cudaPtr () != 0 )
36
38
37
39
if __name__ == '__main__' :
38
40
NewOpenCVTests .bootstrap ()
You can’t perform that action at this time.
0 commit comments