Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
39854ced
Commit
39854ced
authored
Nov 12, 2015
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cuda::StreamAccessor::wrapStream and cuda::EventAccessor::wrapEvent
to import existed CUDA stream or CUDA event to OpenCV
parent
b4112a58
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
16 deletions
+72
-16
cuda.hpp
modules/core/include/opencv2/core/cuda.hpp
+1
-0
cuda.inl.hpp
modules/core/include/opencv2/core/cuda.inl.hpp
+10
-0
cuda_stream_accessor.hpp
modules/core/include/opencv2/core/cuda_stream_accessor.hpp
+3
-4
cuda_stream.cpp
modules/core/src/cuda_stream.cpp
+36
-12
test_stream.cpp
modules/cudaarithm/test/test_stream.cpp
+22
-0
No files found.
modules/core/include/opencv2/core/cuda.hpp
View file @
39854ced
...
@@ -528,6 +528,7 @@ public:
...
@@ -528,6 +528,7 @@ public:
private
:
private
:
Ptr
<
Impl
>
impl_
;
Ptr
<
Impl
>
impl_
;
Event
(
const
Ptr
<
Impl
>&
impl
);
friend
struct
EventAccessor
;
friend
struct
EventAccessor
;
};
};
...
...
modules/core/include/opencv2/core/cuda.inl.hpp
View file @
39854ced
...
@@ -540,6 +540,16 @@ Stream::Stream(const Ptr<Impl>& impl)
...
@@ -540,6 +540,16 @@ Stream::Stream(const Ptr<Impl>& impl)
{
{
}
}
//===================================================================================
// Event
//===================================================================================
inline
Event
::
Event
(
const
Ptr
<
Impl
>&
impl
)
:
impl_
(
impl
)
{
}
//===================================================================================
//===================================================================================
// Initialization & Info
// Initialization & Info
//===================================================================================
//===================================================================================
...
...
modules/core/include/opencv2/core/cuda_stream_accessor.hpp
View file @
39854ced
...
@@ -52,7 +52,7 @@
...
@@ -52,7 +52,7 @@
*/
*/
#include <cuda_runtime.h>
#include <cuda_runtime.h>
#include "opencv2/core/c
vdef.h
"
#include "opencv2/core/c
uda.hpp
"
namespace
cv
namespace
cv
{
{
...
@@ -62,14 +62,12 @@ namespace cv
...
@@ -62,14 +62,12 @@ namespace cv
//! @addtogroup cudacore_struct
//! @addtogroup cudacore_struct
//! @{
//! @{
class
Stream
;
class
Event
;
/** @brief Class that enables getting cudaStream_t from cuda::Stream
/** @brief Class that enables getting cudaStream_t from cuda::Stream
*/
*/
struct
StreamAccessor
struct
StreamAccessor
{
{
CV_EXPORTS
static
cudaStream_t
getStream
(
const
Stream
&
stream
);
CV_EXPORTS
static
cudaStream_t
getStream
(
const
Stream
&
stream
);
CV_EXPORTS
static
Stream
wrapStream
(
cudaStream_t
stream
);
};
};
/** @brief Class that enables getting cudaEvent_t from cuda::Event
/** @brief Class that enables getting cudaEvent_t from cuda::Event
...
@@ -77,6 +75,7 @@ namespace cv
...
@@ -77,6 +75,7 @@ namespace cv
struct
EventAccessor
struct
EventAccessor
{
{
CV_EXPORTS
static
cudaEvent_t
getEvent
(
const
Event
&
event
);
CV_EXPORTS
static
cudaEvent_t
getEvent
(
const
Event
&
event
);
CV_EXPORTS
static
Event
wrapEvent
(
cudaEvent_t
event
);
};
};
//! @}
//! @}
...
...
modules/core/src/cuda_stream.cpp
View file @
39854ced
...
@@ -280,32 +280,37 @@ class cv::cuda::Stream::Impl
...
@@ -280,32 +280,37 @@ class cv::cuda::Stream::Impl
{
{
public
:
public
:
cudaStream_t
stream
;
cudaStream_t
stream
;
Ptr
<
StackAllocator
>
stackAllocator_
;
bool
ownStream
;
Ptr
<
StackAllocator
>
stackAllocator
;
Impl
();
Impl
();
Impl
(
cudaStream_t
stream
);
explicit
Impl
(
cudaStream_t
stream
);
~
Impl
();
~
Impl
();
};
};
cv
::
cuda
::
Stream
::
Impl
::
Impl
()
:
stream
(
0
)
cv
::
cuda
::
Stream
::
Impl
::
Impl
()
:
stream
(
0
)
,
ownStream
(
false
)
{
{
cudaSafeCall
(
cudaStreamCreate
(
&
stream
)
);
cudaSafeCall
(
cudaStreamCreate
(
&
stream
)
);
ownStream
=
true
;
stackAllocator
_
=
makePtr
<
StackAllocator
>
(
stream
);
stackAllocator
=
makePtr
<
StackAllocator
>
(
stream
);
}
}
cv
::
cuda
::
Stream
::
Impl
::
Impl
(
cudaStream_t
stream_
)
:
stream
(
stream_
)
cv
::
cuda
::
Stream
::
Impl
::
Impl
(
cudaStream_t
stream_
)
:
stream
(
stream_
)
,
ownStream
(
false
)
{
{
stackAllocator
_
=
makePtr
<
StackAllocator
>
(
stream
);
stackAllocator
=
makePtr
<
StackAllocator
>
(
stream
);
}
}
cv
::
cuda
::
Stream
::
Impl
::~
Impl
()
cv
::
cuda
::
Stream
::
Impl
::~
Impl
()
{
{
stackAllocator
_
.
release
();
stackAllocator
.
release
();
if
(
stream
)
if
(
stream
&&
ownStream
)
{
cudaStreamDestroy
(
stream
);
cudaStreamDestroy
(
stream
);
}
}
}
#endif
#endif
...
@@ -516,6 +521,11 @@ cudaStream_t cv::cuda::StreamAccessor::getStream(const Stream& stream)
...
@@ -516,6 +521,11 @@ cudaStream_t cv::cuda::StreamAccessor::getStream(const Stream& stream)
return
stream
.
impl_
->
stream
;
return
stream
.
impl_
->
stream
;
}
}
Stream
cv
::
cuda
::
StreamAccessor
::
wrapStream
(
cudaStream_t
stream
)
{
return
Stream
(
makePtr
<
Stream
::
Impl
>
(
stream
));
}
#endif
#endif
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
...
@@ -660,7 +670,7 @@ void cv::cuda::setBufferPoolConfig(int deviceId, size_t stackSize, int stackCoun
...
@@ -660,7 +670,7 @@ void cv::cuda::setBufferPoolConfig(int deviceId, size_t stackSize, int stackCoun
#ifdef HAVE_CUDA
#ifdef HAVE_CUDA
cv
::
cuda
::
BufferPool
::
BufferPool
(
Stream
&
stream
)
:
allocator_
(
stream
.
impl_
->
stackAllocator
_
.
get
())
cv
::
cuda
::
BufferPool
::
BufferPool
(
Stream
&
stream
)
:
allocator_
(
stream
.
impl_
->
stackAllocator
.
get
())
{
{
}
}
...
@@ -693,20 +703,29 @@ class cv::cuda::Event::Impl
...
@@ -693,20 +703,29 @@ class cv::cuda::Event::Impl
{
{
public
:
public
:
cudaEvent_t
event
;
cudaEvent_t
event
;
bool
ownEvent
;
Impl
(
unsigned
int
flags
);
explicit
Impl
(
unsigned
int
flags
);
explicit
Impl
(
cudaEvent_t
event
);
~
Impl
();
~
Impl
();
};
};
cv
::
cuda
::
Event
::
Impl
::
Impl
(
unsigned
int
flags
)
:
event
(
0
)
cv
::
cuda
::
Event
::
Impl
::
Impl
(
unsigned
int
flags
)
:
event
(
0
)
,
ownEvent
(
false
)
{
{
cudaSafeCall
(
cudaEventCreateWithFlags
(
&
event
,
flags
)
);
cudaSafeCall
(
cudaEventCreateWithFlags
(
&
event
,
flags
)
);
ownEvent
=
true
;
}
cv
::
cuda
::
Event
::
Impl
::
Impl
(
cudaEvent_t
e
)
:
event
(
e
),
ownEvent
(
false
)
{
}
}
cv
::
cuda
::
Event
::
Impl
::~
Impl
()
cv
::
cuda
::
Event
::
Impl
::~
Impl
()
{
{
if
(
event
)
if
(
event
&&
ownEvent
)
{
cudaEventDestroy
(
event
);
cudaEventDestroy
(
event
);
}
}
}
cudaEvent_t
cv
::
cuda
::
EventAccessor
::
getEvent
(
const
Event
&
event
)
cudaEvent_t
cv
::
cuda
::
EventAccessor
::
getEvent
(
const
Event
&
event
)
...
@@ -714,6 +733,11 @@ cudaEvent_t cv::cuda::EventAccessor::getEvent(const Event& event)
...
@@ -714,6 +733,11 @@ cudaEvent_t cv::cuda::EventAccessor::getEvent(const Event& event)
return
event
.
impl_
->
event
;
return
event
.
impl_
->
event
;
}
}
Event
cv
::
cuda
::
EventAccessor
::
wrapEvent
(
cudaEvent_t
event
)
{
return
Event
(
makePtr
<
Event
::
Impl
>
(
event
));
}
#endif
#endif
cv
::
cuda
::
Event
::
Event
(
CreateFlags
flags
)
cv
::
cuda
::
Event
::
Event
(
CreateFlags
flags
)
...
...
modules/cudaarithm/test/test_stream.cpp
View file @
39854ced
...
@@ -47,6 +47,7 @@
...
@@ -47,6 +47,7 @@
#include <cuda_runtime.h>
#include <cuda_runtime.h>
#include "opencv2/core/cuda.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/core/cuda_stream_accessor.hpp"
#include "opencv2/ts/cuda_test.hpp"
#include "opencv2/ts/cuda_test.hpp"
using
namespace
cvtest
;
using
namespace
cvtest
;
...
@@ -129,6 +130,27 @@ CUDA_TEST_P(Async, Convert)
...
@@ -129,6 +130,27 @@ CUDA_TEST_P(Async, Convert)
stream
.
waitForCompletion
();
stream
.
waitForCompletion
();
}
}
CUDA_TEST_P
(
Async
,
WrapStream
)
{
cudaStream_t
cuda_stream
=
NULL
;
ASSERT_EQ
(
cudaSuccess
,
cudaStreamCreate
(
&
cuda_stream
));
{
cv
::
cuda
::
Stream
stream
=
cv
::
cuda
::
StreamAccessor
::
wrapStream
(
cuda_stream
);
d_src
.
upload
(
src
,
stream
);
d_src
.
convertTo
(
d_dst
,
CV_32S
,
stream
);
d_dst
.
download
(
dst
,
stream
);
Async
*
test
=
this
;
stream
.
enqueueHostCallback
(
checkConvert
,
test
);
stream
.
waitForCompletion
();
}
ASSERT_EQ
(
cudaSuccess
,
cudaStreamDestroy
(
cuda_stream
));
}
CUDA_TEST_P
(
Async
,
HostMemAllocator
)
CUDA_TEST_P
(
Async
,
HostMemAllocator
)
{
{
cv
::
cuda
::
Stream
stream
;
cv
::
cuda
::
Stream
stream
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment