cubecl_reduce/
error.rs

1use core::fmt;
2
3use cubecl_core::ir::Elem;
4
5#[derive(Debug, PartialEq, Eq, Clone, Hash)]
6pub enum ReduceError {
7    /// Indicate that the hardware / API doesn't support SIMT plane instructions.
8    PlanesUnavailable,
9    /// When the cube count is bigger than the max supported.
10    CubeCountTooLarge,
11    /// Indicate that min_plane_dim != max_plane_dim, thus the exact plane_dim is not fixed.
12    ImprecisePlaneDim,
13    /// Indicate the axis is too large.
14    InvalidAxis { axis: usize, rank: usize },
15    /// Indicate that the shape of the output tensor is invalid for the given input and axis.
16    MismatchShape {
17        expected_shape: Vec<usize>,
18        output_shape: Vec<usize>,
19    },
20    /// Indicate that we can't launch a shared sum because the atomic addition is not supported.
21    MissingAtomicAdd(Elem),
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}