Skip to content

Commit

Permalink
vpr: place: update layer min/max when cube bounding box is used
Browse files Browse the repository at this point in the history
  • Loading branch information
amin1377 committed Apr 3, 2024
1 parent 36ceeca commit 445e6d0
Showing 1 changed file with 107 additions and 8 deletions.
115 changes: 107 additions & 8 deletions vpr/src/place/place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2826,8 +2826,8 @@ static void get_bb_from_scratch(ClusterNetId net_id,
t_bb& coords,
t_bb& num_on_edges,
vtr::NdMatrixProxy<int, 1> num_sink_pin_layer) {
int pnum, x, y, pin_layer, xmin, xmax, ymin, ymax;
int xmin_edge, xmax_edge, ymin_edge, ymax_edge;
int pnum, x, y, pin_layer, xmin, xmax, ymin, ymax, layer_min, layer_max;
int xmin_edge, xmax_edge, ymin_edge, ymax_edge, layer_min_edge, layer_max_edge;

auto& cluster_ctx = g_vpr_ctx.clustering();
auto& place_ctx = g_vpr_ctx.placement();
Expand All @@ -2841,9 +2841,11 @@ static void get_bb_from_scratch(ClusterNetId net_id,
+ physical_tile_type(bnum)->pin_width_offset[pnum];
y = place_ctx.block_locs[bnum].loc.y
+ physical_tile_type(bnum)->pin_height_offset[pnum];
pin_layer = place_ctx.block_locs[bnum].loc.layer;

x = max(min<int>(x, grid.width() - 2), 1);
y = max(min<int>(y, grid.height() - 2), 1);
pin_layer = max(min<int>(pin_layer, grid.get_num_layers()), 0);

xmin = x;
ymin = y;
Expand All @@ -2854,6 +2856,11 @@ static void get_bb_from_scratch(ClusterNetId net_id,
xmax_edge = 1;
ymax_edge = 1;

layer_min = pin_layer;
layer_max = pin_layer;
layer_min_edge = 1;
layer_max_edge = 1;

for (int layer_num = 0; layer_num < grid.get_num_layers(); layer_num++) {
num_sink_pin_layer[layer_num] = 0;
}
Expand All @@ -2876,6 +2883,7 @@ static void get_bb_from_scratch(ClusterNetId net_id,

x = max(min<int>(x, grid.width() - 2), 1); //-2 for no perim channels
y = max(min<int>(y, grid.height() - 2), 1); //-2 for no perim channels
pin_layer = max(min<int>(pin_layer, grid.get_num_layers()), 0);

if (x == xmin) {
xmin_edge++;
Expand Down Expand Up @@ -2903,6 +2911,19 @@ static void get_bb_from_scratch(ClusterNetId net_id,
ymax_edge = 1;
}

if (pin_layer == layer_min) {
layer_min_edge++;
}
if (pin_layer == layer_max) {
layer_max_edge++;
} else if (pin_layer < layer_min) {
layer_min = pin_layer;
layer_min_edge = 1;
} else if (pin_layer > layer_max) {
layer_max = pin_layer;
layer_max_edge++;
}

num_sink_pin_layer[pin_layer]++;
}

Expand All @@ -2912,11 +2933,15 @@ static void get_bb_from_scratch(ClusterNetId net_id,
coords.xmax = xmax;
coords.ymin = ymin;
coords.ymax = ymax;
coords.layer_min = layer_min;
coords.layer_max = layer_max;

num_on_edges.xmin = xmin_edge;
num_on_edges.xmax = xmax_edge;
num_on_edges.ymin = ymin_edge;
num_on_edges.ymax = ymax_edge;
num_on_edges.layer_min = layer_min_edge;
num_on_edges.layer_max = layer_max_edge;
}

/* This routine finds the bounding box of each net from scratch when the bounding box is of type per-layer (i.e. *
Expand Down Expand Up @@ -3127,13 +3152,13 @@ static double get_net_cost(ClusterNetId net_id,
* chany_place_cost_fac[bbptr.xmax][bbptr.xmin - 1];

if (is_multi_layer) {
const auto& move_ctx = g_placer_ctx.move();
int src_layer = 0;


int num_cross_layer_sink = OPEN;
if (num_sink_per_layer[(size_t)net_id][0] > num_sink_per_layer[(size_t)net_id][1]) {
num_cross_layer_sink = num_sink_per_layer[(size_t)net_id][1];
if (num_sink_per_layer[size_t(net_id)][0] > num_sink_per_layer[size_t(net_id)][1]) {
num_cross_layer_sink = num_sink_per_layer[size_t(net_id)][1];
} else {
num_cross_layer_sink = num_sink_per_layer[(size_t)net_id][0];
num_cross_layer_sink = num_sink_per_layer[size_t(net_id)][0];
}
VTR_ASSERT_DEBUG(num_cross_layer_sink >= 0);

Expand Down Expand Up @@ -3190,7 +3215,7 @@ static void get_non_updateable_bb(ClusterNetId net_id,
vtr::NdMatrixProxy<int, 1> num_sink_pin_layer) {
//TODO: account for multiple physical pin instances per logical pin

int xmax, ymax, xmin, ymin, x, y, layer;
int xmax, ymax, xmin, ymin, layer_max, layer_min, x, y, layer;
int pnum;

auto& cluster_ctx = g_vpr_ctx.clustering();
Expand All @@ -3204,11 +3229,14 @@ static void get_non_updateable_bb(ClusterNetId net_id,
+ physical_tile_type(bnum)->pin_width_offset[pnum];
y = place_ctx.block_locs[bnum].loc.y
+ physical_tile_type(bnum)->pin_height_offset[pnum];
layer = place_ctx.block_locs[bnum].loc.layer;

xmin = x;
ymin = y;
xmax = x;
ymax = y;
layer_min = layer;
layer_max = layer;

for (int layer_num = 0; layer_num < device_ctx.grid.get_num_layers(); layer_num++) {
num_sink_pin_layer[layer_num] = 0;
Expand All @@ -3235,6 +3263,12 @@ static void get_non_updateable_bb(ClusterNetId net_id,
ymax = y;
}

if (layer < layer_min) {
layer_min = layer;
} else if (layer > layer_max) {
layer_max = layer;
}

num_sink_pin_layer[layer]++;
}

Expand All @@ -3250,6 +3284,8 @@ static void get_non_updateable_bb(ClusterNetId net_id,
bb_coord_new.ymin = max(min<int>(ymin, device_ctx.grid.height() - 2), 1); //-2 for no perim channels
bb_coord_new.xmax = max(min<int>(xmax, device_ctx.grid.width() - 2), 1); //-2 for no perim channels
bb_coord_new.ymax = max(min<int>(ymax, device_ctx.grid.height() - 2), 1); //-2 for no perim channels
bb_coord_new.layer_min = max(min<int>(layer_min, device_ctx.grid.get_num_layers()), 0);
bb_coord_new.layer_max = max(min<int>(layer_max, device_ctx.grid.get_num_layers()), 0);
}

static void get_non_updateable_layer_bb(ClusterNetId net_id,
Expand Down Expand Up @@ -3349,8 +3385,11 @@ static void update_bb(ClusterNetId net_id,

pin_new_loc.x = max(min<int>(pin_new_loc.x, device_ctx.grid.width() - 2), 1); //-2 for no perim channels
pin_new_loc.y = max(min<int>(pin_new_loc.y, device_ctx.grid.height() - 2), 1); //-2 for no perim channels
pin_new_loc.layer_num = max(min<int>(pin_new_loc.layer_num, device_ctx.grid.get_num_layers()), 0);

pin_old_loc.x = max(min<int>(pin_old_loc.x, device_ctx.grid.width() - 2), 1); //-2 for no perim channels
pin_old_loc.y = max(min<int>(pin_old_loc.y, device_ctx.grid.height() - 2), 1); //-2 for no perim channels
pin_old_loc.layer_num = max(min<int>(pin_old_loc.layer_num, device_ctx.grid.get_num_layers()), 0);

/* Check if the net had been updated before. */
if (bb_updated_before[net_id] == GOT_FROM_SCRATCH) {
Expand Down Expand Up @@ -3519,6 +3558,66 @@ static void update_bb(ClusterNetId net_id,

/* Now account for the layer motion. */
if (num_layers > 1) {

if (pin_new_loc.layer_num < pin_old_loc.layer_num) {
if(pin_new_loc.layer_num == curr_bb_coord->layer_max) {
if (curr_bb_edge->layer_max == 1) {
bb_edge_new.layer_max = 0;
bb_coord_new.layer_max = 0;
} else {
bb_edge_new.layer_max = curr_bb_edge->layer_max - 1;
bb_coord_new.layer_max = curr_bb_coord->layer_max;
}
} else {
bb_edge_new.layer_max = curr_bb_edge->layer_max;
bb_coord_new.layer_max = curr_bb_coord->layer_max;
}

if (pin_new_loc.layer_num < curr_bb_coord->layer_min) { /* Moved past xmin */
bb_coord_new.layer_min = pin_new_loc.layer_num;
bb_edge_new.layer_min = 1;
} else if (pin_new_loc.layer_num == curr_bb_coord->layer_min) { /* Moved to xmin */
bb_coord_new.layer_min = pin_new_loc.layer_num;
bb_edge_new.layer_min = curr_bb_edge->layer_min + 1;
} else { /* Xmin unchanged. */
bb_coord_new.layer_min = curr_bb_coord->layer_min;
bb_edge_new.layer_min = curr_bb_edge->layer_min;
}

} else if (pin_new_loc.layer_num > pin_old_loc.layer_num) {
if (pin_old_loc.layer_num == curr_bb_coord->layer_min) {
if (curr_bb_edge->layer_min == 1) {
bb_edge_new.layer_min = 0;
bb_coord_new.layer_min = 0;
} else {
bb_edge_new.layer_min = curr_bb_edge->layer_min - 1;
bb_coord_new.layer_min = curr_bb_coord->layer_min;
}
} else {
bb_edge_new.layer_min = curr_bb_edge->layer_min;
bb_coord_new.layer_min = curr_bb_coord->layer_min;
}

if (pin_new_loc.layer_num > curr_bb_coord->layer_max) { /* Moved past xmax. */
bb_coord_new.layer_max = pin_new_loc.layer_num;
bb_edge_new.layer_max = 1;
} else if (pin_new_loc.layer_num == curr_bb_coord->layer_max) { /* Moved to xmax */
bb_coord_new.layer_max = pin_new_loc.layer_num;
bb_edge_new.layer_max = curr_bb_edge->layer_max + 1;
} else { /* Xmax unchanged. */
bb_coord_new.layer_max = curr_bb_coord->layer_max;
bb_edge_new.layer_max = curr_bb_edge->layer_max;
}

} else {
bb_coord_new.layer_min = curr_bb_coord->layer_min;
bb_coord_new.layer_max = curr_bb_coord->layer_max;
bb_edge_new.layer_min = curr_bb_coord->layer_min;
bb_edge_new.layer_max = curr_bb_coord->layer_max;
}

VTR_ASSERT(bb_coord_new.layer_min >= 0 && bb_coord_new.layer_max >= 0);

/* We need to update it only if multiple layers are available */
for (int layer_num = 0; layer_num < num_layers; layer_num++) {
num_sink_pin_layer_new[layer_num] = curr_num_sink_pin_layer[layer_num];
Expand Down

0 comments on commit 445e6d0

Please sign in to comment.