Skip to main content

ruprim/reduce/
error.rs

1use ruda_kernel::dsl as kernel_dsl;
2use ruda_kernel::dsl::ir::StorageType;
3use ruda_kernel::dsl::server::LaunchError;
4use thiserror::Error;
5
6#[derive(Error, Debug, Clone)]
7/// This error should be caught and properly handled.
8pub enum ReduceError {
9    /// Indicate that the hardware / API doesn't support SIMT plane instructions.
10    #[error(
11        "Trying to launch a kernel using plane instructions, but there are not supported by the hardware."
12    )]
13    PlanesUnavailable,
14    /// When the ruda count is bigger than the max supported.
15    #[error("The ruda count is larger than the max supported.")]
16    RudaCountTooLarge,
17
18    /// A generic validation error
19    #[error("A generic validation error: {details}")]
20    Validation { details: &'static str },
21
22    /// Indicate that min_plane_dim != max_plane_dim, thus the exact plane_dim is not fixed.
23    #[error(
24        "Trying to launch a kernel using plane instructions, but the min and max plane dimensions are different."
25    )]
26    ImprecisePlaneDim,
27    /// Indicate the axis is too large.
28    #[error("The provided axis ({axis}) must be smaller than the input tensor rank ({rank}).")]
29    InvalidAxis { axis: usize, rank: usize },
30    /// Indicate that the shape of the input tensor is too small for the given input and axis.
31    #[error(
32        "The input reduce axis length (currently {axis_length:?}) should be at least k ({k:?})."
33    )]
34    ReduceAxisTooSmall { axis_length: usize, k: usize },
35    /// Indicate that the shape of the output tensor is invalid for the given input and axis.
36    #[error("The output shape (currently {output_shape:?}) should be {expected_shape:?}.")]
37    MismatchOutputShape {
38        expected_shape: Vec<usize>,
39        output_shape: Vec<usize>,
40    },
41    /// Indicate that we can't launch a shared sum because the atomic addition is not supported.
42    #[error("Atomic add not supported by the client for {0}")]
43    MissingAtomicAdd(StorageType),
44
45    /// An error happened during launch.
46    #[error("An error happened during launch\nCaused by:\n  {0}")]
47    Launch(LaunchError),
48}