-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbarcas.py
82 lines (56 loc) · 2.12 KB
/
barcas.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
from copy import deepcopy
import threading
from circuit import Circuit
from pruning_algorithms.axls import GetInputs, GetOutputs
BASE = "circuits/ripple.carry.4b/"
TOP = "RCA_3_0"
MET = "wce"
RTL = f"{BASE}{TOP}.v"
TB = f"{BASE}{TOP}_tb.v"
SAIF = f"{BASE}{TOP}.saif"
ORIG = f"{BASE}output0.txt"
APPR = f"{BASE}output.txt"
def log (msg):
with open(f"{BASE}log.txt", "a+") as f:
f.write(msg)
print(msg)
def barcas(circuit, max_error):
log(f"Pruning circuit for Max Error of: {max_error}\n")
actual_error = 0
last_stable_circuit = deepcopy(circuit)
modified_circuit = deepcopy(circuit)
for bit in range (0, 4):
for type in ["i","o"]:
if type == "i":
inputs = [f"in1[{bit}]",f"in2[{bit}]"]
nodes = GetInputs(modified_circuit.netl_root, inputs)
else:
outputs = [f"out[{bit}]"]
nodes = GetOutputs(modified_circuit.netl_root, outputs)
#print(nodes)
for node in nodes:
modified_circuit.delete(node.attrib["var"])
obtained_error = modified_circuit.simulate(TB, MET, ORIG, APPR)
nvar = node.attrib["var"];
msg = f"Node Deleted: {nvar}, error({MET}): {obtained_error}\n"
log(msg);
if obtained_error <= max_error:
last_stable_circuit.delete(node.attrib["var"])
actual_error = obtained_error
else:
modified_circuit.undodelete(node.attrib["var"])
if (actual_error == max_error):
break
final_error = last_stable_circuit.simulate(TB, MET, ORIG, APPR, clean=False)
last_stable_circuit.show(show_deletes=True)
input("Press enter...")
msg = f"[FINAL] Expected: {max_error}, Obtained: {final_error}\n"
log(msg)
our_circuit = Circuit(RTL, "NanGate15nm")
for error in [8]: #range (10, 101, 10):
our_circuit.exact_output(TB)
barcas(our_circuit, error)
'''
x = threading.Thread(target=barcas, args=(our_circuit, error,))
x.start()
'''