-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks.py
More file actions
executable file
·82 lines (71 loc) · 2.63 KB
/
Copy pathbenchmarks.py
File metadata and controls
executable file
·82 lines (71 loc) · 2.63 KB
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
#!/usr/bin/env python3
import serial
import sys
import os
import subprocess
import hashlib
import datetime
import time
from utils import m4ignore
dev = serial.Serial("/dev/ttyUSB0", 115200,timeout=10)
def benchmarkBinary(benchmark, binary):
binpath = os.path.join("bin", binary)
info = binary.split('_')
primitive = '_'.join(info[:2])
scheme = '_'.join(info[2:-2])
implementation = info[-2]
if m4ignore(primitive, scheme, implementation):
return
if len(sys.argv) > 1 and scheme not in sys.argv[1:]:
return
print("Flashing {}..".format(binpath))
subprocess.run(["st-flash", "write", binpath, "0x8000000"],
stdout=sys.stdout.buffer, stderr=sys.stdout.buffer)
print("Flashed, now running benchmarks..".format(binary))
state = 'waiting'
marker = b''
# This parses test vector output starting with a number of leading '=',
# and expects a hashtag '#' after the test vector output.
while True:
x = dev.read()
if x == b'' and state == 'waiting':
print("timed out while waiting for the markers")
benchmarkBinary(benchmark, binary)
return
if state == 'waiting':
if x == b'=':
marker += x
continue
# If we saw at least 5 equal signs, assume we've probably started
elif marker.count(b'=') > 5:
state = 'beginning'
vector = []
print(" .. found output marker..")
if state == 'beginning':
if x == b'=':
continue
else:
state = 'reading'
elif state == 'reading':
if x == b'#':
break
else:
vector.append(x)
timestamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d%H%M%S')
filename = os.path.join('benchmarks/', benchmark, primitive, scheme, implementation, timestamp)
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, 'w') as f:
f.write(b''.join(vector).decode('utf-8').strip())
print(" .. wrote benchmarks!")
def doBenchmarks(benchmark):
try:
binaries = [x for x in os.listdir('bin') if (benchmark+".bin") in x]
except FileNotFoundError:
print("There is no bin/ folder. Please first make binaries.")
sys.exit(1)
print("This script flashes the benchmarking binaries onto the board, ")
print(" and then writes the resulting output to the benchmarks directory.")
for binary in binaries:
benchmarkBinary(benchmark, binary)
doBenchmarks("stack")
doBenchmarks("speed")