File indexing completed on 2025-01-18 09:30:00
0001
0002
0003
0004
0005
0006
0007
0008
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
0024
0025
0026
0027
0028
0029
0030 class opencl_error : public std::exception
0031 {
0032 public:
0033
0034 explicit opencl_error(cl_int error) throw()
0035 : m_error(error),
0036 m_error_string(to_string(error))
0037 {
0038 }
0039
0040
0041 ~opencl_error() throw()
0042 {
0043 }
0044
0045
0046 cl_int error_code() const throw()
0047 {
0048 return m_error;
0049 }
0050
0051
0052 std::string error_string() const throw()
0053 {
0054 return m_error_string;
0055 }
0056
0057
0058 const char* what() const throw()
0059 {
0060 return m_error_string.c_str();
0061 }
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
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
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 }
0156 }
0157
0158 #endif