Skip to content

Round compressed grid locations #2509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a01ad1c
do not consider ignored nets in centroid
soheilshahrouz Feb 28, 2024
b2bc727
round centroid point
soheilshahrouz Feb 28, 2024
eb99157
round grid_loc_to_compressed_loc_approx()
soheilshahrouz Feb 28, 2024
106a52a
fix overshadowed declaration
soheilshahrouz Mar 1, 2024
dea9915
update golden restuls for failing strong tests
soheilshahrouz Mar 3, 2024
d3daa98
Merge branch 'master' into round_comp_loc
soheilshahrouz Mar 18, 2024
2dc3760
Merge branch 'master' into round_comp_loc
vaughnbetz Apr 4, 2024
c1118ca
updated golden
soheilshahrouz Apr 10, 2024
d3d8c32
update golden
soheilshahrouz Apr 15, 2024
677c4eb
try to fix vtr_reg_nightly_test1 and vtr_reg_nightly_test1_odin failures
soheilshahrouz May 8, 2024
c958361
Update golden_results in strong_target_pin_util
soheilshahrouz May 8, 2024
ba66b12
remove mmcl from vtr_reg_qor_chain_predictor_off in vtr_reg_nightly_t…
soheilshahrouz Jun 3, 2024
898fdd5
Merge branch 'master' into round_comp_loc
soheilshahrouz Jun 3, 2024
aa131f9
remove mcml from the golden results
soheilshahrouz Jun 3, 2024
c3cf18c
Merge branch 'master' into round_comp_loc
soheilshahrouz Jun 4, 2024
efe606d
Merge branch 'master' into round_comp_loc
soheilshahrouz Jun 6, 2024
89b6bf9
update golden results
soheilshahrouz Jun 7, 2024
d6b7dff
update route_chan_width in vtr_timing_update_diff
soheilshahrouz Jun 10, 2024
55e2328
update min_chan_width_routing_area_total and min_chan_width_routing_a…
soheilshahrouz Jun 11, 2024
88b3970
create a grid in test_compressed_grid
soheilshahrouz Jun 13, 2024
cc2e0c7
fix echo_compressed_grids
soheilshahrouz Jun 13, 2024
c9e423f
unit test for grid_loc_to_compressed_loc_approx()
soheilshahrouz Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/libarchfpga/src/arch_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ std::unordered_set<t_logical_block_type_ptr> get_equivalent_sites_set(t_physical
std::unordered_set<t_logical_block_type_ptr> equivalent_sites;

for (auto& sub_tile : type->sub_tiles) {
for (auto& logical_block : sub_tile.equivalent_sites) {
for (auto logical_block : sub_tile.equivalent_sites) {
equivalent_sites.insert(logical_block);
}
}
Expand Down
4 changes: 3 additions & 1 deletion libs/libarchfpga/src/device_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid
count_instances();
}

DeviceGrid::DeviceGrid(std::string grid_name, vtr::NdMatrix<t_grid_tile, 3> grid, std::vector<t_logical_block_type_ptr> limiting_res)
DeviceGrid::DeviceGrid(std::string grid_name,
vtr::NdMatrix<t_grid_tile, 3> grid,
std::vector<t_logical_block_type_ptr> limiting_res)
: DeviceGrid(std::move(grid_name), std::move(grid)) {
limiting_resources_ = std::move(limiting_res);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/libarchfpga/src/device_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class DeviceGrid {
* @note which can be used for indexing in the second dimension, allowing
* @note traditional 2-d indexing to be used
*/
vtr::NdMatrix<t_grid_tile, 3> grid_; //This stores the grid of complex blocks. It is a a 3D matrix: [0..num_layers-1][0..grid.width()-1][0..grid_height()-1]
vtr::NdMatrix<t_grid_tile, 3> grid_; //This stores the grid of complex blocks. It is a 3D matrix: [0..num_layers-1][0..grid.width()-1][0..grid_height()-1]

///@brief instance_counts_ stores the number of each tile type on each layer. It is initialized in count_instances().
std::vector<std::map<t_physical_tile_type_ptr, size_t>> instance_counts_; /* [layer_num][physical_tile_type_ptr] */
Expand Down
53 changes: 37 additions & 16 deletions vpr/src/place/compressed_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,54 @@
#include "arch_util.h"
#include "globals.h"

/**
* @brief Creates a compressed grid from the given locations.
*
*
* @param locations The location of logical blocks of a specific type.
* [0...layer-1][0...num_instances_on_layer-1] --> (x, y)
* @param num_layers The number of dice.
* @return t_compressed_block_grid The compressed grid created from the given locations.
*/
static t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vector<vtr::Point<int>>>& locations,
int num_layers);


std::vector<t_compressed_block_grid> create_compressed_block_grids() {
auto& device_ctx = g_vpr_ctx.device();
auto& grid = device_ctx.grid;
const int num_layers = grid.get_num_layers();

//Collect the set of x/y locations for each instace of a block type
std::vector<std::vector<std::vector<vtr::Point<int>>>> block_locations(device_ctx.logical_block_types.size()); // [logical_block_type][layer_num][0...num_instance_on_layer] -> (x, y)
for (int block_type_num = 0; block_type_num < (int)device_ctx.logical_block_types.size(); block_type_num++) {
block_locations[block_type_num].resize(num_layers);
//Collect the set of x/y locations for each instance of a block type
// [logical_block_type][layer_num][0...num_instance_on_layer] -> (x, y)
std::vector<std::vector<std::vector<vtr::Point<int>>>> block_locations(device_ctx.logical_block_types.size());

for (const auto& block_type : device_ctx.logical_block_types) {
block_locations[block_type.index].resize(num_layers);
}

for (int layer_num = 0; layer_num < num_layers; layer_num++) {
for (int x = 0; x < (int)grid.width(); ++x) {
for (int y = 0; y < (int)grid.height(); ++y) {
int width_offset = grid.get_width_offset({x, y, layer_num});
int height_offset = grid.get_height_offset(t_physical_tile_loc(x, y, layer_num));
if (width_offset == 0 && height_offset == 0) {

if (width_offset == 0 && height_offset == 0) { // the bottom left corner of a tile
const auto& type = grid.get_physical_type({x, y, layer_num});
auto equivalent_sites = get_equivalent_sites_set(type);

for (auto& block : equivalent_sites) {
for (t_logical_block_type_ptr block_type : equivalent_sites) {
//Only record at block root location
block_locations[block->index][layer_num].emplace_back(x, y);
block_locations[block_type->index][layer_num].emplace_back(x, y);
}
}
}
}
}

// each logical block type has its own compressed grid
std::vector<t_compressed_block_grid> compressed_type_grids(device_ctx.logical_block_types.size());

for (const auto& logical_block : device_ctx.logical_block_types) {
auto compressed_block_grid = create_compressed_block_grid(block_locations[logical_block.index], num_layers);

Expand Down Expand Up @@ -62,22 +80,22 @@ std::vector<t_compressed_block_grid> create_compressed_block_grids() {
}

//Given a set of locations, returns a 2D matrix in a compressed space
t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vector<vtr::Point<int>>>& locations, int num_layers) {
static t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vector<vtr::Point<int>>>& locations,
int num_layers) {
t_compressed_block_grid compressed_grid;

if (locations.empty()) {
return compressed_grid;
}

{
std::vector<std::vector<int>> x_locs(num_layers);
std::vector<std::vector<int>> y_locs(num_layers);
compressed_grid.compressed_to_grid_x.resize(num_layers);
compressed_grid.compressed_to_grid_y.resize(num_layers);

for (int layer_num = 0; layer_num < num_layers; layer_num++) {
auto& layer_x_locs = x_locs[layer_num];
auto& layer_y_locs = y_locs[layer_num];
//Record all the x/y locations seperately
std::vector<int> layer_x_locs;
std::vector<int> layer_y_locs;
//Record all the x/y locations separately
for (auto point : locations[layer_num]) {
layer_x_locs.emplace_back(point.x());
layer_y_locs.emplace_back(point.y());
Expand All @@ -97,6 +115,9 @@ t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vect
}
compressed_grid.compressed_to_grid_x[layer_num] = std::move(layer_x_locs);
compressed_grid.compressed_to_grid_y[layer_num] = std::move(layer_y_locs);

layer_x_locs.clear();
layer_y_locs.clear();
}
}

Expand Down Expand Up @@ -142,7 +163,7 @@ t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vect
}

/*Print the contents of the compressed grids to an echo file*/
void echo_compressed_grids(char* filename, const std::vector<t_compressed_block_grid>& comp_grids) {
void echo_compressed_grids(const char* filename, const std::vector<t_compressed_block_grid>& comp_grids) {
FILE* fp;
fp = vtr::fopen(filename, "w");

Expand All @@ -161,14 +182,14 @@ void echo_compressed_grids(char* filename, const std::vector<t_compressed_block_
fprintf(fp, "\n\nGrid type: %s \n", device_ctx.logical_block_types[i].name);

fprintf(fp, "X coordinates: \n");
for (int j = 0; j < (int)comp_grids[i].compressed_to_grid_x.size(); j++) {
for (int j = 0; j < (int)comp_grids[i].compressed_to_grid_x[layer_num].size(); j++) {
auto grid_loc = comp_grids[i].compressed_loc_to_grid_loc({j, 0, layer_num});
fprintf(fp, "%d ", grid_loc.x);
}
fprintf(fp, "\n");

fprintf(fp, "Y coordinates: \n");
for (int k = 0; k < (int)comp_grids[i].compressed_to_grid_y.size(); k++) {
for (int k = 0; k < (int)comp_grids[i].compressed_to_grid_y[layer_num].size(); k++) {
auto grid_loc = comp_grids[i].compressed_loc_to_grid_loc({0, k, layer_num});
fprintf(fp, "%d ", grid_loc.y);
}
Expand Down
42 changes: 24 additions & 18 deletions vpr/src/place/compressed_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,29 @@ struct t_compressed_block_grid {
* the nearest compressed location to point by rounding it down
*/
inline t_physical_tile_loc grid_loc_to_compressed_loc_approx(t_physical_tile_loc grid_loc) const {
int cx = OPEN;
int cy = OPEN;
int layer_num = grid_loc.layer_num;

auto itr_x = std::lower_bound(compressed_to_grid_x[layer_num].begin(), compressed_to_grid_x[layer_num].end(), grid_loc.x);
if (itr_x == compressed_to_grid_x[layer_num].end())
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x - 1);
else
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x);

auto itr_y = std::lower_bound(compressed_to_grid_y[layer_num].begin(), compressed_to_grid_y[layer_num].end(), grid_loc.y);
if (itr_y == compressed_to_grid_y[layer_num].end())
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y - 1);
else
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y);
auto find_closest_compressed_point = [](int loc, const std::vector<int>& compressed_grid_dim) -> int {
auto itr = std::lower_bound(compressed_grid_dim.begin(), compressed_grid_dim.end(), loc);
int cx;
if (itr < compressed_grid_dim.end() - 1) {
int dist_prev = abs(loc - *itr);
int dist_next = abs(loc - *(itr+1));
if (dist_prev < dist_next) {
cx = std::distance(compressed_grid_dim.begin(), itr);
} else {
cx = std::distance(compressed_grid_dim.begin(), itr + 1);
}
} else if (itr == compressed_grid_dim.end()) {
cx = std::distance(compressed_grid_dim.begin(), itr - 1);
} else {
cx = std::distance(compressed_grid_dim.begin(), itr);
}

return cx;
};

const int layer_num = grid_loc.layer_num;
const int cx = find_closest_compressed_point(grid_loc.x, compressed_to_grid_x[layer_num]);
const int cy = find_closest_compressed_point(grid_loc.y, compressed_to_grid_y[layer_num]);

return {cx, cy, layer_num};
}
Expand Down Expand Up @@ -111,15 +119,13 @@ typedef std::vector<t_compressed_block_grid> t_compressed_block_grids;

std::vector<t_compressed_block_grid> create_compressed_block_grids();

t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vector<vtr::Point<int>>>& locations, int num_layers);

/**
* @brief print the contents of the compressed grids to an echo file
*
* @param filename the name of the file to print to
* @param comp_grids the compressed grids that are used during placement
*
*/
void echo_compressed_grids(char* filename, const std::vector<t_compressed_block_grid>& comp_grids);
void echo_compressed_grids(const char* filename, const std::vector<t_compressed_block_grid>& comp_grids);

#endif
11 changes: 8 additions & 3 deletions vpr/src/place/directed_moves_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ void calculate_centroid_loc(ClusterBlockId b_from,
//iterate over the from block pins
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.block_pins(b_from)) {
ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id);

if (cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
continue;
}

/* Ignore the special case nets which only connects a block to itself *
* Experimentally, it was found that this case greatly degrade QoR */
if (cluster_ctx.clb_nlist.net_sinks(net_id).size() == 1) {
Expand Down Expand Up @@ -122,9 +127,9 @@ void calculate_centroid_loc(ClusterBlockId b_from,
}

//Calculate the centroid location
centroid.x = acc_x / acc_weight;
centroid.y = acc_y / acc_weight;
centroid.layer = acc_layer / acc_weight;
centroid.x = (int)std::round(acc_x / acc_weight);
centroid.y = (int)std::round(acc_y / acc_weight);
centroid.layer = (int)std::round(acc_layer / acc_weight);
}

static std::map<std::string, e_reward_function> available_reward_function = {
Expand Down
Loading
Loading