diff --git a/dv/uvm/Makefile b/dv/uvm/Makefile index b113a3ce..6b175203 100644 --- a/dv/uvm/Makefile +++ b/dv/uvm/Makefile @@ -123,6 +123,7 @@ rtl_sim: --simulator=${SIMULATOR} \ --en_cov ${COV} \ --en_wave ${WAVES} \ + --lsf_cmd="${LSF_CMD}" \ --sim_opts="+signature_addr=0x${SIGNATURE_ADDR}" \ ${SIM_OPTS} diff --git a/dv/uvm/sim.py b/dv/uvm/sim.py index 33d75943..ad5fa69f 100644 --- a/dv/uvm/sim.py +++ b/dv/uvm/sim.py @@ -22,6 +22,7 @@ import random import re import subprocess import sys +import logging sys.path.insert(0, "../../vendor/google_riscv-dv/scripts") sys.path.insert(0, "./riscv_dv_extension") @@ -32,6 +33,23 @@ from spike_log_to_trace_csv import * from ovpsim_log_to_trace_csv import * from instr_trace_compare import * +# TODO: Move this common function to riscv-dv/lib +def setup_logging(verbose): + """Setup the root logger. + + Args: + verbose: Verbose logging + """ + if verbose: + logging.basicConfig(format="%(asctime)s %(filename)s:%(lineno)-5s %(levelname)-8s %(message)s", + datefmt='%a, %d %b %Y %H:%M:%S', + level=logging.DEBUG) + else: + logging.basicConfig(format="%(asctime)s %(levelname)-8s %(message)s", + datefmt='%a, %d %b %Y %H:%M:%S', + level=logging.INFO) + + def process_cmd(keyword, cmd, opts, enable): """ Process the compile and simulation command @@ -63,12 +81,12 @@ def get_simulator_cmd(simulator, simulator_yaml, en_cov, en_wave): compile_cmd : RTL simulator command to compile the instruction generator sim_cmd : RTL simulator command to run the instruction generator """ - print("Processing simulator setup file : %s" % simulator_yaml) + logging.info("Processing simulator setup file : %s" % simulator_yaml) yaml_data = read_yaml(simulator_yaml) # Search for matched simulator for entry in yaml_data: if entry['tool'] == simulator: - print("Found matching simulator: %s" % entry['tool']) + logging.info("Found matching simulator: %s" % entry['tool']) compile_cmd = entry['compile']['cmd'] for i in range(len(compile_cmd)): compile_cmd[i] = process_cmd("", compile_cmd[i], @@ -79,11 +97,11 @@ def get_simulator_cmd(simulator, simulator_yaml, en_cov, en_wave): sim_cmd = process_cmd("", sim_cmd, entry['sim']['cov_opts'], en_cov) sim_cmd = process_cmd("", sim_cmd, entry['sim']['wave_opts'], en_wave) return compile_cmd, sim_cmd - print ("Cannot find RTL simulator %0s" % simulator) + logging.info("Cannot find RTL simulator %0s" % simulator) sys.exit(1) -def rtl_compile(compile_cmd, test_list, output_dir, lsf_cmd, opts, verbose): +def rtl_compile(compile_cmd, test_list, output_dir, lsf_cmd, opts): """Run the instruction generator Args: @@ -92,21 +110,17 @@ def rtl_compile(compile_cmd, test_list, output_dir, lsf_cmd, opts, verbose): output_dir : Output directory of the ELF files lsf_cmd : LSF command to run compilation opts : Compile options for the generator - verbose : Verbose logging """ # Compile the TB - print ("Compiling TB") + logging.info("Compiling TB") for cmd in compile_cmd: cmd = re.sub("", output_dir, cmd) cmd = re.sub("", opts, cmd) - if verbose: - print("Compile command: %s" % cmd) - output = run_cmd(cmd) - if verbose: - print(output) + logging.debug("Compile command: %s" % cmd) + run_cmd(cmd) -def rtl_sim(sim_cmd, test_list, output_dir, bin_dir, lsf_cmd, seed, opts, verbose): +def rtl_sim(sim_cmd, test_list, output_dir, bin_dir, lsf_cmd, seed, opts): """Run the instruction generator Args: @@ -117,13 +131,12 @@ def rtl_sim(sim_cmd, test_list, output_dir, bin_dir, lsf_cmd, seed, opts, verbos lsf_cmd : LSF command to run simulation seed : Seed of RTL simulation opts : Simulation options - verbose : Verbose logging """ # Run the RTL simulation sim_cmd = re.sub("", output_dir, sim_cmd) sim_cmd = re.sub("", opts, sim_cmd) sim_cmd = re.sub("", cwd, sim_cmd) - print ("Running RTL simulation...") + logging.info("Running RTL simulation...") cmd_list = [] for test in test_list: for i in range(test['iterations']): @@ -131,23 +144,23 @@ def rtl_sim(sim_cmd, test_list, output_dir, bin_dir, lsf_cmd, seed, opts, verbos test_sim_cmd = re.sub("", str(rand_seed), sim_cmd) if "sim_opts" in test: test_sim_cmd += test['sim_opts'] - print(test_sim_cmd) sim_dir = output_dir + ("/%s.%d" %(test['test'], i)) run_cmd(("mkdir -p %s" % sim_dir)) os.chdir(sim_dir) - if verbose: - print("Run dir: %s" % sim_dir) binary = ("%s/%s_%d.bin" % (bin_dir, test['test'], i)) - cmd = lsf_cmd + " " + test_sim_cmd.rstrip() + \ + cmd = lsf_cmd + " " + test_sim_cmd + \ (" +UVM_TESTNAME=%s " % test['rtl_test']) + \ (" +bin=%s " % binary) + \ (" -l sim.log ") - print("Running %s with %s" % (test['rtl_test'], binary)) - if verbose: - print(cmd) - output = run_cmd(' '.join(cmd.split())) - if verbose: - print(output) + cmd = re.sub('\n', '', cmd) + if lsf_cmd == "": + logging.info("Running %s with %s" % (test['rtl_test'], binary)) + run_cmd(cmd, 300) + else: + cmd_list.append(cmd) + if lsf_cmd != "": + logging.info("Running %0d simulation jobs." % len(cmd_list)) + run_parallel_cmd(cmd_list, 600) def compare(test_list, iss, output_dir, verbose): @@ -163,7 +176,7 @@ def compare(test_list, iss, output_dir, verbose): for test in test_list: for i in range(0, test['iterations']): elf = ("%s/asm_tests/%s.%d.o" % (output_dir, test['test'], i)) - print("Comparing %s/DUT sim result : %s" % (iss, elf)) + logging.info("Comparing %s/DUT sim result : %s" % (iss, elf)) run_cmd(("echo 'Test binary: %s' >> %s" % (elf, report))) uvm_log = ("%s/rtl_sim/%s.%d/sim.log" % (output_dir, test['test'], i)) rtl_log = ("%s/rtl_sim/%s.%d/trace_core_00000000.log" % (output_dir, test['test'], i)) @@ -180,7 +193,7 @@ def compare(test_list, iss, output_dir, verbose): elif iss == "ovpsim": process_ovpsim_sim_log(iss_log, iss_csv) else: - print("Unsupported ISS" % iss) + logging.info("Unsupported ISS" % iss) sys.exit(1) uvm_result = check_ibex_uvm_log(uvm_log, "ibex", test_name, report, False) if not uvm_result: @@ -201,9 +214,9 @@ def compare(test_list, iss, output_dir, verbose): passed_cnt = run_cmd("grep PASSED %s | wc -l" % report).strip() failed_cnt = run_cmd("grep FAILED %s | wc -l" % report).strip() summary = ("%s PASSED, %s FAILED" % (passed_cnt, failed_cnt)) - print(summary) + logging.info(summary) run_cmd(("echo %s >> %s" % (summary, report))) - print("RTL & ISS regression report is saved to %s" % report) + logging.info("RTL & ISS regression report is saved to %s" % report) # Parse input arguments @@ -242,6 +255,7 @@ parser.add_argument("--lsf_cmd", type=str, default="", command is not specified") args = parser.parse_args() +setup_logging(args.verbose) parser.set_defaults(verbose=False) cwd = os.path.dirname(os.path.realpath(__file__)) @@ -263,13 +277,12 @@ compile_cmd, sim_cmd = get_simulator_cmd(args.simulator, args.simulator_yaml, args.en_cov, args.en_wave) # Compile TB if args.steps == "all" or re.match("compile", args.steps): - rtl_compile(compile_cmd, matched_list, output_dir, - args.lsf_cmd, args.cmp_opts, args.verbose) + rtl_compile(compile_cmd, matched_list, output_dir, args.lsf_cmd, args.cmp_opts) # Run RTL simulation if args.steps == "all" or re.match("sim", args.steps): rtl_sim(sim_cmd, matched_list, output_dir, bin_dir, args.lsf_cmd, - args.seed, args.sim_opts, args.verbose) + args.seed, args.sim_opts) # Compare RTL & ISS simulation result.; if args.steps == "all" or re.match("compare", args.steps):