1#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
2pub enum OCLErrorKind {
3 GetPlatformIDs,
4 GetDeviceIDs,
5 InvalidDeviceIdx,
6 GetDeviceInfo,
7 CreateContext,
8 CreateCommandQueue,
9 WaitForEvents,
10 EnqueueReadBuffer,
11 EnqueueWriteBuffer,
12 EnqueueCopyBuffer,
13 EnqueueNDRangeKernel,
14 CreateBuffer,
15 DeviceNotFound,
16 DeviceNotAvailable,
17 CompilerNotAvailable,
18 MemObjectAllocationFailure,
19 OutOfResources,
20 OutOfHostMemory,
21 ProfilingInfoNotAvailable,
22 MemCopyOverlap,
23 ImageFormatMismatch,
24 ImageFormatNotSupported,
25 BuildProgramFailures,
26 MapFailure,
27 MisalignedSubBufferOffset,
28 ExecStatusErrorForEventsInWaitList,
29 CompileProgramFailure,
30 LinkerNotAvailable,
31 LinkProgramFailure,
32 DevicePartitionFailed,
33 KernelArgInfoNotAvailable,
34 InvalidValue,
35 InvalidDeviceType,
36 InvalidPlatform,
37 InvalidDevice,
38 InvalidContext,
39 InvalidQueueProperties,
40 InvalidCommandQueue,
41 InvalidHostPtr,
42 InvalidMemObject,
43 InvalidImageFormatDescriptor,
44 InvalidImageSize,
45 InvalidSampler,
46 InvalidBinary,
47 InvalidBuildOptions,
48 InvalidProgram,
49 InvalidProgramExecutable,
50 InvalidKernelName,
51 InvalidKernelDefintion,
52 InvalidKernel,
53 InvalidArgIndex,
54 InvalidArgValue,
55 InvalidArgSize,
56 InvalidKernelArgs,
57 InvalidWorkDimension,
58 InvalidWorkGroupSize,
59 InvalidWorkItemSize,
60 InvalidGlobalOffset,
61 InvalidEventWaitList,
62 InvalidEvent,
63 InvalidOperation,
64 InvalidGlObject,
65 InvalidBufferSize,
66 InvalidMIPLevel,
67 InvalidGlobalWorkSize,
68 InvalidProperty,
69 InvalidImageDescriptor,
70 InvalidCompilerOptions,
71 InvalidLinkerOptions,
72 InvalidDevicePartitionCount,
73 InvalidPipeSize,
74 InvalidDeviceQueue,
75 PlatformNotFoundKHR,
76 Unknown,
77}
78
79impl OCLErrorKind {
80 pub fn from_value(value: i32) -> OCLErrorKind {
81 match value {
82 -1 => OCLErrorKind::DeviceNotFound,
83 -2 => OCLErrorKind::DeviceNotAvailable,
84 -3 => OCLErrorKind::CompilerNotAvailable,
85 -4 => OCLErrorKind::MemObjectAllocationFailure,
86 -5 => OCLErrorKind::OutOfResources,
87 -6 => OCLErrorKind::OutOfHostMemory,
88 -7 => OCLErrorKind::ProfilingInfoNotAvailable,
89 -8 => OCLErrorKind::MemCopyOverlap,
90 -9 => OCLErrorKind::ImageFormatMismatch,
91 -10 => OCLErrorKind::ImageFormatNotSupported,
92 -11 => OCLErrorKind::BuildProgramFailures,
93 -12 => OCLErrorKind::MapFailure,
94 -13 => OCLErrorKind::MisalignedSubBufferOffset,
95 -14 => OCLErrorKind::ExecStatusErrorForEventsInWaitList,
96 -15 => OCLErrorKind::CompileProgramFailure,
97 -16 => OCLErrorKind::LinkerNotAvailable,
98 -17 => OCLErrorKind::LinkProgramFailure,
99 -18 => OCLErrorKind::DevicePartitionFailed,
100 -19 => OCLErrorKind::KernelArgInfoNotAvailable,
101 -30 => OCLErrorKind::InvalidValue,
102 -31 => OCLErrorKind::InvalidDeviceType,
103 -32 => OCLErrorKind::InvalidPlatform,
104 -33 => OCLErrorKind::InvalidDevice,
105 -34 => OCLErrorKind::InvalidContext,
106 -35 => OCLErrorKind::InvalidQueueProperties,
107 -36 => OCLErrorKind::InvalidCommandQueue,
108 -37 => OCLErrorKind::InvalidHostPtr,
109 -38 => OCLErrorKind::InvalidMemObject,
110 -39 => OCLErrorKind::InvalidImageFormatDescriptor,
111 -40 => OCLErrorKind::InvalidImageSize,
112 -41 => OCLErrorKind::InvalidSampler,
113 -42 => OCLErrorKind::InvalidBinary,
114 -43 => OCLErrorKind::InvalidBuildOptions,
115 -44 => OCLErrorKind::InvalidProgram,
116 -45 => OCLErrorKind::InvalidProgramExecutable,
117 -46 => OCLErrorKind::InvalidKernelName,
118 -47 => OCLErrorKind::InvalidKernelDefintion,
119 -48 => OCLErrorKind::InvalidKernel,
120 -49 => OCLErrorKind::InvalidArgIndex,
121 -50 => OCLErrorKind::InvalidArgValue,
122 -51 => OCLErrorKind::InvalidArgSize,
123 -52 => OCLErrorKind::InvalidKernelArgs,
124 -53 => OCLErrorKind::InvalidWorkDimension,
125 -54 => OCLErrorKind::InvalidWorkGroupSize,
126 -55 => OCLErrorKind::InvalidWorkItemSize,
127 -56 => OCLErrorKind::InvalidGlobalOffset,
128 -57 => OCLErrorKind::InvalidEventWaitList,
129 -58 => OCLErrorKind::InvalidEvent,
130 -59 => OCLErrorKind::InvalidOperation,
131 -60 => OCLErrorKind::InvalidGlObject,
132 -61 => OCLErrorKind::InvalidBufferSize,
133 -62 => OCLErrorKind::InvalidMIPLevel,
134 -63 => OCLErrorKind::InvalidGlobalWorkSize,
135 -64 => OCLErrorKind::InvalidProperty,
136 -65 => OCLErrorKind::InvalidImageDescriptor,
137 -66 => OCLErrorKind::InvalidCompilerOptions,
138 -67 => OCLErrorKind::InvalidLinkerOptions,
139 -68 => OCLErrorKind::InvalidDevicePartitionCount,
140 -69 => OCLErrorKind::InvalidPipeSize,
141 -70 => OCLErrorKind::InvalidDeviceQueue,
142 -1001 => OCLErrorKind::PlatformNotFoundKHR,
143 _ => OCLErrorKind::Unknown,
144 }
145 }
146}
147
148impl OCLErrorKind {
149 pub fn as_str(&self) -> &'static str {
150 match self {
151 OCLErrorKind::Unknown => "Unkwown OpenCL Error",
152 OCLErrorKind::GetPlatformIDs => "",
153 OCLErrorKind::GetDeviceIDs => "",
154 OCLErrorKind::InvalidDeviceIdx => {
155 "Invalid device idx, specific OpenCL device not found"
156 }
157 OCLErrorKind::GetDeviceInfo => "",
158 OCLErrorKind::CreateContext => "",
159 OCLErrorKind::CreateCommandQueue => "",
160 OCLErrorKind::WaitForEvents => "",
161 OCLErrorKind::EnqueueReadBuffer => "",
162 OCLErrorKind::EnqueueWriteBuffer => "",
163 OCLErrorKind::EnqueueCopyBuffer => "",
164 OCLErrorKind::EnqueueNDRangeKernel => "",
165 OCLErrorKind::CreateBuffer => "",
166 OCLErrorKind::DeviceNotFound => "(-1 DeviceNotFound) No OpenCL device found",
167 OCLErrorKind::DeviceNotAvailable => {
168 "(-2 DeviceNotAvailAble) OpenCL device is currently not available"
169 }
170 OCLErrorKind::CompilerNotAvailable => {
171 "(-3 CompilerNotAvailable) Compiler is not available"
172 }
173 OCLErrorKind::MemObjectAllocationFailure => {
174 "(-4 MemObjectAllocationFailure) Memory for buffer object could not be allocated"
175 }
176 OCLErrorKind::OutOfResources => {
177 "(-5 OutOfResources) Allocation of resources failed on the OpenCL device"
178 }
179 OCLErrorKind::OutOfHostMemory => {
180 "(-6 OutOfHostMemory) Allocation of resources failed on the host device"
181 }
182 OCLErrorKind::ProfilingInfoNotAvailable => "(-7 ProfilingInfoNotAvailable)",
183 OCLErrorKind::MemCopyOverlap => "(-8 MemCopyOverlap)",
184 OCLErrorKind::ImageFormatMismatch => "(-9 ImageFormatMismatch)",
185 OCLErrorKind::ImageFormatNotSupported => "(-10 ImageFormatNotSupported)",
186 OCLErrorKind::BuildProgramFailures => "(-11 BuildProgramFailures)",
187 OCLErrorKind::MapFailure => "(-12 MapFailure)",
188 OCLErrorKind::MisalignedSubBufferOffset => "(-13 MisalignedSubBufferOffset)",
189 OCLErrorKind::ExecStatusErrorForEventsInWaitList => {
190 "(-14 ExecStatusErrorForEventsInWaitList)"
191 }
192 OCLErrorKind::CompileProgramFailure => "(-15 CompileProgramFailure)",
193 OCLErrorKind::LinkerNotAvailable => "(-16 LinkerNotAvailable)",
194 OCLErrorKind::LinkProgramFailure => "(-17 LinkProgramFailure)",
195 OCLErrorKind::DevicePartitionFailed => "(-18 DevicePartitionFailed)",
196 OCLErrorKind::KernelArgInfoNotAvailable => "(-19 KernelArgInfoNotAvailable)",
197 OCLErrorKind::InvalidValue => "(-30 InvalidValue)",
198 OCLErrorKind::InvalidDeviceType => "(-31 InvalidDeviceType)",
199 OCLErrorKind::InvalidPlatform => "(-32 InvalidPlatform)",
200 OCLErrorKind::InvalidDevice => "(-33 InvalidDevice)",
201 OCLErrorKind::InvalidContext => "(-34 InvalidContext)",
202 OCLErrorKind::InvalidQueueProperties => "(-35 InvalidQueueProperties)",
203 OCLErrorKind::InvalidCommandQueue => "(-36 InvalidCommandQueue)",
204 OCLErrorKind::InvalidHostPtr => "(-37 InvalidHostPtr)",
205 OCLErrorKind::InvalidMemObject => "(-38 InvalidMemObject)",
206 OCLErrorKind::InvalidImageFormatDescriptor => "(-39 InvalidImageFormatDescriptor)",
207 OCLErrorKind::InvalidImageSize => "(-40 InvalidImageSize)",
208 OCLErrorKind::InvalidSampler => "(-41 InvalidSampler)",
209 OCLErrorKind::InvalidBinary => "(-42 InvalidBinary)",
210 OCLErrorKind::InvalidBuildOptions => "(-43 InvalidBuildOptions)",
211 OCLErrorKind::InvalidProgram => "(-44 InvalidProgram)",
212 OCLErrorKind::InvalidProgramExecutable => "(-45 InvalidProgramExecutable)",
213 OCLErrorKind::InvalidKernelName => "(-46 InvalidKernelName)",
214 OCLErrorKind::InvalidKernelDefintion => "(-47 InvalidKernelDefinition)",
215 OCLErrorKind::InvalidKernel => "(-48 InvalidKernel)",
216 OCLErrorKind::InvalidArgIndex => "(-49 InvalidArgIndex)",
217 OCLErrorKind::InvalidArgValue => "(-50 InvalidArgValue)",
218 OCLErrorKind::InvalidArgSize => "(-51 InvalidArgSize)",
219 OCLErrorKind::InvalidKernelArgs => "(-52 InvalidKernelArgs) Invalid kernel args",
220 OCLErrorKind::InvalidWorkDimension => "(-53 InvalidWorkDimension)",
221 OCLErrorKind::InvalidWorkGroupSize => "(-54 InvalidWorkGroupSize)",
222 OCLErrorKind::InvalidWorkItemSize => "(-55 InvalidWorkItemSize)",
223 OCLErrorKind::InvalidGlobalOffset => "(-56 InvalidGlobalOffset)",
224 OCLErrorKind::InvalidEventWaitList => "(-57 InvalidEventWaitList)",
225 OCLErrorKind::InvalidEvent => "(-58 InvalidEvent)",
226 OCLErrorKind::InvalidOperation => "(-59 InvalidOperation)",
227 OCLErrorKind::InvalidGlObject => "(-60 InvalidGlObject)",
228 OCLErrorKind::InvalidBufferSize => "(-61 InvalidBufferSize)",
229 OCLErrorKind::InvalidMIPLevel => "(-62 InvalidMIPLevel)",
230 OCLErrorKind::InvalidGlobalWorkSize => "(-63 InvalidGlobalWorkSize)",
231 OCLErrorKind::InvalidProperty => "(-64 InvalidProperty)",
232 OCLErrorKind::InvalidImageDescriptor => "(-65 InvalidImageDescriptor)",
233 OCLErrorKind::InvalidCompilerOptions => "(-66 InvalidCompilerOptions)",
234 OCLErrorKind::InvalidLinkerOptions => "(-67 InvalidLinkerOptions)",
235 OCLErrorKind::InvalidDevicePartitionCount => "(-68 InvalidDevicePartitionCount)",
236 OCLErrorKind::InvalidPipeSize => "(-69 InvalidPipeSize)",
237 OCLErrorKind::InvalidDeviceQueue => "(-70 InvalidDeviceQueue)",
238 OCLErrorKind::PlatformNotFoundKHR => "(-1001 PlatformNotFoundKHR)",
239 }
240 }
241}
242
243impl core::fmt::Debug for OCLErrorKind {
244 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
245 write!(f, "{}", self.as_str())
246 }
247}
248
249impl core::fmt::Display for OCLErrorKind {
250 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
251 write!(f, "{self:?}")
252 }
253}
254
255impl std::error::Error for OCLErrorKind {}