Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reduce cube count too big #423

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/cubecl-reduce/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use core::fmt;
pub enum ReduceError {
/// Indicate that the hardware / API doesn't support SIMT plane instructions.
PlanesUnavailable,
/// When the cube count is bigger than the max supported.
CubeCountTooLarge,
/// Indicate that min_plane_dim != max_plane_dim, thus the exact plane_dim is not fixed.
ImprecisePlaneDim,
/// Indicate the axis is too large.
Expand All @@ -19,6 +21,7 @@ impl fmt::Display for ReduceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::PlanesUnavailable => write!(f, "Trying to launch a kernel using plane instructions, but there are not supported by the hardware."),
Self::CubeCountTooLarge => write!(f, "The cube count is larger than the max supported."),
Self::ImprecisePlaneDim => write!(f, "Trying to launch a kernel using plane instructions, but the min and max plane dimensions are different."),
Self::InvalidAxis{axis, rank} => write!(f, "The provided axis ({axis}) must be smaller than the input tensor rank ({rank})."),
Self::MismatchShape { expected_shape, output_shape } => {
Expand Down
8 changes: 8 additions & 0 deletions crates/cubecl-reduce/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ pub fn reduce<R: Runtime, In: Numeric, Out: Numeric, Inst: Reduce>(
.map(|s| s.validate::<R>(client))
.unwrap_or(Ok(ReduceStrategy::fallback_strategy::<R>(client)))?;
let config = ReduceConfig::generate::<R, In>(client, &input, &output, axis, &strategy);

if let CubeCount::Static(x, y, z) = config.cube_count {
let (max_x, max_y, max_z) = R::max_cube_count();
if x > max_x || y > max_y || z > max_z {
return Err(ReduceError::CubeCountTooLarge);
}
}

launch_reduce::<R, In, Out, Inst>(client, input, output, axis as u32, config, strategy);
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/cubecl-reduce/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl ReduceStrategy {
return Err(ReduceError::ImprecisePlaneDim);
}
}

Ok(self)
}

Expand Down