CLUtil.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Robot Operating System code by the University of Osnabrück
5  * Copyright (c) 2015, University of Osnabrück
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  *
21  * 3. Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  *
39  *
40  * CLUtil.hpp
41  *
42  *
43  * authors:
44  *
45  * Kristin Schmidt <krschmidt@uni-osnabrueck.de>
46  */
47 
48 #ifndef CL_UTIL_HPP
49 #define CL_UTIL_HPP
50 
51 #include <CL/cl2.hpp>
52 
53 namespace rviz_map_plugin
54 {
59 class CLUtil
60 {
61 public:
67  static inline const char* getErrorString(cl_int error)
68  {
69  switch (error)
70  {
71  // run-time and JIT compiler errors
72  case 0:
73  return "CL_SUCCESS";
74  case -1:
75  return "CL_DEVICE_NOT_FOUND";
76  case -2:
77  return "CL_DEVICE_NOT_AVAILABLE";
78  case -3:
79  return "CL_COMPILER_NOT_AVAILABLE";
80  case -4:
81  return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
82  case -5:
83  return "CL_OUT_OF_RESOURCES";
84  case -6:
85  return "CL_OUT_OF_HOST_MEMORY";
86  case -7:
87  return "CL_PROFILING_INFO_NOT_AVAILABLE";
88  case -8:
89  return "CL_MEM_COPY_OVERLAP";
90  case -9:
91  return "CL_IMAGE_FORMAT_MISMATCH";
92  case -10:
93  return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
94  case -11:
95  return "CL_BUILD_PROGRAM_FAILURE";
96  case -12:
97  return "CL_MAP_FAILURE";
98  case -13:
99  return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
100  case -14:
101  return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
102  case -15:
103  return "CL_COMPILE_PROGRAM_FAILURE";
104  case -16:
105  return "CL_LINKER_NOT_AVAILABLE";
106  case -17:
107  return "CL_LINK_PROGRAM_FAILURE";
108  case -18:
109  return "CL_DEVICE_PARTITION_FAILED";
110  case -19:
111  return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
112 
113  // compile-time errors
114  case -30:
115  return "CL_INVALID_VALUE";
116  case -31:
117  return "CL_INVALID_DEVICE_TYPE";
118  case -32:
119  return "CL_INVALID_PLATFORM";
120  case -33:
121  return "CL_INVALID_DEVICE";
122  case -34:
123  return "CL_INVALID_CONTEXT";
124  case -35:
125  return "CL_INVALID_QUEUE_PROPERTIES";
126  case -36:
127  return "CL_INVALID_COMMAND_QUEUE";
128  case -37:
129  return "CL_INVALID_HOST_PTR";
130  case -38:
131  return "CL_INVALID_MEM_OBJECT";
132  case -39:
133  return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
134  case -40:
135  return "CL_INVALID_IMAGE_SIZE";
136  case -41:
137  return "CL_INVALID_SAMPLER";
138  case -42:
139  return "CL_INVALID_BINARY";
140  case -43:
141  return "CL_INVALID_BUILD_OPTIONS";
142  case -44:
143  return "CL_INVALID_PROGRAM";
144  case -45:
145  return "CL_INVALID_PROGRAM_EXECUTABLE";
146  case -46:
147  return "CL_INVALID_KERNEL_NAME";
148  case -47:
149  return "CL_INVALID_KERNEL_DEFINITION";
150  case -48:
151  return "CL_INVALID_KERNEL";
152  case -49:
153  return "CL_INVALID_ARG_INDEX";
154  case -50:
155  return "CL_INVALID_ARG_VALUE";
156  case -51:
157  return "CL_INVALID_ARG_SIZE";
158  case -52:
159  return "CL_INVALID_KERNEL_ARGS";
160  case -53:
161  return "CL_INVALID_WORK_DIMENSION";
162  case -54:
163  return "CL_INVALID_WORK_GROUP_SIZE";
164  case -55:
165  return "CL_INVALID_WORK_ITEM_SIZE";
166  case -56:
167  return "CL_INVALID_GLOBAL_OFFSET";
168  case -57:
169  return "CL_INVALID_EVENT_WAIT_LIST";
170  case -58:
171  return "CL_INVALID_EVENT";
172  case -59:
173  return "CL_INVALID_OPERATION";
174  case -60:
175  return "CL_INVALID_GL_OBJECT";
176  case -61:
177  return "CL_INVALID_BUFFER_SIZE";
178  case -62:
179  return "CL_INVALID_MIP_LEVEL";
180  case -63:
181  return "CL_INVALID_GLOBAL_WORK_SIZE";
182  case -64:
183  return "CL_INVALID_PROPERTY";
184  case -65:
185  return "CL_INVALID_IMAGE_DESCRIPTOR";
186  case -66:
187  return "CL_INVALID_COMPILER_OPTIONS";
188  case -67:
189  return "CL_INVALID_LINKER_OPTIONS";
190  case -68:
191  return "CL_INVALID_DEVICE_PARTITION_COUNT";
192 
193  // extension errors
194  case -1000:
195  return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
196  case -1001:
197  return "CL_PLATFORM_NOT_FOUND_KHR";
198  case -1002:
199  return "CL_INVALID_D3D10_DEVICE_KHR";
200  case -1003:
201  return "CL_INVALID_D3D10_RESOURCE_KHR";
202  case -1004:
203  return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
204  case -1005:
205  return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
206  default:
207  return "Unknown OpenCL error";
208  }
209  };
210 
216  static inline const char* getErrorDescription(cl_int error)
217  {
218  switch (error)
219  {
220  // run-time and JIT compiler errors
221  case 0:
222  return "Indicates that the function executed successfully.";
223  case -1:
224  return "Returned by clGetDeviceIDs and clCreateContextFromType if no OpenCL devices that match "
225  "the specified devices were found.";
226  case -2:
227  return "Returned by clCreateContext and clCreateContextFromType if the specified device is not "
228  "currently available.";
229  case -3:
230  return "Returned by clBuildProgram if the parameter program is created with "
231  "clCreateProgramWithSource and a compiler is not available. For example "
232  "CL_DEVICE_COMPILER_AVAILABLE is set to CL_FALSE.";
233  case -4:
234  return "Returned by the functions listed below if there is a failure to allocate memory for data "
235  "store associated with image or buffer objects specified as arguments to kernel. The exact "
236  "condition that generates this error depends on the calling function. Refer to the "
237  "function for more information. \n"
238  "Returned by the following functions: clCreateBuffer, clEnqueueReadBuffer, "
239  "clEnqueueWriteBuffer, clEnqueueCopyBuffer, clCreateImage2D, clCreateImage3D, "
240  "clEnqueueReadImage, clEnqueueWriteImage, clEnqueueCopyImage, clEnqueueCopyImageToBuffer, "
241  "clEnqueueCopyBufferToImage, clEnqueueMapBuffer, clEnqueueMapImage, "
242  "clEnqueueNDRangeKernel, clEnqueueTask, and clEnqueueNativeKernel ";
243  case -5:
244  return "Returned by clEnqueueNDRangeKernel, clEnqueueTask, and clEnqueueNativeKernel in the event "
245  "of a failure to queue the execution instance of kernel on the command-queue because of "
246  "insufficient resources needed to execute the kernel.";
247  case -6:
248  return "Returned by the functions listed below in the event of a failure to allocate resources "
249  "required by the OpenCL implementation on the host. The exact condition that generates "
250  "this error depends on the calling function. Refer to the function for more information. ";
251  case -7:
252  return "Returned by clGetEventProfilingInfo if the CL_QUEUE_PROFILING_ENABLE flag is not set for "
253  "the command-queue and the profiling information is currently not available (because the "
254  "command identified by event has not completed).";
255  case -8:
256  return "Returned by clEnqueueCopyBuffer and clEnqueueCopyImage if the source and destination "
257  "images are the same image (or the source and destination buffers are the same buffer), "
258  "and the source and destination regions overlap.";
259  case -9:
260  return "Returned by clEnqueueCopyImage if the specified source and destination images are not "
261  "valid image objects.";
262  case -10:
263  return "Returned by clCreateImage2D and clCreateImage3D if the specified image format is not "
264  "supported.";
265  case -11:
266  return "Returned by clBuildProgram if there is a failure to build the program executable. This "
267  "error will be returned if clBuildProgram does not return until the build has completed.";
268  case -12:
269  return "Returned by clEnqueueMapBuffer and clEnqueueMapImage if there is a failure to map the "
270  "requested region into the host address space. This error cannot occur for buffer objects "
271  "created with CL_MEM_USE_HOST_PTR or CL_MEM_ALLOC_HOST_PTR.";
272  case -13:
273  return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
274  case -14:
275  return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
276  case -15:
277  return "CL_COMPILE_PROGRAM_FAILURE";
278  case -16:
279  return "CL_LINKER_NOT_AVAILABLE";
280  case -17:
281  return "CL_LINK_PROGRAM_FAILURE";
282  case -18:
283  return "CL_DEVICE_PARTITION_FAILED";
284  case -19:
285  return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
286 
287  // compile-time errors
288  case -30:
289  return "Returned by the functions listed below if a parameter is not an expected value. The "
290  "exact condition that generates this error depends on the calling function. Refer to the "
291  "function for more information.";
292  case -31:
293  return "Returned by clGetDeviceIDs and clCreateContextFromType if device type specified is not "
294  "valid.";
295  case -32:
296  return "Returned by clGetPlatformInfo and clGetDeviceIDs if the specified platform is not a "
297  "valid platform.\n"
298  "Returned by clCreateContext and clCreateContextFromType if properties is NULL and no "
299  "platform could be selected, or if platform value specified in properties is not a valid "
300  "platform.";
301  case -33:
302  return "Returned by the functions listed below if the device or devices specified are not valid. "
303  "The exact condition that generates this error depends on the calling function. Refer to "
304  "the function for more information.";
305  case -34:
306  return "Returned by the functions listed below if the specified context is not a valid OpenCL "
307  "context, or the context associated with certain parameters are not the same. The exact "
308  "condition that generates this error depends on the calling function. Refer to the "
309  "function for more information.";
310  case -35:
311  return "Returned by clCreateCommandQueue and clSetCommandQueueProperty if specified properties "
312  "are valid but are not supported by the device.";
313  case -36:
314  return "Returned by the functions listed below if the specified command-queue is not a valid "
315  "command-queue. The exact condition that generates this error depends on the calling "
316  "function. Refer to the function for more information.";
317  case -37:
318  return "Returned by the functions listed below if host_ptr is NULL and CL_MEM_USE_HOST_PTR or "
319  "CL_MEM_COPY_HOST_PTR are set in flags or if host_ptr is not NULL but "
320  "CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags. The exact condition "
321  "that generates this error depends on the calling function. Refer to the function for "
322  "more information.\n"
323  "Returned by the functions clCreateBuffer, clCreateImage2D, and clCreateImage3D. ";
324  case -38:
325  return "Returned by the functions listed below if a parameter is not a valid memory, image, or "
326  "buffer object. The exact condition that generates this error depends on the calling "
327  "function. Refer to the function for more information.";
328  case -39:
329  return "Returned by clCreateImage2D and clCreateImage3D if the image format specified is not "
330  "valid or is NULL.\n"
331  "Returned byclCreateFromGLTexture2D and clCreateFromGLTexture3D\n"
332  "Returned by clCreateFromGLRenderbuffer if the OpenGL renderbuffer internal format does "
333  "not map to a supported OpenCL image format. ";
334  case -40:
335  return "Returned by clCreateImage2D if the specified image width or height are 0 or if they "
336  "exceed values specified in CL_DEVICE_IMAGE2D_MAX_WIDTH or CL_DEVICE_IMAGE2D_MAX_HEIGHT "
337  "respectively for all devices in context, or if the specified image row pitch does not "
338  "follow rules described for clCreateImage2D.\n"
339  "Returned by clCreateImage3D if the specified image width or height are 0 or if the image "
340  "depth is <= 1, or if they exceed values specified in CL_DEVICE_IMAGE3D_MAX_WIDTH, "
341  "CL_DEVICE_IMAGE3D_MAX_HEIGHT or CL_DEVICE_IMAGE3D_MAX_DEPTH respectively for all devices "
342  "in context, or if the image row pitch and image slice pitch do not follow rules "
343  "described for clCreateImage3D. ";
344  case -41:
345  return "Returned by clRetainSampler, clReleaseSampler, and clGetSamplerInfo if the specified "
346  "sampler is not a valid sampler object.\n"
347  "Returned by clSetKernelArg for an argument declared to be of type sampler_t when the "
348  "specified arg_value is not a valid sampler object. ";
349  case -42:
350  return "Returned by clBuildProgram and clCreateProgramWithBinary if the program binary is not a "
351  "valid binary for the specified device.";
352  case -43:
353  return "Returned by clBuildProgram if the specified build options are invalid.";
354  case -44:
355  return "Returned by clCreateKernel if there is no successfully built executable for program, and "
356  "returned by clCreateKernelsInProgram if there is no device in program.\n"
357  "Returned by clEnqueueNDRangeKernel and clEnqueueTask if there is no successfully built "
358  "program executable available for device associated with command_queue. ";
359  case -45:
360  return "Returned by clCreateKernel if there is no successfully built executable for program, and "
361  "returned by clCreateKernelsInProgram if there is no device in program.\n"
362  "Returned by clEnqueueNDRangeKernel and clEnqueueTask if there is no successfully built "
363  "program executable available for device associated with command_queue. ";
364  case -46:
365  return "Returned by clCreateKernel if the specified kernel name is not found in program.";
366  case -47:
367  return "Returned by clCreateKernel if the function definition for __kernel function given by "
368  "kernel_name such as the number of arguments, the argument types are not the same for all "
369  "devices for which the program executable has been built.";
370  case -48:
371  return "Returned by the functions listed below if the specified kernel is not a valid kernel "
372  "object. The exact condition that generates this error depends on the calling function. "
373  "Refer to the function for more information.";
374  case -49:
375  return "Returned by clSetKernelArg if an invalid argument index is specified.";
376  case -50:
377  return "Returned by clSetKernelArg if the argument value specified is NULL for an argument that "
378  "is not declared with the __local qualifier or vice-versa.";
379  case -51:
380  return "Returned by clSetKernelArg if argument size specified (arg_size) does not match the size "
381  "of the data type for an argument that is not a memory object, or if the argument is a "
382  "memory object and arg_size != sizeof(cl_mem) or if arg_size is zero and the argument is "
383  "declared with the __local qualifier or if the argument is a sampler and arg_size != "
384  "sizeof(cl_sampler).";
385  case -52:
386  return "Returned by clEnqueueNDRangeKernel and clEnqueueTask if the kernel argument values have "
387  "not been specified.";
388  case -53:
389  return "Returned by clEnqueueNDRangeKernel if work_dim is not a valid value.";
390  case -54:
391  return "Returned by clEnqueueNDRangeKernel and clEnqueueTask if local_work_size is specified and "
392  "number of workitems specified by global_work_size is not evenly divisible by size of "
393  "work-group given by local_work_size or does not match the work-group size specified for "
394  "kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program "
395  "source.";
396  case -55:
397  return "Returned by clEnqueueNDRangeKernel if the number of work-items specified in any of "
398  "local_work_size... [0]... local_work_size[work_dim - 1] is greater than the "
399  "corresponding values specified by CL_DEVICE_MAX_WORK_ITEM_SIZES[0],... "
400  "CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim -1].";
401  case -56:
402  return "Returned by clEnqueueNDRangeKernel if global_work_offset is not NULL.";
403  case -57:
404  return "Returned by the functions listed below if event_wait_list is NULL and "
405  "num_events_in_wait_list > 0, or event_wait_list_list is not NULL and "
406  "num_events_in_wait_list is 0, or specified event objects are not valid events. The exact "
407  "condition that generates this error depends on the calling function. Refer to the "
408  "function for more information.";
409  case -58:
410  return "Returned by the functions listed below if the event objects specified are not valid. The "
411  "exact condition that generates this error depends on the calling function. Refer to the "
412  "function for more information.";
413  case -59:
414  return "Returned by clCreateImage2D, clCreateImage3D, and clCreateSampler if there are no "
415  "devices in context that support images.\n"
416  "Returned by clBuildProgram if the build of a program executable for any of the devices "
417  "specified by a previous call to clBuildProgram for program has not completed, or if "
418  "there are kernel objects attached to program.\n"
419  "Returned by clEnqueueNativeKernel if the specified device cannot execute the native "
420  "kernel.\n"
421  "Returned by clCreateFromGLTexture2D if the miplevel is less than 0.\n"
422  "Returned by clCreateFromGLTexture3D if 3D images are not supported by the OpenCL "
423  "embedded profile. ";
424  case -60:
425  return "Returned by clCreateFromGLBuffer if bufobj is not a GL buffer object or is a GL buffer "
426  "object but does not have an existing data store.\n"
427  "Returned by clCreateFromGLRenderbuffer if renderbuffer is not a GL renderbuffer object "
428  "or if the width or height of renderbuffer is zero.\n"
429  "Returned by clCreateFromGLTexture2D and clCreateFromGLTexture3D if texture is not a GL "
430  "texture object whose type matches texture_target, if the specified miplevel of texture "
431  "is not defined, or if the width, height or depth of the specified miplevel is zero.\n"
432  "Returned by clGetGLObjectInfo and clGetGLTextureInfo if there is no GL object or texture "
433  "associated with memobj.\n"
434  "Returned by clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects if memory objects "
435  "in mem_objects have not been created from a GL object(s). The exact condition that "
436  "generates this error depends on the calling function. ";
437  case -61:
438  return "Returned by clCreateBuffer if the value of the parameter size is 0 or is greater than "
439  "CL_DEVICE_MAX_MEM_ALLOC_SIZE for all devices specified in the parameter context.";
440  case -62:
441  return "CL_INVALID_MIP_LEVEL";
442  case -63:
443  return "CL_INVALID_GLOBAL_WORK_SIZE";
444  case -64:
445  return "CL_INVALID_PROPERTY";
446  case -65:
447  return "CL_INVALID_IMAGE_DESCRIPTOR";
448  case -66:
449  return "CL_INVALID_COMPILER_OPTIONS";
450  case -67:
451  return "CL_INVALID_LINKER_OPTIONS";
452  case -68:
453  return "CL_INVALID_DEVICE_PARTITION_COUNT";
454 
455  // extension errors
456  case -1000:
457  return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
458  case -1001:
459  return "CL_PLATFORM_NOT_FOUND_KHR";
460  case -1002:
461  return "CL_INVALID_D3D10_DEVICE_KHR";
462  case -1003:
463  return "CL_INVALID_D3D10_RESOURCE_KHR";
464  case -1004:
465  return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
466  case -1005:
467  return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
468  default:
469  return "Unknown OpenCL error";
470  }
471  };
472 };
473 
474 } // end namespace rviz_map_plugin
475 
476 #endif
rviz_map_plugin::CLUtil::getErrorString
static const char * getErrorString(cl_int error)
Returns the error string to a given OpenCL error code.
Definition: CLUtil.hpp:67
rviz_map_plugin::CLUtil
Utility class for getting human-readable messages from OpenCL error codes.
Definition: CLUtil.hpp:59
rviz_map_plugin::CLUtil::getErrorDescription
static const char * getErrorDescription(cl_int error)
Returns a description to a given OpenCL error code.
Definition: CLUtil.hpp:216
rviz_map_plugin
Definition: ClusterLabelDisplay.hpp:120
error
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")


rviz_map_plugin
Author(s): Sebastian Pütz , Kristin Schmidt , Jan Philipp Vogtherr , Malte kleine Piening
autogenerated on Sun Jan 21 2024 04:06:25