Skip to main content

hive_gpu/
error.rs

1//! Error types for Hive GPU
2
3use thiserror::Error;
4
5/// Main error type for Hive GPU operations
6#[derive(Error, Debug)]
7pub enum HiveGpuError {
8    /// Invalid vector dimension
9    #[error("Invalid dimension: expected {expected}, got {got}")]
10    InvalidDimension { expected: usize, got: usize },
11
12    /// Dimension mismatch
13    #[error("Dimension mismatch: expected {expected}, got {actual}")]
14    DimensionMismatch { expected: usize, actual: usize },
15
16    /// VRAM limit exceeded
17    #[error("VRAM limit exceeded: requested {requested}, limit {limit}")]
18    VramLimitExceeded { requested: usize, limit: usize },
19
20    /// GPU operation failed
21    #[error("GPU operation failed: {0}")]
22    GpuOperationFailed(String),
23
24    /// No GPU device available
25    #[error("No GPU device available")]
26    NoDeviceAvailable,
27
28    /// Buffer allocation failed
29    #[error("Buffer allocation failed: {0}")]
30    BufferAllocationFailed(String),
31
32    /// Device initialization failed
33    #[error("Device initialization failed: {0}")]
34    DeviceInitializationFailed(String),
35
36    /// Shader compilation failed
37    #[error("Shader compilation failed: {0}")]
38    ShaderCompilationFailed(String),
39
40    /// Memory allocation failed
41    #[error("Memory allocation failed: {0}")]
42    MemoryAllocationFailed(String),
43
44    /// Search operation failed
45    #[error("Search operation failed: {0}")]
46    SearchFailed(String),
47
48    /// Vector not found
49    #[error("Vector not found: {0}")]
50    VectorNotFound(String),
51
52    /// Invalid configuration
53    #[error("Invalid configuration: {0}")]
54    InvalidConfiguration(String),
55
56    /// CUDA driver or runtime failure
57    #[error("CUDA error: {0}")]
58    CudaError(String),
59
60    /// cuBLAS call failure
61    #[error("cuBLAS error: {0}")]
62    CublasError(String),
63
64    /// HIP driver or runtime failure
65    #[error("HIP error: {0}")]
66    HipError(String),
67
68    /// rocBLAS call failure
69    #[error("rocBLAS error: {0}")]
70    RocblasError(String),
71
72    /// Generic ROCm backend error (loader, setup, teardown)
73    #[error("ROCm error: {0}")]
74    RocmError(String),
75
76    /// Vulkan API failure — covers Intel, universal-Vulkan fallback, and
77    /// any host running a Vulkan-capable GPU through the `intel` feature.
78    #[error("Vulkan error: {0}")]
79    VulkanError(String),
80
81    /// Generic Intel backend error (loader, device selection).
82    #[error("Intel backend error: {0}")]
83    IntelError(String),
84
85    /// SPIR-V shader module creation or compilation failure.
86    #[error("SPIR-V compile error: {0}")]
87    SpirvCompileError(String),
88
89    /// Internal error
90    #[error("Internal error: {0}")]
91    InternalError(String),
92
93    /// IO error
94    #[error("IO error: {0}")]
95    IoError(#[from] std::io::Error),
96
97    /// JSON error
98    #[error("JSON error: {0}")]
99    JsonError(#[from] serde_json::Error),
100
101    /// Other errors
102    #[error("{0}")]
103    Other(String),
104}
105
106/// Result type alias for Hive GPU operations
107pub type Result<T> = std::result::Result<T, HiveGpuError>;