oxillama_quant/error.rs
1//! Error types for quantization operations.
2
3use thiserror::Error;
4
5/// Result type alias for quantization operations.
6pub type QuantResult<T> = Result<T, QuantError>;
7
8/// Errors that can occur during quantization kernel operations.
9#[derive(Error, Debug)]
10pub enum QuantError {
11 /// The requested quantization type is not yet implemented.
12 #[error("unsupported quantization type: {quant_type}")]
13 UnsupportedType {
14 /// Display name of the unsupported type.
15 quant_type: String,
16 },
17
18 /// Block size does not match expected value for the quantization type.
19 #[error("block size mismatch: expected {expected}, got {got}")]
20 BlockSizeMismatch {
21 /// Expected block size.
22 expected: usize,
23 /// Actual block size.
24 got: usize,
25 },
26
27 /// Matrix/vector dimension mismatch in a kernel operation.
28 #[error("dimension mismatch: expected {expected}, got {got}")]
29 DimensionMismatch {
30 /// Expected dimension.
31 expected: usize,
32 /// Actual dimension.
33 got: usize,
34 },
35
36 /// A low-level kernel computation error.
37 #[error("kernel error: {message}")]
38 KernelError {
39 /// Description of the kernel error.
40 message: String,
41 },
42
43 /// Block count does not match the expected value for the tensor dimensions.
44 #[error("block count mismatch: expected {expected} blocks, got {got}")]
45 BlockCountMismatch {
46 /// Expected number of blocks.
47 expected: usize,
48 /// Actual number of blocks.
49 got: usize,
50 },
51
52 /// Data buffer is too small for the operation.
53 #[error("buffer too small: need {needed} bytes, have {available}")]
54 BufferTooSmall {
55 /// Required buffer size in bytes.
56 needed: usize,
57 /// Available buffer size in bytes.
58 available: usize,
59 },
60
61 /// Internal error (e.g., lock poisoning).
62 #[error("internal error: {message}")]
63 Internal {
64 /// Description of the internal error.
65 message: String,
66 },
67
68 /// Float GEMM (F16/BF16/F32) computation failure.
69 #[error("float GEMM failed: {0}")]
70 FloatGemmFailed(String),
71}