From 6c253510495d25b8178f53e67c1b7d9655ab5fdf Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Thu, 15 Mar 2018 18:40:05 +0900 Subject: [PATCH] make the asynchronous call to NPP safe * Stop calling nppSetStream --- modules/core/include/opencv2/core/private.cuda.hpp | 6 ++++-- modules/cudaarithm/src/reductions.cpp | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/include/opencv2/core/private.cuda.hpp b/modules/core/include/opencv2/core/private.cuda.hpp index cea280b122..003ff126ba 100644 --- a/modules/core/include/opencv2/core/private.cuda.hpp +++ b/modules/core/include/opencv2/core/private.cuda.hpp @@ -108,6 +108,8 @@ static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The l #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"); } namespace cv { namespace cuda @@ -139,13 +141,13 @@ namespace cv { namespace cuda inline explicit NppStreamHandler(Stream& newStream) { oldStream = nppGetStream(); - nppSetStream(StreamAccessor::getStream(newStream)); + nppSafeSetStream(oldStream, StreamAccessor::getStream(newStream)); } inline explicit NppStreamHandler(cudaStream_t newStream) { oldStream = nppGetStream(); - nppSetStream(newStream); + nppSafeSetStream(oldStream, newStream); } inline ~NppStreamHandler() diff --git a/modules/cudaarithm/src/reductions.cpp b/modules/cudaarithm/src/reductions.cpp index 50185b161e..1adf05fe1a 100644 --- a/modules/cudaarithm/src/reductions.cpp +++ b/modules/cudaarithm/src/reductions.cpp @@ -157,8 +157,6 @@ void cv::cuda::meanStdDev(InputArray _src, OutputArray _dst, Stream& stream) BufferPool pool(stream); GpuMat buf = pool.getBuffer(1, bufSize, CV_8UC1); - NppStreamHandler h(StreamAccessor::getStream(stream)); - nppSafeCall( nppiMean_StdDev_8u_C1R(src.ptr(), static_cast(src.step), sz, buf.ptr(), dst.ptr(), dst.ptr() + 1) ); syncOutput(dst, _dst, stream);