1#[cfg(feature = "opencl")]
2use opencl3::error_codes::ClError;
3#[cfg(feature = "cuda")]
4use rustacuda::error::CudaError;
5
6#[derive(thiserror::Error, Debug)]
8#[allow(clippy::upper_case_acronyms)]
9pub enum GPUError {
10 #[cfg(feature = "opencl")]
12 #[error("Opencl3 Error: {0}{}", match .1 {
13 Some(message) => format!(" {}", message),
14 None => "".to_string(),
15 })]
16 Opencl3(ClError, Option<String>),
17
18 #[cfg(feature = "opencl")]
20 #[error("Program info not available!")]
21 ProgramInfoNotAvailable(ClError),
22
23 #[cfg(feature = "opencl")]
25 #[error("Device info not available!")]
26 DeviceInfoNotAvailable(ClError),
27
28 #[cfg(feature = "cuda")]
30 #[error("Cuda Error: {0}")]
31 Cuda(#[from] CudaError),
32
33 #[error("Device not found!")]
35 DeviceNotFound,
36
37 #[error("Kernel with name {0} not found!")]
39 KernelNotFound(String),
40
41 #[error("IO Error: {0}")]
43 IO(#[from] std::io::Error),
44
45 #[error("Vendor {0} is not supported.")]
47 UnsupportedVendor(String),
48
49 #[error("{0}")]
52 InvalidId(String),
53
54 #[error("{0}")]
56 Generic(String),
57}
58
59#[allow(clippy::upper_case_acronyms)]
61pub type GPUResult<T> = std::result::Result<T, GPUError>;
62
63#[cfg(feature = "opencl")]
64impl From<ClError> for GPUError {
65 fn from(error: ClError) -> Self {
66 GPUError::Opencl3(error, None)
67 }
68}