• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/data/development/ViennaCL/ViennaCL-1.1.2/viennacl/ocl/error.hpp

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

Generated on Sat May 21 2011 20:36:50 for ViennaCL - The Vienna Computing Library by  doxygen 1.7.1