Split calls to run-iss.py

Now we call it once for each test and seed instead of getting riscv-dv
to iterate over all the tests and seeds we've requested.
This commit is contained in:
Rupert Swarbrick 2022-04-19 15:32:06 +01:00 committed by Rupert Swarbrick
parent 19d60932d5
commit b06f30b8a0
3 changed files with 61 additions and 67 deletions

View file

@ -132,8 +132,10 @@ metadata := $(OUT-SEED)/.metadata
# targets. To ensure the directory has been built, add a order-only dependency
# (with the pipe symbol before it) on the directory name and add the directory
# to this list.
gen-dirs := \
$(OUT-DIR) $(OUT-SEED) $(metadata) $(OUT-DIR)rtl_sim $(OUT-DIR)instr_gen
gen-dirs := \
$(OUT-DIR) $(OUT-SEED) \
$(metadata) $(OUT-DIR)rtl_sim $(OUT-DIR)instr_gen \
$(OUT-SEED)/$(ISS)
$(gen-dirs): %:
mkdir -p $@
@ -340,33 +342,27 @@ instr_gen_compile: $(metadata)/.instr_gen.compile_tests.stamp
# Run the instruction set simulator
#
# This (obviously) depends on having compiled the generated programs, so we
# don't have to worry about variables that affect the 'gen' stage. However, the
# ISS variable does affect the output, so we need to dump it. See the 'gen'
# stage for more verbose explanations of how this works.
iss-var-deps := ISS
-include $(metadata)/.iss.vars.mk
iss-vars-prereq = $(call vars-prereq,iss,running ISS,$(iss-var-deps))
# don't have to worry about variables that affect the 'gen' stage. The only
# other variable that's going to affect things is the actual choice of ISS. We
# cheat and include it in the path.
ISS_COMMANDS := $(shell mktemp)
$(metadata)/.iss.run.stamp: \
$(metadata)/.instr_gen.compile_tests.stamp $(iss-vars-prereq) \
$(TESTLIST) \
scripts/construct_makefile.py scripts/run-iss.py | $(metadata)
+$(verb)scripts/run-iss.py \
iss-sim-logs := $(foreach ts,$(tests-and-seeds),$(OUT-SEED)/$(ISS)/$(ts).log)
$(iss-sim-logs): \
$(OUT-SEED)/$(ISS)/%.log: \
$(metadata)/.instr_gen.compile_tests.stamp \
$(TESTLIST) scripts/run-iss.py | $(OUT-SEED)/$(ISS)
$(verb)scripts/run-iss.py \
$(verb-arg) \
--iss=$(ISS) \
--output=$(OUT-SEED)/instr_gen \
--isa=$(ISA_ISS) \
--test $(TEST) \
--test-dot-seed $* \
--start-seed $(SEED) \
--iterations $(ITERATIONS) \
--pmp-num-regions $(PMP_REGIONS) \
--pmp-granularity $(PMP_GRANULARITY)
$(call dump-vars,$(metadata)/.iss.vars.mk,iss,$(iss-var-deps))
@touch $@
--gen-dir=$(OUT-SEED)/instr_gen \
--run-dir=$(@D) \
--isa=$(ISA_ISS)
.PHONY: iss_run
iss_run: $(metadata)/.iss.run.stamp
iss_run: $(iss-sim-logs)
###############################################################################
@ -463,7 +459,7 @@ rtl_sim_run: $(rtl-sim-logs)
#
# For a given TEST/SEED pair, the ISS and RTL logs appear at:
#
# $(OUT-SEED)/instr_gen/$(ISS)_sim/$(TEST).$(SEED).log
# $(OUT-SEED)/$(ISS)/$(TEST).$(SEED).log
# $(OUT-SEED)/rtl_sim/$(TEST).$(SEED)/trace_core_00000000.log
#
# The comparison script compares these and writes to a result file at
@ -476,13 +472,13 @@ comp-results := $(addsuffix /test-result.yml,$(rtl-sim-dirs))
$(comp-results): \
%/test-result.yml: \
$(metadata)/.iss.run.stamp \
$(iss-sim-logs) \
$(rtl-sim-logs) compare.py
@echo Comparing traces for $*
$(verb)./compare.py \
--instr-gen-bin-dir $(OUT-SEED)/instr_gen/asm_test \
--iss $(ISS) \
--iss-log-dir $(OUT-SEED)/instr_gen/$(ISS)_sim \
--iss-log-dir $(OUT-SEED)/$(ISS) \
--start-seed $(SEED) \
--test-dot-seed "$(notdir $*)" \
--output $@ \

View file

@ -120,8 +120,8 @@ def compare_test_run(test: TestEntry,
return TestRunResult(**kv_data)
# There were no UVM errors. Process the log file from the ISS.
iss_log = os.path.join(iss_log_dir, '{}.{}.log'.format(test_name, idx))
iss_csv = os.path.join(iss_log_dir, '{}.{}.csv'.format(test_name, idx))
iss_log = os.path.join(iss_log_dir, '{}.{}.log'.format(test_name, seed))
iss_csv = os.path.join(iss_log_dir, '{}.{}.csv'.format(test_name, seed))
kv_data['iss_trace'] = iss_log
kv_data['iss_trace_csv'] = iss_csv

View file

@ -7,64 +7,62 @@
import argparse
import os
import sys
import tempfile
import construct_makefile
from scripts_lib import start_riscv_dv_run_cmd, run_one
from scripts_lib import read_test_dot_seed, run_one
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--iss', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--test-dot-seed',
type=read_test_dot_seed, required=True)
parser.add_argument('--gen-dir', required=True)
parser.add_argument('--run-dir', required=True)
parser.add_argument('--isa', required=True)
parser.add_argument('--test', required=True)
parser.add_argument('--start-seed', type=int, required=True)
parser.add_argument('--iterations', type=int, required=True)
parser.add_argument('--pmp-num-regions', type=int, required=True)
parser.add_argument('--pmp-granularity', type=int, required=True)
args = parser.parse_args()
iss_opts = []
if args.iss == 'ovpsim':
iss_opts += ['--override',
f'riscvOVPsim/cpu/PMP_registers={args.pmp_num_regions}',
'--override',
f'riscvOVPsim/cpu/PMP_grain={args.pmp_granularity}']
testname, seed = args.test_dot_seed
output_makefile = os.path.join(args.output, 'iss.mk')
if args.start_seed < 0:
raise RuntimeError('Invalid start seed: {}'.format(args.start_seed))
testname, seed = args.test_dot_seed
if seed < args.start_seed:
raise RuntimeError('Start seed is greater than test seed '
f'({args.start_seed} > {seed}).')
with tempfile.NamedTemporaryFile() as tf:
cmd = (start_riscv_dv_run_cmd(args.verbose) +
['--steps=iss_sim',
'--output', args.output,
'--isa', args.isa,
'--iss', args.iss,
'--test', args.test,
'--start_seed', str(args.start_seed),
'--iterations', str(args.iterations),
'--debug', tf.name])
if iss_opts:
cmd += ['--iss_opts', ' '.join(iss_opts)]
iteration = seed - args.start_seed
# Run riscv-dv to generate a bunch of commands
gen_retcode = run_one(args.verbose, cmd)
if gen_retcode:
return gen_retcode
# riscv-dv knows how to run an ISS simulation (see yaml/iss.yaml in the
# vendored directory), but it has definite (and inconvenient!) opinions
# about where files should end up. Rather than fight with it, let's just
# generate the simple ISS command ourselves.
#
# NOTE: This only supports Spike, mainly because it's the only simulator we
# care about at the moment and this whole script is going to go away anyway
# very soon once we've switched across to using cosimulation.
# Now convert that command list to a Makefile
construct_makefile.transform(False, tf.name, output_makefile)
if args.iss != 'spike':
raise RuntimeError(f'Unsupported ISS: {args.iss}')
# Finally, run Make to run those commands
cmd = ['make', '-f', output_makefile, 'all']
if not args.verbose:
cmd.append('-s')
object_name = f'{testname}_{iteration}.o'
log_name = os.path.join(args.run_dir, f'{testname}.{seed}.log')
return run_one(args.verbose, cmd)
spike_dir = os.getenv('SPIKE_PATH')
if spike_dir is not None:
spike = os.path.join(spike_dir, 'spike')
else:
spike = 'spike'
cmd = [spike, '--log-commits',
'--isa', args.isa,
'-l', os.path.join(args.gen_dir, 'asm_test', object_name)]
return run_one(args.verbose,
cmd,
redirect_stdstreams=log_name)
if __name__ == '__main__':