-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark-toom3.py
executable file
·76 lines (71 loc) · 2.78 KB
/
benchmark-toom3.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
#!/usr/bin/env python3
import serial
import subprocess
from math import ceil, floor
dev = serial.Serial("/dev/ttyUSB0", 115200)
results = []
for i in range(1, 1025):
if ceil(i / 3) & 1: # skip toom3 for n with odd limb sizes
continue
layers = 0
while True:
try:
while True:
t = ceil(ceil(i / 3) / (2 ** layers))
if t < 6:
break
if t > 48:
layers += 1
continue
binary = f"benchmark-toom3_{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
break # if we got here, we do not need to continue while True
except:
continue # if any exception occurred, simply try this i again
print("cleaning up...")
subprocess.run(["make", "clean"])
print("done...")