use cubek_test_utils::CatalogEntry;
use crate::components::instructions::ReduceOperationConfig;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReduceBenchKind {
Single,
TwoLaunch,
Fused,
}
pub struct ReduceProblem {
pub shape: Vec<usize>,
pub axis: usize,
pub config: ReduceOperationConfig,
pub kind: ReduceBenchKind,
}
pub fn problems() -> Vec<CatalogEntry<ReduceProblem>> {
let shape = || vec![32, 512, 4095];
let mut entries = vec![
CatalogEntry::new(
"sum_axis2_32x512x4095",
"Sum axis=2 (32x512x4095)",
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::Sum,
kind: ReduceBenchKind::Single,
},
),
CatalogEntry::new(
"arg_topk1_axis2_32x512x4095",
"ArgTopK(1) axis=2 (32x512x4095)",
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::ArgTopK(1),
kind: ReduceBenchKind::Single,
},
),
CatalogEntry::new(
"arg_topk2_axis2_32x512x4095",
"ArgTopK(2) axis=2 (32x512x4095)",
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::ArgTopK(2),
kind: ReduceBenchKind::Single,
},
),
CatalogEntry::new(
"arg_topk3_axis2_32x512x4095",
"ArgTopK(3) axis=2 (32x512x4095)",
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::ArgTopK(3),
kind: ReduceBenchKind::Single,
},
),
];
for k in [1, 2, 3, 5] {
entries.push(CatalogEntry::new(
format!("topk{k}_single_axis2_32x512x4095"),
format!("TopK({k}) values only, 1 launch, axis=2 (32x512x4095)"),
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::TopK(k),
kind: ReduceBenchKind::Single,
},
));
entries.push(CatalogEntry::new(
format!("topk{k}_two_launch_axis2_32x512x4095"),
format!("TopK({k}) values+indices, 2 launches, axis=2 (32x512x4095)"),
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::TopK(k),
kind: ReduceBenchKind::TwoLaunch,
},
));
entries.push(CatalogEntry::new(
format!("topk{k}_fused_axis2_32x512x4095"),
format!("TopK({k}) values+indices, 1 fused launch, axis=2 (32x512x4095)"),
ReduceProblem {
shape: shape(),
axis: 2,
config: ReduceOperationConfig::TopK(k),
kind: ReduceBenchKind::Fused,
},
));
}
for (name, label, config) in [
("max", "Max", ReduceOperationConfig::Max),
("min", "Min", ReduceOperationConfig::Min),
] {
entries.push(CatalogEntry::new(
format!("{name}_single_axis2_32x512x4095"),
format!("{label} values only, 1 launch, axis=2 (32x512x4095)"),
ReduceProblem {
shape: shape(),
axis: 2,
config,
kind: ReduceBenchKind::Single,
},
));
entries.push(CatalogEntry::new(
format!("{name}_two_launch_axis2_32x512x4095"),
format!("{label} values+indices, 2 launches, axis=2 (32x512x4095)"),
ReduceProblem {
shape: shape(),
axis: 2,
config,
kind: ReduceBenchKind::TwoLaunch,
},
));
entries.push(CatalogEntry::new(
format!("{name}_fused_axis2_32x512x4095"),
format!("{label} values+indices, 1 fused launch, axis=2 (32x512x4095)"),
ReduceProblem {
shape: shape(),
axis: 2,
config,
kind: ReduceBenchKind::Fused,
},
));
}
entries
}