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(
"The indices shape (currently {indices_shape:?}) should match the values shape ({values_shape:?})."
)]
MismatchIndicesShape {
values_shape: Vec<usize>,
indices_shape: Vec<usize>,
},
#[error(
"The indices strides (currently {indices_strides:?}) should match the values strides ({values_strides:?})."
)]
MismatchIndicesStrides {
values_strides: Vec<usize>,
indices_strides: Vec<usize>,
},
#[error(
"The operation {operation} has no index to report; reduce_with_indices only supports TopK, ArgTopK, Max, ArgMax, Min and ArgMin."
)]
IndicesUnsupported { operation: &'static str },
#[error("Atomic add not supported by the client for {0}")]
MissingAtomicAdd(StorageType),
#[error(
"Reduce blueprint requires {requested} bytes of shared memory, but only {available} bytes are available on the device."
)]
SharedMemoryOverflow { requested: usize, available: usize },
#[error("An error happened during launch\nCaused by:\n {0}")]
Launch(LaunchError),
}