Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print perf result at the end of simulation #761

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,032 changes: 516 additions & 516 deletions .github/cases/blastoise/default.json

Large diffs are not rendered by default.

892 changes: 446 additions & 446 deletions .github/cases/machamp/default.json

Large diffs are not rendered by default.

1,056 changes: 528 additions & 528 deletions .github/cases/psyduck/default.json

Large diffs are not rendered by default.

892 changes: 446 additions & 446 deletions .github/cases/sandslash/default.json

Large diffs are not rendered by default.

1,024 changes: 512 additions & 512 deletions .github/t1rocket-cases/t1rocket/default.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions .github/workflows/t1rocket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,19 @@ jobs:
--cycle-update-file-path ./cycle-update.md \
--emu-type vcs
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
- name: "Commit cycle updates"
run: |
git config user.name github-actions
git config user.email [email protected]
changed_cases=$(git diff --name-only '.github/**/default.json')

if [ -n "$changed_cases" ]; then
echo "changed cases: $changed_cases"
git add '.github/**/default.json'
git commit -m "[ci] update t1rocket test case cycle data"
git push origin ${{ github.head_ref }}
else
echo "No cycle change detect"
fi
22 changes: 20 additions & 2 deletions .github/workflows/vcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ jobs:
ref: ${{ github.head_ref }}
- name: "Print step summary"
run: |
nix run ".#ci-helper" -- postCI --failed-tests-file-path ./failed-tests.md --emu-type vcs --cycle-update-file-path ./cycle-update.md
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
nix run ".#ci-helper" -- postCI \
--cycle-update-file-path ./cycle-update.md \
--failed-tests-file-path ./failed-tests.md \
--emu-type vcs
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
- name: "Commit cycle updates"
run: |
git config user.name github-actions
git config user.email [email protected]
changed_cases=$(git diff --name-only '.github/**/default.json')

if [ -n "$changed_cases" ]; then
echo "changed cases: $changed_cases"
git add '.github/**/default.json'
git commit -m "[ci] update t1 test case cycle data"
git push origin ${{ github.head_ref }}
else
echo "No cycle change detect"
fi
15 changes: 15 additions & 0 deletions .github/workflows/verilator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,19 @@ jobs:
--failed-tests-file-path ./failed-tests.md \
--cycle-update-file-path ./cycle-update.md
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
echo >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
- name: "Commit cycle updates"
run: |
git config user.name github-actions
git config user.email [email protected]
changed_cases=$(git diff --name-only '.github/**/default.json')

if [ -n "$changed_cases" ]; then
echo "changed cases: $changed_cases"
git add '.github/**/default.json'
git commit -m "[ci] update test case cycle data"
git push origin ${{ github.head_ref }}
else
echo "No cycle change detect"
fi
1 change: 1 addition & 0 deletions difftest/dpi_common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod dpi_target;
pub mod dump;
pub mod plusarg;
pub mod util;

pub use dpi_target::DpiTarget;

Expand Down
15 changes: 15 additions & 0 deletions difftest/dpi_common/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! utility functions

pub fn write_perf_json(cycle: u64) {
let mut content = String::new();
content += "{\n";
content += &format!(" \"total_cycles\": {cycle}\n");
content += "}\n";

match std::fs::write("perf.json", &content) {
Ok(()) => {}
Err(e) => {
tracing::error!("failed to write 'perf.json': {e}");
}
}
}
5 changes: 5 additions & 0 deletions difftest/dpi_t1/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ unsafe extern "C" fn t1_cosim_init() {
TARGET.init(|| Driver::new(scope, dump_control, &args));
}

#[no_mangle]
unsafe extern "C" fn t1_cosim_final() {
dpi_common::util::write_perf_json(crate::get_t());
}

/// evaluate at every 1024 cycles, return reason = 0 to continue simulation,
/// other value is used as error code.
#[no_mangle]
Expand Down
3 changes: 2 additions & 1 deletion difftest/dpi_t1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl OnlineArgs {
}

// keep in sync with TestBench.ClockGen
pub const CYCLE_PERIOD: u64 = 20;
// the value is measured in simulation time unit
pub const CYCLE_PERIOD: u64 = 20000;

/// get cycle
pub fn get_t() -> u64 {
Expand Down
5 changes: 5 additions & 0 deletions difftest/dpi_t1rocket/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ unsafe extern "C" fn t1rocket_cosim_init() {
TARGET.init(|| Driver::new(scope, dump_control, &args));
}

#[no_mangle]
unsafe extern "C" fn t1rocket_cosim_final() {
dpi_common::util::write_perf_json(crate::get_t());
}

/// evaluate at every 1024 cycles, return reason = 0 to continue simulation,
/// other value is used as error code.
#[no_mangle]
Expand Down
3 changes: 2 additions & 1 deletion difftest/dpi_t1rocket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const EXIT_POS: u32 = 0x4000_0000;
const EXIT_CODE: u32 = 0xdead_beef;

// keep in sync with TestBench.ClockGen
pub const CYCLE_PERIOD: u64 = 20;
// the value is measured in simulation time unit
pub const CYCLE_PERIOD: u64 = 20000;

/// get cycle
pub fn get_t() -> u64 {
Expand Down
4 changes: 4 additions & 0 deletions ipemu/src/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter])
|`endif
|
| import "DPI-C" context function void t1_cosim_init();
| import "DPI-C" context function void t1_cosim_final();
| initial begin
| t1_cosim_init();
| clock = 1'b0;
| reset = 1'b1;
| end
| final begin
| t1_cosim_final();
| end
| initial #(11) reset = 1'b0;
| always #10 clock = ~clock;
|endmodule
Expand Down
2 changes: 1 addition & 1 deletion nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ lib.makeScope newScope
# Grouped emulator packages
# ---------------------------------------------------------------------------------
# Nix specification for t1rocket (with rocket-chip as Scalar core) emulator
t1rocket = t1Scope.callPackage ./t1rocket { };
t1rocket = t1Scope.callPackage ./t1rocket.nix { };
# Nix specification for rocket (rocket-chip only) emulator
rocketv = t1Scope.callPackage ../../rocketemu { };

Expand Down
4 changes: 2 additions & 2 deletions nix/t1/run/run-verilator-emu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ stdenvNoCC.mkDerivation (finalAttr: {
zstd $rtlEventOutPath -o $rtlEventOutPath.zstd
rm $rtlEventOutPath

if [ -r perf.txt ]; then
mv perf.txt $out/
if [ -r perf.json ]; then
mv perf.json $out/
fi

${lib.optionalString emulator.enableTrace ''
Expand Down
16 changes: 8 additions & 8 deletions nix/t1/t1rocket/default.nix → nix/t1/t1rocket.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
{
ip = lib.makeScope newScope (scope: {

cases = scope.callPackage ../../../tests { };
run = scope.callPackage ../run { configName = "t1rocket"; };
cases = scope.callPackage ../../tests { };
run = scope.callPackage ./run { configName = "t1rocket"; };

mlirbc = chisel-to-mlirbc {
outputName = "t1rocketemu-parsed.mlirbc";
elaboratorArgs = [
"t1rocketemu"
"--t1rocket-config"
"${../../../t1rocketemu/configs/default.json}"
"${../../t1rocketemu/configs/default.json}"
];
};

Expand All @@ -41,7 +41,7 @@
];
};

makeDPI = scope.callPackage ../../../difftest { };
makeDPI = scope.callPackage ../../difftest { };
verilator-dpi-lib = scope.makeDPI {
outputName = "t1rocket-verilator-dpi-lib";
buildType = "t1rocket";
Expand Down Expand Up @@ -72,7 +72,7 @@
];
};

offline-checker = scope.callPackage ../../../t1rocketemu/offline { };
offline-checker = scope.callPackage ../../t1rocketemu/offline { };

vcs-dpi-lib = scope.makeDPI {
outputName = "t1rocket-vcs-dpi-lib";
Expand All @@ -87,12 +87,12 @@
};

vcs-emu = sv-to-vcs-simulator {
mainProgram = "t1-vcs-simulator";
mainProgram = "t1rocket-vcs-simulator";
rtl = scope.rtl;
vcsLinkLibs = [ "${scope.vcs-dpi-lib}/lib/libdpi_t1rocket.a" ];
};
vcs-emu-trace = sv-to-vcs-simulator {
mainProgram = "t1-vcs-trace-simulator";
mainProgram = "t1rocket-vcs-trace-simulator";
rtl = scope.rtl;
enableTrace = true;
vcsLinkLibs = [ "${scope.vcs-dpi-lib-trace}/lib/libdpi_t1rocket.a" ];
Expand All @@ -112,7 +112,7 @@
throw "Invalid vlen extension `${ext}` specify, expect Zvl{N}b";

# TODO: designConfig should be read from OM
designConfig = with builtins; (fromJSON (readFile ../../../t1rocketemu/configs/default.json)).parameter;
designConfig = with builtins; (fromJSON (readFile ../../t1rocketemu/configs/default.json)).parameter;

# TODO: We should have a type define, to keep t1 and t1rocket feeds same `rtlDesignMetadata` data structure.
rtlDesignMetadata = rec {
Expand Down
62 changes: 0 additions & 62 deletions nix/t1/t1rocket/verilated-c-lib.nix

This file was deleted.

21 changes: 8 additions & 13 deletions script/ci/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ object Main:
@arg(
name = "cycle-update-file-path",
doc = "specify the cycle update markdown file output path"
) cycleUpdateFilePath: Option[String],
) cycleUpdateFilePath: String,
@arg(
name = "emu-type",
doc = "Specify emulation type"
Expand All @@ -226,11 +226,10 @@ object Main:
val failedTestsFile = os.Path(failedTestsFilePath, os.pwd)
os.write.over(failedTestsFile, "## Failed Tests\n")

if cycleUpdateFilePath.nonEmpty then
os.write.over(
os.Path(cycleUpdateFilePath.get, os.pwd),
"## Cycle Update\n"
)
os.write.over(
os.Path(cycleUpdateFilePath, os.pwd),
"## Cycle Update\n"
)

os.walk(os.pwd / ".github" / caseDir)
.filter(_.last == "default.json")
Expand Down Expand Up @@ -261,15 +260,11 @@ object Main:

if cycleUpdateFilePath.nonEmpty then
Logger.info("Collecting cycle update info")
val perfCycleRegex = raw"total_cycles:\s(\d+)".r
val allCycleUpdates = os
.walk(emuResultPath)
.filter(path => path.last == "perf.txt")
.filter(path => path.last == "perf.json")
.map(path => {
val cycle = os.read.lines(path).head match
case perfCycleRegex(cycle) => cycle.toInt
case _ =>
throw new Exception("perf.txt file is not format as expected")
val cycle = ujson.read(os.read(path)).obj("total_cycles").num.toInt
val caseName = path.segments.toSeq.reverse.drop(1).head
(caseName, cycle, cycleRecord.obj(caseName).num.toInt)
})
Expand All @@ -282,7 +277,7 @@ object Main:
else s"* 🐢 $caseName($config): $oldCycle -> $newCycle"

os.write.append(
os.Path(cycleUpdateFilePath.get, os.pwd),
os.Path(cycleUpdateFilePath, os.pwd),
allCycleUpdates.mkString("\n") + "\n"
)

Expand Down
5 changes: 3 additions & 2 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ object Main:
zstdProc.join(-1)
driverProc.join(-1)
if zstdProc.exitCode() != 0 then Logger.fatal("fail to compress data")
if driverProc.exitCode() != 0 then Logger.fatal("fail to compress data")
if driverProc.exitCode() != 0 then Logger.fatal("online driver run failed")

val statePath = outputPath / "driver-state.json"
os.write(
Expand Down Expand Up @@ -332,7 +332,8 @@ object Main:
)
Logger.info(s"Running offline checker: ${driverArgs.mkString(" ")}")

os.proc(driverArgs).call(stdout = os.Inherit, stderr = os.Inherit)
val ret = os.proc(driverArgs).call(stdout = os.Inherit, stderr = os.Inherit, check = false)
if (ret.exitCode != 0) then Logger.fatal("offline checker run failed")
end offline

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
Expand Down
5 changes: 5 additions & 0 deletions t1rocketemu/src/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ class TestBench(generator: SerializableModuleGenerator[T1RocketTile, T1RocketTil
| endfunction;
|
| import "DPI-C" context function void t1rocket_cosim_init();
| import "DPI-C" context function void t1rocket_cosim_final();
| initial begin
| t1rocket_cosim_init();
| clock = 1'b0;
| reset = 1'b1;
| end
| final begin
| t1rocket_cosim_final();
| end
|
| initial #(100) reset = 1'b0;
| always #10 clock = ~clock;
|endmodule
Expand Down
Loading