use cubecl::{ir::StorageType, server::LaunchError};
use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum ReduceError {
#[error(
"Trying to launch a kernel using plane instructions, but there are not supported by the hardware."
)]
PlanesUnavailable,
#[error("The cube count is larger than the max supported.")]
CubeCountTooLarge,
#[error("A generic validation error: {details}")]
Validation { details: &'static str },
#[error(
"Trying to launch a kernel using plane instructions, but the min and max plane dimensions are different."
)]
ImprecisePlaneDim,
#[error("The provided axis ({axis}) must be smaller than the input tensor rank ({rank}).")]
InvalidAxis { axis: usize, rank: usize },
#[error(
"The input reduce axis length (currently {axis_length:?}) should be at least k ({k:?})."
)]
ReduceAxisTooSmall { axis_length: usize, k: usize },
#[error("The output shape (currently {output_shape:?}) should be {expected_shape:?}.")]
MismatchOutputShape {
expected_shape: Vec<usize>,
output_shape: Vec<usize>,
},
#[error("Atomic add not supported by the client for {0}")]
MissingAtomicAdd(StorageType),
#[error("An error happened during launch\nCaused by:\n {0}")]
Launch(LaunchError),
}