ViennaCL - The Vienna Computing Library
1.5.1
|
00001 #ifndef VIENNACL_OCL_ERROR_HPP_ 00002 #define VIENNACL_OCL_ERROR_HPP_ 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 Portions of this software are copyright by UChicago Argonne, LLC. 00009 00010 ----------------- 00011 ViennaCL - The Vienna Computing Library 00012 ----------------- 00013 00014 Project Head: Karl Rupp rupp@iue.tuwien.ac.at 00015 00016 (A list of authors and contributors can be found in the PDF manual) 00017 00018 License: MIT (X11), see file LICENSE in the base directory 00019 ============================================================================= */ 00020 00025 //error levels: 00026 //#define VIENNACL_DEBUG_ALL //print all of the following 00027 //#define VIENNACL_DEBUG_KERNEL //debug any modifications on viennacl::ocl::kernel objects 00028 //#define VIENNACL_DEBUG_COPY //print infos related to setting up/modifying memory objects 00029 //#define VIENNACL_DEBUG_OPENCL //display debug info for the OpenCL layer (platform/context/queue creation, 00030 //#define VIENNACL_DEBUG_DEVICE //Show device info upon allocation 00031 //#define VIENNACL_DEBUG_CONTEXT //Debug queries to context 00032 //#define VIENNACL_DEBUG_BUILD //Show debug info from OpenCL compiler 00033 00034 00035 //backwards compatibility: 00036 #ifdef VIENNACL_BUILD_INFO 00037 #define VIENNACL_DEBUG_ALL 00038 #endif 00039 00040 00041 #ifdef __APPLE__ 00042 #include <OpenCL/cl.h> 00043 #else 00044 #include <CL/cl.h> 00045 #endif 00046 00047 #include <string> 00048 #include <iostream> 00049 #include <exception> 00050 00051 #define VIENNACL_BUG_REPORT_STRING \ 00052 "\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"\ 00053 " * Operating System\n"\ 00054 " * Which OpenCL implementation (AMD, NVIDIA, etc.)\n"\ 00055 " * ViennaCL version\n"\ 00056 "Many thanks in advance!";\ 00057 00058 namespace viennacl 00059 { 00060 namespace ocl 00061 { 00062 //Wrapper for OpenCL exceptions: 00063 00068 class device_not_found : public std::exception 00069 { 00070 virtual const char* what() const throw() 00071 { 00072 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." 00073 VIENNACL_BUG_REPORT_STRING; 00074 } 00075 }; 00076 00078 class device_not_available : public std::exception 00079 { 00080 virtual const char* what() const throw() 00081 { 00082 return "ViennaCL: FATAL ERROR: CL_DEVICE_NOT_AVAILABLE \n ViennaCL could not use the compute device because it is not available." 00083 VIENNACL_BUG_REPORT_STRING; 00084 } 00085 }; 00086 00088 class compiler_not_available : public std::exception 00089 { 00090 virtual const char* what() const throw() 00091 { 00092 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." 00093 VIENNACL_BUG_REPORT_STRING; 00094 } 00095 }; 00096 00098 class mem_object_allocation_failure : public std::exception 00099 { 00100 virtual const char* what() const throw() 00101 { 00102 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." 00103 VIENNACL_BUG_REPORT_STRING; 00104 } 00105 }; 00106 00108 class out_of_resources : public std::exception 00109 { 00110 virtual const char* what() const throw() 00111 { 00112 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." 00113 VIENNACL_BUG_REPORT_STRING; 00114 } 00115 }; 00116 00118 class out_of_host_memory : public std::exception 00119 { 00120 virtual const char* what() const throw() 00121 { 00122 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." 00123 VIENNACL_BUG_REPORT_STRING; 00124 } 00125 }; 00126 00128 class profiling_info_not_available : public std::exception 00129 { 00130 virtual const char* what() const throw() 00131 { 00132 return "ViennaCL: FATAL ERROR: CL_PROFILING_INFO_NOT_AVAILABLE." 00133 VIENNACL_BUG_REPORT_STRING; 00134 } 00135 }; 00136 00138 class mem_copy_overlap : public std::exception 00139 { 00140 virtual const char* what() const throw() 00141 { 00142 return "ViennaCL: FATAL ERROR: CL_MEM_COPY_OVERLAP." 00143 VIENNACL_BUG_REPORT_STRING; 00144 } 00145 }; 00146 00148 class image_format_mismatch : public std::exception 00149 { 00150 virtual const char* what() const throw() 00151 { 00152 return "ViennaCL: FATAL ERROR: CL_IMAGE_FORMAT_MISMATCH." 00153 VIENNACL_BUG_REPORT_STRING; 00154 } 00155 }; 00156 00158 class image_format_not_supported : public std::exception 00159 { 00160 virtual const char* what() const throw() 00161 { 00162 return "ViennaCL: FATAL ERROR: CL_IMAGE_FORMAT_NOT_SUPPORTED." 00163 VIENNACL_BUG_REPORT_STRING; 00164 } 00165 }; 00166 00168 class build_program_failure : public std::exception 00169 { 00170 virtual const char* what() const throw() 00171 { 00172 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." 00173 VIENNACL_BUG_REPORT_STRING; 00174 } 00175 }; 00176 00178 class map_failure : public std::exception 00179 { 00180 virtual const char* what() const throw() 00181 { 00182 return "ViennaCL: FATAL ERROR: CL_MAP_FAILURE." 00183 VIENNACL_BUG_REPORT_STRING; 00184 } 00185 }; 00186 00188 class invalid_value : public std::exception 00189 { 00190 virtual const char* what() const throw() 00191 { 00192 return "ViennaCL: FATAL ERROR: CL_INVALID_VALUE." 00193 VIENNACL_BUG_REPORT_STRING; 00194 } 00195 }; 00196 00198 class invalid_device_type : public std::exception 00199 { 00200 virtual const char* what() const throw() 00201 { 00202 return "ViennaCL: FATAL ERROR: CL_INVALID_DEVICE_TYPE." 00203 VIENNACL_BUG_REPORT_STRING; 00204 } 00205 }; 00206 00208 class invalid_platform : public std::exception 00209 { 00210 virtual const char* what() const throw() 00211 { 00212 return "ViennaCL: FATAL ERROR: CL_INVALID_PLATFORM." 00213 VIENNACL_BUG_REPORT_STRING; 00214 } 00215 }; 00216 00218 class invalid_device : public std::exception 00219 { 00220 virtual const char* what() const throw() 00221 { 00222 return "ViennaCL: FATAL ERROR: CL_INVALID_DEVICE." 00223 VIENNACL_BUG_REPORT_STRING; 00224 } 00225 }; 00226 00228 class invalid_context : public std::exception 00229 { 00230 virtual const char* what() const throw() 00231 { 00232 return "ViennaCL: FATAL ERROR: CL_INVALID_CONTEXT." 00233 VIENNACL_BUG_REPORT_STRING; 00234 } 00235 }; 00236 00238 class invalid_queue_properties : public std::exception 00239 { 00240 virtual const char* what() const throw() 00241 { 00242 return "ViennaCL: FATAL ERROR: CL_INVALID_QUEUE_PROPERTIES." 00243 VIENNACL_BUG_REPORT_STRING; 00244 } 00245 }; 00246 00248 class invalid_command_queue : public std::exception 00249 { 00250 virtual const char* what() const throw() 00251 { 00252 return "ViennaCL: FATAL ERROR: CL_INVALID_COMMAND_QUEUE." 00253 VIENNACL_BUG_REPORT_STRING; 00254 } 00255 }; 00256 00258 class invalid_host_ptr : public std::exception 00259 { 00260 virtual const char* what() const throw() 00261 { 00262 return "ViennaCL: FATAL ERROR: CL_INVALID_HOST_PTR." 00263 VIENNACL_BUG_REPORT_STRING; 00264 } 00265 }; 00266 00268 class invalid_mem_object : public std::exception 00269 { 00270 virtual const char* what() const throw() 00271 { 00272 return "ViennaCL: FATAL ERROR: CL_INVALID_MEM_OBJECT." 00273 VIENNACL_BUG_REPORT_STRING; 00274 } 00275 }; 00276 00278 class invalid_image_format_descriptor : public std::exception 00279 { 00280 virtual const char* what() const throw() 00281 { 00282 return "ViennaCL: FATAL ERROR: CL_INVALID_IMAGE_FORMAT_DESCRIPTOR." 00283 VIENNACL_BUG_REPORT_STRING; 00284 } 00285 }; 00286 00288 class invalid_image_size : public std::exception 00289 { 00290 virtual const char* what() const throw() 00291 { 00292 return "ViennaCL: FATAL ERROR: CL_INVALID_IMAGE_SIZE." 00293 VIENNACL_BUG_REPORT_STRING; 00294 } 00295 }; 00296 00298 class invalid_sampler : public std::exception 00299 { 00300 virtual const char* what() const throw() 00301 { 00302 return "ViennaCL: FATAL ERROR: CL_INVALID_SAMPLER." 00303 VIENNACL_BUG_REPORT_STRING; 00304 } 00305 }; 00306 00308 class invalid_binary : public std::exception 00309 { 00310 virtual const char* what() const throw() 00311 { 00312 return "ViennaCL: FATAL ERROR: CL_INVALID_BINARY." 00313 VIENNACL_BUG_REPORT_STRING; 00314 } 00315 }; 00316 00318 class invalid_build_options : public std::exception 00319 { 00320 virtual const char* what() const throw() 00321 { 00322 return "ViennaCL: FATAL ERROR: CL_INVALID_BUILD_OPTIONS." 00323 VIENNACL_BUG_REPORT_STRING; 00324 } 00325 }; 00326 00328 class invalid_program : public std::exception 00329 { 00330 virtual const char* what() const throw() 00331 { 00332 return "ViennaCL: FATAL ERROR: CL_INVALID_PROGRAM." 00333 VIENNACL_BUG_REPORT_STRING; 00334 } 00335 }; 00336 00338 class invalid_program_executable : public std::exception 00339 { 00340 virtual const char* what() const throw() 00341 { 00342 return "ViennaCL: FATAL ERROR: CL_INVALID_PROGRAM_EXECUTABLE." 00343 VIENNACL_BUG_REPORT_STRING; 00344 } 00345 }; 00346 00348 class invalid_kernel_name : public std::exception 00349 { 00350 virtual const char* what() const throw() 00351 { 00352 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." 00353 VIENNACL_BUG_REPORT_STRING; 00354 } 00355 }; 00356 00358 class invalid_kernel_definition : public std::exception 00359 { 00360 virtual const char* what() const throw() 00361 { 00362 return "ViennaCL: FATAL ERROR: CL_INVALID_KERNEL_DEFINITION." 00363 VIENNACL_BUG_REPORT_STRING; 00364 } 00365 }; 00366 00368 class invalid_kernel : public std::exception 00369 { 00370 virtual const char* what() const throw() 00371 { 00372 return "ViennaCL: FATAL ERROR: CL_INVALID_KERNEL \n The supplied kernel argument is invalid." 00373 VIENNACL_BUG_REPORT_STRING; 00374 } 00375 }; 00376 00378 class invalid_arg_index : public std::exception 00379 { 00380 virtual const char* what() const throw() 00381 { 00382 return "ViennaCL: FATAL ERROR: CL_INVALID_ARG_INDEX." 00383 VIENNACL_BUG_REPORT_STRING; 00384 } 00385 }; 00386 00388 class invalid_arg_value : public std::exception 00389 { 00390 virtual const char* what() const throw() 00391 { 00392 return "ViennaCL: FATAL ERROR: CL_INVALID_ARG_VALUE." 00393 VIENNACL_BUG_REPORT_STRING; 00394 } 00395 }; 00396 00398 class invalid_arg_size : public std::exception 00399 { 00400 virtual const char* what() const throw() 00401 { 00402 return "ViennaCL: FATAL ERROR: CL_INVALID_ARG_SIZE." 00403 VIENNACL_BUG_REPORT_STRING; 00404 } 00405 }; 00406 00408 class invalid_kernel_args : public std::exception 00409 { 00410 virtual const char* what() const throw() 00411 { 00412 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." 00413 VIENNACL_BUG_REPORT_STRING; 00414 } 00415 }; 00416 00418 class invalid_work_dimension : public std::exception 00419 { 00420 virtual const char* what() const throw() 00421 { 00422 return "ViennaCL: FATAL ERROR: CL_INVALID_WORK_DIMENSION" 00423 VIENNACL_BUG_REPORT_STRING; 00424 } 00425 }; 00426 00428 class invalid_work_group_size : public std::exception 00429 { 00430 virtual const char* what() const throw() 00431 { 00432 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." 00433 VIENNACL_BUG_REPORT_STRING; 00434 } 00435 }; 00436 00438 class invalid_work_item_size : public std::exception 00439 { 00440 virtual const char* what() const throw() 00441 { 00442 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." 00443 VIENNACL_BUG_REPORT_STRING; 00444 } 00445 }; 00446 00448 class invalid_global_offset : public std::exception 00449 { 00450 virtual const char* what() const throw() 00451 { 00452 return "ViennaCL: FATAL ERROR: CL_INVALID_GLOBAL_OFFSET." 00453 VIENNACL_BUG_REPORT_STRING; 00454 } 00455 }; 00456 00458 class invalid_event_wait_list : public std::exception 00459 { 00460 virtual const char* what() const throw() 00461 { 00462 return "ViennaCL: FATAL ERROR: CL_INVALID_EVENT_WAIT_LIST." 00463 VIENNACL_BUG_REPORT_STRING; 00464 } 00465 }; 00466 00468 class invalid_event : public std::exception 00469 { 00470 virtual const char* what() const throw() 00471 { 00472 return "ViennaCL: FATAL ERROR: CL_INVALID_EVENT." 00473 VIENNACL_BUG_REPORT_STRING; 00474 } 00475 }; 00476 00478 class invalid_operation : public std::exception 00479 { 00480 virtual const char* what() const throw() 00481 { 00482 return "ViennaCL: FATAL ERROR: CL_INVALID_OPERATION." 00483 VIENNACL_BUG_REPORT_STRING; 00484 } 00485 }; 00486 00488 class invalid_gl_object : public std::exception 00489 { 00490 virtual const char* what() const throw() 00491 { 00492 return "ViennaCL: FATAL ERROR: CL_INVALID_GL_OBJECT." 00493 VIENNACL_BUG_REPORT_STRING; 00494 } 00495 }; 00496 00498 class invalid_buffer_size : public std::exception 00499 { 00500 virtual const char* what() const throw() 00501 { 00502 return "ViennaCL: FATAL ERROR: CL_INVALID_BUFFER_SIZE." 00503 VIENNACL_BUG_REPORT_STRING; 00504 } 00505 }; 00506 00508 class invalid_mip_level : public std::exception 00509 { 00510 virtual const char* what() const throw() 00511 { 00512 return "ViennaCL: FATAL ERROR: CL_INVALID_MIP_LEVEL." 00513 VIENNACL_BUG_REPORT_STRING; 00514 } 00515 }; 00516 00518 class invalid_global_work_size : public std::exception 00519 { 00520 virtual const char* what() const throw() 00521 { 00522 return "ViennaCL: FATAL ERROR: CL_INVALID_GLOBAL_WORK_SIZE." 00523 VIENNACL_BUG_REPORT_STRING; 00524 } 00525 }; 00526 00528 class invalid_property : public std::exception 00529 { 00530 virtual const char* what() const throw() 00531 { 00532 return "ViennaCL: FATAL ERROR: CL_INVALID_PROPERTY." 00533 VIENNACL_BUG_REPORT_STRING; 00534 } 00535 }; 00536 00538 class unknown_error : public std::exception 00539 { 00540 virtual const char* what() const throw() 00541 { 00542 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." 00543 VIENNACL_BUG_REPORT_STRING; 00544 } 00545 }; 00546 00548 class double_precision_not_provided_error : public std::exception 00549 { 00550 virtual const char* what() const throw() 00551 { 00552 return "ViennaCL: FATAL ERROR: You requested to create a ViennaCL type using double precision. However, double precision is not supported by your device." 00553 VIENNACL_BUG_REPORT_STRING; 00554 } 00555 }; 00556 00557 00563 template <typename T> 00564 struct error_checker 00565 { 00566 00568 static void raise_exception(cl_int err) 00569 { 00570 switch (err) 00571 { 00572 case CL_DEVICE_NOT_FOUND: throw device_not_found(); 00573 case CL_DEVICE_NOT_AVAILABLE: throw device_not_available(); 00574 case CL_COMPILER_NOT_AVAILABLE: throw compiler_not_available(); 00575 case CL_MEM_OBJECT_ALLOCATION_FAILURE: throw mem_object_allocation_failure(); 00576 case CL_OUT_OF_RESOURCES: throw out_of_resources(); 00577 case CL_OUT_OF_HOST_MEMORY: throw out_of_host_memory(); 00578 case CL_PROFILING_INFO_NOT_AVAILABLE: throw profiling_info_not_available(); 00579 case CL_MEM_COPY_OVERLAP: throw mem_copy_overlap(); 00580 case CL_IMAGE_FORMAT_MISMATCH: throw image_format_mismatch(); 00581 case CL_IMAGE_FORMAT_NOT_SUPPORTED: throw image_format_not_supported(); 00582 case CL_BUILD_PROGRAM_FAILURE: throw build_program_failure(); 00583 case CL_MAP_FAILURE: throw map_failure(); 00584 00585 case CL_INVALID_VALUE: throw invalid_value(); 00586 case CL_INVALID_DEVICE_TYPE: throw invalid_device_type(); 00587 case CL_INVALID_PLATFORM: throw invalid_platform(); 00588 case CL_INVALID_DEVICE: throw invalid_device(); 00589 case CL_INVALID_CONTEXT: throw invalid_context(); 00590 case CL_INVALID_QUEUE_PROPERTIES: throw invalid_queue_properties(); 00591 case CL_INVALID_COMMAND_QUEUE: throw invalid_command_queue(); 00592 case CL_INVALID_HOST_PTR: throw invalid_host_ptr(); 00593 case CL_INVALID_MEM_OBJECT: throw invalid_mem_object(); 00594 case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: throw invalid_image_format_descriptor(); 00595 case CL_INVALID_IMAGE_SIZE: throw invalid_image_size(); 00596 case CL_INVALID_SAMPLER: throw invalid_sampler(); 00597 case CL_INVALID_BINARY: throw invalid_binary(); 00598 case CL_INVALID_BUILD_OPTIONS: throw invalid_build_options(); 00599 case CL_INVALID_PROGRAM: throw invalid_program(); 00600 case CL_INVALID_PROGRAM_EXECUTABLE: throw invalid_program_executable(); 00601 case CL_INVALID_KERNEL_NAME: throw invalid_kernel_name(); 00602 case CL_INVALID_KERNEL_DEFINITION: throw invalid_kernel_definition(); 00603 case CL_INVALID_KERNEL: throw invalid_kernel(); 00604 case CL_INVALID_ARG_INDEX: throw invalid_arg_index(); 00605 case CL_INVALID_ARG_VALUE: throw invalid_arg_value(); 00606 case CL_INVALID_ARG_SIZE: throw invalid_arg_size(); 00607 case CL_INVALID_KERNEL_ARGS: throw invalid_kernel_args(); 00608 case CL_INVALID_WORK_DIMENSION: throw invalid_work_dimension(); 00609 case CL_INVALID_WORK_GROUP_SIZE: throw invalid_work_group_size(); 00610 case CL_INVALID_WORK_ITEM_SIZE: throw invalid_work_item_size(); 00611 case CL_INVALID_GLOBAL_OFFSET: throw invalid_global_offset(); 00612 case CL_INVALID_EVENT_WAIT_LIST: throw invalid_event_wait_list(); 00613 case CL_INVALID_EVENT: throw invalid_event(); 00614 case CL_INVALID_OPERATION: throw invalid_operation(); 00615 case CL_INVALID_GL_OBJECT: throw invalid_gl_object(); 00616 case CL_INVALID_BUFFER_SIZE: throw invalid_buffer_size(); 00617 case CL_INVALID_MIP_LEVEL: throw invalid_mip_level(); 00618 case CL_INVALID_GLOBAL_WORK_SIZE: throw invalid_global_work_size(); 00619 #ifdef CL_INVALID_PROPERTY 00620 case CL_INVALID_PROPERTY: throw invalid_property(); 00621 #endif 00622 // return "CL_INVALID_GLOBAL_WORK_SIZE"; 00623 00624 default: throw unknown_error(); 00625 } 00626 00627 } //getErrorString 00628 00633 static void checkError(cl_int err, 00634 #ifdef VIENNACL_DEBUG_ALL 00635 const char * file, 00636 const char * func, 00637 int line) 00638 #else 00639 const char *, 00640 const char *, 00641 int) 00642 #endif 00643 { 00644 if (err != CL_SUCCESS) 00645 { 00646 #ifdef VIENNACL_DEBUG_ALL 00647 std::cerr << "ViennaCL: Error " << err << " in function " << func << " ( "<< file << ":" << line << " ) " << std::endl; 00648 #endif 00649 raise_exception(err); 00650 } 00651 } //checkError() 00652 00653 }; //struct 00654 00655 #define VIENNACL_ERR_CHECK(err) viennacl::ocl::error_checker<void>::checkError(err, __FILE__, __FUNCTION__, __LINE__); 00656 00657 } //namespace ocl 00658 } //namespace viennacl 00659 00660 #endif 00661