From a9fb1063193d759fba2c6be84136d4d66c6cae74 Mon Sep 17 00:00:00 2001 From: John Demme Date: Fri, 7 May 2021 16:23:29 -0700 Subject: [PATCH] [circt-rtl-sim] Run each simulation in its own directory (#1031) Some simulators don't like being run in parallel in the same directory. Also, reset the handshake tests to include all IEEE simulators. --- integration_test/Dialect/Handshake/loop.mlir | 4 +-- integration_test/Dialect/Handshake/mac.mlir | 4 +-- .../Dialect/Handshake/memory.mlir | 4 +-- tools/circt-rtl-sim/circt-rtl-sim.py.in | 30 ++++++++++++++----- tools/esi/esi-cosim-runner.py.in | 5 ++-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/integration_test/Dialect/Handshake/loop.mlir b/integration_test/Dialect/Handshake/loop.mlir index 9c0d9a4239..52ca510c78 100644 --- a/integration_test/Dialect/Handshake/loop.mlir +++ b/integration_test/Dialect/Handshake/loop.mlir @@ -1,8 +1,8 @@ -// REQUIRES: vivado +// REQUIRES: ieee-sim // RUN: circt-opt %s --create-dataflow --simple-canonicalizer --cse --handshake-insert-buffer=strategies=all > %loop-handshake.mlir // RUN: circt-opt %loop-handshake.mlir --lower-handshake-to-firrtl --firrtl-lower-types --firrtl-imconstprop --lower-firrtl-to-rtl --rtl-cleanup --simple-canonicalizer --cse --rtl-legalize-names > %loop-rtl.mlir // RUN: circt-translate %loop-rtl.mlir --export-verilog > %loop-export.sv -// RUN: circt-rtl-sim.py %loop-export.sv %S/driver.sv --sim %xsim% --no-default-driver --top driver | FileCheck %s +// RUN: circt-rtl-sim.py %loop-export.sv %S/driver.sv --sim %ieee-sim --no-default-driver --top driver | FileCheck %s // CHECK: Result={{.*}}42 module { diff --git a/integration_test/Dialect/Handshake/mac.mlir b/integration_test/Dialect/Handshake/mac.mlir index a2b61e2eb2..45505eb744 100644 --- a/integration_test/Dialect/Handshake/mac.mlir +++ b/integration_test/Dialect/Handshake/mac.mlir @@ -1,8 +1,8 @@ -// REQUIRES: vivado +// REQUIRES: ieee-sim // RUN: circt-opt %s --create-dataflow --simple-canonicalizer --cse --handshake-insert-buffer > %mac-handshake.mlir // RUN: circt-opt %mac-handshake.mlir --lower-handshake-to-firrtl --firrtl-lower-types --firrtl-imconstprop --lower-firrtl-to-rtl --rtl-memory-sim --rtl-cleanup --simple-canonicalizer --cse --rtl-legalize-names > %mac-rtl.mlir // RUN: circt-translate %mac-rtl.mlir --export-verilog > %mac-export.sv -// RUN: circt-rtl-sim.py %mac-export.sv %S/driver.sv --sim %xsim% --no-default-driver --top driver | FileCheck %s +// RUN: circt-rtl-sim.py %mac-export.sv %S/driver.sv --sim %ieee-sim --no-default-driver --top driver | FileCheck %s // CHECK: Result={{.*}}912 module { diff --git a/integration_test/Dialect/Handshake/memory.mlir b/integration_test/Dialect/Handshake/memory.mlir index 4fc0de7cd1..7ec8f9471c 100644 --- a/integration_test/Dialect/Handshake/memory.mlir +++ b/integration_test/Dialect/Handshake/memory.mlir @@ -1,8 +1,8 @@ -// REQUIRES: vivado +// REQUIRES: ieee-sim // RUN: circt-opt %s --create-dataflow --simple-canonicalizer --cse --handshake-insert-buffer > %memory-handshake.mlir // RUN: circt-opt %memory-handshake.mlir --lower-handshake-to-firrtl --firrtl-lower-types --firrtl-imconstprop --lower-firrtl-to-rtl --rtl-memory-sim --rtl-cleanup --simple-canonicalizer --cse --rtl-legalize-names > %memory-rtl.mlir // RUN: circt-translate %memory-rtl.mlir --export-verilog > %memory-export.sv -// RUN: circt-rtl-sim.py %memory-export.sv %S/driver.sv --sim %xsim% --no-default-driver --top driver | FileCheck %s +// RUN: circt-rtl-sim.py %memory-export.sv %S/driver.sv --sim %ieee-sim --no-default-driver --top driver | FileCheck %s // CHECK: Result={{.*}}34 module { diff --git a/tools/circt-rtl-sim/circt-rtl-sim.py.in b/tools/circt-rtl-sim/circt-rtl-sim.py.in index 0e0d85c937..a2431533a2 100755 --- a/tools/circt-rtl-sim/circt-rtl-sim.py.in +++ b/tools/circt-rtl-sim/circt-rtl-sim.py.in @@ -154,10 +154,6 @@ class Verilator: self.verilator = os.environ["VERILATOR_PATH"] self.top = args.top - if args.objdir != "": - self.ObjDir = args.objdir - else: - self.ObjDir = os.path.basename(args.sources[0]) + ".obj_dir" def compile(self, sources): dpiLibs = filter(lambda fn: fn.endswith(".so") or fn.endswith(".dll"), @@ -165,11 +161,11 @@ class Verilator: self.ldPaths = ":".join([os.path.dirname(x) for x in dpiLibs]) return subprocess.run([ self.verilator, "--cc", "--top-module", self.top, "-sv", "--build", - "--exe", "--Mdir", self.ObjDir, "--assert" + "--exe", "--assert" ] + sources) def run(self, cycles, args): - exe = os.path.join(self.ObjDir, "V" + self.top) + exe = os.path.join("obj_dir", "V" + self.top) cmd = [exe] if cycles >= 0: cmd.append("--cycles") @@ -209,9 +205,13 @@ def __main__(args): argparser.add_argument("--objdir", type=str, default="", - help="(Verilator) Select an 'obj_dir' to use." + + help="Select a directoy in which to run this test." + " Must be different from other tests in the same" + - " directory. Defaults to 'sources[0].obj_dir'.") + " directory. Defaults to 'sources[0].o'.") + argparser.add_argument("--no-objdir", + dest="no_objdir", + action='store_true', + help="Don't create and run in subdir.") argparser.add_argument("--simargs", type=str, default="", @@ -235,6 +235,20 @@ def __main__(args): return args = argparser.parse_args(args[1:]) + sources = [os.path.abspath(s) for s in args.sources] + args.sources = sources + + # Create and cd into a test directory before running + if not args.no_objdir: + if args.objdir != "": + objDir = args.objdir + else: + objDir = os.path.basename(args.sources[0]) + testDir = f"{objDir}.d" + if not os.path.exists(testDir): + os.mkdir(testDir) + os.chdir(testDir) + # Break up simulator string simParts = os.path.split(args.sim) simName = simParts[1] diff --git a/tools/esi/esi-cosim-runner.py.in b/tools/esi/esi-cosim-runner.py.in index c2cafe1736..bda9fd060a 100755 --- a/tools/esi/esi-cosim-runner.py.in +++ b/tools/esi/esi-cosim-runner.py.in @@ -89,8 +89,7 @@ class CosimTestRunner: # Run the simulation compilation step. Requires a simulator to be # installed and working. - cmd = [self.simRunScript, "--no-run", - "--objdir", "o"] \ + cmd = [self.simRunScript, "--no-objdir", "--no-run"] \ + self.sources + self.args print("[INFO] Compile command: " + " ".join(cmd)) vrun = subprocess.run(cmd, capture_output=True, text=True) @@ -159,7 +158,7 @@ class CosimTestRunner: simEnv = os.environ.copy() if "@CMAKE_BUILD_TYPE@" == "Debug": simEnv["COSIM_DEBUG_FILE"] = "cosim_debug.log" - cmd = [self.simRunScript, "--objdir", "o"] + \ + cmd = [self.simRunScript, "--no-objdir"] + \ self.sources + self.args print("[INFO] Sim run command: " + " ".join(cmd)) simProc = subprocess.Popen(cmd,