From 0c4e083de5ed3e65479621471a4babb742d828f4 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Mon, 29 Jul 2024 03:34:44 +0800 Subject: [PATCH] [nix] refactor nix for vcs+verilator emulator --- .github/workflows/pr.yml | 4 +-- nix/t1/default.nix | 68 ++++++++++++++++++++++++++++++--------- nix/t1/elaborate.nix | 2 +- nix/t1/rtl.nix | 11 ++----- tests/default.nix | 6 ++-- tests/make-emu-result.nix | 10 +++--- 6 files changed, 65 insertions(+), 36 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index eaa9321b4..94a3f19cc 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 @@ -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' diff --git a/nix/t1/default.nix b/nix/t1/default.nix index 36dd73427..873db7ac3 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -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 = @@ -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 { diff --git a/nix/t1/elaborate.nix b/nix/t1/elaborate.nix index 691a701cd..a531ac1df 100644 --- a/nix/t1/elaborate.nix +++ b/nix/t1/elaborate.nix @@ -12,7 +12,7 @@ }: assert lib.assertMsg - (lib.elem target [ "ip" "ipemu" "subsystem" "subsystememu" ]) + (lib.elem target [ "ip" "ipemu" ]) "Unknown elaborate target ${target}"; let diff --git a/nix/t1/rtl.nix b/nix/t1/rtl.nix index 9f3beed96..5b9d43369 100644 --- a/nix/t1/rtl.nix +++ b/nix/t1/rtl.nix @@ -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"; diff --git a/tests/default.nix b/tests/default.nix index d84a1effe..009a9be32 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -4,8 +4,8 @@ , newScope , rv32-stdenv , runCommand -, difftest -, difftest-trace +, verilator-emu +, verilator-emu-trace }: let @@ -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 { }; diff --git a/tests/make-emu-result.nix b/tests/make-emu-result.nix index f31553f4f..129de6c0f 100644 --- a/tests/make-emu-result.nix +++ b/tests/make-emu-result.nix @@ -3,8 +3,8 @@ , stdenvNoCC , jq , zstd -, difftest -, difftest-trace +, verilator-emu +, verilator-emu-trace , elaborateConfigJson }: @@ -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" @@ -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 @@ -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