diff --git a/modules/gpu/src/cuda/internal_shared.hpp b/modules/gpu/src/cuda/internal_shared.hpp index c8d4e5b7f6c9d30c784d0a3e0cb11e26707c1724..ce2cfe465c609a96b613d086c46121ebb0ccf2ae 100644 --- a/modules/gpu/src/cuda/internal_shared.hpp +++ b/modules/gpu/src/cuda/internal_shared.hpp @@ -48,28 +48,11 @@ #include "opencv2/core/cuda_devptrs.hpp" #include "opencv2/core/cuda/common.hpp" -#include "opencv2/gpunvidia.hpp" +#include "opencv2/gpunvidia/private.hpp" -#include "safe_call.hpp" -namespace cv { namespace gpu -{ - class NppStStreamHandler - { - public: - inline explicit NppStStreamHandler(cudaStream_t newStream = 0) - { - oldStream = nppStSetActiveCUDAstream(newStream); - } +#include "safe_call.hpp" - inline ~NppStStreamHandler() - { - nppStSetActiveCUDAstream(oldStream); - } - private: - cudaStream_t oldStream; - }; -}} #endif /* __OPENCV_internal_shared_HPP__ */ diff --git a/modules/gpu/src/cuda/safe_call.hpp b/modules/gpu/src/cuda/safe_call.hpp index fa62fb15aa070ee8a2b5384619b07a129de0ef48..1d4a437e632bd3b7bfa14d1bfdff3188209b6f73 100644 --- a/modules/gpu/src/cuda/safe_call.hpp +++ b/modules/gpu/src/cuda/safe_call.hpp @@ -43,30 +43,19 @@ #ifndef __OPENCV_CUDA_SAFE_CALL_HPP__ #define __OPENCV_CUDA_SAFE_CALL_HPP__ -#include #include -#include "opencv2/gpunvidia.hpp" #if defined(__GNUC__) - #define ncvSafeCall(expr) ___ncvSafeCall(expr, __FILE__, __LINE__, __func__) #define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__, __func__) #else /* defined(__CUDACC__) || defined(__MSVC__) */ - #define ncvSafeCall(expr) ___ncvSafeCall(expr, __FILE__, __LINE__) #define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__) #endif namespace cv { namespace gpu { - void ncvError(int err, const char *file, const int line, const char *func = ""); void cufftError(int err, const char *file, const int line, const char *func = ""); }} -static inline void ___ncvSafeCall(int err, const char *file, const int line, const char *func = "") -{ - if (NCV_SUCCESS != err) - cv::gpu::ncvError(err, file, line, func); -} - static inline void ___cufftSafeCall(cufftResult_t err, const char *file, const int line, const char *func = "") { if (CUFFT_SUCCESS != err) diff --git a/modules/gpu/src/error.cpp b/modules/gpu/src/error.cpp index 36759864b0bd3ec29c96bc0e49db6ed6491ce14d..3b8b6b3ee058662d779a1c50ecf4f9a30fc804f4 100644 --- a/modules/gpu/src/error.cpp +++ b/modules/gpu/src/error.cpp @@ -73,58 +73,6 @@ namespace return str; } - ////////////////////////////////////////////////////////////////////////// - // NCV errors - - const ErrorEntry ncv_errors [] = - { - error_entry( NCV_SUCCESS ), - error_entry( NCV_UNKNOWN_ERROR ), - error_entry( NCV_CUDA_ERROR ), - error_entry( NCV_NPP_ERROR ), - error_entry( NCV_FILE_ERROR ), - error_entry( NCV_NULL_PTR ), - error_entry( NCV_INCONSISTENT_INPUT ), - error_entry( NCV_TEXTURE_BIND_ERROR ), - error_entry( NCV_DIMENSIONS_INVALID ), - error_entry( NCV_INVALID_ROI ), - error_entry( NCV_INVALID_STEP ), - error_entry( NCV_INVALID_SCALE ), - error_entry( NCV_INVALID_SCALE ), - error_entry( NCV_ALLOCATOR_NOT_INITIALIZED ), - error_entry( NCV_ALLOCATOR_BAD_ALLOC ), - error_entry( NCV_ALLOCATOR_BAD_DEALLOC ), - error_entry( NCV_ALLOCATOR_INSUFFICIENT_CAPACITY ), - error_entry( NCV_ALLOCATOR_DEALLOC_ORDER ), - error_entry( NCV_ALLOCATOR_BAD_REUSE ), - error_entry( NCV_MEM_COPY_ERROR ), - error_entry( NCV_MEM_RESIDENCE_ERROR ), - error_entry( NCV_MEM_INSUFFICIENT_CAPACITY ), - error_entry( NCV_HAAR_INVALID_PIXEL_STEP ), - error_entry( NCV_HAAR_TOO_MANY_FEATURES_IN_CLASSIFIER ), - error_entry( NCV_HAAR_TOO_MANY_FEATURES_IN_CASCADE ), - error_entry( NCV_HAAR_TOO_LARGE_FEATURES ), - error_entry( NCV_HAAR_XML_LOADING_EXCEPTION ), - error_entry( NCV_NOIMPL_HAAR_TILTED_FEATURES ), - error_entry( NCV_WARNING_HAAR_DETECTIONS_VECTOR_OVERFLOW ), - error_entry( NPPST_SUCCESS ), - error_entry( NPPST_ERROR ), - error_entry( NPPST_CUDA_KERNEL_EXECUTION_ERROR ), - error_entry( NPPST_NULL_POINTER_ERROR ), - error_entry( NPPST_TEXTURE_BIND_ERROR ), - error_entry( NPPST_MEMCPY_ERROR ), - error_entry( NPPST_MEM_ALLOC_ERR ), - error_entry( NPPST_MEMFREE_ERR ), - error_entry( NPPST_INVALID_ROI ), - error_entry( NPPST_INVALID_STEP ), - error_entry( NPPST_INVALID_SCALE ), - error_entry( NPPST_MEM_INSUFFICIENT_BUFFER ), - error_entry( NPPST_MEM_RESIDENCE_ERROR ), - error_entry( NPPST_MEM_INTERNAL_ERROR ) - }; - - const size_t ncv_error_num = sizeof(ncv_errors) / sizeof(ncv_errors[0]); - ////////////////////////////////////////////////////////////////////////// // CUFFT errors @@ -148,12 +96,6 @@ namespace cv { namespace gpu { - void ncvError(int code, const char* file, const int line, const char* func) - { - String msg = getErrorString(code, ncv_errors, ncv_error_num); - cv::error(cv::Error::GpuApiCallError, msg, func, file, line); - } - void cufftError(int code, const char* file, const int line, const char* func) { String msg = getErrorString(code, cufft_errors, cufft_error_num); diff --git a/modules/gpunvidia/include/opencv2/gpunvidia/private.hpp b/modules/gpunvidia/include/opencv2/gpunvidia/private.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e86aaacf3e31668902c9a0b6f89f623870f6075d --- /dev/null +++ b/modules/gpunvidia/include/opencv2/gpunvidia/private.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_CORE_GPUNVIDIA_PRIVATE_HPP__ +#define __OPENCV_CORE_GPUNVIDIA_PRIVATE_HPP__ + +#ifndef __OPENCV_BUILD +# error this is a private header which should not be used from outside of the OpenCV library +#endif + +#include "opencv2/core/gpu_private.hpp" + +#ifndef HAVE_CUDA +# error gpunvidia module requires CUDA +#endif + +#include "opencv2/gpunvidia.hpp" + +namespace cv { namespace gpu +{ + class NppStStreamHandler + { + public: + inline explicit NppStStreamHandler(cudaStream_t newStream = 0) + { + oldStream = nppStSetActiveCUDAstream(newStream); + } + + inline ~NppStStreamHandler() + { + nppStSetActiveCUDAstream(oldStream); + } + + private: + cudaStream_t oldStream; + }; + + NCV_EXPORTS cv::String getNcvErrorMessage(int code); + + static inline void checkNcvError(int err, const char* file, const int line, const char* func) + { + if (NCV_SUCCESS != err) + { + cv::String msg = getNcvErrorMessage(err); + cv::error(cv::Error::GpuApiCallError, msg, func, file, line); + } + } +}} + +#if defined(__GNUC__) + #define ncvSafeCall(expr) cv::gpu::checkNcvError(expr, __FILE__, __LINE__, __func__) +#else /* defined(__CUDACC__) || defined(__MSVC__) */ + #define ncvSafeCall(expr) cv::gpu::checkNcvError(expr, __FILE__, __LINE__, "") +#endif + +#endif // __OPENCV_CORE_GPUNVIDIA_PRIVATE_HPP__ diff --git a/modules/gpunvidia/src/NCV.cpp b/modules/gpunvidia/src/NCV.cpp index 979276c7c82af99d3c145979c6eda894605e5c5f..bf1531d7fb3d6838f65568f30d758fcc55a5d561 100644 --- a/modules/gpunvidia/src/NCV.cpp +++ b/modules/gpunvidia/src/NCV.cpp @@ -48,6 +48,86 @@ // //============================================================================== +namespace +{ + #define error_entry(entry) { entry, #entry } + + struct ErrorEntry + { + int code; + const char* str; + }; + + struct ErrorEntryComparer + { + int code; + ErrorEntryComparer(int code_) : code(code_) {} + bool operator()(const ErrorEntry& e) const { return e.code == code; } + }; + + ////////////////////////////////////////////////////////////////////////// + // NCV errors + + const ErrorEntry ncv_errors [] = + { + error_entry( NCV_SUCCESS ), + error_entry( NCV_UNKNOWN_ERROR ), + error_entry( NCV_CUDA_ERROR ), + error_entry( NCV_NPP_ERROR ), + error_entry( NCV_FILE_ERROR ), + error_entry( NCV_NULL_PTR ), + error_entry( NCV_INCONSISTENT_INPUT ), + error_entry( NCV_TEXTURE_BIND_ERROR ), + error_entry( NCV_DIMENSIONS_INVALID ), + error_entry( NCV_INVALID_ROI ), + error_entry( NCV_INVALID_STEP ), + error_entry( NCV_INVALID_SCALE ), + error_entry( NCV_INVALID_SCALE ), + error_entry( NCV_ALLOCATOR_NOT_INITIALIZED ), + error_entry( NCV_ALLOCATOR_BAD_ALLOC ), + error_entry( NCV_ALLOCATOR_BAD_DEALLOC ), + error_entry( NCV_ALLOCATOR_INSUFFICIENT_CAPACITY ), + error_entry( NCV_ALLOCATOR_DEALLOC_ORDER ), + error_entry( NCV_ALLOCATOR_BAD_REUSE ), + error_entry( NCV_MEM_COPY_ERROR ), + error_entry( NCV_MEM_RESIDENCE_ERROR ), + error_entry( NCV_MEM_INSUFFICIENT_CAPACITY ), + error_entry( NCV_HAAR_INVALID_PIXEL_STEP ), + error_entry( NCV_HAAR_TOO_MANY_FEATURES_IN_CLASSIFIER ), + error_entry( NCV_HAAR_TOO_MANY_FEATURES_IN_CASCADE ), + error_entry( NCV_HAAR_TOO_LARGE_FEATURES ), + error_entry( NCV_HAAR_XML_LOADING_EXCEPTION ), + error_entry( NCV_NOIMPL_HAAR_TILTED_FEATURES ), + error_entry( NCV_WARNING_HAAR_DETECTIONS_VECTOR_OVERFLOW ), + error_entry( NPPST_SUCCESS ), + error_entry( NPPST_ERROR ), + error_entry( NPPST_CUDA_KERNEL_EXECUTION_ERROR ), + error_entry( NPPST_NULL_POINTER_ERROR ), + error_entry( NPPST_TEXTURE_BIND_ERROR ), + error_entry( NPPST_MEMCPY_ERROR ), + error_entry( NPPST_MEM_ALLOC_ERR ), + error_entry( NPPST_MEMFREE_ERR ), + error_entry( NPPST_INVALID_ROI ), + error_entry( NPPST_INVALID_STEP ), + error_entry( NPPST_INVALID_SCALE ), + error_entry( NPPST_MEM_INSUFFICIENT_BUFFER ), + error_entry( NPPST_MEM_RESIDENCE_ERROR ), + error_entry( NPPST_MEM_INTERNAL_ERROR ) + }; + + const size_t ncv_error_num = sizeof(ncv_errors) / sizeof(ncv_errors[0]); +} + +cv::String cv::gpu::getNcvErrorMessage(int code) +{ + size_t idx = std::find_if(ncv_errors, ncv_errors + ncv_error_num, ErrorEntryComparer(code)) - ncv_errors; + + const char* msg = (idx != ncv_error_num) ? ncv_errors[idx].str : "Unknown error code"; + String str = cv::format("%s [Code = %d]", msg, code); + + return str; +} + static void stdDebugOutput(const cv::String &msg) { diff --git a/modules/gpunvidia/src/precomp.hpp b/modules/gpunvidia/src/precomp.hpp index 613670009ec6045075fe6770e6d0a6254446727d..c4e067f52d05c30ad4646da99e5c7d59efa6264e 100644 --- a/modules/gpunvidia/src/precomp.hpp +++ b/modules/gpunvidia/src/precomp.hpp @@ -52,5 +52,6 @@ #include "opencv2/objdetect.hpp" #include "opencv2/core/gpu_private.hpp" +#include "opencv2/gpunvidia/private.hpp" #endif /* __OPENCV_PRECOMP_H__ */