1use core::fmt;
2
3use cubecl_core::ir::StorageType;
4
5#[derive(Debug, PartialEq, Eq, Clone, Hash)]
6pub enum ReduceError {
7    PlanesUnavailable,
9    CubeCountTooLarge,
11    ImprecisePlaneDim,
13    InvalidAxis { axis: usize, rank: usize },
15    MismatchShape {
17        expected_shape: Vec<usize>,
18        output_shape: Vec<usize>,
19    },
20    MissingAtomicAdd(StorageType),
22}
23
24impl fmt::Display for ReduceError {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self {
27            Self::PlanesUnavailable => write!(
28                f,
29                "Trying to launch a kernel using plane instructions, but there are not supported by the hardware."
30            ),
31            Self::CubeCountTooLarge => {
32                write!(f, "The cube count is larger than the max supported.")
33            }
34            Self::ImprecisePlaneDim => write!(
35                f,
36                "Trying to launch a kernel using plane instructions, but the min and max plane dimensions are different."
37            ),
38            Self::InvalidAxis { axis, rank } => write!(
39                f,
40                "The provided axis ({axis}) must be smaller than the input tensor rank ({rank})."
41            ),
42            Self::MismatchShape {
43                expected_shape,
44                output_shape,
45            } => {
46                write!(
47                    f,
48                    "The output shape (currently {output_shape:?}) should be {expected_shape:?}."
49                )
50            }
51            Self::MissingAtomicAdd(elem) => {
52                write!(f, "Atomic add not supported by the client for {elem}")
53            }
54        }
55    }
56}