-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_mult_tests.py
More file actions
97 lines (77 loc) · 3.14 KB
/
Copy pathrun_mult_tests.py
File metadata and controls
97 lines (77 loc) · 3.14 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Run batch multiplication tests using DWM SPIMulator.
Generates energy and latency metrics for multiple (A, B) pairs.
"""
from SPIMulator import process_lines, DBC, SB, memory_size, bit_length
import csv, os
# ---------- Helper functions ----------
def run_mult_test(a_hex, b_hex, bit_length, dbcs, perform_param):
"""Run CPIM sequence for given A and B hex values."""
# Reset metrics
for k in perform_param:
perform_param[k] = 0
total_energy = 0.0
total_cycles = 0
# Create instruction sequence dynamically
lines = [
f"CPIM $0 0x{a_hex} STORE {bit_length} 0 //a\n",
f"CPIM $480 0x{b_hex} STORE {bit_length} 0 //w\n",
f"CPIM $32 $0 MULT 8 0 //a*w\n"
]
# Run simulation
total_energy, total_cycles = process_lines(
lines,
dbcs=dbcs,
perform_param=perform_param,
bit_length=bit_length,
memory_size=memory_size,
total_energy=total_energy,
total_cycles=total_cycles,
SB=SB
)
# Compute final totals (same as main)
total_energy += perform_param['write'] * bit_length * 0.1
total_energy += perform_param['TR_writes'] * 0.3 * bit_length
total_energy += perform_param['read'] * 0.7 * bit_length
total_energy += perform_param['TR_reads'] * 0.504676821 * bit_length
total_energy += perform_param['shift'] * 0.3 * bit_length
total_energy += perform_param['STORE'] * 0
total_energy += perform_param['TR_reads'] * 0.000958797 * bit_length
total_cycles += perform_param['write'] * (9 + 4 + 4 + 4)
total_cycles += perform_param['TR_writes'] * (2 + 9 + 4 + 4 + 4)
total_cycles += perform_param['read'] * (9 + 4 + 4)
total_cycles += perform_param['TR_reads'] * (9 + 4 + 4)
total_cycles += perform_param['shift'] * 2
total_cycles += perform_param['STORE'] * 10
return total_energy, total_cycles, perform_param.copy()
# ---------- Main runner ----------
def main():
dbcs = [DBC() for _ in range(16)]
perform_param = {k: 0 for k in ['write','TR_writes','read','TR_reads','shift','STORE']}
bit_length = 512 # can adjust here
test_pairs = [
("FF", "1F"),
("0F", "0F"),
("A5", "3C"),
("10", "80"),
("01", "FF"),
("AA", "AA"),
]
os.makedirs("results", exist_ok=True)
csv_path = "results/mult_test_results.csv"
with open(csv_path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["A_hex", "B_hex", "Energy", "Cycles",
"write", "TR_writes", "read", "TR_reads", "shift", "STORE"])
for a, b in test_pairs:
energy, cycles, metrics = run_mult_test(a, b, bit_length, dbcs, perform_param)
writer.writerow([a, b, energy, cycles,
metrics["write"], metrics["TR_writes"],
metrics["read"], metrics["TR_reads"],
metrics["shift"], metrics["STORE"]])
print(f"\nMULT {a} × {b}")
print(f"Energy: {energy:.2f} Cycles: {cycles}")
print(f"Metrics: {metrics}")
print(f"\n✅ All results saved to {csv_path}")
if __name__ == "__main__":
main()