-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark-karatsuba.py
executable file
·69 lines (64 loc) · 2.09 KB
/
benchmark-karatsuba.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
#!/usr/bin/env python3
import serial
import subprocess
from math import ceil
dev = serial.Serial("/dev/ttyUSB0", 115200)
results = []
for i in range(1, 1025):
layers = 1
while True:
t = ceil(i / (2 ** layers))
if t < 2:
break
if t > 48:
layers += 1
continue
binary = f"benchmark-karatsuba_{i}_{t}.bin"
print(f">>> making {binary}")
subprocess.run(["make", binary])
print("done")
print(f">>> flashing {binary}")
subprocess.run(["st-flash", "--reset", "write", binary, "0x8000000"])
print("done")
state = 'waiting'
marker = b''
while True:
x = dev.read()
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)
vector = b''.join(vector).decode('utf-8', errors='ignore').split("\n")
for j in range(len(vector)):
if vector[j] == "n: ":
n = int(vector[j+1])
if vector[j] == "t: ":
t = int(vector[j+1])
if vector[j] == "cycles: ":
cycles = int(vector[j+1])
print("## found results")
if vector[j] == "ERROR!":
print("## FOUND AN ERROR!")
results.append([n, t, cycles])
print("| N | t | cycles ")
for result in results:
print(f"| {result[0]} | {result[1]} | {result[2]} ")
layers += 1
print("cleaning up...")
subprocess.run(["make", "clean"])
print("done...")