use thiserror::Error;
pub type Result<T> = std::result::Result<T, GpuAdvancedError>;
#[derive(Debug, Error)]
pub enum GpuAdvancedError {
#[error("GPU device error: {0}")]
DeviceError(String),
#[error("Multi-GPU error: {0}")]
MultiGpuError(String),
#[error("Memory pool error: {0}")]
MemoryPoolError(String),
#[error("Memory allocation failed: size={size}, available={available}")]
AllocationFailed {
size: u64,
available: u64,
},
#[error("Memory out of bounds: offset={offset}, size={size}, pool_size={pool_size}")]
OutOfBounds {
offset: u64,
size: u64,
pool_size: u64,
},
#[error("Shader compiler error: {0}")]
ShaderCompilerError(String),
#[error("Shader optimization error: {0}")]
ShaderOptimizationError(String),
#[error("Shader validation error: {0}")]
ShaderValidationError(String),
#[error("Shader cache error: {0}")]
ShaderCacheError(String),
#[error("GPU computation error: {0}")]
ComputationError(String),
#[error("Buffer error: {0}")]
BufferError(String),
#[error("Synchronization error: {0}")]
SyncError(String),
#[error("Work stealing error: {0}")]
WorkStealingError(String),
#[error("Load balancing error: {0}")]
LoadBalancingError(String),
#[error("No GPU found matching criteria: {0}")]
GpuNotFound(String),
#[error("Invalid GPU index: {index}, total GPUs: {total}")]
InvalidGpuIndex {
index: usize,
total: usize,
},
#[error("Shader not found: {0}")]
ShaderNotFound(String),
#[error("ML inference error: {0}")]
MlInferenceError(String),
#[error("Terrain analysis error: {0}")]
TerrainAnalysisError(String),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Invalid configuration: {0}")]
InvalidConfiguration(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("Base GPU error: {0}")]
GpuError(#[from] oxigdal_gpu::error::GpuError),
#[error("WGPU request device error: {0}")]
RequestDeviceError(#[from] wgpu::RequestDeviceError),
#[error("WGPU buffer async error: {0}")]
BufferAsyncError(#[from] wgpu::BufferAsyncError),
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Feature not implemented: {0}")]
NotImplemented(String),
}
impl GpuAdvancedError {
pub fn device_error(msg: impl Into<String>) -> Self {
Self::DeviceError(msg.into())
}
pub fn multi_gpu_error(msg: impl Into<String>) -> Self {
Self::MultiGpuError(msg.into())
}
pub fn memory_pool_error(msg: impl Into<String>) -> Self {
Self::MemoryPoolError(msg.into())
}
pub fn shader_compiler_error(msg: impl Into<String>) -> Self {
Self::ShaderCompilerError(msg.into())
}
pub fn computation_error(msg: impl Into<String>) -> Self {
Self::ComputationError(msg.into())
}
pub fn invalid_parameter(msg: impl Into<String>) -> Self {
Self::InvalidParameter(msg.into())
}
}