forked from embench/embench-iot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_naxriscv_sim.py
86 lines (64 loc) · 1.97 KB
/
run_naxriscv_sim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
# Python module to run programs on a stm32f4-discovery board
# Copyright (C) 2019 Embecosm Limited
#
# Contributor: Jeremy Bennett <[email protected]>
#
# This file is part of Embench.
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Embench module to run benchmark programs.
This version is suitable for a gdbserver with simulator.
"""
__all__ = [
'get_target_args',
'build_benchmark_cmd',
'decode_results',
]
import argparse
import re
from embench_core import log
cpu_mhz = 1
def get_target_args(remnant):
"""Parse left over arguments"""
parser = argparse.ArgumentParser(description='Get target specific args')
parser.add_argument(
'--regression-path',
type=str,
help='',
)
parser.add_argument(
'--regression-args',
type=str,
default="",
help='',
)
parser.add_argument(
'--cpu-mhz',
type=int,
default=1,
help='Processor clock speed in MHz'
)
return parser.parse_args(remnant)
def build_benchmark_cmd(bench, args):
"""Construct the command to run the benchmark. "args" is a
namespace with target specific arguments"""
global cpu_mhz
cpu_mhz = args.cpu_mhz
#gen_hex = f'riscv64-unknown-elf-objcopy -O ihex {bench} {bench}.hex; HEX=$PWD'
run_test = f'{args.regression_path}/obj_dir/VNaxRiscv --load-elf {bench} --pass-symbol pass --name {bench} --stats-print --stats-toggle-symbol sim_time'
cmd = ['sh', '-c',f'{run_test}']
print("Run " + bench)
return cmd
def decode_results(stdout_str, stderr_str):
"""Extract the results from the output string of the run. Return the
elapsed time in milliseconds or zero if the run failed."""
#print("OUT")
#print(stdout_str)
#print("ERR")
#print(stderr_str)
print(stdout_str)
time = int(stdout_str.partition('\n')[0])
# Time from cycles to milliseconds
global cpu_mhz
return time / cpu_mhz / 1000.0