Skip to content

Commit

Permalink
Upgrades for router statistics
Browse files Browse the repository at this point in the history
* Add p port for network stats tracking
* Add tag field to CSV file
* Remove "trace_en" dependency
* Update testbench
* Add preliminary heatmap script
  • Loading branch information
drichmond committed Oct 26, 2021
1 parent d385ab8 commit bbb2c57
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
67 changes: 67 additions & 0 deletions software/py/router_heatmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!env python3
# Preliminary script.

# For now, run this script from inside of the directory that contains router_stat.csv

import pandas as pd

# Read the CSV into pandas
df = pd.read_csv("router_stat.csv")

# Find the minimum and maximum cycle
cmin = df.global_ctr.min()
cmax = df.global_ctr.max()
# Keep only minimum and maximum entries
df = df[(df.global_ctr == df.global_ctr.min()) | (df.global_ctr == df.global_ctr.max())]
# Stringify the minimum and maximum entries
df["Type"] = df.global_ctr.map({cmax: "End", cmin:"Start"})

# Map the Request and Response directions
df.XY_order = df.XY_order.map({0:"Response", 1:"Request"})

# Drop unnecessary rows
p = df.drop(["timestamp", "global_ctr", "tag"], axis = 1)
duration = cmax - cmin
p.idle = 100.0 * p.idle / duration
p.utilized = 100.0 * p.utilized / duration
p.stalled = 100.0 * p.stalled / duration
p.arbitrated = 100.0 * p.arbitrated / duration
# Map output directions to human readable strings
p.output_dir = p.output_dir.map({0: "0 - P (Router Output)",
1:"1 - W (Router Output)",
2:"2 - E (Router Output)",
3:"3 - N (Router Output)",
4:"4 - S (Router Output)",
5:"5 - RW (Router Output)",
6 :"6 - RE (Router Output)",
15: "0 - P (Router Input)"})

# Map Y indicies to "Index (Type)"
ys = p.y[p.y != 0].unique()
type_map = {y_i:f"{y_i:02d} (T)" for y_i in ys}
type_map[ys.max()] = f"{ys.max():02d} (V)"
type_map[ys.min()] = f"{ys.min():02d} (V)"
type_map[0] = "00 (H)"
p.y = p.y.map(type_map)

# Create a hierarchical index
p = p.set_index(["Type", "XY_order", "output_dir", "y", "x"])

# Select the columns we will print.
f = p[["utilized", "stalled", "arbitrated", "idle"]].copy()
f = f.loc[("End")] - f.loc[("Start")]
f.columns = f.columns.map(lambda x : f"{x:>11}")

with open("router_heatmap.rpt", "w") as fd:
data = f.unstack()
for n in list(data.index.get_level_values('XY_order').unique()):
for d in list(data.index.get_level_values('output_dir').unique()):
row = data.loc[(n, d)]
s = row.to_string(float_format="%5.1f")
if(d == "0 - P (Router Input)"):
s = s.replace("arbitrated", "Stalled by Arbitration")
else:
s = s.replace("arbitrated", "Utilized by Arbitration")
fd.write(f"{d}, {n} Network")
fd.write(s)
fd.write("\n\n")
1 change: 1 addition & 0 deletions testbenches/common/v/bsg_nonsynth_manycore_testbench.v
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ if (enable_router_profiling_p) begin
,.global_ctr_i($root.`HOST_MODULE_PATH.global_ctr)
,.trace_en_i($root.`HOST_MODULE_PATH.trace_en)
,.print_stat_v_i($root.`HOST_MODULE_PATH.print_stat_v)
,.print_stat_tag_i($root.`HOST_MODULE_PATH.print_stat_tag)
);
end

Expand Down
31 changes: 27 additions & 4 deletions testbenches/common/v/router_profiler.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
// {timestamp},{global_ctr},{x},{y},{XY_order_p},{output_dir},{idle},{utilized},{stalled},{arbitrated}

module router_profiler
import bsg_noc_pkg::*;
#(parameter x_cord_width_p="inv"
, parameter y_cord_width_p="inv"
, parameter data_width_p=32
, parameter dims_p="inv"
, parameter XY_order_p="inv"
, parameter dirs_lp = 1+(2*dims_p)
Expand All @@ -26,6 +28,11 @@ module router_profiler
, input reset_i


, input [dirs_lp-1:0] v_i
, input [dirs_lp-1:0] ready_i
, input [dirs_lp-1:0] yumi_o

, input [dirs_lp-1:0][dirs_lp-1:0] req
, input [dirs_lp-1:0][dirs_lp-1:0] req_t
, input [dirs_lp-1:0][dirs_lp-1:0] yumi_lo

Expand All @@ -34,6 +41,7 @@ module router_profiler

, input trace_en_i
, input print_stat_v_i
, input [data_width_p-1:0] print_stat_tag_i
, input [31:0] global_ctr_i
);

Expand All @@ -48,13 +56,19 @@ module router_profiler


router_stat_s [dirs_lp-1:0] stat_r;
router_stat_s stat_p_r;


always_ff @ (posedge clk_i) begin
if (reset_i) begin
stat_r <= '0;
stat_p_r <= '0;
end
else begin
stat_p_r.idle <= stat_p_r.idle + (v_i[P] == 0);
stat_p_r.utilized <= stat_p_r.utilized + (v_i[P] & yumi_o[P]);
stat_p_r.stalled <= stat_p_r.stalled + (v_i[P] & !yumi_o[P]);
stat_p_r.arbitrated <= stat_p_r.arbitrated + (v_i[P] & !yumi_o[P] & ((req[P] & ready_i) != '0));
for (integer i = 0; i < dirs_lp; i++) begin
stat_r[i].idle <= stat_r[i].idle + ($countones(req_t[i]) == 0);
stat_r[i].utilized <= stat_r[i].utilized + ((req_t[i] & yumi_lo[i]) != '0);
Expand Down Expand Up @@ -85,7 +99,7 @@ module router_profiler
& (XY_order_p == 1)) begin

fd = $fopen(tracefile_p, "a");
$fwrite(fd,"timestamp,global_ctr,x,y,XY_order,output_dir,idle,utilized,stalled,arbitrated\n");
$fwrite(fd,"timestamp,global_ctr,tag,x,y,XY_order,output_dir,idle,utilized,stalled,arbitrated\n");
$fclose(fd);

end
Expand All @@ -96,17 +110,26 @@ module router_profiler

// when there is print_stat_v_i signal received, it dumps the stats.
always @ (posedge clk_i) begin
if (~reset_i & trace_en_i & print_stat_v_i) begin
if (~reset_i & print_stat_v_i) begin
fd = $fopen(tracefile_p, "a");
for (integer i = 0; i < dirs_lp; i++) begin
$fwrite(fd, "%0t,%0d,%0d,%0d,%0d,%0d,%0d,%0d,%0d,%0d\n",
$time, global_ctr_i, my_x_i, my_y_i, XY_order_p, i,
$fwrite(fd, "%0t,%0d,%0x,%0d,%0d,%0d,%0d,%0d,%0d,%0d,%0d\n",
$time, global_ctr_i, print_stat_tag_i, my_x_i, my_y_i, XY_order_p, i,
stat_r[i].idle,
stat_r[i].utilized,
stat_r[i].stalled,
stat_r[i].arbitrated
);
end
// Use output_dir = 15 so that it doesn't overlap with potential full ruche implementations
$fwrite(fd, "%0t,%0d,%0x,%0d,%0d,%0d,%0d,%0d,%0d,%0d,%0d\n",
$time, global_ctr_i, print_stat_tag_i, my_x_i, my_y_i, XY_order_p, 15,
stat_p_r.idle,
stat_p_r.utilized,
stat_p_r.stalled,
stat_p_r.arbitrated
);

$fclose(fd);
end
end
Expand Down

0 comments on commit bbb2c57

Please sign in to comment.