|
| 1 | +use std::fmt::Display; |
| 2 | + |
1 | 3 | use cubecl_common::quant::scheme::{QuantScheme, QuantStore, QuantValue}; |
2 | 4 | use cubecl_core::{ |
3 | 5 | Runtime, |
@@ -83,6 +85,119 @@ pub enum Strategy { |
83 | 85 | Auto, |
84 | 86 | } |
85 | 87 |
|
| 88 | +impl Display for Strategy { |
| 89 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 90 | + match self { |
| 91 | + Strategy::Simple { |
| 92 | + read_strategy, |
| 93 | + selection, |
| 94 | + tile_kind, |
| 95 | + } => { |
| 96 | + f.write_fmt(format_args!("matmul_simple_{read_strategy}_{tile_kind}"))?; |
| 97 | + |
| 98 | + match selection { |
| 99 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 100 | + Selection::Inferred(args) => { |
| 101 | + if args.multi_rows { |
| 102 | + f.write_str("_multirows")?; |
| 103 | + } |
| 104 | + } |
| 105 | + }; |
| 106 | + } |
| 107 | + Strategy::DoubleBuffering { |
| 108 | + read_strategy, |
| 109 | + selection, |
| 110 | + tile_kind, |
| 111 | + } => { |
| 112 | + f.write_fmt(format_args!( |
| 113 | + "matmul_double_buffering_{read_strategy}_{tile_kind}" |
| 114 | + ))?; |
| 115 | + |
| 116 | + match selection { |
| 117 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 118 | + Selection::Inferred(args) => { |
| 119 | + if args.specialized { |
| 120 | + f.write_str("_specialized")?; |
| 121 | + } |
| 122 | + } |
| 123 | + }; |
| 124 | + } |
| 125 | + Strategy::Specialized { |
| 126 | + selection, |
| 127 | + tile_kind, |
| 128 | + } => { |
| 129 | + f.write_fmt(format_args!("matmul_specialized_{tile_kind}"))?; |
| 130 | + |
| 131 | + match selection { |
| 132 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 133 | + Selection::Inferred(_) => {} |
| 134 | + }; |
| 135 | + } |
| 136 | + Strategy::SimpleUnit(selection) => { |
| 137 | + f.write_fmt(format_args!("matmul_simple_unit"))?; |
| 138 | + |
| 139 | + match selection { |
| 140 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 141 | + Selection::Inferred(args) => { |
| 142 | + f.write_fmt(format_args!("_{}", args.tile_size))?; |
| 143 | + } |
| 144 | + }; |
| 145 | + } |
| 146 | + Strategy::DoubleUnit(selection) => { |
| 147 | + f.write_str("matmul_double_buffering_unit")?; |
| 148 | + |
| 149 | + match selection { |
| 150 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 151 | + Selection::Inferred(args) => { |
| 152 | + f.write_fmt(format_args!("_{}", args.tile_size))?; |
| 153 | + } |
| 154 | + }; |
| 155 | + } |
| 156 | + Strategy::SimpleVecMat(selection) => { |
| 157 | + f.write_str("vecmat_simple")?; |
| 158 | + |
| 159 | + match selection { |
| 160 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 161 | + Selection::Inferred(_) => {} |
| 162 | + }; |
| 163 | + } |
| 164 | + Strategy::DoubleVecMat(selection) => { |
| 165 | + f.write_str("vecmat_double_buffering")?; |
| 166 | + |
| 167 | + match selection { |
| 168 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 169 | + Selection::Inferred(_) => {} |
| 170 | + }; |
| 171 | + } |
| 172 | + Strategy::OrderedDoubleBuffering { |
| 173 | + selection, |
| 174 | + tile_kind, |
| 175 | + } => { |
| 176 | + f.write_fmt(format_args!("matmul_double_buffering_ordered_{tile_kind}"))?; |
| 177 | + |
| 178 | + match selection { |
| 179 | + Selection::Forced(_) => f.write_str("_forced_selection")?, |
| 180 | + Selection::Inferred(args) => { |
| 181 | + if let Some(k) = args.partition_k { |
| 182 | + f.write_fmt(format_args!("_partition_k{}", k))?; |
| 183 | + } |
| 184 | + if let Some(r) = args.row_count { |
| 185 | + f.write_fmt(format_args!("_row_count{}", r))?; |
| 186 | + } |
| 187 | + if let Some(r) = args.rows_per_plane { |
| 188 | + f.write_fmt(format_args!("_row_per_plane{}", r))?; |
| 189 | + } |
| 190 | + } |
| 191 | + }; |
| 192 | + } |
| 193 | + Strategy::Naive => f.write_str("matmul_naive")?, |
| 194 | + Strategy::Auto => f.write_str("matmul_auto")?, |
| 195 | + }; |
| 196 | + |
| 197 | + Ok(()) |
| 198 | + } |
| 199 | +} |
| 200 | + |
86 | 201 | #[derive(Debug, Clone, Copy)] |
87 | 202 | /// Which reader to use in simple algorithms |
88 | 203 | pub enum ReadingStrategy { |
@@ -113,6 +228,43 @@ pub enum AcceleratedTileKind { |
113 | 228 | Mma, |
114 | 229 | } |
115 | 230 |
|
| 231 | +// Display implementations are used to combine and save names when autotuning. |
| 232 | + |
| 233 | +impl Display for AcceleratedTileKind { |
| 234 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 235 | + match self { |
| 236 | + AcceleratedTileKind::Cmma => f.write_str("cmma"), |
| 237 | + AcceleratedTileKind::Mma => f.write_str("mma"), |
| 238 | + } |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +impl Display for ReadingStrategy { |
| 243 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 244 | + match self { |
| 245 | + ReadingStrategy::Cyclic => f.write_str("cyclic"), |
| 246 | + ReadingStrategy::Strided => f.write_str("strided"), |
| 247 | + ReadingStrategy::Tilewise => f.write_str("tilewise"), |
| 248 | + ReadingStrategy::AsyncCooperative => f.write_str("async_cooperative"), |
| 249 | + ReadingStrategy::AsyncCyclic => f.write_str("async_cyclic"), |
| 250 | + ReadingStrategy::AsyncMaximizeSliceLength => f.write_str("async_maximize_slice_length"), |
| 251 | + ReadingStrategy::AsyncMaximizeUnitCount => f.write_str("async_maximize_unit_count"), |
| 252 | + ReadingStrategy::Tma => f.write_str("tma"), |
| 253 | + } |
| 254 | + } |
| 255 | +} |
| 256 | + |
| 257 | +impl Display for PartialReadingStrategy { |
| 258 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 259 | + match self { |
| 260 | + PartialReadingStrategy::Cyclic => f.write_str("cyclic"), |
| 261 | + PartialReadingStrategy::Tilewise => f.write_str("tilewise"), |
| 262 | + PartialReadingStrategy::Hybrid => f.write_str("hybrid"), |
| 263 | + PartialReadingStrategy::Tma => f.write_str("tma"), |
| 264 | + } |
| 265 | + } |
| 266 | +} |
| 267 | + |
116 | 268 | macro_rules! with_tile_kind { |
117 | 269 | ($kind: expr, $T: ident, $launch: expr) => { |
118 | 270 | match $kind { |
|
0 commit comments