|
1 | 1 | use super::*; |
2 | 2 | use wgpu_test::{gpu_test, GpuTestConfiguration, TestParameters}; |
3 | 3 |
|
| 4 | +// These tests are split into `COOPERATIVE_MATRIX_F16` and |
| 5 | +// `COOPERATIVE_MATRIX_F32` because the latter can run without |
| 6 | +// `wgpu::Features::SHADER_F16`. |
| 7 | + |
4 | 8 | #[gpu_test] |
5 | | -pub static COOPERATIVE_MATRIX: GpuTestConfiguration = GpuTestConfiguration::new() |
| 9 | +pub static COOPERATIVE_MATRIX_F32: GpuTestConfiguration = GpuTestConfiguration::new() |
6 | 10 | .parameters( |
7 | 11 | TestParameters::default() |
8 | 12 | .features(wgpu::Features::EXPERIMENTAL_COOPERATIVE_MATRIX) |
9 | 13 | .limits(wgpu::Limits::default()), |
10 | 14 | ) |
11 | 15 | .run_async(|ctx| async move { |
12 | 16 | let coop_props = ctx.adapter.cooperative_matrix_properties(); |
13 | | - let config = coop_props |
14 | | - .iter() |
15 | | - .find(|prop| { |
16 | | - prop.m_size == 16 |
17 | | - && prop.n_size == 16 |
18 | | - && prop.k_size == 16 |
19 | | - && prop.ab_type == wgpu::CooperativeScalarType::F16 |
20 | | - && prop.cr_type == wgpu::CooperativeScalarType::F16 |
21 | | - }) |
22 | | - .or_else(|| { |
23 | | - coop_props.iter().find(|prop| { |
24 | | - prop.m_size == 8 |
25 | | - && prop.n_size == 8 |
26 | | - && prop.k_size == 8 |
27 | | - && prop.ab_type == wgpu::CooperativeScalarType::F32 |
28 | | - && prop.cr_type == wgpu::CooperativeScalarType::F32 |
29 | | - }) |
30 | | - }) |
31 | | - .unwrap(); |
| 17 | + // `shader.wgsl` hardcodes 8x8 f32 tiles (`coop_mat8x8<f32, ...>`), |
| 18 | + // so only an exact match is usable here. |
| 19 | + let config = coop_props.iter().find(|prop| { |
| 20 | + prop.m_size == 8 |
| 21 | + && prop.n_size == 8 |
| 22 | + && prop.k_size == 8 |
| 23 | + && prop.ab_type == wgpu::CooperativeScalarType::F32 |
| 24 | + && prop.cr_type == wgpu::CooperativeScalarType::F32 |
| 25 | + }); |
| 26 | + let Some(config) = config else { |
| 27 | + // Not every adapter that supports EXPERIMENTAL_COOPERATIVE_MATRIX |
| 28 | + // exposes an 8x8x8 f32/f32 configuration -- e.g. tensor/matrix-core |
| 29 | + // hardware commonly multiplies in a reduced-precision input type |
| 30 | + // and only optionally accumulates at f32, so plain f32 inputs are |
| 31 | + // often unsupported. We can't `.skip()` this per-adapter without |
| 32 | + // that list growing without bound across every GPU architecture |
| 33 | + // contributors happen to test on, so we log and move on instead. |
| 34 | + log::warn!( |
| 35 | + "No 8x8x8 f32 cooperative matrix configuration found among: \ |
| 36 | + {coop_props:?}; skipping test" |
| 37 | + ); |
| 38 | + return; |
| 39 | + }; |
| 40 | + let ExecuteResults { |
| 41 | + max_error, |
| 42 | + tolerance, |
| 43 | + matrix: _, |
| 44 | + } = execute(&ctx.device, &ctx.queue, config).await; |
| 45 | + assert!(max_error < tolerance); |
| 46 | + }); |
| 47 | + |
| 48 | +#[gpu_test] |
| 49 | +pub static COOPERATIVE_MATRIX_F16: GpuTestConfiguration = GpuTestConfiguration::new() |
| 50 | + .parameters( |
| 51 | + TestParameters::default() |
| 52 | + .features(wgpu::Features::EXPERIMENTAL_COOPERATIVE_MATRIX | wgpu::Features::SHADER_F16) |
| 53 | + .limits(wgpu::Limits::default()), |
| 54 | + ) |
| 55 | + .run_async(|ctx| async move { |
| 56 | + let coop_props = ctx.adapter.cooperative_matrix_properties(); |
| 57 | + // `shader_f16_16x16.wgsl` hardcodes 16x16 f16 tiles |
| 58 | + // (`coop_mat16x16<f16, ...>`), so only an exact match is usable here. |
| 59 | + let config = coop_props.iter().find(|prop| { |
| 60 | + prop.m_size == 16 |
| 61 | + && prop.n_size == 16 |
| 62 | + && prop.k_size == 16 |
| 63 | + && prop.ab_type == wgpu::CooperativeScalarType::F16 |
| 64 | + && prop.cr_type == wgpu::CooperativeScalarType::F16 |
| 65 | + }); |
| 66 | + let Some(config) = config else { |
| 67 | + // See the comment in COOPERATIVE_MATRIX_F32 above: not every adapter |
| 68 | + // exposes a 16x16x16 f16/f16 configuration (e.g. some only pair |
| 69 | + // smaller tile sizes with f16), and we don't want a per-adapter |
| 70 | + // `.skip()` list to grow without bound, so we log and move on. |
| 71 | + log::warn!( |
| 72 | + "No 16x16x16 f16 cooperative matrix configuration found among: \ |
| 73 | + {coop_props:?}; skipping test" |
| 74 | + ); |
| 75 | + return; |
| 76 | + }; |
32 | 77 | let ExecuteResults { |
33 | 78 | max_error, |
34 | 79 | tolerance, |
|
0 commit comments