Commit 6c253510 authored by Tomoaki Teshima's avatar Tomoaki Teshima

make the asynchronous call to NPP safe

  * Stop calling nppSetStream
parent 2dff9f4c
...@@ -108,6 +108,8 @@ static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The l ...@@ -108,6 +108,8 @@ static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The l
#else // HAVE_CUDA #else // HAVE_CUDA
#define nppSafeSetStream(oldStream, newStream) { if(oldStream != newStream) { cudaStreamSynchronize(oldStream); nppSetStream(newStream); } }
static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); }
namespace cv { namespace cuda namespace cv { namespace cuda
...@@ -139,13 +141,13 @@ namespace cv { namespace cuda ...@@ -139,13 +141,13 @@ namespace cv { namespace cuda
inline explicit NppStreamHandler(Stream& newStream) inline explicit NppStreamHandler(Stream& newStream)
{ {
oldStream = nppGetStream(); oldStream = nppGetStream();
nppSetStream(StreamAccessor::getStream(newStream)); nppSafeSetStream(oldStream, StreamAccessor::getStream(newStream));
} }
inline explicit NppStreamHandler(cudaStream_t newStream) inline explicit NppStreamHandler(cudaStream_t newStream)
{ {
oldStream = nppGetStream(); oldStream = nppGetStream();
nppSetStream(newStream); nppSafeSetStream(oldStream, newStream);
} }
inline ~NppStreamHandler() inline ~NppStreamHandler()
......
...@@ -157,8 +157,6 @@ void cv::cuda::meanStdDev(InputArray _src, OutputArray _dst, Stream& stream) ...@@ -157,8 +157,6 @@ void cv::cuda::meanStdDev(InputArray _src, OutputArray _dst, Stream& stream)
BufferPool pool(stream); BufferPool pool(stream);
GpuMat buf = pool.getBuffer(1, bufSize, CV_8UC1); GpuMat buf = pool.getBuffer(1, bufSize, CV_8UC1);
NppStreamHandler h(StreamAccessor::getStream(stream));
nppSafeCall( nppiMean_StdDev_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step), sz, buf.ptr<Npp8u>(), dst.ptr<Npp64f>(), dst.ptr<Npp64f>() + 1) ); nppSafeCall( nppiMean_StdDev_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step), sz, buf.ptr<Npp8u>(), dst.ptr<Npp64f>(), dst.ptr<Npp64f>() + 1) );
syncOutput(dst, _dst, stream); syncOutput(dst, _dst, stream);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment