cubecl_reduce/
error.rs

1use core::fmt;
2
3#[derive(Debug, PartialEq, Eq, Clone, Hash)]
4pub enum ReduceError {
5    /// Indicate that the hardware / API doesn't support SIMT plane instructions.
6    PlanesUnavailable,
7    /// When the cube count is bigger than the max supported.
8    CubeCountTooLarge,
9    /// Indicate that min_plane_dim != max_plane_dim, thus the exact plane_dim is not fixed.
10    ImprecisePlaneDim,
11    /// Indicate the axis is too large.
12    InvalidAxis { axis: usize, rank: usize },
13    /// Indicate that the shape of the output tensor is invalid for the given input and axis.
14    MismatchShape {
15        expected_shape: Vec<usize>,
16        output_shape: Vec<usize>,
17    },
18}
19
20impl fmt::Display for ReduceError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            Self::PlanesUnavailable => write!(f, "Trying to launch a kernel using plane instructions, but there are not supported by the hardware."),
24            Self::CubeCountTooLarge => write!(f, "The cube count is larger than the max supported."),
25            Self::ImprecisePlaneDim => write!(f, "Trying to launch a kernel using plane instructions, but the min and max plane dimensions are different."),
26            Self::InvalidAxis{axis, rank} => write!(f, "The provided axis ({axis}) must be smaller than the input tensor rank ({rank})."),
27            Self::MismatchShape { expected_shape, output_shape } => {
28                write!(f, "The output shape (currently {output_shape:?}) should be {expected_shape:?}.")
29            }
30        }
31    }
32}
33
34impl std::error::Error for ReduceError {}