From de6a6cdaf841213e0edc97b3106aa871241f6f1d Mon Sep 17 00:00:00 2001 From: Nathaniel Navarro Date: Wed, 19 Jun 2024 17:16:13 -0400 Subject: [PATCH] [fud2] Add `waves` flag for `--to cocotb-axi` path (#2156) * Being work on dynamic AXI wrapper. Currently, have reduced complexity of channels by not tracking transfer counts and transaction counts and similar. Changes are a bit haphazard, so be careful about assuming aything is "done". Perhapes the AR and AW channels are indeed finished. TODO: Create address-translate module. In particular look at interface for mulitpliers as we might only have pipelined version * add new const_mult to py-builder * AW AR R and W channels might be done. Need to make sure write channel interface is correct. Then need to tie everything together according to diagram. * Finish(?) read and write controller in builder TODO: Wire up translator, read controller, write controller. Then test if this works with current test bench/executor * begin axi dynamic read controller * refactor reg calls in dynamix yxi generator * add import for const-mult in py-builder * WIP: need to work on axi-seq-mem-comp. Namley, need to be able to add attributes to ports * add support for port attributes with method * refactor to also have outputs iwth attributes * remove extra files added somehow * Add attributes to (and rename) add_comp_ports * Fix some formatting issues, should pass runt tests * find and replace add_comp_params * Work on tying together axi_seq_mem comps * WIP: have control program for axi_seq_mem maybe * Fix some misnamed signals. TODO: AFter getting subtyping working want to instantiate an `axi-seq-mem` in the top level wrapper, pass that in as a seq-mem to the main kernel * WIP: attempt at implementing subtyping. TBD if this works * typo in structure * change error for wellformedness subtyping runt test * compile_invoke now compiles, tbd if actually works * some clippy fixes * wip compile invoke changes * added debugging stuff to invoke, still a WIP * WIP: Need to do clean up but also this might allow subtyping???? Hope so * add comments to well-formed * maybe works? * seems to be working! * update runt tests * make clippy happy * formatting * update comments * more runt tests * replace hashed map with linkedhashmap for determinism * fix bug where iterating over too many ports in comp_ports in compile_invoke * more runt tests for subtyping * might be done with generator? need to fix compiler errors * add hardcoded vec_add for convenience: todo: not recognizing seq_mem_d1 * get rid of static interval annotation in axi_seq_mem * first pass at adding dynamic memories * add dyn-mems to primitve library * add yxi support for dyn-mems in calyx-ir-utils * make clippy happy * add yxi test for dyn-mems * formatting * add all mems to generated dynamic axi interface * add input to padding. Execution completes but incorrect writing to sum0 * change test yxi to dynamic from seq mems * drive read_data out properly in read_channel * derive partialeq and eq for InLineAttributes * extract `get_concrete_port` as helper function * compile_invoke formatting * WIP: extract require_subtype. TODO: allow it to take in StaticInvoke as well * factor out subtyping check * elaborate on some comments in well_formed * improve comments * working dynamic generator??????? * rename axi_seq_mem to axi_dyn_mem * add method to get a confg key witha constrained set of values * Add dynamic generation for `axi-wrapped` state Use `--set dynamic=true` targeting 1--to axi-wrapped` * add method to get a confg key witha constrained set of values * Make InvalidValue a c-like struct and fix err msg * formatting * change debug representation to a join * formatting * wip move axi tests around * remove hardcoded dyn-mem-vec-add from dynamic axi generator * add raw dynamic axi generator tests * add dyn_mem import into dynamic axi generator * more dynamic axi runt tests * fud2 cocotb tests for dynamic axi * remove hardcoded compute * remove stderr ipe to dev/null in fud2 cocotb axi tests * trigger ci * return 2> dev/null in runt cocotb axi tests * more runt fixes * more runt fixes, cocotb dynamic test still fails on CI * upgrade pip to get latest stable version of cocotb Changes dockerfile * hook up xPROT signals correctly * add ARPROT in places as well * update runt tests * fix xPROT connections, revert cocotb in dockerfile to 1.6.2 * get axi-wrapped version outputting vcd's (fsts?) * change vcd to fst * formatting * update cocotb tests for new sed (loses pair of {} at start and end * use utf8path instead of path in basname * add brackets around fud2 cocotb expect * make clippy happy --------- Co-authored-by: eys29 --- fud2/fud-core/src/utils.rs | 7 ++++++ fud2/src/lib.rs | 46 +++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/fud2/fud-core/src/utils.rs b/fud2/fud-core/src/utils.rs index 0bfcbd67e1..88bea3ed1a 100644 --- a/fud2/fud-core/src/utils.rs +++ b/fud2/fud-core/src/utils.rs @@ -12,3 +12,10 @@ pub fn relative_path(path: &Utf8Path, base: &Utf8Path) -> Utf8PathBuf { .expect("could not get absolute path"), } } + +/// Get the basename of a file as designated in a &str. +pub fn basename(path: &str) -> &str { + Utf8Path::new(path) + .file_stem() + .expect("Failed to get a basename from the path.") +} diff --git a/fud2/src/lib.rs b/fud2/src/lib.rs index 860693205d..5bac0cac26 100644 --- a/fud2/src/lib.rs +++ b/fud2/src/lib.rs @@ -3,6 +3,7 @@ use std::str::FromStr; use fud_core::{ exec::{SetupRef, StateRef}, run::{EmitResult, StreamEmitter}, + utils::basename, DriverBuilder, }; @@ -825,13 +826,7 @@ pub fn build_driver(bld: &mut DriverBuilder) { |e, input, output| { // Generate the YXI file. // no extension - let file_name = input - .rsplit_once('/') - .unwrap() - .1 - .rsplit_once('.') - .unwrap() - .0; + let file_name = basename(input); // Get yxi file from main compute program. let tmp_yxi = format!("{}.yxi", file_name); @@ -873,12 +868,23 @@ pub fn build_driver(bld: &mut DriverBuilder) { let data_path = e.external_path(data_name.as_ref()); e.var("sim_data", data_path.as_str())?; - // Cocotb is wants files relative to the location of the makefile. + // Cocotb wants files relative to the location of the makefile. // This is annoying to calculate on the fly, so we just copy necessary files to the build directory e.rule("copy", "cp $in $out")?; - e.rule("make-cocotb", "make DATA_PATH=$sim_data VERILOG_SOURCE=$in COCOTB_LOG_LEVEL=CRITICAL > $out")?; - // This cleans up the extra `make` cruft, leaving what is in between `{` and `}.` - e.rule("cleanup-cocotb", r"sed -n '/Output:/,/make\[1\]/{/Output:/d;/make\[1\]/d;p}' $in > $out")?; + + let waves = e.config_constrained_or("waves", vec!["true", "false"], "false")?; + let waves = FromStr::from_str(&waves).expect("The 'waves' flag should be either 'true' or 'false'."); + if waves{ + //adds lines based on what is needed for icarus fst output. + e.rule("iverilog-fst-sed", + r#"sed '/\/\/ COMPONENT END: wrapper/c\`ifdef COCOTB_SIM\n initial begin\n \$$dumpfile ("$fst_file_name");\n \$$dumpvars (0, wrapper);\n #1;\n end\n`endif\n\/\/ COMPONENT END: wrapper' $in > $out"#)?; + } + +e.var("cocotb-args", if waves {"WAVES=1"} else {""})?; + + e.rule("make-cocotb", "make DATA_PATH=$sim_data VERILOG_SOURCE=$in COCOTB_LOG_LEVEL=CRITICAL $cocotb-args > $out")?; + // This cleans up the extra `make` and `FST warning` cruft, leaving what is in between `{` and `}.` + e.rule("cleanup-cocotb", r#"sed -n '/Output:/,/make\[1\]/{/Output:/d;/make\[1\]/d;p}' $in | sed -n ':a;N;$$!ba;s/^[^{]*{\(.*\)}[^}]*$$/\1/p' | sed '1d;$$d' > $out"#)?; Ok(()) }); @@ -908,13 +914,27 @@ pub fn build_driver(bld: &mut DriverBuilder) { &["$cocotb-makefile-dir/run_axi_test.py"], &[], )?; + let waves = e.config_constrained_or( + "waves", + vec!["true", "false"], + "false", + )?; + let waves = FromStr::from_str(&waves) + .expect("The 'waves' flag should be either 'true' or 'false'."); + + let vcd_file_name = format!("{}.fst", basename(input)); + let mut make_in = input; + if waves { + make_in = "dumpvars.v"; + e.build_cmd(&[make_in], "iverilog-fst-sed", &[input], &[])?; + e.arg("fst_file_name", &vcd_file_name)?; + } e.build_cmd( &["tmp.dat"], "make-cocotb", - &[input], + &[make_in], &["Makefile", "axi_test.py", "run_axi_test.py"], )?; - e.build_cmd(&[output], "cleanup-cocotb", &["tmp.dat"], &[])?; Ok(())