Go to the documentation of this file.00001 #ifndef VIENNACL_OCL_ERROR_HPP_
00002 #define VIENNACL_OCL_ERROR_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifdef VIENNACL_BUILD_INFO
00036 #define VIENNACL_DEBUG_ALL
00037 #endif
00038
00039
00040 #ifdef __APPLE__
00041 #include <OpenCL/cl.h>
00042 #else
00043 #include <CL/cl.h>
00044 #endif
00045
00046 #include <string>
00047 #include <iostream>
00048 #include <exception>
00049
00050 #define VIENNACL_BUG_REPORT_STRING \
00051 "\nIf you think that this is a bug in ViennaCL, please report it at viennacl-support@lists.sourceforge.net and supply at least the following information:\n"\
00052 " * Operating System\n"\
00053 " * Which OpenCL implementation (AMD, NVIDIA, etc.)\n"\
00054 " * ViennaCL version\n"\
00055 "Many thanks in advance!";\
00056
00057 namespace viennacl
00058 {
00059 namespace ocl
00060 {
00061
00062 class device_not_found : public std::exception
00063 {
00064 virtual const char* what() const throw()
00065 {
00066 return "ViennaCL: FATAL ERROR: CL_DEVICE_NOT_FOUND \n ViennaCL could not find a suitable device. Please check whether an OpenCL implementation is properly installed and a suitable device available."
00067 VIENNACL_BUG_REPORT_STRING;
00068 }
00069 };
00070
00071 class device_not_available : public std::exception
00072 {
00073 virtual const char* what() const throw()
00074 {
00075 return "ViennaCL: FATAL ERROR: CL_DEVICE_NOT_AVAILABLE \n ViennaCL could not use the compute device because it is not available."
00076 VIENNACL_BUG_REPORT_STRING;
00077 }
00078 };
00079
00080 class compiler_not_available : public std::exception
00081 {
00082 virtual const char* what() const throw()
00083 {
00084 return "ViennaCL: FATAL ERROR: CL_COMPILER_NOT_AVAILABLE \n Your OpenCL framework does not provide an OpenCL compiler. Unfortunately, ViennaCL cannot be used without such a compiler."
00085 VIENNACL_BUG_REPORT_STRING;
00086 }
00087 };
00088
00089 class mem_object_allocation_failure : public std::exception
00090 {
00091 virtual const char* what() const throw()
00092 {
00093 return "ViennaCL: FATAL ERROR: CL_MEM_OBJECT_ALLOCATION_FAILURE \n ViennaCL could not allocate memory on the device. Most likely the device simply ran out of memory."
00094 VIENNACL_BUG_REPORT_STRING;
00095 }
00096 };
00097
00098 class out_of_resources : public std::exception
00099 {
00100 virtual const char* what() const throw()
00101 {
00102 return "ViennaCL: FATAL ERROR: CL_OUT_OF_RESOURCES \n ViennaCL tried to launch a compute kernel, but the device does not provide enough resources. Try changing the global and local work item sizes."
00103 VIENNACL_BUG_REPORT_STRING;
00104 }
00105 };
00106
00107 class out_of_host_memory : public std::exception
00108 {
00109 virtual const char* what() const throw()
00110 {
00111 return "ViennaCL: FATAL ERROR: CL_OUT_OF_HOST_MEMORY \n The host ran out of memory (usually CPU RAM). Please try again on smaller problems."
00112 VIENNACL_BUG_REPORT_STRING;
00113 }
00114 };
00115
00116 class profiling_info_not_available : public std::exception
00117 {
00118 virtual const char* what() const throw()
00119 {
00120 return "ViennaCL: FATAL ERROR: CL_PROFILING_INFO_NOT_AVAILABLE."
00121 VIENNACL_BUG_REPORT_STRING;
00122 }
00123 };
00124
00125 class mem_copy_overlap : public std::exception
00126 {
00127 virtual const char* what() const throw()
00128 {
00129 return "ViennaCL: FATAL ERROR: CL_MEM_COPY_OVERLAP."
00130 VIENNACL_BUG_REPORT_STRING;
00131 }
00132 };
00133
00134 class image_format_mismatch : public std::exception
00135 {
00136 virtual const char* what() const throw()
00137 {
00138 return "ViennaCL: FATAL ERROR: CL_IMAGE_FORMAT_MISMATCH."
00139 VIENNACL_BUG_REPORT_STRING;
00140 }
00141 };
00142
00143 class image_format_not_supported : public std::exception
00144 {
00145 virtual const char* what() const throw()
00146 {
00147 return "ViennaCL: FATAL ERROR: CL_IMAGE_FORMAT_NOT_SUPPORTED."
00148 VIENNACL_BUG_REPORT_STRING;
00149 }
00150 };
00151
00152 class build_program_failure : public std::exception
00153 {
00154 virtual const char* what() const throw()
00155 {
00156 return "ViennaCL: FATAL ERROR: CL_BUILD_PROGRAM_FAILURE \n The OpenCL compiler encountered an error during the compilation of ViennaCL sources. This is most likely a bug in ViennaCL."
00157 VIENNACL_BUG_REPORT_STRING;
00158 }
00159 };
00160
00161 class map_failure : public std::exception
00162 {
00163 virtual const char* what() const throw()
00164 {
00165 return "ViennaCL: FATAL ERROR: CL_MAP_FAILURE."
00166 VIENNACL_BUG_REPORT_STRING;
00167 }
00168 };
00169
00170 class invalid_value : public std::exception
00171 {
00172 virtual const char* what() const throw()
00173 {
00174 return "ViennaCL: FATAL ERROR: CL_INVALID_VALUE."
00175 VIENNACL_BUG_REPORT_STRING;
00176 }
00177 };
00178
00179 class invalid_device_type : public std::exception
00180 {
00181 virtual const char* what() const throw()
00182 {
00183 return "ViennaCL: FATAL ERROR: CL_INVALID_DEVICE_TYPE."
00184 VIENNACL_BUG_REPORT_STRING;
00185 }
00186 };
00187
00188 class invalid_platform : public std::exception
00189 {
00190 virtual const char* what() const throw()
00191 {
00192 return "ViennaCL: FATAL ERROR: CL_INVALID_PLATFORM."
00193 VIENNACL_BUG_REPORT_STRING;
00194 }
00195 };
00196
00197 class invalid_device : public std::exception
00198 {
00199 virtual const char* what() const throw()
00200 {
00201 return "ViennaCL: FATAL ERROR: CL_INVALID_DEVICE."
00202 VIENNACL_BUG_REPORT_STRING;
00203 }
00204 };
00205
00206 class invalid_context : public std::exception
00207 {
00208 virtual const char* what() const throw()
00209 {
00210 return "ViennaCL: FATAL ERROR: CL_INVALID_CONTEXT."
00211 VIENNACL_BUG_REPORT_STRING;
00212 }
00213 };
00214
00215 class invalid_queue_properties : public std::exception
00216 {
00217 virtual const char* what() const throw()
00218 {
00219 return "ViennaCL: FATAL ERROR: CL_INVALID_QUEUE_PROPERTIES."
00220 VIENNACL_BUG_REPORT_STRING;
00221 }
00222 };
00223
00224 class invalid_command_queue : public std::exception
00225 {
00226 virtual const char* what() const throw()
00227 {
00228 return "ViennaCL: FATAL ERROR: CL_INVALID_COMMAND_QUEUE."
00229 VIENNACL_BUG_REPORT_STRING;
00230 }
00231 };
00232
00233 class invalid_host_ptr : public std::exception
00234 {
00235 virtual const char* what() const throw()
00236 {
00237 return "ViennaCL: FATAL ERROR: CL_INVALID_HOST_PTR."
00238 VIENNACL_BUG_REPORT_STRING;
00239 }
00240 };
00241
00242 class invalid_mem_object : public std::exception
00243 {
00244 virtual const char* what() const throw()
00245 {
00246 return "ViennaCL: FATAL ERROR: CL_INVALID_MEM_OBJECT."
00247 VIENNACL_BUG_REPORT_STRING;
00248 }
00249 };
00250
00251 class invalid_image_format_descriptor : public std::exception
00252 {
00253 virtual const char* what() const throw()
00254 {
00255 return "ViennaCL: FATAL ERROR: CL_INVALID_IMAGE_FORMAT_DESCRIPTOR."
00256 VIENNACL_BUG_REPORT_STRING;
00257 }
00258 };
00259
00260 class invalid_image_size : public std::exception
00261 {
00262 virtual const char* what() const throw()
00263 {
00264 return "ViennaCL: FATAL ERROR: CL_INVALID_IMAGE_SIZE."
00265 VIENNACL_BUG_REPORT_STRING;
00266 }
00267 };
00268
00269 class invalid_sampler : public std::exception
00270 {
00271 virtual const char* what() const throw()
00272 {
00273 return "ViennaCL: FATAL ERROR: CL_INVALID_SAMPLER."
00274 VIENNACL_BUG_REPORT_STRING;
00275 }
00276 };
00277
00278 class invalid_binary : public std::exception
00279 {
00280 virtual const char* what() const throw()
00281 {
00282 return "ViennaCL: FATAL ERROR: CL_INVALID_BINARY."
00283 VIENNACL_BUG_REPORT_STRING;
00284 }
00285 };
00286
00287 class invalid_build_options : public std::exception
00288 {
00289 virtual const char* what() const throw()
00290 {
00291 return "ViennaCL: FATAL ERROR: CL_INVALID_BUILD_OPTIONS."
00292 VIENNACL_BUG_REPORT_STRING;
00293 }
00294 };
00295
00296 class invalid_program : public std::exception
00297 {
00298 virtual const char* what() const throw()
00299 {
00300 return "ViennaCL: FATAL ERROR: CL_INVALID_PROGRAM."
00301 VIENNACL_BUG_REPORT_STRING;
00302 }
00303 };
00304
00305 class invalid_program_executable : public std::exception
00306 {
00307 virtual const char* what() const throw()
00308 {
00309 return "ViennaCL: FATAL ERROR: CL_INVALID_PROGRAM_EXECUTABLE."
00310 VIENNACL_BUG_REPORT_STRING;
00311 }
00312 };
00313
00314 class invalid_kernel_name : public std::exception
00315 {
00316 virtual const char* what() const throw()
00317 {
00318 return "ViennaCL: FATAL ERROR: CL_INVALID_KERNEL_NAME \n The supplied kernel name is invalid. If you have written your own OpenCL kernel, please check that the correct kernel name is used in the initalization of the kernel object."
00319 VIENNACL_BUG_REPORT_STRING;
00320 }
00321 };
00322
00323 class invalid_kernel_definition : public std::exception
00324 {
00325 virtual const char* what() const throw()
00326 {
00327 return "ViennaCL: FATAL ERROR: CL_INVALID_KERNEL_DEFINITION."
00328 VIENNACL_BUG_REPORT_STRING;
00329 }
00330 };
00331
00332 class invalid_kernel : public std::exception
00333 {
00334 virtual const char* what() const throw()
00335 {
00336 return "ViennaCL: FATAL ERROR: CL_INVALID_KERNEL \n The supplied kernel argument is invalid."
00337 VIENNACL_BUG_REPORT_STRING;
00338 }
00339 };
00340
00341 class invalid_arg_index : public std::exception
00342 {
00343 virtual const char* what() const throw()
00344 {
00345 return "ViennaCL: FATAL ERROR: CL_INVALID_ARG_INDEX."
00346 VIENNACL_BUG_REPORT_STRING;
00347 }
00348 };
00349
00350 class invalid_arg_value : public std::exception
00351 {
00352 virtual const char* what() const throw()
00353 {
00354 return "ViennaCL: FATAL ERROR: CL_INVALID_ARG_VALUE."
00355 VIENNACL_BUG_REPORT_STRING;
00356 }
00357 };
00358
00359 class invalid_arg_size : public std::exception
00360 {
00361 virtual const char* what() const throw()
00362 {
00363 return "ViennaCL: FATAL ERROR: CL_INVALID_ARG_SIZE."
00364 VIENNACL_BUG_REPORT_STRING;
00365 }
00366 };
00367
00368 class invalid_kernel_args : public std::exception
00369 {
00370 virtual const char* what() const throw()
00371 {
00372 return "ViennaCL: FATAL ERROR: CL_INVALID_KERNEL_ARGS \n The supplied kernel arguments do not fit the kernel parameter list. If you have written your own OpenCL kernel, please check that the correct kernel arguments are set in the appropriate order."
00373 VIENNACL_BUG_REPORT_STRING;
00374 }
00375 };
00376
00377 class invalid_work_dimension : public std::exception
00378 {
00379 virtual const char* what() const throw()
00380 {
00381 return "ViennaCL: FATAL ERROR: CL_INVALID_WORK_DIMENSION"
00382 VIENNACL_BUG_REPORT_STRING;
00383 }
00384 };
00385
00386 class invalid_work_group_size : public std::exception
00387 {
00388 virtual const char* what() const throw()
00389 {
00390 return "ViennaCL: FATAL ERROR: CL_INVALID_WORK_GROUP_SIZE \n The supplied work group size is invalid. If you have set this value manually, please reconsider your choice."
00391 VIENNACL_BUG_REPORT_STRING;
00392 }
00393 };
00394
00395 class invalid_work_item_size : public std::exception
00396 {
00397 virtual const char* what() const throw()
00398 {
00399 return "ViennaCL: FATAL ERROR: CL_INVALID_WORK_ITEM_SIZE \n The work item size is invalid. If you have set this value manually, please reconsider your choice."
00400 VIENNACL_BUG_REPORT_STRING;
00401 }
00402 };
00403
00404 class invalid_global_offset : public std::exception
00405 {
00406 virtual const char* what() const throw()
00407 {
00408 return "ViennaCL: FATAL ERROR: CL_INVALID_GLOBAL_OFFSET."
00409 VIENNACL_BUG_REPORT_STRING;
00410 }
00411 };
00412
00413 class invalid_event_wait_list : public std::exception
00414 {
00415 virtual const char* what() const throw()
00416 {
00417 return "ViennaCL: FATAL ERROR: CL_INVALID_EVENT_WAIT_LIST."
00418 VIENNACL_BUG_REPORT_STRING;
00419 }
00420 };
00421
00422 class invalid_event : public std::exception
00423 {
00424 virtual const char* what() const throw()
00425 {
00426 return "ViennaCL: FATAL ERROR: CL_INVALID_EVENT."
00427 VIENNACL_BUG_REPORT_STRING;
00428 }
00429 };
00430
00431 class invalid_operation : public std::exception
00432 {
00433 virtual const char* what() const throw()
00434 {
00435 return "ViennaCL: FATAL ERROR: CL_INVALID_OPERATION."
00436 VIENNACL_BUG_REPORT_STRING;
00437 }
00438 };
00439
00440 class invalid_gl_object : public std::exception
00441 {
00442 virtual const char* what() const throw()
00443 {
00444 return "ViennaCL: FATAL ERROR: CL_INVALID_GL_OBJECT."
00445 VIENNACL_BUG_REPORT_STRING;
00446 }
00447 };
00448
00449 class invalid_buffer_size : public std::exception
00450 {
00451 virtual const char* what() const throw()
00452 {
00453 return "ViennaCL: FATAL ERROR: CL_INVALID_BUFFER_SIZE."
00454 VIENNACL_BUG_REPORT_STRING;
00455 }
00456 };
00457
00458 class invalid_mip_level : public std::exception
00459 {
00460 virtual const char* what() const throw()
00461 {
00462 return "ViennaCL: FATAL ERROR: CL_INVALID_MIP_LEVEL."
00463 VIENNACL_BUG_REPORT_STRING;
00464 }
00465 };
00466
00467 class invalid_global_work_size : public std::exception
00468 {
00469 virtual const char* what() const throw()
00470 {
00471 return "ViennaCL: FATAL ERROR: CL_INVALID_GLOBAL_WORK_SIZE."
00472 VIENNACL_BUG_REPORT_STRING;
00473 }
00474 };
00475
00476 class invalid_property : public std::exception
00477 {
00478 virtual const char* what() const throw()
00479 {
00480 return "ViennaCL: FATAL ERROR: CL_INVALID_PROPERTY."
00481 VIENNACL_BUG_REPORT_STRING;
00482 }
00483 };
00484
00485 class unknown_error : public std::exception
00486 {
00487 virtual const char* what() const throw()
00488 {
00489 return "ViennaCL: FATAL ERROR: ViennaCL encountered an unknown OpenCL error. In some cases, this might be due to an invalid global work size, but it can also be due to several compilation errors."
00490 VIENNACL_BUG_REPORT_STRING;
00491 }
00492 };
00493
00494
00495 class double_precision_not_provided_error : public std::exception
00496 {
00497 virtual const char* what() const throw()
00498 {
00499 return "ViennaCL: FATAL ERROR: You requested to create a ViennaCL type using double precision. However, double precision is not supported by your device."
00500 VIENNACL_BUG_REPORT_STRING;
00501 }
00502 };
00503
00504
00510 template <typename T>
00511 struct error_checker
00512 {
00513
00515 static void raise_exception(cl_int err)
00516 {
00517 switch (err)
00518 {
00519 case CL_DEVICE_NOT_FOUND: throw device_not_found(); break;
00520 case CL_DEVICE_NOT_AVAILABLE: throw device_not_available(); break;
00521 case CL_COMPILER_NOT_AVAILABLE: throw compiler_not_available(); break;
00522 case CL_MEM_OBJECT_ALLOCATION_FAILURE: throw mem_object_allocation_failure(); break;
00523 case CL_OUT_OF_RESOURCES: throw out_of_resources(); break;
00524 case CL_OUT_OF_HOST_MEMORY: throw out_of_host_memory(); break;
00525 case CL_PROFILING_INFO_NOT_AVAILABLE: throw profiling_info_not_available(); break;
00526 case CL_MEM_COPY_OVERLAP: throw mem_copy_overlap(); break;
00527 case CL_IMAGE_FORMAT_MISMATCH: throw image_format_mismatch(); break;
00528 case CL_IMAGE_FORMAT_NOT_SUPPORTED: throw image_format_not_supported(); break;
00529 case CL_BUILD_PROGRAM_FAILURE: throw build_program_failure(); break;
00530 case CL_MAP_FAILURE: throw map_failure(); break;
00531
00532 case CL_INVALID_VALUE: throw invalid_value(); break;
00533 case CL_INVALID_DEVICE_TYPE: throw invalid_device_type(); break;
00534 case CL_INVALID_PLATFORM: throw invalid_platform(); break;
00535 case CL_INVALID_DEVICE: throw invalid_device(); break;
00536 case CL_INVALID_CONTEXT: throw invalid_context(); break;
00537 case CL_INVALID_QUEUE_PROPERTIES: throw invalid_queue_properties(); break;
00538 case CL_INVALID_COMMAND_QUEUE: throw invalid_command_queue(); break;
00539 case CL_INVALID_HOST_PTR: throw invalid_host_ptr(); break;
00540 case CL_INVALID_MEM_OBJECT: throw invalid_mem_object(); break;
00541 case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: throw invalid_image_format_descriptor(); break;
00542 case CL_INVALID_IMAGE_SIZE: throw invalid_image_size(); break;
00543 case CL_INVALID_SAMPLER: throw invalid_sampler(); break;
00544 case CL_INVALID_BINARY: throw invalid_binary(); break;
00545 case CL_INVALID_BUILD_OPTIONS: throw invalid_build_options(); break;
00546 case CL_INVALID_PROGRAM: throw invalid_program(); break;
00547 case CL_INVALID_PROGRAM_EXECUTABLE: throw invalid_program_executable(); break;
00548 case CL_INVALID_KERNEL_NAME: throw invalid_kernel_name(); break;
00549 case CL_INVALID_KERNEL_DEFINITION: throw invalid_kernel_definition(); break;
00550 case CL_INVALID_KERNEL: throw invalid_kernel(); break;
00551 case CL_INVALID_ARG_INDEX: throw invalid_arg_index(); break;
00552 case CL_INVALID_ARG_VALUE: throw invalid_arg_value(); break;
00553 case CL_INVALID_ARG_SIZE: throw invalid_arg_size(); break;
00554 case CL_INVALID_KERNEL_ARGS: throw invalid_kernel_args(); break;
00555 case CL_INVALID_WORK_DIMENSION: throw invalid_work_dimension(); break;
00556 case CL_INVALID_WORK_GROUP_SIZE: throw invalid_work_group_size(); break;
00557 case CL_INVALID_WORK_ITEM_SIZE: throw invalid_work_item_size(); break;
00558 case CL_INVALID_GLOBAL_OFFSET: throw invalid_global_offset(); break;
00559 case CL_INVALID_EVENT_WAIT_LIST: throw invalid_event_wait_list(); break;
00560 case CL_INVALID_EVENT: throw invalid_event(); break;
00561 case CL_INVALID_OPERATION: throw invalid_operation(); break;
00562 case CL_INVALID_GL_OBJECT: throw invalid_gl_object(); break;
00563 case CL_INVALID_BUFFER_SIZE: throw invalid_buffer_size(); break;
00564 case CL_INVALID_MIP_LEVEL: throw invalid_mip_level(); break;
00565 case CL_INVALID_GLOBAL_WORK_SIZE: throw invalid_global_work_size(); break;
00566 #ifdef CL_INVALID_PROPERTY
00567 case CL_INVALID_PROPERTY: throw invalid_property(); break;
00568 #endif
00569
00570
00571 default: throw unknown_error();
00572 }
00573
00574 }
00575
00580 static void checkError(cl_int err, const std::string & file, const std::string & func, int line)
00581 {
00582 if (err != CL_SUCCESS)
00583 {
00584 #ifdef VIENNACL_DEBUG_ALL
00585 std::cerr << "ViennaCL: Error " << err << " in function " << func << " ( "<< file << ":" << line << " ) " << std::endl;
00586 #endif
00587 raise_exception(err);
00588 }
00589 }
00590
00591 };
00592
00593 #define VIENNACL_ERR_CHECK(err) viennacl::ocl::error_checker<void>::checkError(err, __FILE__, __FUNCTION__, __LINE__);
00594
00595 }
00596 }
00597
00598 #endif
00599