1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 *
7 */
8
9 //
10 //
11 //
12
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 //
17 //
18 //
19
20 #include "assert_cl.h"
21
22 //
23 //
24 //
25
26 #define CL_VAL_TO_STRING(err) case err: return #err
27
28 //
29 //
30 //
31
32 #define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000
33
34 //
35 //
36 //
37
38 char const *
cl_get_error_string(cl_int const err)39 cl_get_error_string(cl_int const err)
40 {
41 switch (err)
42 {
43 CL_VAL_TO_STRING(CL_SUCCESS);
44 CL_VAL_TO_STRING(CL_DEVICE_NOT_FOUND);
45 CL_VAL_TO_STRING(CL_DEVICE_NOT_AVAILABLE);
46 CL_VAL_TO_STRING(CL_COMPILER_NOT_AVAILABLE);
47 CL_VAL_TO_STRING(CL_MEM_OBJECT_ALLOCATION_FAILURE);
48 CL_VAL_TO_STRING(CL_OUT_OF_RESOURCES);
49 CL_VAL_TO_STRING(CL_OUT_OF_HOST_MEMORY);
50 CL_VAL_TO_STRING(CL_PROFILING_INFO_NOT_AVAILABLE);
51 CL_VAL_TO_STRING(CL_MEM_COPY_OVERLAP);
52 CL_VAL_TO_STRING(CL_IMAGE_FORMAT_MISMATCH);
53 CL_VAL_TO_STRING(CL_IMAGE_FORMAT_NOT_SUPPORTED);
54 CL_VAL_TO_STRING(CL_BUILD_PROGRAM_FAILURE);
55 CL_VAL_TO_STRING(CL_MAP_FAILURE);
56 CL_VAL_TO_STRING(CL_MISALIGNED_SUB_BUFFER_OFFSET);
57 CL_VAL_TO_STRING(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
58 CL_VAL_TO_STRING(CL_COMPILE_PROGRAM_FAILURE);
59 CL_VAL_TO_STRING(CL_LINKER_NOT_AVAILABLE);
60 CL_VAL_TO_STRING(CL_LINK_PROGRAM_FAILURE);
61 CL_VAL_TO_STRING(CL_DEVICE_PARTITION_FAILED);
62 CL_VAL_TO_STRING(CL_KERNEL_ARG_INFO_NOT_AVAILABLE);
63 CL_VAL_TO_STRING(CL_INVALID_VALUE);
64 CL_VAL_TO_STRING(CL_INVALID_DEVICE_TYPE);
65 CL_VAL_TO_STRING(CL_INVALID_PLATFORM);
66 CL_VAL_TO_STRING(CL_INVALID_DEVICE);
67 CL_VAL_TO_STRING(CL_INVALID_CONTEXT);
68 CL_VAL_TO_STRING(CL_INVALID_QUEUE_PROPERTIES);
69 CL_VAL_TO_STRING(CL_INVALID_COMMAND_QUEUE);
70 CL_VAL_TO_STRING(CL_INVALID_HOST_PTR);
71 CL_VAL_TO_STRING(CL_INVALID_MEM_OBJECT);
72 CL_VAL_TO_STRING(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR);
73 CL_VAL_TO_STRING(CL_INVALID_IMAGE_SIZE);
74 CL_VAL_TO_STRING(CL_INVALID_SAMPLER);
75 CL_VAL_TO_STRING(CL_INVALID_BINARY);
76 CL_VAL_TO_STRING(CL_INVALID_BUILD_OPTIONS);
77 CL_VAL_TO_STRING(CL_INVALID_PROGRAM);
78 CL_VAL_TO_STRING(CL_INVALID_PROGRAM_EXECUTABLE);
79 CL_VAL_TO_STRING(CL_INVALID_KERNEL_NAME);
80 CL_VAL_TO_STRING(CL_INVALID_KERNEL_DEFINITION);
81 CL_VAL_TO_STRING(CL_INVALID_KERNEL);
82 CL_VAL_TO_STRING(CL_INVALID_ARG_INDEX);
83 CL_VAL_TO_STRING(CL_INVALID_ARG_VALUE);
84 CL_VAL_TO_STRING(CL_INVALID_ARG_SIZE);
85 CL_VAL_TO_STRING(CL_INVALID_KERNEL_ARGS);
86 CL_VAL_TO_STRING(CL_INVALID_WORK_DIMENSION);
87 CL_VAL_TO_STRING(CL_INVALID_WORK_GROUP_SIZE);
88 CL_VAL_TO_STRING(CL_INVALID_WORK_ITEM_SIZE);
89 CL_VAL_TO_STRING(CL_INVALID_GLOBAL_OFFSET);
90 CL_VAL_TO_STRING(CL_INVALID_EVENT_WAIT_LIST);
91 CL_VAL_TO_STRING(CL_INVALID_EVENT);
92 CL_VAL_TO_STRING(CL_INVALID_OPERATION);
93 CL_VAL_TO_STRING(CL_INVALID_GL_OBJECT);
94 CL_VAL_TO_STRING(CL_INVALID_BUFFER_SIZE);
95 CL_VAL_TO_STRING(CL_INVALID_MIP_LEVEL);
96 CL_VAL_TO_STRING(CL_INVALID_GLOBAL_WORK_SIZE);
97 CL_VAL_TO_STRING(CL_INVALID_PROPERTY);
98 CL_VAL_TO_STRING(CL_INVALID_IMAGE_DESCRIPTOR);
99 CL_VAL_TO_STRING(CL_INVALID_COMPILER_OPTIONS);
100 CL_VAL_TO_STRING(CL_INVALID_LINKER_OPTIONS);
101 CL_VAL_TO_STRING(CL_INVALID_DEVICE_PARTITION_COUNT);
102 // CL_VAL_TO_STRING(CL_INVALID_PIPE_SIZE);
103 // CL_VAL_TO_STRING(CL_INVALID_DEVICE_QUEUE);
104
105 //
106 // Extensions:
107 //
108 // cl_khr_gl_sharing
109 //
110 CL_VAL_TO_STRING(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR);
111
112 //
113 //
114 //
115 default:
116 return "UNKNOWN ERROR CODE";
117 }
118 }
119
120 //
121 //
122 //
123
124 cl_int
assert_cl(cl_int const code,char const * const file,int const line,bool const abort)125 assert_cl(cl_int const code, char const * const file, int const line, bool const abort)
126 {
127 if (code != CL_SUCCESS)
128 {
129 char const * const cl_err_str = cl_get_error_string(code);
130
131 fprintf(stderr,
132 "\"%s\", line %d: assert_cl( %d ) = \"%s\"",
133 file,line,code,cl_err_str);
134
135 if (abort)
136 {
137 // stop profiling and reset device here if necessary
138 exit(code);
139 }
140 }
141
142 return code;
143 }
144
145 //
146 //
147 //
148
149 void
cl_get_event_info(cl_event event,cl_int * const status,cl_command_type * const type)150 cl_get_event_info(cl_event event,
151 cl_int * const status,
152 cl_command_type * const type)
153 {
154 if (status != NULL) {
155 cl(GetEventInfo(event,
156 CL_EVENT_COMMAND_EXECUTION_STATUS,
157 sizeof(*status),
158 status,
159 NULL));
160 }
161
162 if (type != NULL) {
163 cl(GetEventInfo(event,
164 CL_EVENT_COMMAND_TYPE,
165 sizeof(*type),
166 type,
167 NULL));
168 }
169 }
170
171
172 char const *
cl_get_event_command_status_string(cl_int const status)173 cl_get_event_command_status_string(cl_int const status)
174 {
175 switch (status)
176 {
177 CL_VAL_TO_STRING(CL_QUEUED);
178 CL_VAL_TO_STRING(CL_SUBMITTED);
179 CL_VAL_TO_STRING(CL_RUNNING);
180 CL_VAL_TO_STRING(CL_COMPLETE);
181
182 default:
183 return "UNKNOWN COMMAND STATUS";
184 }
185 }
186
187 char const *
cl_get_event_command_type_string(cl_command_type const type)188 cl_get_event_command_type_string(cl_command_type const type)
189 {
190 switch (type)
191 {
192 CL_VAL_TO_STRING(CL_COMMAND_NDRANGE_KERNEL);
193 CL_VAL_TO_STRING(CL_COMMAND_TASK);
194 CL_VAL_TO_STRING(CL_COMMAND_NATIVE_KERNEL);
195 CL_VAL_TO_STRING(CL_COMMAND_READ_BUFFER);
196 CL_VAL_TO_STRING(CL_COMMAND_WRITE_BUFFER);
197 CL_VAL_TO_STRING(CL_COMMAND_COPY_BUFFER);
198 CL_VAL_TO_STRING(CL_COMMAND_READ_IMAGE);
199 CL_VAL_TO_STRING(CL_COMMAND_WRITE_IMAGE);
200 CL_VAL_TO_STRING(CL_COMMAND_COPY_IMAGE);
201 CL_VAL_TO_STRING(CL_COMMAND_COPY_BUFFER_TO_IMAGE);
202 CL_VAL_TO_STRING(CL_COMMAND_COPY_IMAGE_TO_BUFFER);
203 CL_VAL_TO_STRING(CL_COMMAND_MAP_BUFFER);
204 CL_VAL_TO_STRING(CL_COMMAND_MAP_IMAGE);
205 CL_VAL_TO_STRING(CL_COMMAND_UNMAP_MEM_OBJECT);
206 CL_VAL_TO_STRING(CL_COMMAND_MARKER);
207 CL_VAL_TO_STRING(CL_COMMAND_ACQUIRE_GL_OBJECTS);
208 CL_VAL_TO_STRING(CL_COMMAND_RELEASE_GL_OBJECTS);
209 CL_VAL_TO_STRING(CL_COMMAND_READ_BUFFER_RECT);
210 CL_VAL_TO_STRING(CL_COMMAND_WRITE_BUFFER_RECT);
211 CL_VAL_TO_STRING(CL_COMMAND_COPY_BUFFER_RECT);
212 CL_VAL_TO_STRING(CL_COMMAND_USER);
213 CL_VAL_TO_STRING(CL_COMMAND_BARRIER);
214 CL_VAL_TO_STRING(CL_COMMAND_MIGRATE_MEM_OBJECTS);
215 CL_VAL_TO_STRING(CL_COMMAND_FILL_BUFFER);
216 CL_VAL_TO_STRING(CL_COMMAND_FILL_IMAGE);
217 CL_VAL_TO_STRING(CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR);
218
219 default:
220 return "UNKNOWN EVENT COMMAND TYPE";
221 }
222 }
223