Neko  0.9.99
A portable framework for high-order spectral element flow simulations
check.c
Go to the documentation of this file.
1 /*
2  Copyright (c) 2022-2024, The Neko Authors
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions
7  are met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 
12  * Redistributions in binary form must reproduce the above
13  copyright notice, this list of conditions and the following
14  disclaimer in the documentation and/or other materials provided
15  with the distribution.
16 
17  * Neither the name of the authors nor the names of its
18  contributors may be used to endorse or promote products derived
19  from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 #ifdef __APPLE__
36 #include <OpenCL/cl.h>
37 #else
38 #include <CL/cl.h>
39 #endif
40 
41 #include <stdio.h>
42 #include <stdarg.h>
43 #include <stdlib.h>
44 #include <device/opencl/check.h>
45 
46 #define CL_ERR_STR(err) case err: return #err
47 
51 const char *clGetError(const cl_int err) {
52 
53  switch(err) {
54  CL_ERR_STR(CL_SUCCESS);
55  CL_ERR_STR(CL_DEVICE_NOT_FOUND);
56  CL_ERR_STR(CL_DEVICE_NOT_AVAILABLE);
57  CL_ERR_STR(CL_COMPILER_NOT_AVAILABLE);
58  CL_ERR_STR(CL_MEM_OBJECT_ALLOCATION_FAILURE);
59  CL_ERR_STR(CL_OUT_OF_RESOURCES);
60  CL_ERR_STR(CL_OUT_OF_HOST_MEMORY);
61  CL_ERR_STR(CL_PROFILING_INFO_NOT_AVAILABLE);
62  CL_ERR_STR(CL_MEM_COPY_OVERLAP);
63  CL_ERR_STR(CL_IMAGE_FORMAT_MISMATCH);
64  CL_ERR_STR(CL_IMAGE_FORMAT_NOT_SUPPORTED);
65  CL_ERR_STR(CL_BUILD_PROGRAM_FAILURE);
66  CL_ERR_STR(CL_MAP_FAILURE);
67  CL_ERR_STR(CL_MISALIGNED_SUB_BUFFER_OFFSET);
68  CL_ERR_STR(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
69  CL_ERR_STR(CL_COMPILE_PROGRAM_FAILURE);
70  CL_ERR_STR(CL_LINKER_NOT_AVAILABLE);
71  CL_ERR_STR(CL_LINK_PROGRAM_FAILURE);
72  CL_ERR_STR(CL_DEVICE_PARTITION_FAILED);
73  CL_ERR_STR(CL_KERNEL_ARG_INFO_NOT_AVAILABLE);
74  CL_ERR_STR(CL_INVALID_VALUE);
75  CL_ERR_STR(CL_INVALID_DEVICE_TYPE);
76  CL_ERR_STR(CL_INVALID_PLATFORM);
77  CL_ERR_STR(CL_INVALID_DEVICE);
78  CL_ERR_STR(CL_INVALID_CONTEXT);
79  CL_ERR_STR(CL_INVALID_QUEUE_PROPERTIES);
80  CL_ERR_STR(CL_INVALID_COMMAND_QUEUE);
81  CL_ERR_STR(CL_INVALID_HOST_PTR);
82  CL_ERR_STR(CL_INVALID_MEM_OBJECT);
83  CL_ERR_STR(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR);
84  CL_ERR_STR(CL_INVALID_IMAGE_SIZE);
85  CL_ERR_STR(CL_INVALID_SAMPLER);
86  CL_ERR_STR(CL_INVALID_BINARY);
87  CL_ERR_STR(CL_INVALID_BUILD_OPTIONS);
88  CL_ERR_STR(CL_INVALID_PROGRAM);
89  CL_ERR_STR(CL_INVALID_PROGRAM_EXECUTABLE);
90  CL_ERR_STR(CL_INVALID_KERNEL_NAME);
91  CL_ERR_STR(CL_INVALID_KERNEL_DEFINITION);
92  CL_ERR_STR(CL_INVALID_KERNEL);
93  CL_ERR_STR(CL_INVALID_ARG_INDEX);
94  CL_ERR_STR(CL_INVALID_ARG_VALUE);
95  CL_ERR_STR(CL_INVALID_ARG_SIZE);
96  CL_ERR_STR(CL_INVALID_KERNEL_ARGS);
97  CL_ERR_STR(CL_INVALID_WORK_DIMENSION);
98  CL_ERR_STR(CL_INVALID_WORK_GROUP_SIZE);
99  CL_ERR_STR(CL_INVALID_WORK_ITEM_SIZE);
100  CL_ERR_STR(CL_INVALID_GLOBAL_OFFSET);
101  CL_ERR_STR(CL_INVALID_EVENT_WAIT_LIST);
102  CL_ERR_STR(CL_INVALID_EVENT);
103  CL_ERR_STR(CL_INVALID_OPERATION);
104  CL_ERR_STR(CL_INVALID_GL_OBJECT);
105  CL_ERR_STR(CL_INVALID_BUFFER_SIZE);
106  CL_ERR_STR(CL_INVALID_MIP_LEVEL);
107  CL_ERR_STR(CL_INVALID_GLOBAL_WORK_SIZE);
108  CL_ERR_STR(CL_INVALID_PROPERTY);
109  CL_ERR_STR(CL_INVALID_IMAGE_DESCRIPTOR);
110  CL_ERR_STR(CL_INVALID_COMPILER_OPTIONS);
111  CL_ERR_STR(CL_INVALID_LINKER_OPTIONS);
112  CL_ERR_STR(CL_INVALID_DEVICE_PARTITION_COUNT);
113  }
114 }
115 
116 
120 void opencl_check(const char *fname, const int line, const cl_int err)
121 {
122  if (err != CL_SUCCESS) {
123  const char *err_str = clGetError(err);
124  fprintf(stderr, "%s in %s:%d \n", err_str, fname, line);
125  exit(1);
126  }
127 }
#define CL_ERR_STR(err)
Definition: check.c:46
void opencl_check(const char *fname, const int line, const cl_int err)
Definition: check.c:120
const char * clGetError(const cl_int err)
Definition: check.c:51