Skip to content

Commit

Permalink
refactor: move diffing utility to separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
romnn committed Mar 10, 2024
1 parent 8fc8e64 commit 6a75b41
Show file tree
Hide file tree
Showing 37 changed files with 201 additions and 58 deletions.
59 changes: 56 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
"trace",
"trace/invoke",
"trace/model",
"xtask",
"xtask", "diff",
]

[profile.dev]
Expand Down Expand Up @@ -140,6 +140,7 @@ pretty_assertions_sorted = "1"
cxx = "1"
paste = "1"
num-traits = "0"
diff = { path = "./diff" }
criterion = { version = "0.5", features = ["async_tokio"] }

# sanity check stats against playground
Expand Down
1 change: 1 addition & 0 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ strum = { version = "0", features = ["derive"] }

gpucachesim = { path = "../" }
trace-model = { path = "../trace/model" }
diff = { path = "../diff" }
utils = { path = "../utils" }

# running the benchmarks
Expand Down
1 change: 0 additions & 1 deletion benchmarks/src/babelstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ mod tests {
use color_eyre::eyre;
use gpucachesim::exec::tracegen::fmt::{self, Addresses, SimplifiedTraceInstruction};
use ndarray::Array1;
use utils::diff;

const EPSILON: f32 = 0.0001;

Expand Down
1 change: 0 additions & 1 deletion benchmarks/src/matrixmul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ mod tests {
use gpucachesim::exec::tracegen::fmt;
use ndarray::Array2;
use rand::Rng;
use utils::diff;

const EPSILON: f32 = 0.0001;

Expand Down
1 change: 0 additions & 1 deletion benchmarks/src/pchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ mod tests {
use color_eyre::eyre;
use gpucachesim::exec::tracegen::fmt::{self, SimplifiedTraceInstruction};
use ndarray::Array1;
use utils::diff;

const KB: usize = 1024;
const MB: usize = 1024 * 1024;
Expand Down
1 change: 0 additions & 1 deletion benchmarks/src/simple_matrixmul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ mod tests {
use gpucachesim::exec::tracegen::fmt;
use ndarray::Array2;
use rand::Rng;
use utils::diff;

const EPSILON: f32 = 0.01;

Expand Down
1 change: 0 additions & 1 deletion benchmarks/src/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ mod tests {
use color_eyre::eyre;
use gpucachesim::exec::tracegen::fmt;
use ndarray::Array2;
use utils::diff;

const EPSILON: f32 = 0.0001;

Expand Down
1 change: 0 additions & 1 deletion benchmarks/src/vectoradd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ mod tests {
use color_eyre::eyre;
use gpucachesim::exec::tracegen::fmt::{self, Addresses, SimplifiedTraceInstruction};
use ndarray::Array1;
use utils::diff;

const EPSILON: f32 = 0.0001;

Expand Down
15 changes: 15 additions & 0 deletions diff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "diff"
version = "0.1.0"
edition = "2021"
publish = true

[features]
default = []

[package.metadata.cargo-feature-combinations]
denylist = ["default"]

[dependencies]
console = "0"
similar = { version = "2.2.0", features = ["inline"] }
16 changes: 8 additions & 8 deletions utils/src/diff.rs → diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ pub mod print {
fn test_object() {
macro_rules! print_object {
($expr:expr, $mode:ident) => {{
use $crate::diff::print::PrintObject;
use $crate::print::PrintObject;
#[allow(unused_mut)]
let mut _tmp = ($expr,);
_tmp.print_object($crate::diff::print::PrintMode::$mode)
_tmp.print_object($crate::print::PrintMode::$mode)
.map(|x| x.to_string())
}};
}
Expand All @@ -96,11 +96,11 @@ pub mod print {

assert_eq!(
print_object!(&DoNotCallMe, Default).as_deref(),
Some("utils::diff::print::test_object::DoNotCallMe")
Some("diff::print::test_object::DoNotCallMe")
);
assert_eq!(
print_object!(&NoDebugNoString, Default).as_deref(),
Some("utils::diff::print::test_object::NoDebugNoString")
Some("diff::print::test_object::NoDebugNoString")
);
assert_eq!(
print_object!(vec![1, 2, 3], Default).as_deref(),
Expand Down Expand Up @@ -396,7 +396,7 @@ macro_rules! __assert_eq {
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
use $crate::diff::{
use $crate::{
print::{PrintMode, PrintObject},
SimpleDiff,
};
Expand Down Expand Up @@ -477,7 +477,7 @@ macro_rules! assert_eq {
}};
}

pub use assert_eq;
// pub use assert_eq;

#[macro_export]
macro_rules! __diff {
Expand All @@ -490,7 +490,7 @@ macro_rules! __diff {
) => {{
match (&($left), &($right)) {
(left_val, right_val) => {
use $crate::diff::{
use $crate::{
print::{PrintMode, PrintObject},
SimpleDiff,
};
Expand Down Expand Up @@ -584,7 +584,7 @@ macro_rules! diff {
// }};
}

pub use diff;
// pub use diff;

#[cfg(test)]
pub mod tests {
Expand Down
1 change: 1 addition & 0 deletions exec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ futures = "0.3"
approx = "0.5"
rand = "0"
ndarray = { version = "0", features = ["approx-0_5"] }
diff = { path = "../diff" }
1 change: 0 additions & 1 deletion exec/src/tracegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ mod tests {
use std::path::PathBuf;
use tokio::sync::Mutex;
use trace_model::Dim;
use utils::diff;

const EPSILON: f32 = 0.0001;
use ndarray::Array2;
Expand Down
4 changes: 4 additions & 0 deletions ptx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ itertools = "0"
object = "0"
bytes = "1"

[dev-dependencies]
once_cell = "1"
pest-test = "0"

[lib]
crate-type = ["cdylib", "rlib"]
2 changes: 1 addition & 1 deletion ptx/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::ptx::Rule;
use super::parser::Rule;
use pest::Span;
use std::path::PathBuf;
use thiserror::Error;
Expand Down
22 changes: 11 additions & 11 deletions ptx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ extern crate pest_ast;
extern crate pest;

mod ast;
mod ptx;
mod parser;

use crate::ptx::Rule;
use crate::parser::Rule;
use ast::{ASTNode, FunctionDeclHeader, ParseError};
use color_eyre::eyre;
use pest::iterators::Pair;
Expand Down Expand Up @@ -168,7 +168,7 @@ fn walk(pair: Pair<Rule>) -> eyre::Result<ASTNode> {
pub fn gpgpu_ptx_sim_load_ptx_from_filename(path: &Path) -> eyre::Result<u32> {
let source = fs::read_to_string(path)?;
// let source = String::from_utf8(fs::read(path)?)?;
let parse_tree = ptx::Parser::parse(ptx::Rule::program, &source)?;
let parse_tree = parser::Parser::parse(parser::Rule::program, &source)?;

// let ast: Program = parse_tree.try_into()?;
// Program::from(&parse_tree);
Expand Down Expand Up @@ -229,7 +229,7 @@ mod tests {
#[test]
fn $name() -> eyre::Result<()> {
let (rule, source, expected) = $value;
let nodes = ptx::Parser::parse(rule, &source)?
let nodes = parser::Parser::parse(rule, &source)?
.map(|p| walk(p))
.collect::<eyre::Result<Vec<ASTNode>>>()?;
assert_eq!(Some(expected), nodes.into_iter().next());
Expand All @@ -240,12 +240,12 @@ mod tests {
}

ast_tests! {
ast_integer_decimal_0: (ptx::Rule::integer, "0", ASTNode::SignedInt(0)),
ast_integer_decimal_1: (ptx::Rule::integer, "-12", ASTNode::SignedInt(-12)),
ast_integer_decimal_2: (ptx::Rule::integer, "12U", ASTNode::UnsignedInt(12)),
ast_integer_decimal_3: (ptx::Rule::integer, "01110011001", ASTNode::SignedInt(1110011001)),
ast_integer_binary_0: (ptx::Rule::integer, "0b01110011001", ASTNode::SignedInt(921)),
ast_integer_binary_1: (ptx::Rule::integer, "0b01110011001U", ASTNode::UnsignedInt(921)),
ast_integer_decimal_0: (parser::Rule::integer, "0", ASTNode::SignedInt(0)),
ast_integer_decimal_1: (parser::Rule::integer, "-12", ASTNode::SignedInt(-12)),
ast_integer_decimal_2: (parser::Rule::integer, "12U", ASTNode::UnsignedInt(12)),
ast_integer_decimal_3: (parser::Rule::integer, "01110011001", ASTNode::SignedInt(1110011001)),
ast_integer_binary_0: (parser::Rule::integer, "0b01110011001", ASTNode::SignedInt(921)),
ast_integer_binary_1: (parser::Rule::integer, "0b01110011001U", ASTNode::UnsignedInt(921)),
}

// #[cfg(feature = "local-data")]
Expand All @@ -260,7 +260,7 @@ mod tests {
let ptx_code = std::fs::read_to_string(ptx_file)?;
println!("{}", &ptx_code);

let parse_tree = ptx::Parser::parse(ptx::Rule::program, &ptx_code)?;
let parse_tree = parser::Parser::parse(parser::Rule::program, &ptx_code)?;
dbg!(&parse_tree);
// gpgpu_ptx_sim_load_ptx_from_filename(&ptx_file)?;
Ok(())
Expand Down
Loading

0 comments on commit 6a75b41

Please sign in to comment.