Skip to content

Commit

Permalink
Make yxi a standalone tool (#2125)
Browse files Browse the repository at this point in the history
* create yxi tool

* remove yxi feature

* change fud2 and runt to use new yxi tool

* new runt tests for yxi ref mems

* formatting and remove unused mod

* more yxi tests and organization

* update fud2 snapshot

* remove --features yxi from github actions

---------

Co-authored-by: Nathaniel Navarro <[email protected]>
  • Loading branch information
rachitnigam and nathanielnrn authored Jun 11, 2024
1 parent be274e6 commit 9a9ddb2
Show file tree
Hide file tree
Showing 32 changed files with 285 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --features yxi --manifest-path /home/calyx/Cargo.toml
args: --workspace --manifest-path /home/calyx/Cargo.toml

# - name: Source code doc tests
# uses: actions-rs/cargo@v1
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"data-conversion",
"tools/btor2/btor2i",
"tools/cider-data-converter",
"tools/yxi",
]
exclude = ["site"]

Expand Down Expand Up @@ -92,7 +93,6 @@ path = "src/main.rs"
[features]
default = []
serialize = ["calyx-ir/serialize", "serde/rc", "calyx-backend/sexp"]
yxi = ["serialize", "calyx-backend/yxi", "calyx-ir/yxi"]

[build-dependencies]
calyx-stdlib = { path = "calyx-stdlib", version = "0.7.1" }
Expand Down
1 change: 0 additions & 1 deletion calyx-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ mlir = []
xilinx = ["dep:quick-xml"]
resources = ["dep:csv"]
sexp = ["dep:serde_with", "dep:serde_sexpr", "serde/rc", "calyx-ir/serialize"]
yxi = ["calyx-ir/yxi"]
6 changes: 0 additions & 6 deletions calyx-backend/src/backend_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub enum BackendOpt {
Mlir,
Resources,
Sexp,
#[cfg(feature = "yxi")]
Yxi,
Firrtl,
PrimitiveUses,
None,
Expand All @@ -30,8 +28,6 @@ fn backends() -> Vec<(&'static str, BackendOpt)> {
("mlir", BackendOpt::Mlir),
("resources", BackendOpt::Resources),
("sexp", BackendOpt::Sexp),
#[cfg(feature = "yxi")]
("yxi", BackendOpt::Yxi),
("firrtl", BackendOpt::Firrtl),
("primitive-uses", BackendOpt::PrimitiveUses),
("none", BackendOpt::None),
Expand Down Expand Up @@ -75,8 +71,6 @@ impl ToString for BackendOpt {
Self::Verilog => "verilog",
Self::Xilinx => "xilinx",
Self::XilinxXml => "xilinx-xml",
#[cfg(feature = "yxi")]
Self::Yxi => "yxi",
Self::Calyx => "calyx",
Self::Firrtl => "firrtl",
Self::PrimitiveUses => "primitive-uses",
Expand Down
5 changes: 0 additions & 5 deletions calyx-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ pub use primitive_uses::PrimitiveUsesBackend;
pub use traits::Backend;
pub use verilog::VerilogBackend;

#[cfg(feature = "yxi")]
mod yxi;
#[cfg(feature = "yxi")]
pub use yxi::YxiBackend;

#[cfg(feature = "mlir")]
mod mlir;
#[cfg(feature = "mlir")]
Expand Down
81 changes: 0 additions & 81 deletions calyx-backend/src/yxi.rs

This file was deleted.

4 changes: 2 additions & 2 deletions calyx-ir/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Helpers used to examine calyx programs. Used in Xilinx and Yxi backends among others.
use super::{BoolAttr, Cell, Component, RRC};
use calyx_utils::Id;
#[cfg(feature = "yxi")]
#[cfg(feature = "serialize")]
use serde::Serialize;

// Returns Vec<String> of `@external` or `ref` memory names
Expand All @@ -25,7 +25,7 @@ pub fn external_and_ref_memories_cells(comp: &Component) -> Vec<RRC<Cell>> {
.collect()
}

#[cfg_attr(feature = "yxi", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(Clone, Copy)]
pub enum MemoryType {
Combinational,
Expand Down
22 changes: 12 additions & 10 deletions fud2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ pub fn build_driver(bld: &mut DriverBuilder) {
e.build_cmd(&[only_refs_calyx], "external-to-ref", &[input], &[])?;

// Get YXI to generate JSON for testbench generation
e.build_cmd(&[memories_json], "calyx", &[only_externals_calyx], &[])?;
e.arg("backend", "yxi")?;
e.build_cmd(&[memories_json], "yxi", &[only_externals_calyx], &[])?;
// generate custom testbench
e.build_cmd(
&[testbench],
Expand Down Expand Up @@ -740,15 +739,20 @@ pub fn build_driver(bld: &mut DriverBuilder) {
},
);

let yxi_setup = bld.setup("YXI setup", |e| {
e.config_var_or("yxi", "yxi", "$calyx-base/target/debug/yxi")?;
e.rule("yxi", "$yxi -l $calyx-base $in > $out")?;
Ok(())
});

let yxi = bld.state("yxi", &["yxi"]);
bld.op(
"calyx-to-yxi",
&[calyx_setup],
&[calyx_setup, yxi_setup],
calyx,
yxi,
|e, input, output| {
e.build_cmd(&[output], "calyx", &[input], &[])?;
e.arg("backend", "yxi")?;
e.build_cmd(&[output], "yxi", &[input], &[])?;
Ok(())
},
);
Expand All @@ -762,6 +766,7 @@ pub fn build_driver(bld: &mut DriverBuilder) {
"$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.
Expand All @@ -775,7 +780,7 @@ pub fn build_driver(bld: &mut DriverBuilder) {
});
bld.op(
"axi-wrapped",
&[calyx_setup, wrapper_setup],
&[calyx_setup, yxi_setup, wrapper_setup],
calyx,
calyx,
|e, input, output| {
Expand All @@ -790,11 +795,8 @@ pub fn build_driver(bld: &mut DriverBuilder) {
.0;

// Get yxi file from main compute program.
// TODO(nate): Eventually (#1952) This will be able to use the `yxi` operation
// instead of hardcoding the build cmd calyx rule with arguments
let tmp_yxi = format!("{}.yxi", file_name);
e.build_cmd(&[&tmp_yxi], "calyx", &[input], &[])?;
e.arg("backend", "yxi")?;
e.build_cmd(&[&tmp_yxi], "yxi", &[input], &[])?;

// Generate the AXI wrapper.
let refified_calyx = format!("refified_{}.futil", file_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ rule add-verilog-primitives
# build targets
build external.futil: ref-to-external stdin
build ref.futil: external-to-ref stdin
build memory-info.json: calyx external.futil
backend = yxi
build memory-info.json: yxi external.futil
build tb.sv: generate-refmem-testbench memory-info.json
build tmp-out.fir: calyx ref.futil
backend = firrtl
Expand Down
24 changes: 15 additions & 9 deletions runt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ flags=$(head -n 1 {} | cut -c 3-)
./target/debug/calyx {} $flags -l .
"""

#yxi is not part of [core]
[[tests]]
name = "yxi backend"
paths = ["yxi/tests/backend/*.futil"]
name = "yxi tool"
paths = ["yxi/tests/yxi-tool/*.futil"]
cmd = """
./target/debug/calyx {} -b yxi
./target/debug/yxi {}
"""

[[tests]]
name = "fud2 yxi"
paths = ["yxi/tests/ref-mems-vec-add.futil"]
cmd = """
fud2 {} --from calyx --to yxi
"""

##### Frontend Tests #####
Expand Down Expand Up @@ -549,31 +555,31 @@ fud e {} -s verilog.cycle_limit 500 \
##### Calyx AXI tests #####
[[tests]]
name = "calyx-py AXI wrapper generation"
paths = ["yxi/tests/*.yxi"]
paths = ["yxi/tests/axi/*.yxi"]
cmd = """
python3 yxi/axi-calyx/axi-generator.py {}
"""

#Ignore fud2 stderr for now due to ninja nondeterminism
[[tests]]
name = "fud2 AXI wrapper invocation"
paths = ["yxi/tests/fud2/seq-mem-vec-add.futil"]
paths = ["yxi/tests/axi/seq-mem-vec-add.futil"]
cmd = """
fud2 {} --to calyx --through axi-wrapped 2> /dev/null
"""

[[tests]]
name = "fud2 AXI-wrapped to verilog"
paths = ["yxi/tests/fud2/seq-mem-vec-add-axi-wrapped.futil"]
paths = ["yxi/tests/axi/seq-mem-vec-add-axi-wrapped.futil"]
cmd = """
fud2 {} --from calyx --to verilog-noverify 2> /dev/null
"""

[[tests]]
name = "fud2 cocotb execution"
paths = ["yxi/tests/fud2/seq-mem-vec-add-verilog.v"]
paths = ["yxi/tests/axi/seq-mem-vec-add-verilog.v"]
cmd = """
fud2 {} --from verilog-noverify --to cocotb-axi --set sim.data=yxi/tests/fud2/vectorized-add.data 2> /dev/null
fud2 {} --from verilog-noverify --to cocotb-axi --set sim.data=yxi/tests/axi/vectorized-add.data 2> /dev/null
"""

##### Xilinx Tests ######
Expand Down
7 changes: 0 additions & 7 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
use argh::FromArgs;
#[cfg(feature = "serialize")]
use calyx_backend::SexpBackend;
#[cfg(feature = "yxi")]
use calyx_backend::YxiBackend;
use calyx_backend::{
xilinx::{XilinxInterfaceBackend, XilinxXmlBackend},
Backend, BackendOpt, FirrtlBackend, MlirBackend, PrimitiveUsesBackend,
Expand Down Expand Up @@ -173,11 +171,6 @@ impl Opts {
let backend = XilinxXmlBackend;
backend.run(context, self.output)
}
#[cfg(feature = "yxi")]
BackendOpt::Yxi => {
let backend = YxiBackend;
backend.run(context, self.output)
}
BackendOpt::Firrtl => {
let backend = FirrtlBackend;
backend.run(context, self.output)
Expand Down
6 changes: 1 addition & 5 deletions tools/data_gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ fn main() -> CalyxResult<()> {
let ws = frontend::Workspace::construct(&p.file_path, &p.lib_path)?;
let ctx: ir::Context = ir::from_ast::ast_to_ir(ws)?;

let comp = ctx
.components
.into_iter()
.find(|comp| comp.name == ctx.entrypoint)
.expect("No top-level component found.");
let comp = ctx.entrypoint();

let data_vec: Vec<CellData> =
comp.cells.iter().filter_map(get_data).collect();
Expand Down
28 changes: 28 additions & 0 deletions tools/yxi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "yxi"
authors.workspace = true
license-file.workspace = true
keywords.workspace = true
repository.workspace = true
readme.workspace = true
description.workspace = true
categories.workspace = true
homepage.workspace = true
edition.workspace = true
version.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde.workspace = true
argh.workspace = true
serde_json = "1.0.79"

calyx-utils = { path = "../../calyx-utils" }
calyx-frontend = { path = "../../calyx-frontend" }
calyx-opt = { path = "../../calyx-opt" }

[dependencies.calyx-ir]
path = "../../calyx-ir"
features = ["serialize"]
Loading

0 comments on commit 9a9ddb2

Please sign in to comment.