CLUtil.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #define CL_HPP_ENABLE_EXCEPTIONS
4 #define CL_HPP_MINIMUM_OPENCL_VERSION 120 // Need to set to 120 on CUDA 8
5 #define CL_HPP_TARGET_OPENCL_VERSION 120 // Need to set to 120 on CUDA 8
6 
7 #if defined LVR2_USE_OPENCL_NEW_API
8  #include <CL/cl2.hpp>
9 #else
10  #include <CL/cl.hpp>
11 #endif
12 
13 namespace lvr2
14 {
15 
19 class CLUtil
20 {
21 public:
22 
30  static inline const char* getErrorString(cl_int error)
31  {
32  switch (error)
33  {
34  // run-time and JIT compiler errors
35  case 0: return "CL_SUCCESS";
36  case -1: return "CL_DEVICE_NOT_FOUND";
37  case -2: return "CL_DEVICE_NOT_AVAILABLE";
38  case -3: return "CL_COMPILER_NOT_AVAILABLE";
39  case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
40  case -5: return "CL_OUT_OF_RESOURCES";
41  case -6: return "CL_OUT_OF_HOST_MEMORY";
42  case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
43  case -8: return "CL_MEM_COPY_OVERLAP";
44  case -9: return "CL_IMAGE_FORMAT_MISMATCH";
45  case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
46  case -11: return "CL_BUILD_PROGRAM_FAILURE";
47  case -12: return "CL_MAP_FAILURE";
48  case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
49  case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
50  case -15: return "CL_COMPILE_PROGRAM_FAILURE";
51  case -16: return "CL_LINKER_NOT_AVAILABLE";
52  case -17: return "CL_LINK_PROGRAM_FAILURE";
53  case -18: return "CL_DEVICE_PARTITION_FAILED";
54  case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
55 
56  // compile-time errors
57  case -30: return "CL_INVALID_VALUE";
58  case -31: return "CL_INVALID_DEVICE_TYPE";
59  case -32: return "CL_INVALID_PLATFORM";
60  case -33: return "CL_INVALID_DEVICE";
61  case -34: return "CL_INVALID_CONTEXT";
62  case -35: return "CL_INVALID_QUEUE_PROPERTIES";
63  case -36: return "CL_INVALID_COMMAND_QUEUE";
64  case -37: return "CL_INVALID_HOST_PTR";
65  case -38: return "CL_INVALID_MEM_OBJECT";
66  case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
67  case -40: return "CL_INVALID_IMAGE_SIZE";
68  case -41: return "CL_INVALID_SAMPLER";
69  case -42: return "CL_INVALID_BINARY";
70  case -43: return "CL_INVALID_BUILD_OPTIONS";
71  case -44: return "CL_INVALID_PROGRAM";
72  case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
73  case -46: return "CL_INVALID_KERNEL_NAME";
74  case -47: return "CL_INVALID_KERNEL_DEFINITION";
75  case -48: return "CL_INVALID_KERNEL";
76  case -49: return "CL_INVALID_ARG_INDEX";
77  case -50: return "CL_INVALID_ARG_VALUE";
78  case -51: return "CL_INVALID_ARG_SIZE";
79  case -52: return "CL_INVALID_KERNEL_ARGS";
80  case -53: return "CL_INVALID_WORK_DIMENSION";
81  case -54: return "CL_INVALID_WORK_GROUP_SIZE";
82  case -55: return "CL_INVALID_WORK_ITEM_SIZE";
83  case -56: return "CL_INVALID_GLOBAL_OFFSET";
84  case -57: return "CL_INVALID_EVENT_WAIT_LIST";
85  case -58: return "CL_INVALID_EVENT";
86  case -59: return "CL_INVALID_OPERATION";
87  case -60: return "CL_INVALID_GL_OBJECT";
88  case -61: return "CL_INVALID_BUFFER_SIZE";
89  case -62: return "CL_INVALID_MIP_LEVEL";
90  case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
91  case -64: return "CL_INVALID_PROPERTY";
92  case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
93  case -66: return "CL_INVALID_COMPILER_OPTIONS";
94  case -67: return "CL_INVALID_LINKER_OPTIONS";
95  case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
96 
97  // extension errors
98  case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
99  case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
100  case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
101  case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
102  case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
103  case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
104  default: return "Unknown OpenCL error";
105  }
106  };
107 
115  static inline const char* getErrorDescription(cl_int error)
116  {
117  switch (error)
118  {
119  // run-time and JIT compiler errors
120  case 0: return "Indicates that the function executed successfully.";
121  case -1: return "Returned by clGetDeviceIDs and clCreateContextFromType if no OpenCL devices that match "
122  "the specified devices were found.";
123  case -2: return "Returned by clCreateContext and clCreateContextFromType if the specified device is not "
124  "currently available.";
125  case -3: return "Returned by clBuildProgram if the parameter program is created with "
126  "clCreateProgramWithSource and a compiler is not available. For example "
127  "CL_DEVICE_COMPILER_AVAILABLE is set to CL_FALSE.";
128  case -4: return "Returned by the functions listed below if there is a failure to allocate memory for data "
129  "store associated with image or buffer objects specified as arguments to kernel. The exact "
130  "condition that generates this error depends on the calling function. Refer to the "
131  "function for more information. \n"
132  "Returned by the following functions: clCreateBuffer, clEnqueueReadBuffer, "
133  "clEnqueueWriteBuffer, clEnqueueCopyBuffer, clCreateImage2D, clCreateImage3D, "
134  "clEnqueueReadImage, clEnqueueWriteImage, clEnqueueCopyImage, clEnqueueCopyImageToBuffer, "
135  "clEnqueueCopyBufferToImage, clEnqueueMapBuffer, clEnqueueMapImage, "
136  "clEnqueueNDRangeKernel, clEnqueueTask, and clEnqueueNativeKernel ";
137  case -5: return "Returned by clEnqueueNDRangeKernel, clEnqueueTask, and clEnqueueNativeKernel in the event "
138  "of a failure to queue the execution instance of kernel on the command-queue because of "
139  "insufficient resources needed to execute the kernel.";
140  case -6: return "Returned by the functions listed below in the event of a failure to allocate resources "
141  "required by the OpenCL implementation on the host. The exact condition that generates "
142  "this error depends on the calling function. Refer to the function for more information. ";
143  case -7: return "Returned by clGetEventProfilingInfo if the CL_QUEUE_PROFILING_ENABLE flag is not set for "
144  "the command-queue and the profiling information is currently not available (because the "
145  "command identified by event has not completed).";
146  case -8: return "Returned by clEnqueueCopyBuffer and clEnqueueCopyImage if the source and destination "
147  "images are the same image (or the source and destination buffers are the same buffer), "
148  "and the source and destination regions overlap.";
149  case -9: return "Returned by clEnqueueCopyImage if the specified source and destination images are not "
150  "valid image objects.";
151  case -10: return "Returned by clCreateImage2D and clCreateImage3D if the specified image format is not "
152  "supported.";
153  case -11: return "Returned by clBuildProgram if there is a failure to build the program executable. This "
154  "error will be returned if clBuildProgram does not return until the build has completed.";
155  case -12: return "Returned by clEnqueueMapBuffer and clEnqueueMapImage if there is a failure to map the "
156  "requested region into the host address space. This error cannot occur for buffer objects "
157  "created with CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR.";
158  case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
159  case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
160  case -15: return "CL_COMPILE_PROGRAM_FAILURE";
161  case -16: return "CL_LINKER_NOT_AVAILABLE";
162  case -17: return "CL_LINK_PROGRAM_FAILURE";
163  case -18: return "CL_DEVICE_PARTITION_FAILED";
164  case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
165 
166  // compile-time errors
167  case -30: return "Returned by the functions listed below if a parameter is not an expected value. The "
168  "exact condition that generates this error depends on the calling function. Refer to the "
169  "function for more information.";
170  case -31: return "Returned by clGetDeviceIDs and clCreateContextFromType if device type specified is not "
171  "valid.";
172  case -32: return "Returned by clGetPlatformInfo and clGetDeviceIDs if the specified platform is not a "
173  "valid platform.\n"
174  "Returned by clCreateContext and clCreateContextFromType if properties is NULL and no "
175  "platform could be selected, or if platform value specified in properties is not a valid "
176  "platform.";
177  case -33: return "Returned by the functions listed below if the device or devices specified are not valid. "
178  "The exact condition that generates this error depends on the calling function. Refer to "
179  "the function for more information.";
180  case -34: return "Returned by the functions listed below if the specified context is not a valid OpenCL "
181  "context, or the context associated with certain parameters are not the same. The exact "
182  "condition that generates this error depends on the calling function. Refer to the "
183  "function for more information.";
184  case -35: return "Returned by clCreateCommandQueue and clSetCommandQueueProperty if specified properties "
185  "are valid but are not supported by the device.";
186  case -36: return "Returned by the functions listed below if the specified command-queue is not a valid "
187  "command-queue. The exact condition that generates this error depends on the calling "
188  "function. Refer to the function for more information.";
189  case -37: return "Returned by the functions listed below if host_ptr is NULL and CL_MEM_USE_HOST_PTR or "
190  "CL_MEM_COPY_HOST_PTR are set in flags or if host_ptr is not NULL but "
191  "CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags. The exact condition "
192  "that generates this error depends on the calling function. Refer to the function for "
193  "more information.\n"
194  "Returned by the functions clCreateBuffer, clCreateImage2D, and clCreateImage3D. ";
195  case -38: return "Returned by the functions listed below if a parameter is not a valid memory, image, or "
196  "buffer object. The exact condition that generates this error depends on the calling "
197  "function. Refer to the function for more information.";
198  case -39: return "Returned by clCreateImage2D and clCreateImage3D if the image format specified is not "
199  "valid or is NULL.\n"
200  "Returned byclCreateFromGLTexture2D and clCreateFromGLTexture3D\n"
201  "Returned by clCreateFromGLRenderbuffer if the OpenGL renderbuffer internal format does "
202  "not map to a supported OpenCL image format. ";
203  case -40: return "Returned by clCreateImage2D if the specified image width or height are 0 or if they "
204  "exceed values specified in CL_DEVICE_IMAGE2D_MAX_WIDTH or CL_DEVICE_IMAGE2D_MAX_HEIGHT "
205  "respectively for all devices in context, or if the specified image row pitch does not "
206  "follow rules described for clCreateImage2D.\n"
207  "Returned by clCreateImage3D if the specified image width or height are 0 or if the image "
208  "depth is <= 1, or if they exceed values specified in CL_DEVICE_IMAGE3D_MAX_WIDTH, "
209  "CL_DEVICE_IMAGE3D_MAX_HEIGHT or CL_DEVICE_IMAGE3D_MAX_DEPTH respectively for all devices "
210  "in context, or if the image row pitch and image slice pitch do not follow rules "
211  "described for clCreateImage3D. ";
212  case -41: return "Returned by clRetainSampler, clReleaseSampler, and clGetSamplerInfo if the specified "
213  "sampler is not a valid sampler object.\n"
214  "Returned by clSetKernelArg for an argument declared to be of type sampler_t when the "
215  "specified arg_value is not a valid sampler object. ";
216  case -42: return "Returned by clBuildProgram and clCreateProgramWithBinary if the program binary is not a "
217  "valid binary for the specified device.";
218  case -43: return "Returned by clBuildProgram if the specified build options are invalid.";
219  case -44: return "Returned by clCreateKernel if there is no successfully built executable for program, and "
220  "returned by clCreateKernelsInProgram if there is no device in program.\n"
221  "Returned by clEnqueueNDRangeKernel and clEnqueueTask if there is no successfully built "
222  "program executable available for device associated with command_queue. ";
223  case -45: return "Returned by clCreateKernel if there is no successfully built executable for program, and "
224  "returned by clCreateKernelsInProgram if there is no device in program.\n"
225  "Returned by clEnqueueNDRangeKernel and clEnqueueTask if there is no successfully built "
226  "program executable available for device associated with command_queue. ";
227  case -46: return "Returned by clCreateKernel if the specified kernel name is not found in program.";
228  case -47: return "Returned by clCreateKernel if the function definition for __kernel function given by "
229  "kernel_name such as the number of arguments, the argument types are not the same for all "
230  "devices for which the program executable has been built.";
231  case -48: return "Returned by the functions listed below if the specified kernel is not a valid kernel "
232  "object. The exact condition that generates this error depends on the calling function. "
233  "Refer to the function for more information.";
234  case -49: return "Returned by clSetKernelArg if an invalid argument index is specified.";
235  case -50: return "Returned by clSetKernelArg if the argument value specified is NULL for an argument that "
236  "is not declared with the __local qualifier or vice-versa.";
237  case -51: return "Returned by clSetKernelArg if argument size specified (arg_size) does not match the size "
238  "of the data type for an argument that is not a memory object, or if the argument is a "
239  "memory object and arg_size != sizeof(cl_mem) or if arg_size is zero and the argument is "
240  "declared with the __local qualifier or if the argument is a sampler and arg_size != "
241  "sizeof(cl_sampler).";
242  case -52: return "Returned by clEnqueueNDRangeKernel and clEnqueueTask if the kernel argument values have "
243  "not been specified.";
244  case -53: return "Returned by clEnqueueNDRangeKernel if work_dim is not a valid value.";
245  case -54: return "Returned by clEnqueueNDRangeKernel and clEnqueueTask if local_work_size is specified and "
246  "number of workitems specified by global_work_size is not evenly divisible by size of "
247  "work-group given by local_work_size or does not match the work-group size specified for "
248  "kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program "
249  "source.";
250  case -55: return "Returned by clEnqueueNDRangeKernel if the number of work-items specified in any of "
251  "local_work_size... [0]... local_work_size[work_dim - 1] is greater than the "
252  "corresponding values specified by CL_DEVICE_MAX_WORK_ITEM_SIZES[0],... "
253  "CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim -1].";
254  case -56: return "Returned by clEnqueueNDRangeKernel if global_work_offset is not NULL.";
255  case -57: return "Returned by the functions listed below if event_wait_list is NULL and "
256  "num_events_in_wait_list > 0, or event_wait_list_list is not NULL and "
257  "num_events_in_wait_list is 0, or specified event objects are not valid events. The exact "
258  "condition that generates this error depends on the calling function. Refer to the "
259  "function for more information.";
260  case -58: return "Returned by the functions listed below if the event objects specified are not valid. The "
261  "exact condition that generates this error depends on the calling function. Refer to the "
262  "function for more information.";
263  case -59: return "Returned by clCreateImage2D, clCreateImage3D, and clCreateSampler if there are no "
264  "devices in context that support images.\n"
265  "Returned by clBuildProgram if the build of a program executable for any of the devices "
266  "specified by a previous call to clBuildProgram for program has not completed, or if "
267  "there are kernel objects attached to program.\n"
268  "Returned by clEnqueueNativeKernel if the specified device cannot execute the native "
269  "kernel.\n"
270  "Returned by clCreateFromGLTexture2D if the miplevel is less than 0.\n"
271  "Returned by clCreateFromGLTexture3D if 3D images are not supported by the OpenCL "
272  "embedded profile. ";
273  case -60: return "Returned by clCreateFromGLBuffer if bufobj is not a GL buffer object or is a GL buffer "
274  "object but does not have an existing data store.\n"
275  "Returned by clCreateFromGLRenderbuffer if renderbuffer is not a GL renderbuffer object "
276  "or if the width or height of renderbuffer is zero.\n"
277  "Returned by clCreateFromGLTexture2D and clCreateFromGLTexture3D if texture is not a GL "
278  "texture object whose type matches texture_target, if the specified miplevel of texture "
279  "is not defined, or if the width, height or depth of the specified miplevel is zero.\n"
280  "Returned by clGetGLObjectInfo and clGetGLTextureInfo if there is no GL object or texture "
281  "associated with memobj.\n"
282  "Returned by clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects if memory objects "
283  "in mem_objects have not been created from a GL object(s). The exact condition that "
284  "generates this error depends on the calling function. ";
285  case -61: return "Returned by clCreateBuffer if the value of the parameter size is 0 or is greater than "
286  "CL_DEVICE_MAX_MEM_ALLOC_SIZE for all devices specified in the parameter context.";
287  case -62: return "CL_INVALID_MIP_LEVEL";
288  case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
289  case -64: return "CL_INVALID_PROPERTY";
290  case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
291  case -66: return "CL_INVALID_COMPILER_OPTIONS";
292  case -67: return "CL_INVALID_LINKER_OPTIONS";
293  case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
294 
295  // extension errors
296  case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
297  case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
298  case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
299  case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
300  case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
301  case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
302  default: return "Unknown OpenCL error";
303  }
304  };
305 };
306 
307 } // namespace lvr2
lvr2::CLUtil::getErrorString
static const char * getErrorString(cl_int error)
Util method that maps error codes to CL error strings.
Definition: CLUtil.hpp:30
lvr2::CLUtil::getErrorDescription
static const char * getErrorDescription(cl_int error)
Util method that maps error codes to CL error description messages.
Definition: CLUtil.hpp:115
lvr2::CLUtil
Util class for CL that maps error codes to human readable strings.
Definition: CLUtil.hpp:19
lvr2
Definition: BaseBufferManipulators.hpp:39
kfusion::cuda::error
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
Error handler. All GPU functions from this subsystem call the function to report an error....
Definition: device_memory.cpp:7


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23