Skip to content

Commit

Permalink
[difftest] cosmic refactor (break verilator temporally)
Browse files Browse the repository at this point in the history
  • Loading branch information
FanShupei committed Aug 27, 2024
1 parent 5a0798d commit a03093f
Show file tree
Hide file tree
Showing 20 changed files with 282 additions and 161 deletions.
65 changes: 21 additions & 44 deletions difftest/Cargo.lock

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

5 changes: 2 additions & 3 deletions difftest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ members = [
"test_common",
"spike_rs",
"offline",
"online_dpi",
"online_drive",
"online_vcs",
"dpi_t1",
"dpi_common",
]
exclude = [
"spike_interfaces"
Expand Down
14 changes: 14 additions & 0 deletions difftest/dpi_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "dpi_common"
edition = "2021"
version.workspace = true

[dependencies]
svdpi = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[features]
vcs = ["svdpi/vpi"]
verilator = ["svdpi/sv2023"]
trace = []
13 changes: 13 additions & 0 deletions difftest/dpi_common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tracing_subscriber::{EnvFilter, FmtSubscriber};

pub fn setup_logger() {
let global_logger = FmtSubscriber::builder()
.with_env_filter(EnvFilter::from_default_env()) // default level: error
.without_time()
.with_target(false)
.with_ansi(true)
.compact()
.finish();
tracing::subscriber::set_global_default(global_logger)
.expect("internal error: fail to setup log subscriber");
}
7 changes: 5 additions & 2 deletions difftest/online_dpi/Cargo.toml → difftest/dpi_t1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[package]
name = "online_dpi"
name = "dpi_t1"
edition = "2021"
version.workspace = true

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

[lib]
crate-type = ["staticlib"]

[dependencies]
common = { path = "../test_common" }
dpi_common = { path = "../dpi_common" }
spike_rs = { path = "../spike_rs" }
clap = { workspace = true }
tracing = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ unsafe extern "C" fn axi_write_indexedAccessPort(
#[no_mangle]
unsafe extern "C" fn t1_cosim_init() {
let args = OfflineArgs::parse();
args.common_args.setup_logger().unwrap();
dpi_common::setup_logger();

let scope = SvScope::get_current().expect("failed to get scope in t1_cosim_init");

Expand Down
22 changes: 16 additions & 6 deletions difftest/online_dpi/src/drive.rs → difftest/dpi_t1/src/drive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common::spike_runner::SpikeRunner;
use common::MEM_SIZE;
use spike_rs::runner::SpikeRunner;
use spike_rs::runner::{SpikeArgs, MEM_SIZE};
use spike_rs::spike_event::MemAccessRecord;
use spike_rs::spike_event::SpikeEvent;
use spike_rs::util::load_elf_to_buffer;
Expand Down Expand Up @@ -161,7 +161,17 @@ impl Driver {
let (dump_start, dump_end) = parse_range(&args.dump_range);

let mut self_ = Self {
spike_runner: SpikeRunner::new(&args.common_args, false),
spike_runner: SpikeRunner::new(
&SpikeArgs {
elf_file: args.elf_file.clone(),
log_file: args.log_file.clone(),
log_level: args.log_level.clone(),
vlen: args.vlen,
dlen: args.dlen,
set: args.set.clone(),
},
false,
),

#[cfg(feature = "trace")]
scope,
Expand All @@ -174,17 +184,17 @@ impl Driver {
#[cfg(feature = "trace")]
dump_started: false,

dlen: args.common_args.dlen,
dlen: args.dlen,
timeout: args.timeout,
last_commit_cycle: 0,

issued: 0,
vector_lsu_count: 0,
shadow_mem: ShadowMem::new(),
};
self_.spike_runner.load_elf(&args.common_args.elf_file).unwrap();
self_.spike_runner.load_elf(&args.elf_file).unwrap();

load_elf_to_buffer(&mut self_.shadow_mem.mem, &args.common_args.elf_file).unwrap();
load_elf_to_buffer(&mut self_.shadow_mem.mem, &args.elf_file).unwrap();
self_
}

Expand Down
52 changes: 52 additions & 0 deletions difftest/dpi_t1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::path::PathBuf;

use clap::Parser;

pub mod dpi;
pub mod drive;

#[derive(Parser)]
pub(crate) struct OfflineArgs {
/// Path to the ELF file
#[arg(long)]
pub elf_file: PathBuf,

/// Path to the log file
#[arg(long)]
pub log_file: Option<PathBuf>,

/// Log level: trace, debug, info, warn, error
#[arg(long, default_value = "info")]
pub log_level: String,

/// vlen config
#[arg(long, default_value = env!("DESIGN_VLEN"))]
pub vlen: u32,

/// dlen config
#[arg(long, default_value = env!("DESIGN_DLEN"))]
pub dlen: u32,

/// ISA config
#[arg(long, default_value = env!("SPIKE_ISA_STRING"))]
pub set: String,

#[cfg(feature = "trace")]
#[arg(long)]
pub wave_path: String,

#[cfg(feature = "trace")]
#[arg(long, default_value = "")]
pub dump_range: String,

#[arg(long, default_value_t = 1000000)]
pub timeout: u64,
}

// keep in sync with TestBench.ClockGen
pub const CYCLE_PERIOD: u64 = 20;

/// get cycle
pub fn get_t() -> u64 {
svdpi::get_time() / CYCLE_PERIOD
}
9 changes: 4 additions & 5 deletions difftest/offline/src/difftest.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use common::spike_runner::SpikeRunner;
use spike_rs::runner::{SpikeArgs, SpikeRunner};
use std::path::Path;
use tracing::info;

use common::rtl_config::RTLConfig;
use common::CommonArgs;

use crate::dut::Dut;
use crate::json_events::*;
Expand All @@ -17,12 +16,12 @@ pub struct Difftest {
}

impl Difftest {
pub fn new(args: CommonArgs) -> Self {
pub fn new(args: &SpikeArgs) -> Self {
let config = RTLConfig { vlen: args.vlen, dlen: args.dlen };
Self {
runner: SpikeRunner::new(&args, true),
runner: SpikeRunner::new(args, true),
dut: Dut::new(Path::new(
&args.log_file.expect("difftest must be run with a log file"),
args.log_file.as_ref().expect("difftest must be run with a log file"),
)),
config,
}
Expand Down
3 changes: 1 addition & 2 deletions difftest/offline/src/json_events.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use common::spike_runner::SpikeRunner;
use num_bigint::BigUint;
use serde::{Deserialize, Deserializer};
use spike_rs::spike_event::LSU_IDX_DEFAULT;
use spike_rs::{runner::SpikeRunner, spike_event::LSU_IDX_DEFAULT};
use tracing::{debug, info};

#[derive(Deserialize, Debug, PartialEq, Clone)]
Expand Down
68 changes: 61 additions & 7 deletions difftest/offline/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,43 @@ mod difftest;
mod dut;
mod json_events;

use std::path::PathBuf;

use clap::Parser;
use spike_rs::runner::{SpikeArgs, SpikeRunner};
use tracing::info;

use common::spike_runner::SpikeRunner;
use common::CommonArgs;

use crate::difftest::Difftest;

fn run_spike(args: &CommonArgs) -> anyhow::Result<()> {
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// Path to the ELF file
#[arg(long)]
pub elf_file: PathBuf,

/// Path to the log file
#[arg(long)]
pub log_file: Option<PathBuf>,

/// Log level: trace, debug, info, warn, error
#[arg(long, default_value = "info")]
pub log_level: String,

/// vlen config
#[arg(long, default_value = env!("DESIGN_VLEN"))]
pub vlen: u32,

/// dlen config
#[arg(long, default_value = env!("DESIGN_DLEN"))]
pub dlen: u32,

/// ISA config
#[arg(long, default_value = env!("SPIKE_ISA_STRING"))]
pub set: String,
}

fn run_spike(args: &SpikeArgs) -> anyhow::Result<()> {
let mut count: u64 = 0;

let spike = SpikeRunner::new(args, true);
Expand All @@ -32,9 +60,18 @@ fn run_spike(args: &CommonArgs) -> anyhow::Result<()> {

fn main() -> anyhow::Result<()> {
// parse args
let args = CommonArgs::parse();
let args = Args::parse();

args.setup_logger()?;
setup_logger();

let args = SpikeArgs {
elf_file: args.elf_file,
log_file: args.log_file,
log_level: args.log_level,
vlen: args.vlen,
dlen: args.dlen,
set: args.set,
};

// if there is no log file, just run spike and quit
if args.log_file.is_none() {
Expand All @@ -43,7 +80,7 @@ fn main() -> anyhow::Result<()> {
}

// if there is a log file, run difftest
let mut diff = Difftest::new(args);
let mut diff = Difftest::new(&args);

loop {
match diff.diff() {
Expand All @@ -55,3 +92,20 @@ fn main() -> anyhow::Result<()> {
}
}
}

fn setup_logger() {
// setup log
// let log_level: Level = self.log_level.parse()?;
// let global_logger = FmtSubscriber::builder()
// .with_env_filter(EnvFilter::from_default_env())
// .with_max_level(log_level)
// .without_time()
// .with_target(false)
// .with_ansi(true)
// .compact()
// .finish();
// tracing::subscriber::set_global_default(global_logger)
// .expect("internal error: fail to setup log subscriber");
// Ok(())
todo!()
}
Loading

0 comments on commit a03093f

Please sign in to comment.