Automatic Differentiation
 
Loading...
Searching...
No Matches
check_opencl.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_ERR_CHECK_OPENCL_HPP
2#define STAN_MATH_OPENCL_ERR_CHECK_OPENCL_HPP
3#ifdef STAN_OPENCL
4
7#include <CL/opencl.hpp>
8#include <iostream>
9#include <stdexcept>
10#include <string>
11
12namespace stan {
13namespace math {
14
23inline void check_opencl_error(const char *function, const cl::Error &e) {
24 switch (e.err()) {
25 case 0:
26 // CL_SUCCESS - no need to throw
27 return;
28 case -1:
29 system_error(function, e.what(), e.err(), "CL_DEVICE_NOT_FOUND");
30 case -2:
31 system_error(function, e.what(), e.err(), "CL_DEVICE_NOT_AVAILABLE");
32 case -3:
33 system_error(function, e.what(), e.err(), "CL_COMPILER_NOT_AVAILABLE");
34 case -4:
35 system_error(function, e.what(), e.err(),
36 "CL_MEM_OBJECT_ALLOCATION_FAILURE");
37 case -5:
38 system_error(function, e.what(), e.err(), "CL_OUT_OF_RESOURCES");
39 case -6:
40 system_error(function, e.what(), e.err(), "CL_OUT_OF_HOST_MEMORY");
41 case -7:
42 system_error(function, e.what(), e.err(),
43 "CL_PROFILING_INFO_NOT_AVAILABLE");
44 case -8:
45 system_error(function, e.what(), e.err(), "CL_MEM_COPY_OVERLAP");
46 case -9:
47 system_error(function, e.what(), e.err(), "CL_IMAGE_FORMAT_MISMATCH");
48 case -10:
49 system_error(function, e.what(), e.err(),
50 "CL_IMAGE_FORMAT_NOT_SUPPORTED");
51 case -11:
52 system_error(function, e.what(), e.err(), "CL_BUILD_PROGRAM_FAILURE");
53 case -12:
54 system_error(function, e.what(), e.err(), "CL_MAP_FAILURE");
55 case -13:
56 system_error(function, e.what(), e.err(),
57 "CL_MISALIGNED_SUB_BUFFER_OFFSET");
58 case -14:
59 system_error(function, e.what(), e.err(),
60 "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST");
61 case -15:
62 system_error(function, e.what(), e.err(), "CL_COMPILE_PROGRAM_FAILURE");
63 case -16:
64 system_error(function, e.what(), e.err(), "CL_LINKER_NOT_AVAILABLE");
65 case -17:
66 system_error(function, e.what(), e.err(), "CL_LINK_PROGRAM_FAILURE");
67 case -18:
68 system_error(function, e.what(), e.err(), "CL_DEVICE_PARTITION_FAILED");
69 case -19:
70 system_error(function, e.what(), e.err(),
71 "CL_KERNEL_ARG_INFO_NOT_AVAILABLE");
72 case -30:
73 system_error(function, e.what(), e.err(), "CL_INVALID_VALUE");
74 case -31:
75 system_error(function, e.what(), e.err(), "CL_INVALID_DEVICE_TYPE");
76 case -32:
77 system_error(function, e.what(), e.err(), "CL_INVALID_PLATFORM");
78 case -33:
79 system_error(function, e.what(), e.err(), "CL_INVALID_DEVICE");
80 case -34:
81 system_error(function, e.what(), e.err(), "CL_INVALID_CONTEXT");
82 case -35:
83 system_error(function, e.what(), e.err(), "CL_INVALID_QUEUE_PROPERTIES");
84 case -36:
85 system_error(function, e.what(), e.err(), "CL_INVALID_COMMAND_QUEUE");
86 case -37:
87 system_error(function, e.what(), e.err(), "CL_INVALID_HOST_PTR");
88 case -38:
89 system_error(function, e.what(), e.err(), "CL_INVALID_MEM_OBJECT");
90 case -39:
91 system_error(function, e.what(), e.err(),
92 "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR");
93 case -40:
94 system_error(function, e.what(), e.err(), "CL_INVALID_IMAGE_SIZE");
95 case -41:
96 system_error(function, e.what(), e.err(), "CL_INVALID_SAMPLER");
97 case -42:
98 system_error(function, e.what(), e.err(), "CL_INVALID_BINARY");
99 case -43:
100 system_error(function, e.what(), e.err(), "CL_INVALID_BUILD_OPTIONS");
101 case -44:
102 system_error(function, e.what(), e.err(), "CL_INVALID_PROGRAM");
103 case -45:
104 system_error(function, e.what(), e.err(),
105 "CL_INVALID_PROGRAM_EXECUTABLE");
106 case -46:
107 system_error(function, e.what(), e.err(), "CL_INVALID_KERNEL_NAME");
108 case -47:
109 system_error(function, e.what(), e.err(), "CL_INVALID_KERNEL_DEFINITION");
110 case -48:
111 system_error(function, e.what(), e.err(), "CL_INVALID_KERNEL");
112 case -49:
113 system_error(function, e.what(), e.err(), "CL_INVALID_ARG_INDEX");
114 case -50:
115 system_error(function, e.what(), e.err(), "CL_INVALID_ARG_VALUE");
116 case -51:
117 system_error(function, e.what(), e.err(), "CL_INVALID_ARG_SIZE");
118 case -52:
119 system_error(function, e.what(), e.err(), "CL_INVALID_KERNEL_ARGS");
120 case -53:
121 system_error(function, e.what(), e.err(), "CL_INVALID_WORK_DIMENSION");
122 case -54:
123 system_error(function, e.what(), e.err(), "CL_INVALID_WORK_GROUP_SIZE");
124 case -55:
125 system_error(function, e.what(), e.err(), "CL_INVALID_WORK_ITEM_SIZE");
126 case -56:
127 system_error(function, e.what(), e.err(), "CL_INVALID_GLOBAL_OFFSET");
128 case -57:
129 system_error(function, e.what(), e.err(), "CL_INVALID_EVENT_WAIT_LIST");
130 case -58:
131 system_error(function, e.what(), e.err(), "CL_INVALID_EVENT");
132 case -59:
133 system_error(function, e.what(), e.err(), "CL_INVALID_OPERATION");
134 case -60:
135 system_error(function, e.what(), e.err(), "CL_INVALID_GL_OBJECT");
136 case -61:
137 system_error(function, e.what(), e.err(), "CL_INVALID_BUFFER_SIZE");
138 case -62:
139 system_error(function, e.what(), e.err(), "CL_INVALID_MIP_LEVEL");
140 case -63:
141 system_error(function, e.what(), e.err(), "CL_INVALID_GLOBAL_WORK_SIZE");
142 case -64:
143 system_error(function, e.what(), e.err(), "CL_INVALID_PROPERTY");
144 case -65:
145 system_error(function, e.what(), e.err(), "CL_INVALID_IMAGE_DESCRIPTOR");
146 case -66:
147 system_error(function, e.what(), e.err(), "CL_INVALID_COMPILER_OPTIONS");
148 case -67:
149 system_error(function, e.what(), e.err(), "CL_INVALID_LINKER_OPTIONS");
150 case -68:
151 system_error(function, e.what(), e.err(),
152 "CL_INVALID_DEVICE_PARTITION_COUNT");
153 case -69:
154 system_error(function, e.what(), e.err(), "CL_INVALID_PIPE_SIZE");
155 case -70:
156 system_error(function, e.what(), e.err(), "CL_INVALID_DEVICE_QUEUE");
157 case -1000:
158 system_error(function, e.what(), e.err(),
159 "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR");
160 case -1001:
161 system_error(function, e.what(), e.err(), "CL_PLATFORM_NOT_FOUND_KHR");
162 case -1002:
163 system_error(function, e.what(), e.err(), "CL_INVALID_D3D10_DEVICE_KHR");
164 case -1003:
165 system_error(function, e.what(), e.err(),
166 "CL_INVALID_D3D10_RESOURCE_KHR");
167 case -1004:
168 system_error(function, e.what(), e.err(),
169 "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR");
170 case -1005:
171 system_error(function, e.what(), e.err(),
172 "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR");
173 case -1006:
174 system_error(function, e.what(), e.err(), "CL_INVALID_D3D11_DEVICE_KHR");
175 case -1007:
176 system_error(function, e.what(), e.err(),
177 "CL_INVALID_D3D11_RESOURCE_KHR");
178 case -1008:
179 system_error(function, e.what(), e.err(),
180 "CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR");
181 case -1009:
182 system_error(function, e.what(), e.err(),
183 "CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR");
184 case -101:
185 system_error(function, e.what(), e.err(), "CL_INVALID_D3D9_DEVICE_NV ");
186 case -1011:
187 system_error(function, e.what(), e.err(), "CL_INVALID_D3D9_RESOURCE_NV ");
188 case -1012:
189 system_error(function, e.what(), e.err(),
190 "CL_D3D9_RESOURCE_ALREADY_ACQUIRED_NV "
191 "CL_DX9_RESOURCE_ALREADY_ACQUIRED_INTEL");
192 case -1013:
193 system_error(function, e.what(), e.err(),
194 "CL_D3D9_RESOURCE_NOT_ACQUIRED_NV "
195 "CL_DX9_RESOURCE_NOT_ACQUIRED_INTEL");
196 case -1092:
197 system_error(function, e.what(), e.err(),
198 "CL_EGL_RESOURCE_NOT_ACQUIRED_KHR");
199 case -1093:
200 system_error(function, e.what(), e.err(), "CL_INVALID_EGL_OBJECT_KHR");
201 case -1094:
202 system_error(function, e.what(), e.err(), "CL_INVALID_ACCELERATOR_INTEL");
203 case -1095:
204 system_error(function, e.what(), e.err(),
205 "CL_INVALID_ACCELERATOR_TYPE_INTEL");
206 case -1096:
207 system_error(function, e.what(), e.err(),
208 "CL_INVALID_ACCELERATOR_DESCRIPTOR_INTEL");
209 case -1097:
210 system_error(function, e.what(), e.err(),
211 "CL_ACCELERATOR_TYPE_NOT_SUPPORTED_INTEL");
212 case -1098:
213 system_error(function, e.what(), e.err(),
214 "CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL");
215 case -1099:
216 system_error(function, e.what(), e.err(),
217 "CL_INVALID_VA_API_MEDIA_SURFACE_INTEL");
218 case -1100:
219 system_error(function, e.what(), e.err(),
220 "CL_VA_API_MEDIA_SURFACE_ALREADY_ACQUIRED_INTEL");
221 case -1101:
222 system_error(function, e.what(), e.err(),
223 "CL_VA_API_MEDIA_SURFACE_NOT_ACQUIRED_INTEL");
224 case -9999:
225 system_error(function, e.what(), e.err(), "ILLEGAL_READ_OR_WRITE_NVIDIA");
226 default:
227 system_error(function, e.what(), e.err(),
228 std::to_string(e.err()).c_str());
229 }
230}
231} // namespace math
232} // namespace stan
233#endif
234#endif
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occurred.
static constexpr double e()
Return the base of the natural logarithm.
Definition constants.hpp:20
void system_error(const char *function, const char *name, const int &y, const char *msg1, const char *msg2)
Throw a system error with a consistently formatted message.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...