Skip to content

Commit

Permalink
[nix] refactor nix for vcs+verilator emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Avimitin authored and sequencer committed Jul 28, 2024
1 parent ed846cf commit 0c4e083
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Build verilator emulator"
run: |
nix build '.#t1.${{ matrix.config }}.ip.difftest' -L --no-link --cores 64
nix build '.#t1.${{ matrix.config }}.ip.verilator-emu' -L --no-link --cores 64
- name: "Build all testcases"
run: |
# Build testcases with vlen 1024 and vlen 4096
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Build verilator emulator with trace"
run: nix build '.#t1.${{ matrix.config }}.ip.difftest-trace' -L --no-link --cores 64
run: nix build '.#t1.${{ matrix.config }}.ip.verilator-emu-trace' -L --no-link --cores 64

test-emit:
if: '! github.event.pull_request.draft'
Expand Down
68 changes: 52 additions & 16 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lib.makeScope newScope
elaborateConfigJson = configPath;
elaborateConfig = builtins.fromJSON (lib.readFile configPath);

cases = innerSelf.callPackage ../../tests { difftest = ip.difftest; difftest-trace = ip.difftest-trace; };
cases = innerSelf.callPackage ../../tests { verilator-emu = ip.verilator-emu; verilator-emu-trace = ip.verilator-emu-trace; };

# for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time
cases-x86 =
Expand All @@ -62,27 +62,63 @@ lib.makeScope newScope
ip = rec {
recurseForDerivations = true;

elaborate = innerSelf.callPackage ./elaborate.nix { target = "ip"; /* use-binder = true; */ };
# T1 RTL.
elaborate = innerSelf.callPackage ./elaborate.nix { target = "ip"; };
mlirbc = innerSelf.callPackage ./mlirbc.nix { inherit elaborate; };
rtl = innerSelf.callPackage ./rtl.nix { inherit mlirbc; };

rtl = innerSelf.callPackage ./rtl.nix {
inherit mlirbc;
mfcArgs = lib.escapeShellArgs [
"-O=release"
"--disable-all-randomization"
"--split-verilog"
"--preserve-values=all"
"--strip-debug-info"
"--strip-fir-debug-info"
"--verification-flavor=sva"
"--lowering-options=verifLabels,omitVersionComment,emittedLineLength=240,locationInfoStyle=none"
];
};
omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };

om = innerSelf.callPackage ./om.nix { inherit mlirbc; };

emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; /* use-binder = true; */ };
emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
emu-rtl = innerSelf.callPackage ./rtl.nix { mlirbc = emu-mlirbc; };

verilated = innerSelf.callPackage ./verilated.nix { rtl = emu-rtl; };
verilated-trace = innerSelf.callPackage ./verilated.nix { rtl = emu-rtl; enable-trace = true; };

emu = innerSelf.callPackage ./ipemu.nix { rtl = ip.emu-rtl; stdenv = moldStdenv; };
emu-trace = innerSelf.callPackage ./ipemu.nix { rtl = emu-rtl; stdenv = moldStdenv; do-trace = true; };

difftest = innerSelf.callPackage ../../difftest/verilator.nix { inherit verilated; };
difftest-trace = innerSelf.callPackage ../../difftest/verilator.nix { verilated = verilated-trace; };
# T1 Verilator Emulator
verilator-emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
verilator-emu-rtl = innerSelf.callPackage ./rtl.nix {
mlirbc = emu-mlirbc;
mfcArgs = lib.escapeShellArgs [
"-O=release"
"--split-verilog"
"--preserve-values=all"
"--verification-flavor=if-else-fatal"
"--lowering-options=verifLabels,omitVersionComment"
"--strip-debug-info"
];
};
verilator-emu-rtl-verilated = innerSelf.callPackage ./verilated.nix { rtl = verilator-emu-rtl; stdenv = moldStdenv; };
verilator-emu-rtl-verilated-trace = innerSelf.callPackage ./verilated.nix { rtl = verilator-emu-rtl; stdenv = moldStdenv; enable-trace = true; };
verilator-emu = innerSelf.callPackage ../../difftest/verilator.nix { verilated = verilator-emu-rtl-verilated; };
verilator-emu-trace = innerSelf.callPackage ../../difftest/verilator.nix { verilated = verilator-emu-rtl-verilated-trace; };

# T1 VCS Emulator
vcs-emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
vcs-emu-rtl = innerSelf.callPackage ./rtl.nix {
mlirbc = emu-mlirbc;
mfcArgs = lib.escapeShellArgs [
"-O=release"
"--split-verilog"
"--preserve-values=all"
"--verification-flavor=sva"
"--lowering-options=verifLabels,omitVersionComment"
"--strip-debug-info"
];
};
vcs-dpi-lib = innerSelf.callPackage ../../difftest/online_vcs { };
vcs-dpi-lib-trace = vcs-dpi-lib.override { enable-trace = true; };
vcs-emu-compiled = innerSelf.callPackage ./vcs.nix { inherit vcs-dpi-lib; rtl = vcs-emu-rtl; };
vcs-emu-compiled-trace = innerSelf.callPackage ./vcs.nix { vcs-dpi-lib = vcs-dpi-lib-trace; rtl = vcs-emu-rtl; };
};

subsystem = rec {
Expand Down
2 changes: 1 addition & 1 deletion nix/t1/elaborate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}:

assert lib.assertMsg
(lib.elem target [ "ip" "ipemu" "subsystem" "subsystememu" ])
(lib.elem target [ "ip" "ipemu" ])
"Unknown elaborate target ${target}";

let
Expand Down
11 changes: 2 additions & 9 deletions nix/t1/rtl.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{ stdenvNoCC
, lib

, mfcArgs
, circt
, mlirbc
}:

let
mfcArgs = lib.escapeShellArgs [
"-O=debug"
"--split-verilog"
"--preserve-values=named"
"--lowering-options=verifLabels,omitVersionComment"
"--strip-debug-info"
];
fixupFilelist = lib.elem mlirbc.elaborateTarget [ "ipemu" "subsystememu" ];
fixupFilelist = lib.elem mlirbc.elaborateTarget [ "ipemu" ];
in
stdenvNoCC.mkDerivation {
name = "t1-${mlirbc.elaborateConfig}-${mlirbc.elaborateTarget}-rtl";
Expand Down
6 changes: 3 additions & 3 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
, newScope
, rv32-stdenv
, runCommand
, difftest
, difftest-trace
, verilator-emu
, verilator-emu-trace
}:

let
Expand All @@ -20,7 +20,7 @@ let
scope = lib.recurseIntoAttrs (lib.makeScope newScope (casesSelf: {
recurseForDerivations = true;

inherit difftest difftest-trace;
inherit verilator-emu verilator-emu-trace;

makeEmuResult = casesSelf.callPackage ./make-emu-result.nix { };

Expand Down
10 changes: 5 additions & 5 deletions tests/make-emu-result.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
, stdenvNoCC
, jq
, zstd
, difftest
, difftest-trace
, verilator-emu
, verilator-emu-trace
, elaborateConfigJson
}:

Expand All @@ -19,7 +19,7 @@ let

dontUnpack = true;

difftestDriver = "${difftest}/bin/online_drive";
difftestDriver = "${verilator-emu}/bin/online_drive";
difftestArgs = [
"--elf-file"
"${testCase}/bin/${testCase.pname}.elf"
Expand Down Expand Up @@ -76,7 +76,7 @@ let
'';

passthru.with-trace = self.overrideAttrs (old: {
difftestDriver = "${difftest-trace}/bin/online_drive";
difftestDriver = "${verilator-emu-trace}/bin/online_drive";
difftestArgs = old.difftestArgs ++ [ "--wave-path" "${placeholder "out"}/wave.fst" ];
postCheck = ''
if [ ! -r "$out/wave.fst" ]; then
Expand All @@ -89,7 +89,7 @@ let
passthru.with-offline = self.overrideAttrs (old: {
preInstall = ''
set +e
"${difftest}/bin/offline" \
"${verilator-emu}/bin/offline" \
--elf-file ${testCase}/bin/${testCase.pname}.elf \
--log-file $out/rtl-event.jsonl \
--log-level ERROR &> $out/offline-check-journal
Expand Down

0 comments on commit 0c4e083

Please sign in to comment.