1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
42 #include "precomp.hpp"
45 using namespace cv::gpu;
52 #define error_entry(entry) { entry, #entry }
60 struct ErrorEntryComparer
63 ErrorEntryComparer(int code_) : code(code_) {};
64 bool operator()(const ErrorEntry& e) const { return e.code == code; }
67 string getErrorString(int code, const ErrorEntry* errors, size_t n)
69 size_t idx = find_if(errors, errors + n, ErrorEntryComparer(code)) - errors;
71 const string& msg = (idx != n) ? errors[idx].str : string("Unknown error code");
74 ostr << msg << " [Code = " << code << "]";
79 //////////////////////////////////////////////////////////////////////////
82 const ErrorEntry npp_errors [] =
84 #if defined (_MSC_VER)
85 error_entry( NPP_NOT_SUFFICIENT_COMPUTE_CAPABILITY ),
88 #if NPP_VERSION < 5500
89 error_entry( NPP_BAD_ARG_ERROR ),
90 error_entry( NPP_COEFF_ERROR ),
91 error_entry( NPP_RECT_ERROR ),
92 error_entry( NPP_QUAD_ERROR ),
93 error_entry( NPP_MEMFREE_ERR ),
94 error_entry( NPP_MEMSET_ERR ),
95 error_entry( NPP_MEM_ALLOC_ERR ),
96 error_entry( NPP_HISTO_NUMBER_OF_LEVELS_ERROR ),
97 error_entry( NPP_MIRROR_FLIP_ERR ),
98 error_entry( NPP_INVALID_INPUT ),
99 error_entry( NPP_POINTER_ERROR ),
100 error_entry( NPP_WARNING ),
101 error_entry( NPP_ODD_ROI_WARNING ),
103 error_entry( NPP_INVALID_HOST_POINTER_ERROR ),
104 error_entry( NPP_INVALID_DEVICE_POINTER_ERROR ),
105 error_entry( NPP_LUT_PALETTE_BITSIZE_ERROR ),
106 error_entry( NPP_ZC_MODE_NOT_SUPPORTED_ERROR ),
107 error_entry( NPP_MEMFREE_ERROR ),
108 error_entry( NPP_MEMSET_ERROR ),
109 error_entry( NPP_QUALITY_INDEX_ERROR ),
110 error_entry( NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR ),
111 error_entry( NPP_CHANNEL_ORDER_ERROR ),
112 error_entry( NPP_ZERO_MASK_VALUE_ERROR ),
113 error_entry( NPP_QUADRANGLE_ERROR ),
114 error_entry( NPP_RECTANGLE_ERROR ),
115 error_entry( NPP_COEFFICIENT_ERROR ),
116 error_entry( NPP_NUMBER_OF_CHANNELS_ERROR ),
117 error_entry( NPP_COI_ERROR ),
118 error_entry( NPP_DIVISOR_ERROR ),
119 error_entry( NPP_CHANNEL_ERROR ),
120 error_entry( NPP_STRIDE_ERROR ),
121 error_entry( NPP_ANCHOR_ERROR ),
122 error_entry( NPP_MASK_SIZE_ERROR ),
123 error_entry( NPP_MIRROR_FLIP_ERROR ),
124 error_entry( NPP_MOMENT_00_ZERO_ERROR ),
125 error_entry( NPP_THRESHOLD_NEGATIVE_LEVEL_ERROR ),
126 error_entry( NPP_THRESHOLD_ERROR ),
127 error_entry( NPP_CONTEXT_MATCH_ERROR ),
128 error_entry( NPP_FFT_FLAG_ERROR ),
129 error_entry( NPP_FFT_ORDER_ERROR ),
130 error_entry( NPP_SCALE_RANGE_ERROR ),
131 error_entry( NPP_DATA_TYPE_ERROR ),
132 error_entry( NPP_OUT_OFF_RANGE_ERROR ),
133 error_entry( NPP_DIVIDE_BY_ZERO_ERROR ),
134 error_entry( NPP_MEMORY_ALLOCATION_ERR ),
135 error_entry( NPP_RANGE_ERROR ),
136 error_entry( NPP_BAD_ARGUMENT_ERROR ),
137 error_entry( NPP_NO_MEMORY_ERROR ),
138 error_entry( NPP_ERROR_RESERVED ),
139 error_entry( NPP_NO_OPERATION_WARNING ),
140 error_entry( NPP_DIVIDE_BY_ZERO_WARNING ),
141 error_entry( NPP_WRONG_INTERSECTION_ROI_WARNING ),
144 error_entry( NPP_NOT_SUPPORTED_MODE_ERROR ),
145 error_entry( NPP_ROUND_MODE_NOT_SUPPORTED_ERROR ),
146 error_entry( NPP_RESIZE_NO_OPERATION_ERROR ),
147 error_entry( NPP_LUT_NUMBER_OF_LEVELS_ERROR ),
148 error_entry( NPP_TEXTURE_BIND_ERROR ),
149 error_entry( NPP_WRONG_INTERSECTION_ROI_ERROR ),
150 error_entry( NPP_NOT_EVEN_STEP_ERROR ),
151 error_entry( NPP_INTERPOLATION_ERROR ),
152 error_entry( NPP_RESIZE_FACTOR_ERROR ),
153 error_entry( NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR ),
154 error_entry( NPP_MEMCPY_ERROR ),
155 error_entry( NPP_ALIGNMENT_ERROR ),
156 error_entry( NPP_STEP_ERROR ),
157 error_entry( NPP_SIZE_ERROR ),
158 error_entry( NPP_NULL_POINTER_ERROR ),
159 error_entry( NPP_CUDA_KERNEL_EXECUTION_ERROR ),
160 error_entry( NPP_NOT_IMPLEMENTED_ERROR ),
161 error_entry( NPP_ERROR ),
162 error_entry( NPP_NO_ERROR ),
163 error_entry( NPP_SUCCESS ),
164 error_entry( NPP_WRONG_INTERSECTION_QUAD_WARNING ),
165 error_entry( NPP_MISALIGNED_DST_ROI_WARNING ),
166 error_entry( NPP_AFFINE_QUAD_INCORRECT_WARNING ),
167 error_entry( NPP_DOUBLE_SIZE_WARNING )
170 const size_t npp_error_num = sizeof(npp_errors) / sizeof(npp_errors[0]);
172 //////////////////////////////////////////////////////////////////////////
175 const ErrorEntry ncv_errors [] =
177 error_entry( NCV_SUCCESS ),
178 error_entry( NCV_UNKNOWN_ERROR ),
179 error_entry( NCV_CUDA_ERROR ),
180 error_entry( NCV_NPP_ERROR ),
181 error_entry( NCV_FILE_ERROR ),
182 error_entry( NCV_NULL_PTR ),
183 error_entry( NCV_INCONSISTENT_INPUT ),
184 error_entry( NCV_TEXTURE_BIND_ERROR ),
185 error_entry( NCV_DIMENSIONS_INVALID ),
186 error_entry( NCV_INVALID_ROI ),
187 error_entry( NCV_INVALID_STEP ),
188 error_entry( NCV_INVALID_SCALE ),
189 error_entry( NCV_INVALID_SCALE ),
190 error_entry( NCV_ALLOCATOR_NOT_INITIALIZED ),
191 error_entry( NCV_ALLOCATOR_BAD_ALLOC ),
192 error_entry( NCV_ALLOCATOR_BAD_DEALLOC ),
193 error_entry( NCV_ALLOCATOR_INSUFFICIENT_CAPACITY ),
194 error_entry( NCV_ALLOCATOR_DEALLOC_ORDER ),
195 error_entry( NCV_ALLOCATOR_BAD_REUSE ),
196 error_entry( NCV_MEM_COPY_ERROR ),
197 error_entry( NCV_MEM_RESIDENCE_ERROR ),
198 error_entry( NCV_MEM_INSUFFICIENT_CAPACITY ),
199 error_entry( NCV_HAAR_INVALID_PIXEL_STEP ),
200 error_entry( NCV_HAAR_TOO_MANY_FEATURES_IN_CLASSIFIER ),
201 error_entry( NCV_HAAR_TOO_MANY_FEATURES_IN_CASCADE ),
202 error_entry( NCV_HAAR_TOO_LARGE_FEATURES ),
203 error_entry( NCV_HAAR_XML_LOADING_EXCEPTION ),
204 error_entry( NCV_NOIMPL_HAAR_TILTED_FEATURES ),
205 error_entry( NCV_WARNING_HAAR_DETECTIONS_VECTOR_OVERFLOW ),
206 error_entry( NPPST_SUCCESS ),
207 error_entry( NPPST_ERROR ),
208 error_entry( NPPST_CUDA_KERNEL_EXECUTION_ERROR ),
209 error_entry( NPPST_NULL_POINTER_ERROR ),
210 error_entry( NPPST_TEXTURE_BIND_ERROR ),
211 error_entry( NPPST_MEMCPY_ERROR ),
212 error_entry( NPPST_MEM_ALLOC_ERR ),
213 error_entry( NPPST_MEMFREE_ERR ),
214 error_entry( NPPST_INVALID_ROI ),
215 error_entry( NPPST_INVALID_STEP ),
216 error_entry( NPPST_INVALID_SCALE ),
217 error_entry( NPPST_MEM_INSUFFICIENT_BUFFER ),
218 error_entry( NPPST_MEM_RESIDENCE_ERROR ),
219 error_entry( NPPST_MEM_INTERNAL_ERROR )
222 const size_t ncv_error_num = sizeof(ncv_errors) / sizeof(ncv_errors[0]);
224 //////////////////////////////////////////////////////////////////////////
227 const ErrorEntry cufft_errors[] =
229 error_entry( CUFFT_INVALID_PLAN ),
230 error_entry( CUFFT_ALLOC_FAILED ),
231 error_entry( CUFFT_INVALID_TYPE ),
232 error_entry( CUFFT_INVALID_VALUE ),
233 error_entry( CUFFT_INTERNAL_ERROR ),
234 error_entry( CUFFT_EXEC_FAILED ),
235 error_entry( CUFFT_SETUP_FAILED ),
236 error_entry( CUFFT_INVALID_SIZE ),
237 error_entry( CUFFT_UNALIGNED_DATA )
240 const int cufft_error_num = sizeof(cufft_errors) / sizeof(cufft_errors[0]);
242 //////////////////////////////////////////////////////////////////////////
245 const ErrorEntry cublas_errors[] =
247 error_entry( CUBLAS_STATUS_SUCCESS ),
248 error_entry( CUBLAS_STATUS_NOT_INITIALIZED ),
249 error_entry( CUBLAS_STATUS_ALLOC_FAILED ),
250 error_entry( CUBLAS_STATUS_INVALID_VALUE ),
251 error_entry( CUBLAS_STATUS_ARCH_MISMATCH ),
252 error_entry( CUBLAS_STATUS_MAPPING_ERROR ),
253 error_entry( CUBLAS_STATUS_EXECUTION_FAILED ),
254 error_entry( CUBLAS_STATUS_INTERNAL_ERROR )
257 const int cublas_error_num = sizeof(cublas_errors) / sizeof(cublas_errors[0]);
264 void nppError(int code, const char *file, const int line, const char *func)
266 string msg = getErrorString(code, npp_errors, npp_error_num);
267 cv::gpu::error(msg.c_str(), file, line, func);
270 void ncvError(int code, const char *file, const int line, const char *func)
272 string msg = getErrorString(code, ncv_errors, ncv_error_num);
273 cv::gpu::error(msg.c_str(), file, line, func);
276 void cufftError(int code, const char *file, const int line, const char *func)
278 string msg = getErrorString(code, cufft_errors, cufft_error_num);
279 cv::gpu::error(msg.c_str(), file, line, func);
282 void cublasError(int code, const char *file, const int line, const char *func)
284 string msg = getErrorString(code, cublas_errors, cublas_error_num);
285 cv::gpu::error(msg.c_str(), file, line, func);