use rlx_opscope::bytes::{analyze, human_bytes};
use rlx_opscope::demo;
fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
let mut positional = Vec::new();
let mut ridge = 100.0f64;
let mut it = args.iter();
while let Some(a) = it.next() {
match a.as_str() {
"--ridge" => {
ridge = it
.next()
.and_then(|v| v.parse().ok())
.unwrap_or_else(|| panic!("--ridge needs a number"));
}
_ => positional.push(a.clone()),
}
}
let kind = positional
.first()
.map(String::as_str)
.unwrap_or("transformer");
let layers: usize = positional.get(1).and_then(|v| v.parse().ok()).unwrap_or(4);
let graph = demo::build(kind, layers);
let cost = analyze(&graph);
println!("graph: {kind} x{layers} ({} nodes)\n", graph.nodes().len());
println!("{}", cost.report(12));
let (mem, comp) = cost.roofline_split(ridge);
let total = mem + comp;
if total > 0 {
println!(
"roofline @ {ridge:.0} flop/byte: {} memory-bound ({:.1}%), {} compute-bound ({:.1}%)",
human_bytes(mem),
100.0 * mem as f64 / total as f64,
human_bytes(comp),
100.0 * comp as f64 / total as f64,
);
}
}