Skip to content

Floorplanning during place moves #1704

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 28 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b13814b
Added floorplan constraint checks to the placement move generators
sfkhalid Apr 7, 2021
1c4d515
added comments and changed cluster_floorplanning_check -> cluster_flo…
sfkhalid Apr 8, 2021
88bc674
Took out commented code
sfkhalid Apr 8, 2021
9009b6c
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid Apr 14, 2021
9e84342
Created a helper function (floorplan_legal) to check the floorplannin…
sfkhalid Apr 14, 2021
2c12618
Ran make format
sfkhalid Apr 14, 2021
c124415
Merge 'floorplanning_during_place_moves' of https://github.com/verilo…
sfkhalid Apr 14, 2021
79378a4
Added ability to write our constraints XML files after placement
sfkhalid Apr 22, 2021
77d32e7
removed extra code in write_place_constraints
sfkhalid Apr 27, 2021
5efca5a
Changed serializer file to write using contexts
sfkhalid Apr 28, 2021
fbe99b5
Locking down blocks to each place
sfkhalid Apr 29, 2021
ebfbc75
Added expand and subtile options
sfkhalid Apr 29, 2021
0f910b8
Made minor change to serializer file to get rid of compiler warnings
sfkhalid Apr 29, 2021
c8fef8e
Made subtile option a bool
sfkhalid Apr 29, 2021
26ba44f
Fixed issue where long atom and partition names were not being printe…
sfkhalid May 4, 2021
c8b2a6b
Fixed issue where subtile value would not be printed if it was zero
sfkhalid May 5, 2021
7b2674d
Added comments and did minor function refactoring to routines related…
sfkhalid May 5, 2021
f3d08c4
Removed some unneeded code and changed some function parameters to co…
sfkhalid May 5, 2021
2e7b05d
Added a lookup for which atoms are in a cluster in clustered_netlist_…
sfkhalid May 6, 2021
4c50e8b
Add comment to describe loop that fills in constraints object for wri…
sfkhalid May 6, 2021
76458b5
Merge branch 'master' into floorplanning_during_place_moves
vaughnbetz May 6, 2021
b352690
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid May 6, 2021
efc2dec
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid May 9, 2021
1e80b92
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid May 10, 2021
7df3f45
Commented ClusterAtomsLookup class
sfkhalid May 10, 2021
cbf5a1c
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid May 11, 2021
8376186
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid May 12, 2021
6371351
Merge branch 'master' into floorplanning_during_place_moves
sfkhalid May 13, 2021
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
3 changes: 3 additions & 0 deletions vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void SetupVPR(const t_options* Options,
FileNameOpts->CmosTechFile = Options->CmosTechFile;
FileNameOpts->out_file_prefix = Options->out_file_prefix;
FileNameOpts->read_vpr_constraints_file = Options->read_vpr_constraints_file;
FileNameOpts->write_vpr_constraints_file = Options->write_vpr_constraints_file;

FileNameOpts->verify_file_digests = Options->verify_file_digests;

Expand Down Expand Up @@ -585,6 +586,8 @@ static void SetupPlacerOpts(const t_options& Options, t_placer_opts* PlacerOpts)
PlacerOpts->place_reward_fun = Options.place_reward_fun;
PlacerOpts->place_crit_limit = Options.place_crit_limit;
PlacerOpts->place_agent_algorithm = Options.place_agent_algorithm;
PlacerOpts->place_constraint_expand = Options.place_constraint_expand;
PlacerOpts->place_constraint_subtile = Options.place_constraint_subtile;
}

static void SetupAnalysisOpts(const t_options& Options, t_analysis_opts& analysis_opts) {
Expand Down
23 changes: 23 additions & 0 deletions vpr/src/base/clustered_netlist_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "clustered_netlist_utils.h"
#include "globals.h"
ClusteredPinAtomPinsLookup::ClusteredPinAtomPinsLookup(const ClusteredNetlist& clustered_netlist, const AtomNetlist& atom_netlist, const IntraLbPbPinLookup& pb_gpin_lookup) {
init_lookup(clustered_netlist, atom_netlist, pb_gpin_lookup);
}
Expand Down Expand Up @@ -33,3 +34,25 @@ void ClusteredPinAtomPinsLookup::init_lookup(const ClusteredNetlist& clustered_n
}
}
}

ClusterAtomsLookup::ClusterAtomsLookup() {
init_lookup();
}

void ClusterAtomsLookup::init_lookup() {
auto& atom_ctx = g_vpr_ctx.atom();
auto& cluster_ctx = g_vpr_ctx.clustering();

cluster_atoms.resize(cluster_ctx.clb_nlist.blocks().size());

for (auto atom_blk_id : atom_ctx.nlist.blocks()) {
ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id);

cluster_atoms[clb_index].push_back(atom_blk_id);
}
}

std::vector<AtomBlockId> ClusterAtomsLookup::atoms_in_cluster(ClusterBlockId blk_id) {
std::vector<AtomBlockId> atoms = cluster_atoms[blk_id];
return atoms;
}
18 changes: 18 additions & 0 deletions vpr/src/base/clustered_netlist_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ class ClusteredPinAtomPinsLookup {
vtr::vector<AtomPinId, ClusterPinId> atom_pin_connected_cluster_pin_;
};

/*
* This lookup is used to see which atoms are in each cluster block.
* Getting the atoms inside of a cluster is an order k lookup.
* The data is initialized automatically upon creation of the object.
* The class should only be used after the clustered netlist is created.
*/
class ClusterAtomsLookup {
public:
ClusterAtomsLookup();
std::vector<AtomBlockId> atoms_in_cluster(ClusterBlockId blk_id);

private:
void init_lookup();

private:
//Store the atom ids of the atoms inside each cluster
vtr::vector<ClusterBlockId, std::vector<AtomBlockId>> cluster_atoms;
};
#endif
6 changes: 5 additions & 1 deletion vpr/src/base/gen/vpr_constraints_uxsdcxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "pugixml.hpp"

#include "vpr_constraints_uxsdcxx_interface.h"

//sentinel value for indicating that a subtile has not been specified
constexpr int NO_SUBTILE = -1;

/* All uxsdcxx functions and structs live in this namespace. */
namespace uxsd {

Expand Down Expand Up @@ -730,7 +734,7 @@ inline void write_partition(T& in, std::ostream& os, Context& context) {
for (size_t i = 0, n = in.num_partition_add_region(context); i < n; i++) {
auto child_context = in.get_partition_add_region(i, context);
os << "<add_region";
if ((bool)in.get_add_region_subtile(child_context))
if (in.get_add_region_subtile(child_context) != NO_SUBTILE)
os << " subtile=\"" << in.get_add_region_subtile(child_context) << "\"";
os << " x_high=\"" << in.get_add_region_x_high(child_context) << "\"";
os << " x_low=\"" << in.get_add_region_x_low(child_context) << "\"";
Expand Down
26 changes: 25 additions & 1 deletion vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,11 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
.show_in(argparse::ShowIn::HELP_ONLY);

file_grp.add_argument(args.read_vpr_constraints_file, "--read_vpr_constraints")
.help("Reads the floorplanning constraints from the specified XML file.")
.help("Reads the floorplanning constraints that packing and placement must respect from the specified XML file.")
.show_in(argparse::ShowIn::HELP_ONLY);

file_grp.add_argument(args.write_vpr_constraints_file, "--write_vpr_constraints")
.help("Writes out new floorplanning constraints based on current placement to the specified XML file.")
.show_in(argparse::ShowIn::HELP_ONLY);

file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead")
Expand Down Expand Up @@ -1873,6 +1877,26 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
"Its range equals to [0., 1.].")
.default_value("0.7")
.show_in(argparse::ShowIn::HELP_ONLY);

place_grp.add_argument(args.place_constraint_expand, "--place_constraint_expand")
.help(
"The value used to decide how much to expand the floorplan constraint region when writing"
"a floorplan constraint XML file. Takes in an integer value from zero to infinity."
"If the value is zero, the block stays at the same x, y location. If it is"
"greater than zero the constraint region expands by the specified value in each direction."
"For example, if 1 was specified, a block at the x, y location (1, 1) would have a constraint region"
"of 2x2 centered around (1, 1), from (0, 0) to (2, 2).")
.default_value("0")
.show_in(argparse::ShowIn::HELP_ONLY);

place_grp.add_argument<bool, ParseOnOff>(args.place_constraint_subtile, "--place_constraint_subtile")
.help(
"The bool used to say whether to print subtile constraints when printing a floorplan constraints XML file."
"If it is off, no subtile locations are specified when printing the floorplan constraints."
"If it is on, the floorplan constraints are printed with the subtiles from current placement.")
.default_value("off")
.show_in(argparse::ShowIn::HELP_ONLY);

/*
* place_grp.add_argument(args.place_timing_cost_func, "--place_timing_cost_func")
* .help(
Expand Down
3 changes: 3 additions & 0 deletions vpr/src/base/read_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct t_options {
argparse::ArgValue<std::string> write_rr_graph_file;
argparse::ArgValue<std::string> read_rr_graph_file;
argparse::ArgValue<std::string> read_vpr_constraints_file;
argparse::ArgValue<std::string> write_vpr_constraints_file;

argparse::ArgValue<std::string> write_placement_delay_lookup;
argparse::ArgValue<std::string> read_placement_delay_lookup;
Expand Down Expand Up @@ -128,6 +129,8 @@ struct t_options {
argparse::ArgValue<std::string> place_reward_fun;
//argparse::ArgValue<int> place_timing_cost_func;
argparse::ArgValue<float> place_crit_limit;
argparse::ArgValue<int> place_constraint_expand;
argparse::ArgValue<bool> place_constraint_subtile;

/* Timing-driven placement options only */
argparse::ArgValue<float> PlaceTimingTradeoff;
Expand Down
8 changes: 7 additions & 1 deletion vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include "cluster.h"
#include "output_clustering.h"
#include "vpr_constraints_reader.h"

#include "vpr_constraints_writer.h"
#include "pack_report.h"
#include "overuse_report.h"

Expand Down Expand Up @@ -617,6 +617,7 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
bool vpr_place_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
VTR_LOG("\n");
const auto& placer_opts = vpr_setup.PlacerOpts;
const auto& filename_opts = vpr_setup.FileNameOpts;
if (placer_opts.doPlacement == STAGE_SKIP) {
//pass
} else {
Expand All @@ -635,6 +636,11 @@ bool vpr_place_flow(t_vpr_setup& vpr_setup, const t_arch& arch) {
post_place_sync();
}

//Write out a vpr floorplanning constraints file if the option is specified
if (!filename_opts.write_vpr_constraints_file.empty()) {
write_vpr_floorplan_constraints(filename_opts.write_vpr_constraints_file.c_str(), placer_opts.place_constraint_expand, placer_opts.place_constraint_subtile);
}

return true;
}

Expand Down
123 changes: 84 additions & 39 deletions vpr/src/base/vpr_constraints_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,24 @@
* For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md'
*/

/*
* Used for the PartitionReadContext, which is used when writing out a constraints XML file.
* Groups together the information needed when printing a partition.
*/
struct partition_info {
Partition part;
std::vector<AtomBlockId> atoms;
PartitionId part_id;
};

/*
* The contexts that end with "ReadContext" are used when writing out the XML file.
* The contexts that end with "WriteContext" are used when reading in the XML file.
*/
struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTypes {
using AddAtomReadContext = void*;
using AddRegionReadContext = void*;
using PartitionReadContext = void*;
using AddAtomReadContext = AtomBlockId;
using AddRegionReadContext = Region;
using PartitionReadContext = partition_info;
using PartitionListReadContext = void*;
using VprConstraintsReadContext = void*;
using AddAtomWriteContext = void*;
Expand All @@ -65,6 +79,12 @@ struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTyp

class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstraintsContextTypes> {
public:
VprConstraintsSerializer()
: report_error_(nullptr) {}
VprConstraintsSerializer(VprConstraints constraints)
: constraints_(constraints)
, report_error_(nullptr) {}

void start_load(const std::function<void(const char*)>* report_error_in) final {
// report_error_in should be invoked if VprConstraintsSerializer encounters
// an error during the read.
Expand All @@ -89,8 +109,10 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
* <xs:attribute name="name_pattern" type="xs:string" use="required" />
* </xs:complexType>
*/
virtual inline const char* get_add_atom_name_pattern(void*& /*ctx*/) final {
return temp_.c_str();
virtual inline const char* get_add_atom_name_pattern(AtomBlockId& blk_id) final {
auto& atom_ctx = g_vpr_ctx.atom();
temp_atom_string_ = atom_ctx.nlist.block_name(blk_id);
return temp_atom_string_.c_str();
}

virtual inline void set_add_atom_name_pattern(const char* name_pattern, void*& /*ctx*/) final {
Expand Down Expand Up @@ -141,33 +163,32 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
* <xs:attribute name="subtile" type="xs:int" />
* </xs:complexType>
*/
virtual inline int get_add_region_subtile(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline int get_add_region_subtile(Region& r) final {
return r.get_sub_tile();
}

virtual inline void set_add_region_subtile(int subtile, void*& /*ctx*/) final {
loaded_region.set_sub_tile(subtile);
}

virtual inline int get_add_region_x_high(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline int get_add_region_x_high(Region& r) final {
vtr::Rect<int> rect = r.get_region_rect();
return rect.xmax();
}

virtual inline int get_add_region_x_low(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline int get_add_region_x_low(Region& r) final {
vtr::Rect<int> rect = r.get_region_rect();
return rect.xmin();
}

virtual inline int get_add_region_y_high(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline int get_add_region_y_high(Region& r) final {
vtr::Rect<int> rect = r.get_region_rect();
return rect.ymax();
}

virtual inline int get_add_region_y_low(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline int get_add_region_y_low(Region& r) final {
vtr::Rect<int> rect = r.get_region_rect();
return rect.ymin();
}

/** Generated for complex type "partition":
Expand All @@ -179,8 +200,9 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
* <xs:attribute name="name" type="xs:string" use="required" />
* </xs:complexType>
*/
virtual inline const char* get_partition_name(void*& /*ctx*/) final {
return temp_.c_str();
virtual inline const char* get_partition_name(partition_info& part_info) final {
temp_part_string_ = part_info.part.get_name();
return temp_part_string_.c_str();
}
virtual inline void set_partition_name(const char* name, void*& /*ctx*/) final {
loaded_partition.set_name(name);
Expand All @@ -200,12 +222,11 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
}
}

virtual inline size_t num_partition_add_atom(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline size_t num_partition_add_atom(partition_info& part_info) final {
return part_info.atoms.size();
}
virtual inline void* get_partition_add_atom(int /*n*/, void*& /*ctx*/) final {
return nullptr;
virtual inline AtomBlockId get_partition_add_atom(int n, partition_info& part_info) final {
return part_info.atoms[n];
}

virtual inline void preallocate_partition_add_region(void*& /*ctx*/, size_t /*size*/) final {}
Expand All @@ -223,12 +244,15 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
loaded_region = clear_region;
}

virtual inline size_t num_partition_add_region(void*& /*ctx*/) final {
int i = 0;
return i;
virtual inline size_t num_partition_add_region(partition_info& part_info) final {
PartitionRegion pr = part_info.part.get_part_region();
std::vector<Region> regions = pr.get_partition_region();
return regions.size();
}
virtual inline void* get_partition_add_region(int /*n*/, void*& /*ctx*/) final {
return nullptr;
virtual inline Region get_partition_add_region(int n, partition_info& part_info) final {
PartitionRegion pr = part_info.part.get_part_region();
std::vector<Region> regions = pr.get_partition_region();
return regions[n];
}

/** Generated for complex type "partition_list":
Expand Down Expand Up @@ -256,12 +280,24 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
num_partitions_++;
}
virtual inline size_t num_partition_list_partition(void*& /*ctx*/) final {
int i = 0;
return i;
return constraints_.get_num_partitions();
}

virtual inline void* get_partition_list_partition(int /*n*/, void*& /*ctx*/) final {
return nullptr;
/*
* The argument n is the partition id. Get all the data for partition n so it can be
* written out.
*/
virtual inline partition_info get_partition_list_partition(int n, void*& /*ctx*/) final {
PartitionId partid(n);
Partition part = constraints_.get_partition(partid);
std::vector<AtomBlockId> atoms = constraints_.get_part_atoms(partid);

partition_info part_info;
part_info.part = part;
part_info.part_id = partid;
part_info.atoms = atoms;

return part_info;
}

/** Generated for complex type "vpr_constraints":
Expand Down Expand Up @@ -297,17 +333,26 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
virtual void finish_load() final {
}

//temp data for loads
//temp data for writes
std::string temp_atom_string_;
std::string temp_part_string_;

/*
* Temp data for loads and writes.
* During loads, constraints_ is filled in based on the data read in from the XML file.
* During writes, constraints_ contains the data that is to be written out to the XML file,
* and is passed in via the constructor.
*/
VprConstraints constraints_;
const std::function<void(const char*)>* report_error_;

//temp data structures to be loaded during file reading
Region loaded_region;
Partition loaded_partition;
PartitionRegion loaded_part_region;
VprConstraints constraints_;

//temp string used when a method must return a const char*
std::string temp_;
std::string temp_ = "vpr";

//used to count the number of partitions read in from the file
int num_partitions_ = 0;
Expand Down
Loading