#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum GpuError {
#[cfg(feature = "cuda")]
#[error("CUDA driver error: {0}")]
Driver(#[from] cudarc::driver::DriverError),
#[cfg(not(feature = "cuda"))]
#[error("GPU operations require the `cuda` feature")]
NoCudaFeature,
#[error("invalid device ordinal {ordinal} (only {count} devices available)")]
InvalidDevice {
ordinal: usize,
count: usize,
},
#[error("device mismatch: expected cuda:{expected}, got cuda:{got}")]
DeviceMismatch {
expected: usize,
got: usize,
},
#[error(
"GPU out of memory: requested {requested_bytes} bytes but only \
{free_bytes} bytes free"
)]
OutOfMemory {
requested_bytes: usize,
free_bytes: usize,
},
#[error(
"memory budget exceeded: requested {requested_bytes} bytes, \
budget is {budget_bytes} bytes with {used_bytes} bytes already used"
)]
BudgetExceeded {
requested_bytes: usize,
budget_bytes: usize,
used_bytes: usize,
},
#[error("buffer length mismatch: {a} vs {b}")]
LengthMismatch {
a: usize,
b: usize,
},
#[error("{op}: shape mismatch, expected {expected:?}, got {got:?}")]
ShapeMismatch {
op: &'static str,
expected: Vec<usize>,
got: Vec<usize>,
},
#[cfg(feature = "cuda")]
#[error("cuBLAS error: {0}")]
Blas(#[from] cudarc::cublas::result::CublasError),
#[cfg(feature = "cuda")]
#[error("cuSOLVER error: {0}")]
Solver(#[from] cudarc::cusolver::result::CusolverError),
#[cfg(feature = "cuda")]
#[error("cuFFT error: {0}")]
Fft(#[from] cudarc::cufft::result::CufftError),
#[cfg(feature = "cuda")]
#[error("PTX kernel compilation failed for `{kernel}`: {source}")]
PtxCompileFailed {
kernel: &'static str,
#[source]
source: cudarc::driver::DriverError,
},
#[error("{op} not implemented for '{dtype}' on CUDA")]
Unsupported {
op: &'static str,
dtype: &'static str,
},
#[error("invalid state: {message}")]
InvalidState {
message: String,
},
}
pub type GpuResult<T> = Result<T, GpuError>;