Skip to content

Commit

Permalink
Merge branch 'master' into specify_loc_for_custom_SB
Browse files Browse the repository at this point in the history
  • Loading branch information
saaramahmoudi authored Oct 6, 2024
2 parents 2a6d0ff + 999961a commit b3d803b
Show file tree
Hide file tree
Showing 51 changed files with 1,758 additions and 1,550 deletions.
2 changes: 1 addition & 1 deletion vpr/src/analytical_place/full_legalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class APClusterPlacer {
// to share the code.

// Clear the grid locations (stolen from initial_placement)
clear_all_grid_locs(blk_loc_registry);
blk_loc_registry.clear_all_grid_locs();

// Deal with the placement constraints.
propagate_place_constraints();
Expand Down
76 changes: 67 additions & 9 deletions vpr/src/base/blk_loc_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int BlkLocRegistry::tile_pin_index(const ClusterPinId pin) const {
}

int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const {
auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& cluster_ctx = g_vpr_ctx.clustering();

// Get the logical pin index of pin within its logical block type
ClusterPinId pin_id = cluster_ctx.clb_nlist.net_pin(net_id, net_pin_index);
Expand All @@ -45,22 +45,22 @@ int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net
}

void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& location) {
auto& device_ctx = g_vpr_ctx.device();
auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();

const std::string& block_name = cluster_ctx.clb_nlist.block_name(blk_id);

//Check if block location is out of range of grid dimensions
// Check if block location is out of range of grid dimensions
if (location.x < 0 || location.x > int(device_ctx.grid.width() - 1)
|| location.y < 0 || location.y > int(device_ctx.grid.height() - 1)) {
VPR_THROW(VPR_ERROR_PLACE, "Block %s with ID %d is out of range at location (%d, %d). \n",
block_name.c_str(), blk_id, location.x, location.y);
}

//Set the location of the block
// Set the location of the block
block_locs_[blk_id].loc = location;

//Check if block is at an illegal location
// Check if block is at an illegal location
auto physical_tile = device_ctx.grid.get_physical_type({location.x, location.y, location.layer});
auto logical_block = cluster_ctx.clb_nlist.block_type(blk_id);

Expand All @@ -77,13 +77,71 @@ void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& l
location.layer);
}

//Mark the grid location and usage of the block
// Mark the grid location and usage of the block
grid_blocks_.set_block_at_location(location, blk_id);
grid_blocks_.increment_usage({location.x, location.y, location.layer});

place_sync_external_block_connections(blk_id);
}

void BlkLocRegistry::clear_all_grid_locs() {
const auto& device_ctx = g_vpr_ctx.device();

std::unordered_set<int> blk_types_to_be_cleared;
const auto& logical_block_types = device_ctx.logical_block_types;

// Insert all the logical block types into the set except the empty type
// clear_block_type_grid_locs does not expect empty type to be among given types
for (const t_logical_block_type& logical_type : logical_block_types) {
if (!is_empty_type(&logical_type)) {
blk_types_to_be_cleared.insert(logical_type.index);
}
}

clear_block_type_grid_locs(blk_types_to_be_cleared);
}

void BlkLocRegistry::clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index) {
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();

bool clear_all_block_types = false;

/* check if all types should be cleared
* logical_block_types contain empty type, needs to be ignored.
* Not having any type in unplaced_blk_types_index means that it is the first iteration, hence all grids needs to be cleared
*/
if (unplaced_blk_types_index.size() == device_ctx.logical_block_types.size() - 1) {
clear_all_block_types = true;
}

/* We'll use the grid to record where everything goes. Initialize to the grid has no
* blocks placed anywhere.
*/
for (int layer_num = 0; layer_num < device_ctx.grid.get_num_layers(); layer_num++) {
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
const t_physical_tile_type_ptr type = device_ctx.grid.get_physical_type({i, j, layer_num});
int itype = type->index;
if (clear_all_block_types || unplaced_blk_types_index.count(itype)) {
grid_blocks_.set_usage({i, j, layer_num}, 0);
for (int k = 0; k < device_ctx.physical_tile_types[itype].capacity; k++) {
grid_blocks_.set_block_at_location({i, j, k, layer_num}, ClusterBlockId::INVALID());
}
}
}
}
}

// Similarly, mark all blocks as not being placed yet.
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
int blk_type = cluster_ctx.clb_nlist.block_type(blk_id)->index;
if (clear_all_block_types || unplaced_blk_types_index.count(blk_type)) {
block_locs_[blk_id].loc = t_pl_loc();
}
}
}

void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk) {
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& clb_nlist = cluster_ctx.clb_nlist;
Expand Down Expand Up @@ -119,7 +177,7 @@ void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk)
}

void BlkLocRegistry::apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
auto& device_ctx = g_vpr_ctx.device();
const auto& device_ctx = g_vpr_ctx.device();

VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::APPLY);

Expand Down Expand Up @@ -177,7 +235,7 @@ void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_af
}

void BlkLocRegistry::revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
auto& device_ctx = g_vpr_ctx.device();
const auto& device_ctx = g_vpr_ctx.device();

VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT);

Expand Down
13 changes: 13 additions & 0 deletions vpr/src/base/blk_loc_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class BlkLocRegistry {
*/
void set_block_location(ClusterBlockId blk_id, const t_pl_loc& location);

/**
* @brief Initializes the grid to empty. It also initializes the location for
* all blocks to unplaced.
*/
void clear_all_grid_locs();

/**
* @brief Set chosen grid locations to EMPTY block id before each placement iteration
*
* @param unplaced_blk_types_index Block types that their grid locations must be cleared.
*/
void clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index);

/**
* @brief Syncs the logical block pins corresponding to the input iblk with the corresponding chosen physical tile
* @param iblk cluster block ID to sync within the assigned physical tile
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/setup_noc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void create_noc_routers(const t_noc_inf& noc_info,
const vtr::vector<int, t_noc_router_tile_position>& noc_router_tiles) {
// keep track of the router assignments (store the user router id that was assigned to each physical router tile)
// this is used in error checking, after determining the closest physical router for a user described router in the arch file,
// the datastructure below can be used to check if that physical router was already assigned previously
// the data structure below can be used to check if that physical router was already assigned previously
std::vector<int> router_assignments;
router_assignments.resize(noc_router_tiles.size(), PHYSICAL_ROUTER_NOT_ASSIGNED);

Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/setup_noc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct t_noc_router_tile_position {
* @brief Based on the NoC information provided by the user in the architecture
* description file, a NoC model is created. The model defines the
* constraints of the NoC as well as its layout on the FPGA device.
* The datastructure used to define the model is "NocStorage" and that
* The data structure used to define the model is "NocStorage" and that
* is created here and stored within the noc_ctx.
*
* @param arch Contains the parsed information from the architecture
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void vpr_setup_clock_networks(t_vpr_setup& vpr_setup, const t_arch& Arch) {
* constraints. Additionally, the graphics state is updated
* to include a NoC button to display it.
*
* @param vpr_setup A datastructure that stores all the user provided option
* @param vpr_setup A data structure that stores all the user provided option
* to vpr.
* @param arch Contains the parsed information from the architecture
* description file.
Expand Down Expand Up @@ -1327,7 +1327,7 @@ static void free_routing() {
}

/**
* @brief handles the deletion of NoC related datastructures.
* @brief handles the deletion of NoC related data structures.
*/
static void free_noc() {}

Expand Down
15 changes: 8 additions & 7 deletions vpr/src/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void init_draw_coords(float clb_width, const BlkLocRegistry& blk_loc_registry) {
/* Store a reference to block location variables so that other drawing
* functions can access block location information without accessing
* the global placement state, which is inaccessible during placement.*/
set_graphics_blk_loc_registry_ref(blk_loc_registry);
draw_state->set_graphics_blk_loc_registry_ref(blk_loc_registry);

if (!draw_state->show_graphics && !draw_state->save_graphics
&& draw_state->graphics_commands.empty())
Expand Down Expand Up @@ -1004,8 +1004,8 @@ static void highlight_blocks(double x, double y) {
return; /* Nothing was found on any layer*/
}

auto& cluster_ctx = g_vpr_ctx.clustering();
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();

VTR_ASSERT(clb_index != ClusterBlockId::INVALID());

Expand Down Expand Up @@ -1046,14 +1046,15 @@ static void highlight_blocks(double x, double y) {
ClusterBlockId get_cluster_block_id_from_xy_loc(double x, double y) {
t_draw_coords* draw_coords = get_draw_coords_vars();
t_draw_state* draw_state = get_draw_state_vars();
auto clb_index = ClusterBlockId::INVALID();
auto& device_ctx = g_vpr_ctx.device();
auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& grid_blocks = get_graphics_blk_loc_registry_ref().grid_blocks();
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& grid_blocks = draw_state->get_graphics_blk_loc_registry_ref().grid_blocks();

/// determine block ///
ezgl::rectangle clb_bbox;

auto clb_index = ClusterBlockId::INVALID();

//iterate over grid z (layers) first. Start search of the block at the top layer to prioritize highlighting of blocks at higher levels during overlapping of layers.
for (int layer_num = device_ctx.grid.get_num_layers() - 1; layer_num >= 0; layer_num--) {
if (!draw_state->draw_layer_display[layer_num].visible) {
Expand Down
39 changes: 18 additions & 21 deletions vpr/src/draw/draw_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ const std::vector<ezgl::color> kelly_max_contrast_colors = {
void drawplace(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
t_draw_coords* draw_coords = get_draw_coords_vars();
auto& device_ctx = g_vpr_ctx.device();
auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& grid_blocks = get_graphics_blk_loc_registry_ref().grid_blocks();
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& grid_blocks = draw_state->get_graphics_blk_loc_registry_ref().grid_blocks();

ClusterBlockId bnum;
int num_sub_tiles;
Expand Down Expand Up @@ -224,12 +224,9 @@ void drawplace(ezgl::renderer* g) {
void drawnets(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
t_draw_coords* draw_coords = get_draw_coords_vars();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();

ClusterBlockId b1, b2;
auto& cluster_ctx = g_vpr_ctx.clustering();
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();

float transparency_factor;
float NET_ALPHA = draw_state->net_alpha;

g->set_line_dash(ezgl::line_dash::none);
Expand All @@ -250,7 +247,7 @@ void drawnets(ezgl::renderer* g) {
continue;
}

b1 = cluster_ctx.clb_nlist.net_driver_block(net_id);
ClusterBlockId b1 = cluster_ctx.clb_nlist.net_driver_block(net_id);

//The layer of the net driver block
driver_block_layer_num = block_locs[b1].loc.layer;
Expand All @@ -262,7 +259,7 @@ void drawnets(ezgl::renderer* g) {

ezgl::point2d driver_center = draw_coords->get_absolute_clb_bbox(b1, cluster_ctx.clb_nlist.block_type(b1)).center();
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.net_sinks(net_id)) {
b2 = cluster_ctx.clb_nlist.pin_block(pin_id);
ClusterBlockId b2 = cluster_ctx.clb_nlist.pin_block(pin_id);

//the layer of the pin block (net sinks)
sink_block_layer_num =block_locs[b2].loc.layer;
Expand All @@ -272,7 +269,7 @@ void drawnets(ezgl::renderer* g) {
if (!element_visibility.visible) {
continue; /* Don't Draw */
}
transparency_factor = element_visibility.alpha;
float transparency_factor = element_visibility.alpha;

//Take the highest of the 2 transparency values that the user can select from the UI
// Compare the current cross layer transparency to the overall Net transparency set by the user.
Expand Down Expand Up @@ -800,8 +797,8 @@ void draw_placement_macros(ezgl::renderer* g) {
}
t_draw_coords* draw_coords = get_draw_coords_vars();

auto& place_ctx = g_vpr_ctx.placement();
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
const auto& place_ctx = g_vpr_ctx.placement();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();

for (const t_pl_macro& pl_macro : place_ctx.pl_macros) {

Expand Down Expand Up @@ -1184,8 +1181,9 @@ void draw_crit_path_elements(const std::vector<tatum::TimingPath>& paths, const
}

int get_timing_path_node_layer_num(tatum::NodeId node) {
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
auto& atom_ctx = g_vpr_ctx.atom();
t_draw_state* draw_state = get_draw_state_vars();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
const auto& atom_ctx = g_vpr_ctx.atom();

AtomPinId atom_pin = atom_ctx.lookup.tnode_atom_pin(node);
AtomBlockId atom_block = atom_ctx.nlist.pin_block(atom_pin);
Expand Down Expand Up @@ -1415,9 +1413,9 @@ void draw_block_pin_util() {
if (draw_state->show_blk_pin_util == DRAW_NO_BLOCK_PIN_UTIL)
return;

auto& device_ctx = g_vpr_ctx.device();
auto& cluster_ctx = g_vpr_ctx.clustering();
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();

std::map<t_physical_tile_type_ptr, size_t> total_input_pins;
std::map<t_physical_tile_type_ptr, size_t> total_output_pins;
Expand Down Expand Up @@ -1475,9 +1473,8 @@ void draw_block_pin_util() {
}

void draw_reset_blk_colors() {
auto& cluster_ctx = g_vpr_ctx.clustering();
auto blks = cluster_ctx.clb_nlist.blocks();
for (auto blk : blks) {
const auto& cluster_ctx = g_vpr_ctx.clustering();
for (auto blk : cluster_ctx.clb_nlist.blocks()) {
draw_reset_blk_color(blk);
}
}
Expand Down
15 changes: 0 additions & 15 deletions vpr/src/draw/draw_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ static t_draw_state draw_state;
*/
static t_draw_coords draw_coords;

/**
* @brief Stores a reference to a PlaceLocVars to be used in the graphics code.
* @details This reference let us pass in a currently-being-optimized placement state,
* rather than using the global placement state in placement context that is valid only once placement is done
*/
static std::optional<std::reference_wrapper<const BlkLocRegistry>> blk_loc_registry_ref;

/*********************** Accessor Subroutines Definition ********************/

/* This accessor function returns pointer to the global variable
Expand All @@ -47,12 +40,4 @@ t_draw_state* get_draw_state_vars() {
return &draw_state;
}

void set_graphics_blk_loc_registry_ref(const BlkLocRegistry& blk_loc_registry) {
blk_loc_registry_ref = std::ref(blk_loc_registry);
}

const BlkLocRegistry& get_graphics_blk_loc_registry_ref() {
return blk_loc_registry_ref->get();
}

#endif // NO_GRAPHICS
18 changes: 0 additions & 18 deletions vpr/src/draw/draw_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,6 @@ t_draw_coords* get_draw_coords_vars();

t_draw_state* get_draw_state_vars();

/**
* @brief Set the reference to placement location variable.
*
* During the placement stage, this reference should point to a local object
* in the placement stage because the placement stage does not change the
* global stage in place_ctx until the end of placement. After the placement is
* done, the reference should point to the global state stored in place_ctx.
*
* @param blk_loc_registry The PlaceLocVars that the reference will point to.
*/
void set_graphics_blk_loc_registry_ref(const BlkLocRegistry& blk_loc_registry);

/**
* @brief Returns the reference to placement block location variables.
* @return A const reference to placement block location variables.
*/
const BlkLocRegistry& get_graphics_blk_loc_registry_ref();

#endif // NO_GRAPHICS

#endif
Loading

0 comments on commit b3d803b

Please sign in to comment.