-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.py
127 lines (114 loc) · 3.31 KB
/
simulator.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
Module: simulator
Desp: top wrapper for 2D mesh NoC simulator
version: 0.0.1
requirements: network_map.py,
single_pkt_test.py,
random_pkt_test.py
constant_pkt_test.py
networkx
Changelog: 0.0.1 - initial release
"""
import argparse
import networkx as nx
import time
from network_map import coordinates_2_id
from network_map import coordinates_2_id_list
from network_map import id_2_coordinates
import single_pkt_test as SPT
import random_pkt_test as RPT
import constant_pkt_test as CPT
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
return v
def main(args):
m, n = args.m, args.n
print(args)
# create the network mapping
noc_map = nx.grid_2d_graph(m, n) # (rows, columns)
noc_map_nodes = list(noc_map.nodes)
if args.test_mode == 0:
SPT.sub_simulator(args, noc_map, noc_map_nodes)
elif args.test_mode == 1:
RPT.sub_simulator(args, noc_map, noc_map_nodes)
elif args.test_mode == 2:
CPT.sub_simulator(args, noc_map, noc_map_nodes)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="noc simulator", formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument("--m", type=int, default="4", help="m, number of rows")
parser.add_argument("--n", type=int, default="4", help="n, number of columns")
parser.add_argument(
"--algo_type",
type=int,
default="0",
help="""type of routers to test.
0:basic XY,
1:modified XY,
2:Adaptive Routing,
3:ELRA,
4:CA router
5:all routers""",
)
parser.add_argument("--cycle_limit", type=int, default="1000", help="cycles limit")
parser.add_argument(
"--load_cycles",
type=int,
default="20",
help="cycles to inject packets in test mode 2",
)
parser.add_argument(
"--target_rate",
type=float,
default="5",
help="probability of sending spikes in test mode 1, low 0-10 high",
)
parser.add_argument(
"--test_mode",
type=int,
default="0",
help="0->single pkt test, 1->random pkt test, 2->congestion awareness test",
)
parser.add_argument(
"--runs",
type=int,
default="1",
help="number of runs in random pkt test",
)
parser.add_argument(
"--verbose",
type=int,
default="0",
help="""
0->only num of pkt received per router
1-> L0 + average clk cycles
2-> L1 + all packet information
3-> L2 + heatmap""",
)
parser.add_argument(
"--print_output",
type=str2bool,
default=True,
help="Whether to print simulator output in terminal",
)
parser.add_argument(
"--sim_data_path",
type=str,
default="./sim_data.txt",
help="path to save the simulation data",
)
parser.add_argument(
"--sim_summary_path",
type=str,
default="./sim_summary.txt",
help="path to save the simulation data summary, for random pkt test",
)
args = parser.parse_args()
main(args)