-
Notifications
You must be signed in to change notification settings - Fork 415
Refactor init place for floorplanning #1817
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
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eabd91f
Added a routine to calculate number of tiles covered by a floorplan r…
sfkhalid 5ae899b
Added a sort pl macros function to initial placement so that macros a…
sfkhalid 41c7925
Added comment for new routines and renamed variables for clarity
sfkhalid de0a806
Changed the way the floorplan constraints number is added to the tota…
sfkhalid c90a8b2
Created GridTileLookup class for storing number of tiles of each type…
sfkhalid a1078e2
Made changes to get_region_size function and added get_region_with_su…
sfkhalid 1828622
Added comments for grid tile counting and cleaned up code by removing…
sfkhalid 6cb8e02
Merge branch 'master' into refactor_init_place_for_floorplanning
sfkhalid 13b1f78
Added a comment
sfkhalid 8df329e
Removed unused lines of code
sfkhalid 6f47ee0
Change cumulative total to be the number of subtiles at each location…
sfkhalid 7e0f712
Moved region tile count routines to GridTileLookup class, added comme…
sfkhalid be92c46
Merge branch 'master' into refactor_init_place_for_floorplanning
sfkhalid e1d3211
Added comments to data members of GridTileLookup class
sfkhalid e073a4d
Updated golden results for vtr_reg_qor_chain_predictor_off
sfkhalid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include "grid_tile_lookup.h" | ||
|
||
void GridTileLookup::initialize_grid_tile_matrices() { | ||
auto& device_ctx = g_vpr_ctx.device(); | ||
|
||
//Will store the max number of tile locations for each logical block type | ||
max_tile_counts.resize(device_ctx.logical_block_types.size()); | ||
|
||
for (const auto& type : device_ctx.logical_block_types) { | ||
vtr::NdMatrix<int, 2> type_count({device_ctx.grid.width(), device_ctx.grid.height()}); | ||
fill_type_matrix(&type, type_count); | ||
block_type_matrices.push_back(type_count); | ||
} | ||
} | ||
|
||
void GridTileLookup::fill_type_matrix(t_logical_block_type_ptr block_type, vtr::NdMatrix<int, 2>& type_count) { | ||
auto& device_ctx = g_vpr_ctx.device(); | ||
|
||
int num_rows = device_ctx.grid.height(); | ||
int num_cols = device_ctx.grid.width(); | ||
|
||
/* | ||
* Iterating through every location on the grid to store the number of subtiles of | ||
* the correct type at each location. For each location, we store the cumulative | ||
* number of tiles of the type up to that location - meaning we store the number of | ||
* subtiles at the location, plus the number of subtiles at the locations above and to | ||
* the left of it. | ||
*/ | ||
for (int i_col = type_count.dim_size(0) - 1; i_col >= 0; i_col--) { | ||
for (int j_row = type_count.dim_size(1) - 1; j_row >= 0; j_row--) { | ||
auto& tile = device_ctx.grid[i_col][j_row].type; | ||
type_count[i_col][j_row] = 0; | ||
|
||
if (is_tile_compatible(tile, block_type)) { | ||
for (const auto& sub_tile : tile->sub_tiles) { | ||
if (is_sub_tile_compatible(tile, block_type, sub_tile.capacity.low)) { | ||
type_count[i_col][j_row] = sub_tile.capacity.total(); | ||
} | ||
} | ||
} | ||
|
||
if (i_col < num_cols - 1) { | ||
type_count[i_col][j_row] += type_count[i_col + 1][j_row]; | ||
} | ||
if (j_row < num_rows - 1) { | ||
type_count[i_col][j_row] += type_count[i_col][j_row + 1]; | ||
} | ||
if (i_col < (num_cols - 1) && j_row < (num_rows - 1)) { | ||
type_count[i_col][j_row] -= type_count[i_col + 1][j_row + 1]; | ||
} | ||
} | ||
} | ||
|
||
//The total number of subtiles for the block type will be at [0][0] | ||
max_tile_counts[block_type->index] = type_count[0][0]; | ||
} | ||
|
||
vtr::NdMatrix<int, 2>& GridTileLookup::get_type_grid(t_logical_block_type_ptr block_type) { | ||
return block_type_matrices[block_type->index]; | ||
} | ||
|
||
int GridTileLookup::total_type_tiles(t_logical_block_type_ptr block_type) { | ||
return max_tile_counts[block_type->index]; | ||
} | ||
|
||
/* | ||
* This routine uses pre-computed values from the grids for each block type to get the number of grid tiles | ||
* covered by a region. | ||
* For a region with no subtiles specified, the number of grid tiles can be calculated by adding | ||
* and subtracting four values from within/at the edge of the region. | ||
* The region with subtile case is taken care of by a helper routine, region_with_subtile_count(). | ||
*/ | ||
int GridTileLookup::region_tile_count(const Region& reg, t_logical_block_type_ptr block_type) { | ||
vtr::Rect<int> reg_rect = reg.get_region_rect(); | ||
int subtile = reg.get_sub_tile(); | ||
|
||
int xmin = reg_rect.xmin(); | ||
int ymin = reg_rect.ymin(); | ||
int xmax = reg_rect.xmax(); | ||
int ymax = reg_rect.ymax(); | ||
auto& type_grid = block_type_matrices[block_type->index]; | ||
|
||
int xdim = type_grid.dim_size(0); | ||
int ydim = type_grid.dim_size(1); | ||
|
||
int num_tiles = 0; | ||
|
||
if (subtile == NO_SUBTILE) { | ||
num_tiles = type_grid[xmin][ymin]; | ||
|
||
if ((ymax + 1) < ydim) { | ||
num_tiles -= type_grid[xmin][ymax + 1]; | ||
} | ||
|
||
if ((xmax + 1) < xdim) { | ||
num_tiles -= type_grid[xmax + 1][ymin]; | ||
} | ||
|
||
if ((xmax + 1) < xdim && (ymax + 1) < ydim) { | ||
num_tiles += type_grid[xmax + 1][ymax + 1]; | ||
} | ||
} else { | ||
num_tiles = region_with_subtile_count(reg, block_type); | ||
} | ||
|
||
return num_tiles; | ||
} | ||
|
||
/* | ||
* This routine is for the subtile specified case; an O(region_size) scan needs to be done to check whether each grid | ||
* location in the region is compatible for the block at the subtile specified. | ||
*/ | ||
int GridTileLookup::region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type) { | ||
auto& device_ctx = g_vpr_ctx.device(); | ||
int num_sub_tiles = 0; | ||
vtr::Rect<int> reg_rect = reg.get_region_rect(); | ||
int subtile = reg.get_sub_tile(); | ||
|
||
int xmin = reg_rect.xmin(); | ||
int ymin = reg_rect.ymin(); | ||
int xmax = reg_rect.xmax(); | ||
int ymax = reg_rect.ymax(); | ||
|
||
for (int i = xmax; i >= xmin; i--) { | ||
for (int j = ymax; j >= ymin; j--) { | ||
auto& tile = device_ctx.grid[i][j].type; | ||
if (is_sub_tile_compatible(tile, block_type, subtile)) { | ||
num_sub_tiles++; | ||
} | ||
} | ||
} | ||
|
||
return num_sub_tiles; | ||
} | ||
|
||
void GridTileLookup::print_type_matrix(vtr::NdMatrix<int, 2>& type_count) { | ||
for (int i_col = type_count.dim_size(0) - 1; i_col >= 0; i_col--) { | ||
for (int j_row = type_count.dim_size(1) - 1; j_row >= 0; j_row--) { | ||
VTR_LOG("%d ", type_count[i_col][j_row]); | ||
} | ||
VTR_LOG("\n"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This class is used to store a grid for each logical block type that stores the cumulative number of subtiles | ||
* for that type available at each location in the grid. The cumulative number of subtiles is the subtiles at the | ||
* location plus the subtiles available at the grid locations above and to the left of the locations. | ||
* Having these grids allows for O(1) lookups about the number of subtiles available for a given type of block | ||
* in a rectangular region. | ||
* This lookup class is used during initial placement when sorting blocks by the size of their floorplan constraint | ||
* regions. | ||
*/ | ||
#ifndef VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_ | ||
#define VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_ | ||
|
||
#include "place_util.h" | ||
#include "globals.h" | ||
|
||
class GridTileLookup { | ||
public: | ||
vtr::NdMatrix<int, 2>& get_type_grid(t_logical_block_type_ptr block_type); | ||
|
||
void initialize_grid_tile_matrices(); | ||
|
||
void fill_type_matrix(t_logical_block_type_ptr block_type, vtr::NdMatrix<int, 2>& type_count); | ||
|
||
void print_type_matrix(vtr::NdMatrix<int, 2>& type_count); | ||
|
||
int region_tile_count(const Region& reg, t_logical_block_type_ptr block_type); | ||
|
||
int region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type); | ||
|
||
int total_type_tiles(t_logical_block_type_ptr block_type); | ||
|
||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private: | ||
std::vector<vtr::NdMatrix<int, 2>> block_type_matrices; | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::vector<int> max_tile_counts; | ||
}; | ||
|
||
#endif /* VPR_SRC_PLACE_GRID_TILE_LOOKUP_H_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.