|
| 1 | + |
| 2 | +#include "blk_loc_registry.h" |
| 3 | +#include "globals.h" |
| 4 | + |
| 5 | +const vtr::vector_map<ClusterBlockId, t_block_loc>& BlkLocRegistry::block_locs() const { |
| 6 | + return block_locs_; |
| 7 | +} |
| 8 | + |
| 9 | +vtr::vector_map<ClusterBlockId, t_block_loc>& BlkLocRegistry::mutable_block_locs() { |
| 10 | + return block_locs_; |
| 11 | +} |
| 12 | + |
| 13 | +const GridBlock& BlkLocRegistry::grid_blocks() const { |
| 14 | + return grid_blocks_; |
| 15 | +} |
| 16 | + |
| 17 | +GridBlock& BlkLocRegistry::mutable_grid_blocks() { |
| 18 | + return grid_blocks_; |
| 19 | +} |
| 20 | + |
| 21 | +const vtr::vector_map<ClusterPinId, int>& BlkLocRegistry::physical_pins() const { |
| 22 | + return physical_pins_; |
| 23 | +} |
| 24 | + |
| 25 | +vtr::vector_map<ClusterPinId, int>& BlkLocRegistry::mutable_physical_pins() { |
| 26 | + return physical_pins_; |
| 27 | +} |
| 28 | + |
| 29 | +int BlkLocRegistry::tile_pin_index(const ClusterPinId pin) const { |
| 30 | + return physical_pins_[pin]; |
| 31 | +} |
| 32 | + |
| 33 | +int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const { |
| 34 | + auto& cluster_ctx = g_vpr_ctx.clustering(); |
| 35 | + |
| 36 | + // Get the logical pin index of pin within its logical block type |
| 37 | + ClusterPinId pin_id = cluster_ctx.clb_nlist.net_pin(net_id, net_pin_index); |
| 38 | + |
| 39 | + return this->tile_pin_index(pin_id); |
| 40 | +} |
| 41 | + |
| 42 | +void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& location) { |
| 43 | + auto& device_ctx = g_vpr_ctx.device(); |
| 44 | + auto& cluster_ctx = g_vpr_ctx.clustering(); |
| 45 | + |
| 46 | + const std::string& block_name = cluster_ctx.clb_nlist.block_name(blk_id); |
| 47 | + |
| 48 | + //Check if block location is out of range of grid dimensions |
| 49 | + if (location.x < 0 || location.x > int(device_ctx.grid.width() - 1) |
| 50 | + || location.y < 0 || location.y > int(device_ctx.grid.height() - 1)) { |
| 51 | + VPR_THROW(VPR_ERROR_PLACE, "Block %s with ID %d is out of range at location (%d, %d). \n", |
| 52 | + block_name.c_str(), blk_id, location.x, location.y); |
| 53 | + } |
| 54 | + |
| 55 | + //Set the location of the block |
| 56 | + block_locs_[blk_id].loc = location; |
| 57 | + |
| 58 | + //Check if block is at an illegal location |
| 59 | + auto physical_tile = device_ctx.grid.get_physical_type({location.x, location.y, location.layer}); |
| 60 | + auto logical_block = cluster_ctx.clb_nlist.block_type(blk_id); |
| 61 | + |
| 62 | + if (location.sub_tile >= physical_tile->capacity || location.sub_tile < 0) { |
| 63 | + VPR_THROW(VPR_ERROR_PLACE, "Block %s subtile number (%d) is out of range. \n", block_name.c_str(), location.sub_tile); |
| 64 | + } |
| 65 | + |
| 66 | + if (!is_sub_tile_compatible(physical_tile, logical_block, block_locs_[blk_id].loc.sub_tile)) { |
| 67 | + VPR_THROW(VPR_ERROR_PLACE, "Attempt to place block %s with ID %d at illegal location (%d,%d,%d). \n", |
| 68 | + block_name.c_str(), |
| 69 | + blk_id, |
| 70 | + location.x, |
| 71 | + location.y, |
| 72 | + location.layer); |
| 73 | + } |
| 74 | + |
| 75 | + //Mark the grid location and usage of the block |
| 76 | + grid_blocks_.set_block_at_location(location, blk_id); |
| 77 | + grid_blocks_.increment_usage({location.x, location.y, location.layer}); |
| 78 | + |
| 79 | + place_sync_external_block_connections(blk_id); |
| 80 | +} |
| 81 | + |
| 82 | +void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk) { |
| 83 | + const auto& cluster_ctx = g_vpr_ctx.clustering(); |
| 84 | + const auto& clb_nlist = cluster_ctx.clb_nlist; |
| 85 | + |
| 86 | + t_pl_loc block_loc = block_locs_[iblk].loc; |
| 87 | + |
| 88 | + auto physical_tile = physical_tile_type(block_loc); |
| 89 | + auto logical_block = clb_nlist.block_type(iblk); |
| 90 | + |
| 91 | + int sub_tile_index = get_sub_tile_index(iblk, block_locs_); |
| 92 | + auto sub_tile = physical_tile->sub_tiles[sub_tile_index]; |
| 93 | + |
| 94 | + VTR_ASSERT(sub_tile.num_phy_pins % sub_tile.capacity.total() == 0); |
| 95 | + |
| 96 | + int max_num_block_pins = sub_tile.num_phy_pins / sub_tile.capacity.total(); |
| 97 | + /* Logical location and physical location is offset by z * max_num_block_pins */ |
| 98 | + |
| 99 | + int rel_capacity = block_loc.sub_tile - sub_tile.capacity.low; |
| 100 | + |
| 101 | + for (ClusterPinId pin : clb_nlist.block_pins(iblk)) { |
| 102 | + int logical_pin_index = clb_nlist.pin_logical_index(pin); |
| 103 | + int sub_tile_pin_index = get_sub_tile_physical_pin(sub_tile_index, physical_tile, logical_block, logical_pin_index); |
| 104 | + |
| 105 | + int new_physical_pin_index = sub_tile.sub_tile_to_tile_pin_indices[sub_tile_pin_index + rel_capacity * max_num_block_pins]; |
| 106 | + |
| 107 | + auto result = physical_pins_.find(pin); |
| 108 | + if (result != physical_pins_.end()) { |
| 109 | + physical_pins_[pin] = new_physical_pin_index; |
| 110 | + } else { |
| 111 | + physical_pins_.insert(pin, new_physical_pin_index); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments