Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:00

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_EXCEPTION_OPENCL_ERROR_HPP
0012 #define BOOST_COMPUTE_EXCEPTION_OPENCL_ERROR_HPP
0013 
0014 #include <exception>
0015 #include <string>
0016 #include <sstream>
0017 
0018 #include <boost/compute/cl.hpp>
0019 
0020 namespace boost {
0021 namespace compute {
0022 
0023 /// \class opencl_error
0024 /// \brief A run-time OpenCL error.
0025 ///
0026 /// The opencl_error class represents an error returned from an OpenCL
0027 /// function.
0028 ///
0029 /// \see context_error
0030 class opencl_error : public std::exception
0031 {
0032 public:
0033     /// Creates a new opencl_error exception object for \p error.
0034     explicit opencl_error(cl_int error) throw()
0035         : m_error(error),
0036           m_error_string(to_string(error))
0037     {
0038     }
0039 
0040     /// Destroys the opencl_error object.
0041     ~opencl_error() throw()
0042     {
0043     }
0044 
0045     /// Returns the numeric error code.
0046     cl_int error_code() const throw()
0047     {
0048         return m_error;
0049     }
0050 
0051     /// Returns a string description of the error.
0052     std::string error_string() const throw()
0053     {
0054         return m_error_string;
0055     }
0056 
0057     /// Returns a C-string description of the error.
0058     const char* what() const throw()
0059     {
0060         return m_error_string.c_str();
0061     }
0062 
0063     /// Static function which converts the numeric OpenCL error code \p error
0064     /// to a human-readable string.
0065     ///
0066     /// For example:
0067     /// \code
0068     /// std::cout << opencl_error::to_string(CL_INVALID_KERNEL_ARGS) << std::endl;
0069     /// \endcode
0070     ///
0071     /// Will print "Invalid Kernel Arguments".
0072     ///
0073     /// If the error code is unknown (e.g. not a valid OpenCL error), a string
0074     /// containing "Unknown OpenCL Error" along with the error number will be
0075     /// returned.
0076     static std::string to_string(cl_int error)
0077     {
0078         switch(error){
0079         case CL_SUCCESS: return "Success";
0080         case CL_DEVICE_NOT_FOUND: return "Device Not Found";
0081         case CL_DEVICE_NOT_AVAILABLE: return "Device Not Available";
0082         case CL_COMPILER_NOT_AVAILABLE: return "Compiler Not Available";
0083         case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "Memory Object Allocation Failure";
0084         case CL_OUT_OF_RESOURCES: return "Out of Resources";
0085         case CL_OUT_OF_HOST_MEMORY: return "Out of Host Memory";
0086         case CL_PROFILING_INFO_NOT_AVAILABLE: return "Profiling Information Not Available";
0087         case CL_MEM_COPY_OVERLAP: return "Memory Copy Overlap";
0088         case CL_IMAGE_FORMAT_MISMATCH: return "Image Format Mismatch";
0089         case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "Image Format Not Supported";
0090         case CL_BUILD_PROGRAM_FAILURE: return "Build Program Failure";
0091         case CL_MAP_FAILURE: return "Map Failure";
0092         case CL_INVALID_VALUE: return "Invalid Value";
0093         case CL_INVALID_DEVICE_TYPE: return "Invalid Device Type";
0094         case CL_INVALID_PLATFORM: return "Invalid Platform";
0095         case CL_INVALID_DEVICE: return "Invalid Device";
0096         case CL_INVALID_CONTEXT: return "Invalid Context";
0097         case CL_INVALID_QUEUE_PROPERTIES: return "Invalid Queue Properties";
0098         case CL_INVALID_COMMAND_QUEUE: return "Invalid Command Queue";
0099         case CL_INVALID_HOST_PTR: return "Invalid Host Pointer";
0100         case CL_INVALID_MEM_OBJECT: return "Invalid Memory Object";
0101         case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "Invalid Image Format Descriptor";
0102         case CL_INVALID_IMAGE_SIZE: return "Invalid Image Size";
0103         case CL_INVALID_SAMPLER: return "Invalid Sampler";
0104         case CL_INVALID_BINARY: return "Invalid Binary";
0105         case CL_INVALID_BUILD_OPTIONS: return "Invalid Build Options";
0106         case CL_INVALID_PROGRAM: return "Invalid Program";
0107         case CL_INVALID_PROGRAM_EXECUTABLE: return "Invalid Program Executable";
0108         case CL_INVALID_KERNEL_NAME: return "Invalid Kernel Name";
0109         case CL_INVALID_KERNEL_DEFINITION: return "Invalid Kernel Definition";
0110         case CL_INVALID_KERNEL: return "Invalid Kernel";
0111         case CL_INVALID_ARG_INDEX: return "Invalid Argument Index";
0112         case CL_INVALID_ARG_VALUE: return "Invalid Argument Value";
0113         case CL_INVALID_ARG_SIZE: return "Invalid Argument Size";
0114         case CL_INVALID_KERNEL_ARGS: return "Invalid Kernel Arguments";
0115         case CL_INVALID_WORK_DIMENSION: return "Invalid Work Dimension";
0116         case CL_INVALID_WORK_GROUP_SIZE: return "Invalid Work Group Size";
0117         case CL_INVALID_WORK_ITEM_SIZE: return "Invalid Work Item Size";
0118         case CL_INVALID_GLOBAL_OFFSET: return "Invalid Global Offset";
0119         case CL_INVALID_EVENT_WAIT_LIST: return "Invalid Event Wait List";
0120         case CL_INVALID_EVENT: return "Invalid Event";
0121         case CL_INVALID_OPERATION: return "Invalid Operation";
0122         case CL_INVALID_GL_OBJECT: return "Invalid GL Object";
0123         case CL_INVALID_BUFFER_SIZE: return "Invalid Buffer Size";
0124         case CL_INVALID_MIP_LEVEL: return "Invalid MIP Level";
0125         case CL_INVALID_GLOBAL_WORK_SIZE: return "Invalid Global Work Size";
0126         #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0127         case CL_COMPILE_PROGRAM_FAILURE: return "Compile Program Failure";
0128         case CL_LINKER_NOT_AVAILABLE: return "Linker Not Available";
0129         case CL_LINK_PROGRAM_FAILURE: return "Link Program Failure";
0130         case CL_DEVICE_PARTITION_FAILED: return "Device Partition Failed";
0131         case CL_KERNEL_ARG_INFO_NOT_AVAILABLE: return "Kernel Argument Info Not Available";
0132         case CL_INVALID_PROPERTY: return "Invalid Property";
0133         case CL_INVALID_IMAGE_DESCRIPTOR: return "Invalid Image Descriptor";
0134         case CL_INVALID_COMPILER_OPTIONS: return "Invalid Compiler Options";
0135         case CL_INVALID_LINKER_OPTIONS: return "Invalid Linker Options";
0136         case CL_INVALID_DEVICE_PARTITION_COUNT: return "Invalid Device Partition Count";
0137         #endif // BOOST_COMPUTE_CL_VERSION_1_2
0138         #ifdef BOOST_COMPUTE_CL_VERSION_2_0
0139         case CL_INVALID_PIPE_SIZE: return "Invalid Pipe Size";
0140         case CL_INVALID_DEVICE_QUEUE: return "Invalid Device Queue";
0141         #endif
0142         default: {
0143             std::stringstream s;
0144             s << "Unknown OpenCL Error (" << error << ")";
0145             return s.str();
0146         }
0147         }
0148     }
0149 
0150 private:
0151     cl_int m_error;
0152     std::string m_error_string;
0153 };
0154 
0155 } // end compute namespace
0156 } // end boost namespace
0157 
0158 #endif // BOOST_COMPUTE_EXCEPTION_OPENCL_ERROR_HPP