Skip to content

Commit

Permalink
Introduce calyx -> axi-wrapped-calyx fud2 path (#1994)
Browse files Browse the repository at this point in the history
* merge Fud2 example (#1965)

* Sketch an example fud2 op

* Fix typo

---------

Co-authored-by: Adrian Sampson <[email protected]>

* axi-generator.py takes yxi file as argument (run python3 axi-generator.py input.yxi)

* bash script for whole axi workflow

* add input.yxi to axi-generator.py call in sim.sh

* pass runt test?

* diff between generated-axi-with-vec-add and fudaxi/cat.futil

* to verilog should theoretically work

* pass diff

* axi.sh works on fixed-vec-add-w-imports

* add futil to yxi operation to fud2

* almost working axi-gen

* Update fud2 calyx -> axi-wrapped-calyx path.

Testing locally on vec add, the hard-coded cocotb tests pass, meaning
there is parity with the previous bash scripts

* fud2 formatting

* update fud2 snapshots

* cleanup of extra files

* formatting of axi-generator

* make dedicated test dir for yxi

* tidy up old comments

* remove extra fixed-vec-add-w-imports.futil

* add runt tests for fud2 invocation

* update dockerfile to install fud2 attempt1

* dockerfile and fud2 attempt 2

---------

Co-authored-by: Elise Song <[email protected]>
Co-authored-by: Adrian Sampson <[email protected]>
Co-authored-by: eys29 <[email protected]>
  • Loading branch information
4 people authored Apr 22, 2024
1 parent f2d3fc6 commit 619fbcc
Show file tree
Hide file tree
Showing 20 changed files with 871 additions and 167 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ RUN mkdir -p /root/.config
ENV PATH=$PATH:/root/.local/bin
ENV PYTHONPATH=/root/.local/lib/python3.9/site-packages:$PYTHONPATH

# Link fud2
WORKDIR /home/calyx
run mkdir -p ~/.local/bin
RUN ln -s /home/calyx/target/debug/fud2 ~/.local/bin/
RUN printf "[calyx]\nbase = \"/home/calyx\"" >> ~/.config/fud2.toml

# Install calyx-py
WORKDIR /home/calyx/calyx-py
RUN FLIT_ROOT_INSTALL=1 flit install --symlink
Expand Down
87 changes: 87 additions & 0 deletions fud2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ fn setup_calyx(
"calyx",
"$calyx-exe -l $calyx-base -b $backend $args $in > $out",
)?;
e.rule(
"calyx-pass",
"$calyx-exe -l $calyx-base -p $pass $args $in > $out",
)?;
Ok(())
});
bld.op(
Expand Down Expand Up @@ -458,4 +462,87 @@ pub fn build_driver(bld: &mut DriverBuilder) {
Ok(())
},
);

let yxi = bld.state("yxi", &["yxi"]);
bld.op(
"calyx-to-yxi",
&[calyx_setup],
calyx,
yxi,
|e, input, output| {
e.build_cmd(&[output], "calyx", &[input], &[])?;
e.arg("backend", "yxi")?;
Ok(())
},
);

let wrapper_setup = bld.setup("YXI and AXI generation", |e| {
// Define a `gen-axi` rule that invokes our Python code generator program.
// For now point to standalone axi-generator.py. Can maybe turn this into a rsrc file?
e.config_var_or(
"axi-generator",
"axi.generator",
"$calyx-base/yxi/axi-calyx/axi-generator.py",
)?;
e.config_var_or("python", "python", "python3")?;
e.rule("gen-axi", "$python $axi-generator $in > $out")?;

// Define a simple `combine` rule that just concatenates any numer of files.
e.rule("combine", "cat $in > $out")?;

e.rule(
"remove-imports",
"sed '1,/component main/{/component main/!d}' $in > $out",
)?;
Ok(())
});
bld.op(
"axi-wrapped",
&[calyx_setup, wrapper_setup],
calyx,
calyx,
|e, input, output| {
// Generate the YXI file.
//no extension
let file_name = input
.rsplit_once('/')
.unwrap()
.1
.rsplit_once('.')
.unwrap()
.0;
let tmp_yxi = format!("{}.yxi", file_name);

//Get yxi file from main compute program.
//TODO(nate): Can this use the `yxi` operation instead of hardcoding the build cmd calyx rule with arguments?
e.build_cmd(&[&tmp_yxi], "calyx", &[input], &[])?;
e.arg("backend", "yxi")?;

// Generate the AXI wrapper.
let refified_calyx = format!("refified_{}.futil", file_name);
e.build_cmd(&[&refified_calyx], "calyx-pass", &[input], &[])?;
e.arg("pass", "external-to-ref")?;

let axi_wrapper = "axi_wrapper.futil";
e.build_cmd(&[axi_wrapper], "gen-axi", &[&tmp_yxi], &[])?;

// Generate no-imports version of the refified calyx.
let no_imports_calyx = format!("no_imports_{}", refified_calyx);
e.build_cmd(
&[&no_imports_calyx],
"remove-imports",
&[&refified_calyx],
&[],
)?;

// Combine the original Calyx and the wrapper.
e.build_cmd(
&[output],
"combine",
&[axi_wrapper, &no_imports_calyx],
&[],
)?;
Ok(())
},
);
}
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_debug.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# Cider interpreter
cider-exe = $calyx-base/target/debug/cider
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_firrtl_verilog.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# Firrtl to Verilog compiler
firrtl-exe = /test/bin/firrtl
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_icarus_dat.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# RTL simulation
python = python3
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_icarus_vcd.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# RTL simulation
python = python3
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_interp_dat.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# Cider interpreter
cider-exe = $calyx-base/target/debug/cider
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_verilator_dat.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# RTL simulation
python = python3
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_verilator_vcd.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# RTL simulation
python = python3
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_verilog.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# build targets
build stdin.sv: calyx stdin
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_xrt-trace_vcd.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# Xilinx tools
vivado-dir = /test/xilinx/vivado
Expand Down
2 changes: 2 additions & 0 deletions fud2/tests/snapshots/tests__emit@calyx_xrt_dat.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ calyx-base = /test/calyx
calyx-exe = $calyx-base/target/debug/calyx
rule calyx
command = $calyx-exe -l $calyx-base -b $backend $args $in > $out
rule calyx-pass
command = $calyx-exe -l $calyx-base -p $pass $args $in > $out

# Xilinx tools
vivado-dir = /test/xilinx/vivado
Expand Down
13 changes: 10 additions & 3 deletions runt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,19 @@ fud e {} -s verilog.cycle_limit 500 \
-s verilog.data {}.data \
--to dat -q
"""

##### Cayx AXI tests #####
[[tests]]
name = "calyx-py AXI wrapper generation"
paths = ["yxi/axi-calyx/axi-generator.py"]
paths = ["yxi/tests/*.yxi"]
cmd = """
python3 {}
python3 yxi/axi-calyx/axi-generator.py {}
"""

[[tests]]
name = "fud2 axi-wrapper invocation"
paths = ["yxi/tests/fud2/*.futil"]
cmd = """
fud2 {} --to calyx --through axi-wrapped
"""

##### Xilinx Tests ######
Expand Down
Loading

0 comments on commit 619fbcc

Please sign in to comment.