cubecl_runtime/throughput/
cmma.rs1use crate::{client::ComputeClient, runtime::Runtime};
2use cubecl_ir::{ElemType, StorageType};
3
4#[derive(Eq, PartialEq, Clone, Hash, Debug, Copy)]
6#[cfg_attr(std_io, derive(serde::Serialize, serde::Deserialize))]
7pub struct ComputeCmmaConfig {
8 pub accumulator_type: AccumulatorType,
10 pub cmma_dims: CmmaDims,
12}
13
14pub type AccumulatorType = ElemType;
16
17#[derive(Eq, PartialEq, Clone, Hash, Debug, Copy)]
19#[cfg_attr(std_io, derive(serde::Serialize, serde::Deserialize))]
20pub struct CmmaDims {
21 pub m: usize,
23 pub n: usize,
25 pub k: usize,
27}
28
29impl CmmaDims {
30 pub fn num_elems(&self) -> usize {
32 self.m * self.n * self.k
33 }
34}
35
36pub fn select_cmma_tile<R: Runtime>(
38 client: &ComputeClient<R>,
39 lhs: StorageType,
40 rhs: StorageType,
41 acc: StorageType,
42 (m, n, k): (usize, usize, usize),
43) -> Option<(u32, u32, u32)> {
44 let props = client.properties();
45
46 props
47 .features
48 .matmul
49 .cmma
50 .iter()
51 .chain(props.features.matmul.mma.iter())
53 .filter(|it| it.a_type == lhs && it.b_type == rhs && it.cd_type == acc)
55 .filter(|it| m >= it.m as usize && n >= it.n as usize && k >= it.k as usize)
57 .max_by_key(|it| it.m as u64 * it.n as u64 * it.k as u64)
59 .map(|it| (it.m, it.n, it.k))
60}