main.rs
110 lignes · 3467 octets
//! `chipai`: command line entry point of the ChipAi design chain //! (open-weight LLM → quantized reference → DSLX → SystemVerilog → PPA). //! //! Every subcommand maps to one stage of the pipeline described in //! `docs/05-chaine-outils.md`. Stages are wired in as their crates land; //! until then they fail with an explicit "not implemented" message. use anyhow::{Result, bail}; use clap::{Parser, Subcommand}; /// Execution target for a command: the local machine or a remote host over SSH. /// /// Parsed from `--target local` or `--target ssh://user@host`. #[derive(Debug, Clone, PartialEq, Eq)] pub enum Target { Local, Ssh { host: String }, } impl std::str::FromStr for Target { type Err = String; fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { match s { "local" => Ok(Target::Local), _ => match s.strip_prefix("ssh://") { Some(host) if !host.is_empty() => Ok(Target::Ssh { host: host.to_owned(), }), _ => Err(format!( "invalid target `{s}`: expected `local` or `ssh://host`" )), }, } } } #[derive(Parser, Debug)] #[command(name = "chipai", version, about = "ChipAi: turn an open-weight LLM into RTL", long_about = None)] struct Cli { /// Where to run the command: `local` or `ssh://user@host` (a VM reachable over SSH). #[arg(long, global = true, default_value = "local")] target: Target, #[command(subcommand)] command: Command, } #[derive(Subcommand, Debug)] enum Command { /// Download a model (config + safetensors + tokenizer) from Hugging Face. Fetch, /// Run the reference forward passes (float and bit-exact integer) and dump activations. Ref, /// Quantize weights (W4 group-wise, A8) and report accuracy degradation. Quant, /// Produce golden test vectors per kernel, per layer and end to end. Vectors, /// Generate DSLX sources, ROM images and the top-level design for a model. Gen, /// Simulate the design (DSLX interpreter, IR JIT, Verilator) against golden vectors. Sim, /// Synthesize blocks (Yosys, OpenROAD flow scripts) and collect PPA reports. Synth, /// Emit diagrams of the generated design (Mermaid, netlist SVG, IR graphs). Diagrams, /// Aggregate PPA reports and extrapolate to the full model. Report, } fn main() -> Result<()> { let cli = Cli::parse(); let stage = match cli.command { Command::Fetch => "fetch", Command::Ref => "ref", Command::Quant => "quant", Command::Vectors => "vectors", Command::Gen => "gen", Command::Sim => "sim", Command::Synth => "synth", Command::Diagrams => "diagrams", Command::Report => "report", }; bail!( "stage `{stage}` is not implemented yet (target: {:?})", cli.target ) } #[cfg(test)] mod tests { use super::*; #[test] fn target_parses_local_and_ssh() { assert_eq!("local".parse::<Target>().unwrap(), Target::Local); assert_eq!( "ssh://mac-vm".parse::<Target>().unwrap(), Target::Ssh { host: "mac-vm".into() } ); } #[test] fn target_rejects_garbage_and_empty_host() { assert!("ssh://".parse::<Target>().is_err()); assert!("docker".parse::<Target>().is_err()); } }
GitRust