Skip to content

Commit bf6126c

Browse files
Feat/execution error (#1075)
1 parent a093f96 commit bf6126c

File tree

122 files changed

+1080
-626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1080
-626
lines changed

crates/cubecl-attention/src/base.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,8 @@ pub fn launch_attention<R: Runtime, A: Algorithm>(
156156
.hypercube_config()
157157
.cube_count_plan(&problem, &selection);
158158

159-
unsafe {
160-
<BlackboxAcceleratedAlgorithm as Algorithm>::BatchAttention::launch_unchecked::<
161-
TensorArgs,
162-
R,
163-
>(
159+
let result = unsafe {
160+
<BlackboxAcceleratedAlgorithm as Algorithm>::BatchAttention::launch_unchecked::<TensorArgs, R>(
164161
client,
165162
config.cube_dim(),
166163
cube_count_plan.resolve(),
@@ -176,8 +173,11 @@ pub fn launch_attention<R: Runtime, A: Algorithm>(
176173
cube_count_plan.as_args(),
177174
config,
178175
attention_elems,
179-
);
180-
}
176+
)
177+
};
181178

182-
Ok(())
179+
match result {
180+
Ok(_) => Ok(()),
181+
Err(err) => Err(AttentionSetupError::Execution(err)),
182+
}
183183
}

crates/cubecl-attention/src/components/batch/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait BatchAttentionFamily: Send + Sync + 'static {
3535
cube_count_input: CubeCountInputArgs<'a, R>,
3636
config: Self::Config,
3737
dtypes: &AttentionElems,
38-
);
38+
) -> Result<(), LaunchError>;
3939

4040
/// Constructs the configuration based on the Attention problem, selection, and line sizes.
4141
///

crates/cubecl-attention/src/components/batch/simple/setup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22

3-
use cubecl_core::client::ComputeClient;
3+
use cubecl_core::{client::ComputeClient, server::LaunchError};
44

55
use crate::components::{
66
AttentionElems, AttentionLineSizes, AttentionPrecision, AttentionProblem, AttentionSelection,
@@ -49,7 +49,7 @@ impl<GA: GlobalAttentionFamily> BatchAttentionFamily for SimpleBatchAttentionFam
4949
cube_count_input: crate::components::batch::CubeCountInputArgs<'a, R>,
5050
config: Self::Config,
5151
dtypes: &AttentionElems,
52-
) {
52+
) -> Result<(), LaunchError> {
5353
unsafe {
5454
attention::launch_unchecked::<AA, Self, R>(
5555
client,
@@ -60,7 +60,7 @@ impl<GA: GlobalAttentionFamily> BatchAttentionFamily for SimpleBatchAttentionFam
6060
cube_count_input,
6161
config,
6262
dtypes.into(),
63-
);
63+
)
6464
}
6565
}
6666
}

crates/cubecl-attention/src/components/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cubecl_core::{CubeCount, CubeDim, LineSizeError};
1+
use cubecl_core::{CubeCount, CubeDim, LineSizeError, server::LaunchError};
22
use cubecl_matmul::components::MatmulSetupError;
33
use std::fmt::{Debug, Display};
44

@@ -15,6 +15,9 @@ pub enum AttentionSetupError {
1515

1616
/// Error in underlying matmul
1717
MatmulSetup(MatmulSetupError),
18+
19+
/// An error that happened during execution.
20+
Execution(LaunchError),
1821
}
1922

2023
/// A specific feature required for attention is not available in the current runtime or hardware.
@@ -75,6 +78,9 @@ impl Debug for AttentionSetupError {
7578
AttentionSetupError::MatmulSetup(matmul_setup_error) => {
7679
writeln!(f, "{matmul_setup_error:?}")
7780
}
81+
AttentionSetupError::Execution(error) => {
82+
writeln!(f, "{error:?}")
83+
}
7884
}
7985
}
8086
}

crates/cubecl-attention/src/tests/attention_test_launcher.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn test_attention_algorithm<A, P, R>(
9595
.hypercube_config()
9696
.cube_count_plan(&problem, &selection);
9797

98-
unsafe {
98+
let result = unsafe {
9999
A::BatchAttention::launch_unchecked::<TensorArgs, R>(
100100
&client,
101101
config.cube_dim(),
@@ -138,8 +138,16 @@ pub fn test_attention_algorithm<A, P, R>(
138138
cube_count_plan.as_args(),
139139
config,
140140
&attention_elems,
141-
);
142-
}
141+
)
142+
};
143+
144+
match result {
145+
Ok(_) => {}
146+
Err(err) => {
147+
println!("Skipping the test with an execution error {err:?}");
148+
return;
149+
}
150+
};
143151

144152
P::assert_result(
145153
&query.original_data.unwrap(),

crates/cubecl-attention/src/tests/test_utils.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ macro_rules! sample_float {
276276
let dtype = Self::as_type_native_unchecked();
277277
let output = TensorHandle::empty(client, shape.to_vec(), dtype);
278278

279-
cubecl_random::random_uniform(&client, f32::from_int(-1), f32::from_int(1), output.as_ref(), dtype);
279+
cubecl_random::random_uniform(&client, f32::from_int(-1), f32::from_int(1), output.as_ref(), dtype).unwrap();
280280

281281
output
282282
}
@@ -306,7 +306,8 @@ impl Sampleable for flex32 {
306306
f32::from_int(1),
307307
output.as_ref(),
308308
dtype,
309-
);
309+
)
310+
.unwrap();
310311

311312
output
312313
}
@@ -328,7 +329,8 @@ impl Sampleable for tf32 {
328329
f32::from_int(1),
329330
output.as_ref(),
330331
dtype,
331-
);
332+
)
333+
.unwrap();
332334

333335
output
334336
}
@@ -344,7 +346,7 @@ impl Sampleable for bool {
344346
let dtype = bool::as_type_native_unchecked();
345347
let output = TensorHandle::empty(client, shape.to_vec(), dtype);
346348

347-
cubecl_random::random_bernoulli(client, 0.5, output.as_ref(), dtype);
349+
cubecl_random::random_bernoulli(client, 0.5, output.as_ref(), dtype).unwrap();
348350

349351
output
350352
}
@@ -360,7 +362,7 @@ impl Sampleable for u8 {
360362
let dtype = u8::as_type_native_unchecked();
361363
let output = TensorHandle::empty(client, shape.to_vec(), dtype);
362364

363-
cubecl_random::random_bernoulli(client, 0.5, output.as_ref(), dtype);
365+
cubecl_random::random_bernoulli(client, 0.5, output.as_ref(), dtype).unwrap();
364366

365367
output
366368
}

crates/cubecl-convolution/src/components/error.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
use core::fmt::Debug;
2+
use cubecl_core::server::LaunchError;
13
use cubecl_matmul::components::{MatmulAvailabilityError, MatmulSetupError};
2-
use std::fmt::Debug;
34

45
#[allow(clippy::large_enum_variant)]
56
pub enum ConvSetupError {
67
Matmul(MatmulSetupError),
78
Groups(usize),
89
Unknown,
10+
Launch(LaunchError),
11+
}
12+
13+
impl From<LaunchError> for ConvSetupError {
14+
fn from(value: LaunchError) -> Self {
15+
Self::Launch(value)
16+
}
917
}
1018

1119
impl Debug for ConvSetupError {
@@ -21,6 +29,7 @@ impl Debug for ConvSetupError {
2129
)
2230
}
2331
ConvSetupError::Unknown => write!(f, "Unknown"),
32+
ConvSetupError::Launch(err) => write!(f, "Launch error {err:?}"),
2433
}
2534
}
2635
}

crates/cubecl-convolution/src/components/global/entry_point.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub trait ConvolutionLaunch<Config> {
3838
problem: &ConvolutionProblem,
3939
config: Config,
4040
dtypes: &MatmulElems,
41-
);
41+
) -> Result<(), LaunchError>;
4242
}
4343

4444
#[cube(launch_unchecked)]

crates/cubecl-convolution/src/components/global/multi_stage/tma/launch.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use cubecl_core::{CubeCount, CubeDim, Runtime, client::ComputeClient, prelude::ScalarArg};
1+
use cubecl_core::{
2+
CubeCount, CubeDim, Runtime, client::ComputeClient, prelude::ScalarArg, server::LaunchError,
3+
};
24
use cubecl_matmul::components::{
35
InputRuntimeArg, MatmulElems, OutputRuntimeArg,
46
global::{PartitionedStageFamily, args::MatmulArgs},
@@ -36,7 +38,7 @@ impl<
3638
problem: &ConvolutionProblem,
3739
config: GlobalConfig<Self>,
3840
dtypes: &MatmulElems,
39-
) {
41+
) -> Result<(), LaunchError> {
4042
let padded_channels =
4143
(problem.channels as u32).next_multiple_of(config.stage_config.elements_in_tile_k());
4244

@@ -66,7 +68,7 @@ impl<
6668
dtypes.lhs_stage,
6769
dtypes.rhs_stage,
6870
dtypes.acc_stage,
69-
);
71+
)
7072
}
7173
}
7274
}

crates/cubecl-convolution/src/components/global/single_stage/simple/launch.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use cubecl_core::{CubeCount, CubeDim, Runtime, client::ComputeClient, prelude::ScalarArg};
1+
use cubecl_core::{
2+
CubeCount, CubeDim, Runtime, client::ComputeClient, prelude::ScalarArg, server::LaunchError,
3+
};
24
use cubecl_matmul::components::{
35
InputRuntimeArg, MatmulElems, OutputRuntimeArg,
46
global::{PartitionedStageFamily, args::MatmulArgs},
@@ -36,7 +38,7 @@ impl<
3638
problem: &ConvolutionProblem,
3739
config: GlobalConfig<Self>,
3840
dtypes: &MatmulElems,
39-
) {
41+
) -> Result<(), LaunchError> {
4042
let shape_channels = FastDivmodArgs::new(client, problem.channels as u32);
4143

4244
let runtime_args = RuntimeArgsLaunch::new(
@@ -63,7 +65,7 @@ impl<
6365
dtypes.lhs_stage,
6466
dtypes.rhs_stage,
6567
dtypes.acc_stage,
66-
);
68+
)
6769
}
6870
}
6971
}

0 commit comments

Comments
 (0)