Commit f2df7848 authored by Anatoly Baksheev's avatar Anatoly Baksheev

fixed error reporting in GPU module (exceptions in destructors, etc)

parent d7d0754f
......@@ -245,7 +245,7 @@ enum {
CV_StsNotImplemented= -213, /* the requested function/feature is not implemented */
CV_StsBadMemBlock= -214, /* an allocated block has been corrupted */
CV_StsAssert= -215, /* assertion failed */
CV_GpuNotFound= -216,
CV_GpuNotSupported= -216,
CV_GpuApiCallError= -217,
CV_GpuNppCallError= -218
};
......
......@@ -527,6 +527,9 @@ CV_IMPL const char* cvErrorStr( int status )
case CV_StsNotImplemented : return "The function/feature is not implemented";
case CV_StsBadMemBlock : return "Memory block has been corrupted";
case CV_StsAssert : return "Assertion failed";
case CV_GpuNotSupported : return "No GPU support";
case CV_GpuApiCallError : return "GPU API error";
case CV_GpuNppCallError : return "NPP API error";
};
sprintf(buf, "Unknown %s code %d", status >= 0 ? "status":"error", status);
......
......@@ -83,19 +83,18 @@ namespace cv
public:
//! default constructor
GpuMat();
//! constructs GpuMatrix of the specified size and type
// (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
GpuMat(int _rows, int _cols, int _type);
GpuMat(Size _size, int _type);
//! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
GpuMat(int rows, int cols, int type);
GpuMat(Size size, int type);
//! constucts GpuMatrix and fills it with the specified value _s.
GpuMat(int _rows, int _cols, int _type, const Scalar& _s);
GpuMat(Size _size, int _type, const Scalar& _s);
GpuMat(int rows, int cols, int type, const Scalar& s);
GpuMat(Size size, int type, const Scalar& s);
//! copy constructor
GpuMat(const GpuMat& m);
//! constructor for GpuMatrix headers pointing to user-allocated data
GpuMat(int _rows, int _cols, int _type, void* _data, size_t _step = Mat::AUTO_STEP);
GpuMat(Size _size, int _type, void* _data, size_t _step = Mat::AUTO_STEP);
GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
//! creates a matrix header for a part of the bigger matrix
GpuMat(const GpuMat& m, const Range& rowRange, const Range& colRange);
......@@ -117,7 +116,7 @@ namespace cv
template <class T> operator DevMem2D_<T>() const;
template <class T> operator PtrStep_<T>() const;
//! pefroms blocking upload data to GpuMat. .
//! pefroms blocking upload data to GpuMat.
void upload(const cv::Mat& m);
//! upload async
......@@ -156,15 +155,15 @@ namespace cv
//! sets every GpuMatrix element to s
GpuMat& operator = (const Scalar& s);
//! sets some of the GpuMatrix elements to s, according to the mask
GpuMat& setTo(const Scalar& s, const GpuMat& mask=GpuMat());
GpuMat& setTo(const Scalar& s, const GpuMat& mask = GpuMat());
//! creates alternative GpuMatrix header for the same data, with different
// number of channels and/or different number of rows. see cvReshape.
GpuMat reshape(int _cn, int _rows=0) const;
GpuMat reshape(int cn, int rows = 0) const;
//! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type.
// previous data is unreferenced if needed.
void create(int _rows, int _cols, int _type);
void create(Size _size, int _type);
void create(int rows, int cols, int type);
void create(Size size, int type);
//! decreases reference counter;
// deallocate the data when reference counter reaches 0.
void release();
......@@ -205,12 +204,12 @@ namespace cv
bool empty() const;
//! returns pointer to y-th row
uchar* ptr(int y=0);
const uchar* ptr(int y=0) const;
uchar* ptr(int y = 0);
const uchar* ptr(int y = 0) const;
//! template version of the above method
template<typename _Tp> _Tp* ptr(int y=0);
template<typename _Tp> const _Tp* ptr(int y=0) const;
template<typename _Tp> _Tp* ptr(int y = 0);
template<typename _Tp> const _Tp* ptr(int y = 0) const;
//! matrix transposition
GpuMat t() const;
......@@ -238,6 +237,11 @@ namespace cv
uchar* dataend;
};
//#define TemplatedGpuMat // experimental now, deprecated to use
#ifdef TemplatedGpuMat
#include "GpuMat_BetaDeprecated.hpp"
#endif
//////////////////////////////// CudaMem ////////////////////////////////
// CudaMem is limited cv::Mat with page locked memory allocation.
// Page locked memory is only needed for async and faster coping to GPU.
......@@ -252,12 +256,12 @@ namespace cv
CudaMem();
CudaMem(const CudaMem& m);
CudaMem(int _rows, int _cols, int _type, int _alloc_type = ALLOC_PAGE_LOCKED);
CudaMem(Size _size, int _type, int _alloc_type = ALLOC_PAGE_LOCKED);
CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED);
CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
//! creates from cv::Mat with coping data
explicit CudaMem(const Mat& m, int _alloc_type = ALLOC_PAGE_LOCKED);
explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
~CudaMem();
......@@ -267,8 +271,8 @@ namespace cv
CudaMem clone() const;
//! allocates new matrix data unless the matrix already has specified size and type.
void create(int _rows, int _cols, int _type, int _alloc_type = ALLOC_PAGE_LOCKED);
void create(Size _size, int _type, int _alloc_type = ALLOC_PAGE_LOCKED);
void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED);
void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
//! decrements reference counter and released memory if needed.
void release();
......
......@@ -54,53 +54,54 @@ using namespace cv::gpu;
namespace
{
#define error_entry(entry) { entry, #entry }
struct NppError
{
int error;
string str;
}
npp_errors [] =
{
{ NPP_NOT_SUPPORTED_MODE_ERROR, "NPP_NOT_SUPPORTED_MODE_ERROR" },
{ NPP_ROUND_MODE_NOT_SUPPORTED_ERROR, "NPP_ROUND_MODE_NOT_SUPPORTED_ERROR" },
{ NPP_RESIZE_NO_OPERATION_ERROR, "NPP_RESIZE_NO_OPERATION_ERROR" },
{ NPP_BAD_ARG_ERROR, "NPP_BAD_ARG_ERROR" },
{ NPP_LUT_NUMBER_OF_LEVELS_ERROR, "NPP_LUT_NUMBER_OF_LEVELS_ERROR" },
{ NPP_TEXTURE_BIND_ERROR, "NPP_TEXTURE_BIND_ERROR" },
{ NPP_COEFF_ERROR, "NPP_COEFF_ERROR" },
{ NPP_RECT_ERROR, "NPP_RECT_ERROR" },
{ NPP_QUAD_ERROR, "NPP_QUAD_ERROR" },
{ NPP_WRONG_INTERSECTION_ROI_ERROR, "NPP_WRONG_INTERSECTION_ROI_ERROR" },
{ NPP_NOT_EVEN_STEP_ERROR, "NPP_NOT_EVEN_STEP_ERROR" },
{ NPP_INTERPOLATION_ERROR, "NPP_INTERPOLATION_ERROR" },
{ NPP_RESIZE_FACTOR_ERROR, "NPP_RESIZE_FACTOR_ERROR" },
{ NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR, "NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR" },
{ NPP_MEMFREE_ERR, "NPP_MEMFREE_ERR" },
{ NPP_MEMSET_ERR, "NPP_MEMSET_ERR" },
{ NPP_MEMCPY_ERROR, "NPP_MEMCPY_ERROR" },
{ NPP_MEM_ALLOC_ERR, "NPP_MEM_ALLOC_ERR" },
{ NPP_HISTO_NUMBER_OF_LEVELS_ERROR, "NPP_HISTO_NUMBER_OF_LEVELS_ERROR" },
{ NPP_MIRROR_FLIP_ERR, "NPP_MIRROR_FLIP_ERR" },
{ NPP_INVALID_INPUT, "NPP_INVALID_INPUT" },
{ NPP_ALIGNMENT_ERROR, "NPP_ALIGNMENT_ERROR" },
{ NPP_STEP_ERROR, "NPP_STEP_ERROR" },
{ NPP_SIZE_ERROR, "NPP_SIZE_ERROR" },
{ NPP_POINTER_ERROR, "NPP_POINTER_ERROR" },
{ NPP_NULL_POINTER_ERROR, "NPP_NULL_POINTER_ERROR" },
{ NPP_CUDA_KERNEL_EXECUTION_ERROR, "NPP_CUDA_KERNEL_EXECUTION_ERROR" },
{ NPP_NOT_IMPLEMENTED_ERROR, "NPP_NOT_IMPLEMENTED_ERROR" },
{ NPP_ERROR, "NPP_ERROR" },
{ NPP_NO_ERROR, "NPP_NO_ERROR" },
{ NPP_SUCCESS, "NPP_SUCCESS" },
{ NPP_WARNING, "NPP_WARNING" },
{ NPP_WRONG_INTERSECTION_QUAD_WARNING, "NPP_WRONG_INTERSECTION_QUAD_WARNING" },
{ NPP_MISALIGNED_DST_ROI_WARNING, "NPP_MISALIGNED_DST_ROI_WARNING" },
{ NPP_AFFINE_QUAD_INCORRECT_WARNING, "NPP_AFFINE_QUAD_INCORRECT_WARNING" },
//disabled in NPP for cuda 3.2-rc
//{ NPP_AFFINE_QUAD_CHANGED_WARNING, "NPP_AFFINE_QUAD_CHANGED_WARNING" },
//{ NPP_ADJUSTED_ROI_SIZE_WARNING, "NPP_ADJUSTED_ROI_SIZE_WARNING" },
{ NPP_DOUBLE_SIZE_WARNING, "NPP_DOUBLE_SIZE_WARNING" },
{ NPP_ODD_ROI_WARNING, "NPP_ODD_ROI_WARNING" }
error_entry( NPP_NOT_SUPPORTED_MODE_ERROR ),
error_entry( NPP_ROUND_MODE_NOT_SUPPORTED_ERROR ),
error_entry( NPP_RESIZE_NO_OPERATION_ERROR ),
error_entry( NPP_NOT_SUFFICIENT_COMPUTE_CAPABILITY ),
error_entry( NPP_BAD_ARG_ERROR ),
error_entry( NPP_LUT_NUMBER_OF_LEVELS_ERROR ),
error_entry( NPP_TEXTURE_BIND_ERROR ),
error_entry( NPP_COEFF_ERROR ),
error_entry( NPP_RECT_ERROR ),
error_entry( NPP_QUAD_ERROR ),
error_entry( NPP_WRONG_INTERSECTION_ROI_ERROR ),
error_entry( NPP_NOT_EVEN_STEP_ERROR ),
error_entry( NPP_INTERPOLATION_ERROR ),
error_entry( NPP_RESIZE_FACTOR_ERROR ),
error_entry( NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR ),
error_entry( NPP_MEMFREE_ERR ),
error_entry( NPP_MEMSET_ERR ),
error_entry( NPP_MEMCPY_ERROR ),
error_entry( NPP_MEM_ALLOC_ERR ),
error_entry( NPP_HISTO_NUMBER_OF_LEVELS_ERROR ),
error_entry( NPP_MIRROR_FLIP_ERR ),
error_entry( NPP_INVALID_INPUT ),
error_entry( NPP_ALIGNMENT_ERROR ),
error_entry( NPP_STEP_ERROR ),
error_entry( NPP_SIZE_ERROR ),
error_entry( NPP_POINTER_ERROR ),
error_entry( NPP_NULL_POINTER_ERROR ),
error_entry( NPP_CUDA_KERNEL_EXECUTION_ERROR ),
error_entry( NPP_NOT_IMPLEMENTED_ERROR ),
error_entry( NPP_ERROR ),
error_entry( NPP_NO_ERROR ),
error_entry( NPP_SUCCESS ),
error_entry( NPP_WARNING ),
error_entry( NPP_WRONG_INTERSECTION_QUAD_WARNING ),
error_entry( NPP_MISALIGNED_DST_ROI_WARNING ),
error_entry( NPP_AFFINE_QUAD_INCORRECT_WARNING ),
error_entry( NPP_DOUBLE_SIZE_WARNING ),
error_entry( NPP_ODD_ROI_WARNING )
};
int error_num = sizeof(npp_errors)/sizeof(npp_errors[0]);
......@@ -136,8 +137,18 @@ namespace cv
void error(const char *error_string, const char *file, const int line, const char *func)
{
//if (uncaught_exception())
cv::error( cv::Exception(CV_GpuApiCallError, error_string, func, file, line) );
int code = CV_GpuApiCallError;
if (std::uncaught_exception())
{
const char* errorStr = cvErrorStr(code);
const char* function = func ? func : "unknown function";
std::cerr << "OpenCV Error: " << errorStr << "(" << error_string << ") in " << function << ", file " << file << ", line " << line;
std::cerr.flush();
}
else
cv::error( cv::Exception(code, error_string, func, file, line) );
}
}
}
......
......@@ -55,6 +55,7 @@
#include <vector>
#include <algorithm>
#include <sstream>
#include <exception>
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/imgproc/imgproc.hpp"
......@@ -68,7 +69,7 @@
#else /* defined(HAVE_CUDA) */
static inline void throw_nogpu() { CV_Error(CV_GpuNotFound, "The library is compilled with no GPU support"); }
static inline void throw_nogpu() { CV_Error(CV_GpuNotFound, "The library is compilled without GPU support"); }
#endif /* defined(HAVE_CUDA) */
......
......@@ -69,8 +69,8 @@ static inline bool check_and_treat_gpu_exception(const cv::Exception& e, CvTS* t
{
switch (e.code)
{
case CV_GpuNotFound:
ts->printf(CvTS::LOG, "\nGpu not found");
case CV_GpuNotSupported:
ts->printf(CvTS::LOG, "\nGpu not supported by the library");
break;
case CV_GpuApiCallError:
......
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