Skip to content

Commit 268b32c

Browse files
Ravensloftygatecat
authored andcommitted
router2: additional heatmap data
1 parent b3b2392 commit 268b32c

File tree

3 files changed

+135
-7
lines changed

3 files changed

+135
-7
lines changed

common/route/router2.cc

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ struct Router2
11591159
return success;
11601160
}
11611161

1162-
void write_wiretype_heatmap(std::ostream &out)
1162+
void write_congestion_by_wiretype_heatmap(std::ostream &out)
11631163
{
11641164
dict<IdString, std::vector<int>> cong_by_type;
11651165
size_t max_cong = 0;
@@ -1185,6 +1185,33 @@ struct Router2
11851185
}
11861186
}
11871187

1188+
void write_utilisation_by_wiretype_heatmap(std::ostream &out)
1189+
{
1190+
dict<IdString, int> util_by_type;
1191+
for (auto &wd : flat_wires) {
1192+
IdString type = ctx->getWireType(wd.w);
1193+
if (wd.curr_cong > 0)
1194+
util_by_type[type] += wd.curr_cong;
1195+
}
1196+
// Write csv
1197+
for (auto &u : util_by_type)
1198+
out << u.first.c_str(ctx) << "," << u.second << std::endl;
1199+
}
1200+
1201+
void write_congestion_by_coordinate_heatmap(std::ostream &out)
1202+
{
1203+
auto util_by_coord = std::vector<std::vector<int>>(ctx->getGridDimX() + 1, std::vector<int>(ctx->getGridDimY() + 1, 0));
1204+
for (auto &wd : flat_wires)
1205+
if (wd.curr_cong > 1)
1206+
util_by_coord[wd.x][wd.y] += wd.curr_cong;
1207+
// Write csv
1208+
for (auto &x : util_by_coord) {
1209+
for (auto y : x)
1210+
out << y << ",";
1211+
out << std::endl;
1212+
}
1213+
}
1214+
11881215
int mid_x = 0, mid_y = 0;
11891216

11901217
void partition_nets()
@@ -1444,12 +1471,30 @@ struct Router2
14441471
update_congestion();
14451472

14461473
if (!cfg.heatmap.empty()) {
1447-
std::string filename(cfg.heatmap + "_" + std::to_string(iter) + ".csv");
1448-
std::ofstream cong_map(filename);
1449-
if (!cong_map)
1450-
log_error("Failed to open wiretype heatmap %s for writing.\n", filename.c_str());
1451-
write_wiretype_heatmap(cong_map);
1452-
log_info(" wrote wiretype heatmap to %s.\n", filename.c_str());
1474+
{
1475+
std::string filename(cfg.heatmap + "_congestion_by_wiretype_" + std::to_string(iter) + ".csv");
1476+
std::ofstream cong_map(filename);
1477+
if (!cong_map)
1478+
log_error("Failed to open congestion-by-wiretype heatmap %s for writing.\n", filename.c_str());
1479+
write_congestion_by_wiretype_heatmap(cong_map);
1480+
log_info(" wrote congestion-by-wiretype heatmap to %s.\n", filename.c_str());
1481+
}
1482+
{
1483+
std::string filename(cfg.heatmap + "_utilisation_by_wiretype_" + std::to_string(iter) + ".csv");
1484+
std::ofstream cong_map(filename);
1485+
if (!cong_map)
1486+
log_error("Failed to open utilisation-by-wiretype heatmap %s for writing.\n", filename.c_str());
1487+
write_utilisation_by_wiretype_heatmap(cong_map);
1488+
log_info(" wrote utilisation-by-wiretype heatmap to %s.\n", filename.c_str());
1489+
}
1490+
{
1491+
std::string filename(cfg.heatmap + "_congestion_by_coordinate_" + std::to_string(iter) + ".csv");
1492+
std::ofstream cong_map(filename);
1493+
if (!cong_map)
1494+
log_error("Failed to open congestion-by-coordinate heatmap %s for writing.\n", filename.c_str());
1495+
write_congestion_by_coordinate_heatmap(cong_map);
1496+
log_info(" wrote congestion-by-coordinate heatmap to %s.\n", filename.c_str());
1497+
}
14531498
}
14541499
int tmgfail = 0;
14551500
if (timing_driven)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import csv
2+
import sys
3+
4+
import matplotlib.pyplot as plt
5+
6+
data = []
7+
8+
file = 1
9+
try:
10+
while True:
11+
print("{}/heatmap_congestion_by_coordinate_{}.csv".format(sys.argv[1], file))
12+
with open("{}/heatmap_congestion_by_coordinate_{}.csv".format(sys.argv[1], file)) as f:
13+
file_data = []
14+
reader = csv.reader(f, delimiter=',')
15+
for row in reader:
16+
file_data.append([float(x) for x in row if x != ''])
17+
data.append(file_data)
18+
file += 1
19+
except FileNotFoundError:
20+
pass
21+
22+
for i, file_data in enumerate(data):
23+
plt.imshow(file_data, cmap="gray", aspect="equal")
24+
plt.title("heatmap for iteration {}".format(i+1))
25+
plt.tight_layout()
26+
plt.savefig("{}/heatmap_congestion_by_coordinate_{:03}.png".format(sys.argv[1], i), dpi=300)
27+
plt.clf()

python/plot_congestion_by_wiretype.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import csv
2+
import sys
3+
4+
import matplotlib.pyplot as plt
5+
6+
data = {}
7+
max_bars = {}
8+
9+
file = 1
10+
try:
11+
while True:
12+
print("{}/heatmap_congestion_by_wiretype_{}.csv".format(sys.argv[1], file))
13+
with open("{}/heatmap_congestion_by_wiretype_{}.csv".format(sys.argv[1], file)) as f:
14+
reader = csv.reader(f, delimiter=',')
15+
for row in [x for x in reader][1:]:
16+
key = row[0]
17+
values = [float(x) for x in row[1:] if x != '']
18+
# Ignore wires without overuse
19+
values[0] = 0
20+
values[1] = 0
21+
if key not in data:
22+
data[key] = []
23+
max_bars[key] = 0
24+
data[key].append(values)
25+
max_bars[key] = max(max_bars[key], len(values))
26+
file += 1
27+
except FileNotFoundError:
28+
pass
29+
finally:
30+
file -= 1
31+
32+
to_remove = []
33+
for key in data.keys():
34+
if sum([sum(values) for values in data[key]]) == 0:
35+
# Prune entries that never have any overuse to attempt to reduce visual clutter
36+
to_remove.append(key)
37+
else:
38+
# Pad entries as needed
39+
for values in data[key]:
40+
while len(values) < max_bars[key]:
41+
values.append(0)
42+
for key in to_remove:
43+
del data[key]
44+
45+
COLS = 2
46+
for i in range(file):
47+
plt.suptitle("heatmap for iteration {}".format(i))
48+
fig, axs = plt.subplots((len(data.keys())+(COLS-1))//COLS, COLS)
49+
for j, key in enumerate(data.keys()):
50+
if sum(data[key][i]) > 0:
51+
axs[j//COLS, j%COLS].bar([x for x in range(len(data[key][i]))], data[key][i])
52+
axs[j//COLS, j%COLS].set_title(key)
53+
else:
54+
axs[j//COLS, j%COLS].set_axis_off()
55+
plt.savefig("{}/heatmap_congestion_by_wiretype_{:03}.png".format(sys.argv[1], i), dpi=300)
56+
plt.close()

0 commit comments

Comments
 (0)