Skip to content

[ClusterLegalizer] Cluster Legalizer API #2709

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
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
2 changes: 2 additions & 0 deletions vpr/src/base/SetupGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <vector>
#include "physical_types.h"

class DeviceGrid;

///@brief Find the device satisfying the specified minimum resources
/// minimum_instance_counts and target_device_utilization are not required when specifying a fixed layout
DeviceGrid create_device_grid(const std::string& layout_name,
Expand Down
15 changes: 10 additions & 5 deletions vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <cstring>
#include <cmath>

#include "cluster_util.h"
#include "vpr_context.h"
#include "vtr_assert.h"
#include "vtr_math.h"
#include "vtr_log.h"
Expand Down Expand Up @@ -359,9 +361,7 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a

fflush(stdout);

auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
auto& device_ctx = g_vpr_ctx.mutable_device();
helper_ctx.lb_type_rr_graphs = vpr_setup->PackerRRGraph;
device_ctx.pad_loc_type = vpr_setup->PlacerOpts.pad_loc_type;
}

Expand Down Expand Up @@ -613,12 +613,13 @@ bool vpr_pack_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
//Load a previous packing from the .net file
vpr_load_packing(vpr_setup, arch);

//Load cluster_constraints data structure here since loading pack file
load_cluster_constraints();
}

}

// Load cluster_constraints data structure.
load_cluster_constraints();

/* Sanity check the resulting netlist */
check_netlist(packer_opts.pack_verbosity);

Expand Down Expand Up @@ -696,6 +697,7 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
"Must have valid .net filename to load packing");

auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
const AtomContext& atom_ctx = g_vpr_ctx.atom();

/* Ensure we have a clean start with void net remapping information */
cluster_ctx.post_routing_clb_pin_nets.clear();
Expand All @@ -706,8 +708,11 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
vpr_setup.FileNameOpts.verify_file_digests,
vpr_setup.PackerOpts.pack_verbosity);

/* Load the mapping between clusters and their atoms */
init_clb_atoms_lookup(cluster_ctx.atoms_lookup, atom_ctx, cluster_ctx.clb_nlist);

process_constant_nets(g_vpr_ctx.mutable_atom().nlist,
g_vpr_ctx.atom().lookup,
atom_ctx.lookup,
cluster_ctx.clb_nlist,
vpr_setup.constant_net_method,
vpr_setup.PackerOpts.pack_verbosity);
Expand Down
16 changes: 7 additions & 9 deletions vpr/src/base/vpr_constraints_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
#include "vpr_constraints_serializer.h"
#include "vpr_constraints_uxsdcxx.h"

#include "vtr_time.h"
#include "vpr_context.h"

#include "globals.h"
#include "pugixml.hpp"
#include "pugixml_util.hpp"
#include "clustered_netlist_utils.h"

#include <fstream>
#include <unordered_set>
#include "vpr_constraints_writer.h"
#include "region.h"
#include "re_cluster_util.h"

/**
* @brief Create a partition with the given name and a single region.
Expand All @@ -30,7 +28,6 @@ static Partition create_partition(const std::string& part_name, const Region& re

void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions) {
VprConstraints constraints;

if (horizontal_partitions != 0 && vertical_partitions != 0) {
setup_vpr_floorplan_constraints_cutpoints(constraints, horizontal_partitions, vertical_partitions);
} else {
Expand Down Expand Up @@ -83,16 +80,17 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
part.set_part_region(pr);
constraints.mutable_place_constraints().add_partition(part);

const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);

const std::unordered_set<AtomBlockId>& atoms = cluster_ctx.atoms_lookup[blk_id];
for (AtomBlockId atom_id : atoms) {
constraints.mutable_place_constraints().add_constrained_atom(atom_id, partid);
}
part_id++;
}
}

void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints) {
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
int horizontal_cutpoints,
int vertical_cutpoints) {
auto& cluster_ctx = g_vpr_ctx.clustering();
auto& block_locs = g_vpr_ctx.placement().block_locs();
auto& device_ctx = g_vpr_ctx.device();
Expand Down Expand Up @@ -158,7 +156,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
* appropriate region accordingly
*/
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
const std::unordered_set<AtomBlockId>& atoms = cluster_ctx.atoms_lookup[blk_id];
int x = block_locs[blk_id].loc.x;
int y = block_locs[blk_id].loc.y;
int width = device_ctx.grid.width();
Expand Down
16 changes: 13 additions & 3 deletions vpr/src/base/vpr_constraints_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_
#define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_

class VprConstraints;

/**
* @brief Write out floorplan constraints to an XML file based on current placement
*
Expand All @@ -35,7 +37,11 @@
* @param subtile Specifies whether to write out the constraint regions with or without
* subtile values.
*/
void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions);
void write_vpr_floorplan_constraints(const char* file_name,
int expand,
bool subtile,
int horizontal_partitions,
int vertical_partitions);

/**
* @brief Populates VprConstraints by creating a partition for each clustered block.
Expand All @@ -50,7 +56,9 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
* @param subtile Specifies whether to write out the constraint regions with or without
* subtile values.
*/
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile);
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
int expand,
bool subtile);

/**
* @brief Populates VprConstraints by dividing the grid into multiple partitions.
Expand All @@ -62,6 +70,8 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
* @param horizontal_cutpoints The number of horizontal cut-lines.
* @param vertical_cutpoints The number of vertical cut_lines.
*/
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints);
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
int horizontal_cutpoints,
int vertical_cutpoints);

#endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */
80 changes: 12 additions & 68 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#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"
Expand Down Expand Up @@ -78,12 +79,6 @@ struct AtomContext : public Context {

/// @brief Mappings to/from the Atom Netlist to physically described .blif models
AtomLookup lookup;

/// @brief Prepacker object which performs prepacking and stores the pack
/// molecules. Has a method to get the pack molecule of an AtomBlock.
/// TODO: This is mainly only used in the clusterer. It can probably be
/// removed from the AtomContext entirely.
Prepacker prepacker;
};

/**
Expand Down Expand Up @@ -286,69 +281,23 @@ struct ClusteringContext : public Context {
* CLB Netlist
********************************************************************/

///@brief New netlist class derived from Netlist
/// @brief New netlist class derived from Netlist
ClusteredNetlist clb_nlist;

/* Database for nets of each clb block pin after routing stage
* - post_routing_clb_pin_nets:
* mapping of pb_type pins to clustered net ids
* - pre_routing_net_pin_mapping:
* a copy of mapping for current pb_route index to previous pb_route index
* Record the previous pin mapping for finding the correct pin index during timing analysis
*/
/// @brief Database for nets of each clb block pin after routing stage.
/// - post_routing_clb_pin_nets:
/// mapping of pb_type pins to clustered net ids.
/// - pre_routing_net_pin_mapping:
/// a copy of mapping for current pb_route index to previous pb_route index
/// Record the previous pin mapping for finding the correct pin index during
/// timing analysis.
std::map<ClusterBlockId, std::map<int, ClusterNetId>> post_routing_clb_pin_nets;
std::map<ClusterBlockId, std::map<int, int>> pre_routing_net_pin_mapping;
};

/**
* @brief State relating to helper data structure using in the clustering stage
*
* This should contain helper data structures that are useful in the clustering/packing stage.
* They are encapsulated here as they are useful in clustering and reclustering algorithms that may be used
* in packing or placement stages.
*/
struct ClusteringHelperContext : public Context {
// A map used to save the number of used instances from each logical block type.
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;

// Stats keeper for placement information during packing/clustering
t_cluster_placement_stats* cluster_placement_stats;

// total number of models in the architecture
int num_models;

int max_cluster_size;
t_pb_graph_node** primitives_list;

bool enable_pin_feasibility_filter;
int feasible_block_array_size;

// total number of CLBs
int total_clb_num;

// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;

// the utilization of external input/output pins during packing (between 0 and 1)
t_ext_pin_util_targets target_external_pin_util;

// During clustering, a block is related to un-clustered primitives with nets.
// This relation has three types: low fanout, high fanout, and transitive
// high_fanout_thresholds stores the threshold for nets to a block type to be considered high fanout
t_pack_high_fanout_thresholds high_fanout_thresholds;

// A vector of unordered_sets of AtomBlockIds that are inside each clustered block [0 .. num_clustered_blocks-1]
// unordered_set for faster insertion/deletion during the iterative improvement process of packing
/// @brief A vector of unordered_sets of AtomBlockIds that are inside each
/// clustered block [0 .. num_clustered_blocks-1]
/// This is populated when the packing is loaded.
vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>> atoms_lookup;

/** Stores the NoC group ID of each atom block. Atom blocks that belong
* to different NoC groups can't be clustered with each other into the
* same clustered block.*/
vtr::vector<AtomBlockId, NocGroupId> atom_noc_grp_id;

~ClusteringHelperContext() {
delete[] primitives_list;
}
};

/**
Expand Down Expand Up @@ -728,9 +677,6 @@ class VprContext : public Context {
const ClusteringContext& clustering() const { return clustering_; }
ClusteringContext& mutable_clustering() { return clustering_; }

const ClusteringHelperContext& cl_helper() const { return helper_; }
ClusteringHelperContext& mutable_cl_helper() { return helper_; }

const PlacementContext& placement() const { return placement_; }
PlacementContext& mutable_placement() { return placement_; }

Expand Down Expand Up @@ -760,8 +706,6 @@ class VprContext : public Context {
PowerContext power_;

ClusteringContext clustering_;
ClusteringHelperContext helper_;

PlacementContext placement_;
RoutingContext routing_;
FloorplanningContext constraints_;
Expand Down
9 changes: 0 additions & 9 deletions vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,6 @@ enum class e_cluster_seed {
BLEND2
};

enum class e_block_pack_status {
BLK_PASSED,
BLK_FAILED_FEASIBLE,
BLK_FAILED_ROUTE,
BLK_FAILED_FLOORPLANNING,
BLK_FAILED_NOC_GROUP,
BLK_STATUS_UNDEFINED
};

struct t_ext_pin_util {
t_ext_pin_util() = default;
t_ext_pin_util(float in, float out)
Expand Down
Loading
Loading