metrale_circuit/pipeline/
query.rs1use std::fmt::Write as _;
13
14use crate::hardware::plan::NOVEL_EMITTER;
15use crate::hardware::{ModelUnderPlan, OnePlan};
16
17pub fn precision_text(
21 model: &ModelUnderPlan,
22 one: &OnePlan,
23 pattern: Option<&str>,
24) -> Result<String, String> {
25 let c = &model.circuit;
26 let plan = &one.planned.plan;
27 let mut s = String::new();
28 let _ = writeln!(
29 s,
30 "# required node pipelines: {} on {} ({}), {} n={}",
31 model.label,
32 one.resolved.device.id,
33 one.resolved.device.class,
34 plan.mode.name(),
35 plan.rows
36 );
37 let _ = writeln!(s, "# precision: {}", model.precision);
38 for (k, v) in &one.header {
39 if k == "settings" || k == "checkpoint" {
40 let _ = writeln!(s, "# {k}: {v}");
41 }
42 }
43 let _ = writeln!(
44 s,
45 "# node op: in -> [steps] -> out; (rule) marks what the routing states over the reference"
46 );
47 let mut matched = 0usize;
48 for g in &plan.groups {
49 let mut shown = false;
50 for &n in &g.nodes {
51 let node = &c.nodes[n];
52 if pattern.is_some_and(|p| !crate::precision::glob(p, &node.id)) {
53 continue;
54 }
55 let Some(line) = one.planned.pipelines.line(n) else {
56 continue;
57 };
58 matched += 1;
59 let ran = if g.emitter == NOVEL_EMITTER {
62 format!("gap: no kernel of {} covers it", one.resolved.device.class)
63 } else if shown {
64 format!("{}: the launch group above", g.rule)
65 } else if g.kernels.is_empty() {
66 format!("{}: host ({})", g.rule, g.emitter)
67 } else {
68 let mut k: Vec<String> = Vec::new();
69 for id in &g.kernels {
70 let id = id.to_string();
71 if !k.contains(&id) {
72 k.push(id);
73 }
74 }
75 format!("{}: {}", g.rule, k.join(" + "))
76 };
77 shown = true;
78 let _ = writeln!(s, "{} {}: {line}\n <- {ran}", node.id, node.op.name());
79 }
80 }
81 if matched == 0 {
82 return Err(format!(
83 "no node of the {} n={} plan matches `{}`",
84 plan.mode.name(),
85 plan.rows,
86 pattern.unwrap_or("*")
87 ));
88 }
89 Ok(s)
90}