diff --git a/crates/ipu-codegen/src/planner/mod.rs b/crates/ipu-codegen/src/planner/mod.rs index 88e383aa..07cecdae 100644 --- a/crates/ipu-codegen/src/planner/mod.rs +++ b/crates/ipu-codegen/src/planner/mod.rs @@ -100,6 +100,44 @@ mod tests { use super::*; use crate::{Precision, TensorFormat, TensorTiling}; + #[test] + #[ignore] + fn trace_budget_ranking() { + let mut high = HighGraph::new(); + let x = high.host_input("left", [4, 729, 1152]).unwrap(); + let up = high.parameter("up", [1, 1152, 4304]).unwrap(); + let down = high.parameter("down", [1, 4304, 1152]).unwrap(); + let y = high.gemm(x, up).unwrap(); + let y = high.gelu(y).unwrap(); + let y = high.gemm(y, down).unwrap(); + high.set_outputs([y]).unwrap(); + let precision = Precision::F8F143 { scale_exponent: -2 }; + let mut config = PipelineConfig::new(Target::Ipu21, 1472).with_input( + x, TensorFormat { precision, layout: Layout::logical_linear(1472, 4) }); + for id in [x, up, down] { config.input_precisions.insert(id, precision); } + let boundaries = boundary_layouts(&high, &config); + for generation_budget in [586960, 393216] { + config.tile_memory_budget_bytes = generation_budget; + let catalogue = candidates::catalogue(&high, &boundaries, &config).unwrap(); + eprintln!("CATALOGUE {generation_budget}: {:?}", catalogue.iter().map(Vec::len).collect::>()); + for search_budget in [586960, 393216] { + config.tile_memory_budget_bytes = search_budget; + let mut search = Search::new(&high, &boundaries, &config, SearchLimits::default()).unwrap(); + for (position, candidates) in catalogue.iter().enumerate() { + for state in search.take_states(position) { + search.extend(position, &state, candidates).unwrap(); + } + } + let graph = search.finish().unwrap(); + eprintln!("PLAN generation={generation_budget} search={search_budget} cycles={} exchange={} memory={:?}", graph.estimated_cycles, graph.estimated_exchange_cycles, graph.peak_memory); + for op in &graph.operations { + let cost = crate::estimate::operation_cost(config.target, op, &graph.values, graph.tile_count); + eprintln!("OP {:?} {:?}: {:?}", op.source, op.kind, cost); + } + } + } + } + pub(super) fn gelu(x: f64) -> f64 { 0.5 * x * (1.0 + (0.7978845608 * (x + 0.044715 * x.powi(3))).tanh()) }