Skip to content
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

[Pack] Removed Global Overfilled Partition Regions #2894

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 2 additions & 8 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
#include <mutex>

#include "FlatPlacementInfo.h"
#include "user_place_constraints.h"
#include "user_route_constraints.h"
#include "vpr_types.h"
#include "vtr_ndmatrix.h"
#include "vtr_optional.h"
#include "vtr_vector.h"
#include "vtr_vector_map.h"
#include "atom_netlist.h"
#include "clustered_netlist.h"
#include "rr_graph_view.h"
#include "rr_graph_storage.h"
#include "rr_graph_builder.h"
#include "rr_node.h"
#include "rr_rc_data.h"
#include "tatum/TimingGraph.hpp"
#include "tatum/TimingConstraints.hpp"
#include "power.h"
Expand All @@ -27,10 +26,7 @@
#include "clock_connection_builders.h"
#include "route_tree.h"
#include "router_lookahead.h"
#include "place_macro.h"
#include "compressed_grid.h"
#include "metadata_storage.h"
#include "vpr_constraints.h"
#include "noc_storage.h"
#include "noc_traffic_flows.h"
#include "noc_routing.h"
Expand Down Expand Up @@ -513,8 +509,6 @@ struct FloorplanningContext : public Context {
*
*/
std::vector<vtr::vector<ClusterBlockId, PartitionRegion>> compressed_cluster_constraints;

std::vector<PartitionRegion> overfull_partition_regions;
};

/**
Expand Down
7 changes: 3 additions & 4 deletions vpr/src/pack/attraction_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ AttractionInfo::AttractionInfo(bool attraction_groups_on) {
}
}

void AttractionInfo::create_att_groups_for_overfull_regions() {
void AttractionInfo::create_att_groups_for_overfull_regions(
const std::vector<PartitionRegion>& overfull_partition_regions) {
const auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
auto& atom_ctx = g_vpr_ctx.atom();
int num_parts = floorplanning_ctx.constraints.get_num_partitions();
Expand All @@ -48,8 +49,6 @@ void AttractionInfo::create_att_groups_for_overfull_regions() {
atom_attraction_group.resize(num_atoms);
fill(atom_attraction_group.begin(), atom_attraction_group.end(), AttractGroupId::INVALID());

const std::vector<PartitionRegion>& overfull_prs = floorplanning_ctx.overfull_partition_regions;

/*
* Create an attraction group for each partition that overlaps with at least one overfull partition
*/
Expand All @@ -58,7 +57,7 @@ void AttractionInfo::create_att_groups_for_overfull_regions() {

const Partition& part = floorplanning_ctx.constraints.get_partition(partid);

for (const PartitionRegion& overfull_pr : overfull_prs) {
for (const PartitionRegion& overfull_pr : overfull_partition_regions) {
PartitionRegion intersect_pr = intersection(part.get_part_region(), overfull_pr);
if (!intersect_pr.empty()) {
AttractionGroup group_info;
Expand Down
5 changes: 4 additions & 1 deletion vpr/src/pack/attraction_groups.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "vtr_vector.h"
#include "atom_netlist_fwd.h"

// Forward declarations
class PartitionRegion;

/**
* @file
* @brief This file defines the AttractionInfo class, which is used to store atoms in attraction groups, which are
Expand Down Expand Up @@ -53,7 +56,7 @@ class AttractionInfo {
* Create attraction groups for the partitions that contain overfull regions (i.e.
* The region has more blocks of a certain type assigned to than are actually available).
*/
void create_att_groups_for_overfull_regions();
void create_att_groups_for_overfull_regions(const std::vector<PartitionRegion>& overfull_partition_regions);

/*
* Create attraction groups for all partitions.
Expand Down
18 changes: 8 additions & 10 deletions vpr/src/pack/constraints_report.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include "constraints_report.h"
#include "cluster_legalizer.h"
#include "globals.h"
#include "grid_tile_lookup.h"

bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_legalizer) {
bool floorplan_constraints_regions_overfull(
std::vector<PartitionRegion>& overfull_partition_regions,
const ClusterLegalizer& cluster_legalizer,
const std::vector<t_logical_block_type>& logical_block_types) {
GridTileLookup grid_tiles;

auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& device_ctx = g_vpr_ctx.device();

const std::vector<t_logical_block_type>& block_types = device_ctx.logical_block_types;

// keep record of how many blocks of each type are assigned to each PartitionRegion
std::unordered_map<PartitionRegion, std::vector<int>> pr_count_info;

Expand All @@ -22,7 +19,7 @@ bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_lega
t_logical_block_type_ptr bt = cluster_legalizer.get_cluster_type(cluster_id);
auto got = pr_count_info.find(pr);
if (got == pr_count_info.end()) {
std::vector<int> block_type_counts(block_types.size(), 0);
std::vector<int> block_type_counts(logical_block_types.size(), 0);
block_type_counts[bt->index]++;
pr_count_info.insert({pr, block_type_counts});
} else {
Expand All @@ -35,15 +32,15 @@ bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_lega
for (const auto& [pr, block_type_counts] : pr_count_info) {
const std::vector<Region>& regions = pr.get_regions();

for (const t_logical_block_type& block_type : block_types) {
for (const t_logical_block_type& block_type : logical_block_types) {
int num_assigned_blocks = block_type_counts[block_type.index];
int num_tiles = std::accumulate(regions.begin(), regions.end(), 0, [&grid_tiles, &block_type](int acc, const Region& reg) -> int {
return acc + grid_tiles.region_tile_count(reg, &block_type);
});

if (num_assigned_blocks > num_tiles) {
floorplan_regions_overfull = true;
floorplanning_ctx.overfull_partition_regions.push_back(pr);
overfull_partition_regions.push_back(pr);
VTR_LOG("\n\nA partition including the following regions has been assigned %d blocks of type %s, "
"but only has %d tiles of that type\n",
num_assigned_blocks, block_type.name.c_str(), num_tiles);
Expand All @@ -62,3 +59,4 @@ bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_lega

return floorplan_regions_overfull;
}

15 changes: 11 additions & 4 deletions vpr/src/pack/constraints_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
* floorplan regions have been packed with too many clusters.
*/

#ifndef VPR_SRC_PACK_CONSTRAINTS_REPORT_H_
#define VPR_SRC_PACK_CONSTRAINTS_REPORT_H_
#pragma once

#include <vector>

class ClusterLegalizer;
class PartitionRegion;
struct t_logical_block_type;

/**
* @brief Check if any constraint partition regions are overfull,
Expand All @@ -23,8 +26,12 @@ class ClusterLegalizer;
* VPR can still work if these assumptions do not hold true, but for tight overlapping
* partitions, the placement engine may fail to find a legal placement.
*
* Adds the overfilled partition regions to the overfull_partition_regions vector.
*
* @return True if there is at least one overfull partition.
*/
bool floorplan_constraints_regions_overfull(const ClusterLegalizer& cluster_legalizer);
bool floorplan_constraints_regions_overfull(
std::vector<PartitionRegion> &overfull_partition_regions,
const ClusterLegalizer& cluster_legalizer,
const std::vector<t_logical_block_type>& logical_block_types);

#endif /* VPR_SRC_PACK_CONSTRAINTS_REPORT_H_ */
1 change: 0 additions & 1 deletion vpr/src/pack/greedy_clusterer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "attraction_groups.h"
#include "cluster_legalizer.h"
#include "cluster_util.h"
#include "constraints_report.h"
#include "greedy_candidate_selector.h"
#include "greedy_seed_selector.h"
#include "physical_types.h"
Expand Down
16 changes: 13 additions & 3 deletions vpr/src/pack/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "constraints_report.h"
#include "globals.h"
#include "greedy_clusterer.h"
#include "partition_region.h"
#include "physical_types_util.h"
#include "prepack.h"
#include "verify_flat_placement.h"
Expand Down Expand Up @@ -99,6 +100,12 @@ bool try_pack(t_packer_opts* packer_opts,
VTR_LOG("%d attraction groups were created during prepacking.\n", attraction_groups.num_attraction_groups());
VTR_LOG("Finish prepacking.\n");

// We keep track of the overfilled partition regions from all pack iterations in
// this vector. This is so that if the first iteration fails due to overfilled
// partition regions, and it fails again, we can carry over the previous failed
// partition regions to the current iteration.
std::vector<PartitionRegion> overfull_partition_regions;

// Verify that the Flat Placement is valid for packing.
if (flat_placement_info.valid) {
unsigned num_errors = verify_flat_placement_for_packing(flat_placement_info,
Expand Down Expand Up @@ -196,7 +203,10 @@ bool try_pack(t_packer_opts* packer_opts,
* is not dense enough and there are floorplan constraints, it is presumed that the constraints are the cause
* of the floorplan not fitting, so attraction groups are turned on for later iterations.
*/
bool floorplan_regions_overfull = floorplan_constraints_regions_overfull(cluster_legalizer);
bool floorplan_regions_overfull = floorplan_constraints_regions_overfull(overfull_partition_regions,
cluster_legalizer,
device_ctx.logical_block_types);

bool floorplan_not_fitting = (floorplan_regions_overfull || g_vpr_ctx.floorplanning().constraints.get_num_partitions() > 0);

if (fits_on_device && !floorplan_regions_overfull) {
Expand Down Expand Up @@ -228,13 +238,13 @@ bool try_pack(t_packer_opts* packer_opts,
*/
} else if (pack_iteration == 1 && floorplan_not_fitting) {
VTR_LOG("Floorplan regions are overfull: trying to pack again using cluster attraction groups. \n");
attraction_groups.create_att_groups_for_overfull_regions();
attraction_groups.create_att_groups_for_overfull_regions(overfull_partition_regions);
attraction_groups.set_att_group_pulls(1);

} else if (pack_iteration >= 2 && pack_iteration < 5 && floorplan_not_fitting) {
if (pack_iteration == 2) {
VTR_LOG("Floorplan regions are overfull: trying to pack again with more attraction groups exploration. \n");
attraction_groups.create_att_groups_for_overfull_regions();
attraction_groups.create_att_groups_for_overfull_regions(overfull_partition_regions);
VTR_LOG("Pack iteration is %d\n", pack_iteration);
} else if (pack_iteration == 3) {
attraction_groups.create_att_groups_for_all_regions();
Expand Down
6 changes: 1 addition & 5 deletions vpr/src/route/clock_connection_builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

#include "globals.h"
#include "arch_util.h"
#include "rr_graph2.h"

#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_error.h"
#include "rr_rc_data.h"

#include <random>
#include <math.h>
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/route/clock_network_builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include "globals.h"

#include "rr_rc_data.h"
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_error.h"

void static populate_segment_values(int seg_index,
std::string name,
Expand Down
1 change: 1 addition & 0 deletions vpr/src/route/rr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>
#include "alloc_and_load_rr_indexed_data.h"
#include "physical_types_util.h"
#include "rr_rc_data.h"
#include "vtr_assert.h"

#include "vtr_util.h"
Expand Down
7 changes: 1 addition & 6 deletions vpr/src/route/rr_graph_timing_params.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#include <cstdio>

#include "vtr_memory.h"

#include "vpr_types.h"
#include "vpr_error.h"

#include "globals.h"
#include "rr_graph.h"
#include "rr_graph_utils.h"
#include "rr_graph2.h"
#include "rr_rc_data.h"
#include "rr_graph_timing_params.h"

/****************** Subroutine definitions *********************************/
Expand Down