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 13 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
19 changes: 19 additions & 0 deletions vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,10 @@ 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("Writes the floorplanning constraints from placement to the specified XML file.")
.show_in(argparse::ShowIn::HELP_ONLY);

file_grp.add_argument(args.write_vpr_constraints_file, "--write_vpr_constraints")
.help("Reads the floorplanning constraints from the specified XML file.")
.show_in(argparse::ShowIn::HELP_ONLY);

Expand Down Expand Up @@ -1873,6 +1877,21 @@ 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. If it is zero, the block stays locked in its place. If it is"
"greater than zero the constraint region expands by the specified value in each direction.")
.default_value("0")
.show_in(argparse::ShowIn::HELP_ONLY);

place_grp.add_argument(args.place_constraint_subtile, "--place_constraint_subtile")
.help(
"The value used to specify a subtile constraints when writing a floorplan constraints XML file.")
.default_value("-1")
.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<int> 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 @@ -660,11 +660,17 @@ void vpr_place(t_vpr_setup& vpr_setup, const t_arch& arch) {
arch.num_directs);

auto& filename_opts = vpr_setup.FileNameOpts;
auto& placer_opts = vpr_setup.PlacerOpts;
auto& cluster_ctx = g_vpr_ctx.clustering();

print_place(filename_opts.NetFile.c_str(),
cluster_ctx.clb_nlist.netlist_id().c_str(),
filename_opts.PlaceFile.c_str());

//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);
}
}

void vpr_load_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/base/vpr_constraints_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
void load_vpr_constraints_file(const char* read_vpr_constraints_name) {
vtr::ScopedStartFinishTimer timer("Loading VPR constraints file");

VprConstraintsSerializer reader;
VprConstraints constraints;
VprConstraintsSerializer reader(constraints);

if (vtr::check_file_name_extension(read_vpr_constraints_name, ".xml")) {
try {
Expand Down
97 changes: 59 additions & 38 deletions vpr/src/base/vpr_constraints_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@
*
* For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md'
*/
struct partition_info {
Partition part;
std::vector<AtomBlockId> atoms;
PartitionId part_id;
};

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 +70,11 @@ 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 +99,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();
auto atom_name = atom_ctx.nlist.block_name(blk_id);
return atom_name.c_str();
}

virtual inline void set_add_atom_name_pattern(const char* name_pattern, void*& /*ctx*/) final {
Expand Down Expand Up @@ -141,33 +153,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 +190,8 @@ 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 {
return part_info.part.get_name().c_str();
}
virtual inline void set_partition_name(const char* name, void*& /*ctx*/) final {
loaded_partition.set_name(name);
Expand All @@ -200,12 +211,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 +233,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 +269,20 @@ 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;
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 @@ -298,16 +319,16 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
}

//temp data for loads
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_ = "test";

//used to count the number of partitions read in from the file
int num_partitions_ = 0;
Expand Down
84 changes: 84 additions & 0 deletions vpr/src/base/vpr_constraints_writer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* vpr_constraints_writer.cpp
*
* Author: khalid88
*/

#include "vpr_constraints_serializer.h"
#include "vpr_constraints_uxsdcxx.h"

#include "vtr_time.h"

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

#include <fstream>
#include "vpr_constraints_writer.h"

void write_vpr_floorplan_constraints(const char* file_name, int expand, int subtile) {
auto& place_ctx = g_vpr_ctx.placement();
auto& atom_ctx = g_vpr_ctx.atom();
auto& cluster_ctx = g_vpr_ctx.clustering();

//Fill in all the info needed for locking atoms to their locations
VprConstraints constraints;

std::map<ClusterBlockId, std::vector<AtomBlockId>> cluster_atoms;

for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
cluster_atoms.insert({blk_id, std::vector<AtomBlockId>()});
}

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);
}

int part_id = 0;
for (auto i = cluster_atoms.begin(); i != cluster_atoms.end(); i++) {
std::string part_name;
part_name = cluster_ctx.clb_nlist.block_name(i->first);

PartitionId partid(part_id);

Partition part;
part.set_name(part_name);

PartitionRegion pr;
Region reg;

auto loc = place_ctx.block_locs[i->first].loc;

reg.set_region_rect(loc.x - expand, loc.y - expand, loc.x + expand, loc.y + expand);
reg.set_sub_tile(subtile);

pr.add_to_part_region(reg);
part.set_part_region(pr);
constraints.add_partition(part);

int num_atoms = i->second.size();

for (auto j = 0; j < num_atoms; j++) {
AtomBlockId atom_id = i->second[j];
constraints.add_constrained_atom(atom_id, partid);
}
part_id++;
}

VprConstraintsSerializer reader(constraints);

if (vtr::check_file_name_extension(file_name, ".xml")) {
std::fstream fp;
fp.open(file_name, std::fstream::out | std::fstream::trunc);
fp.precision(std::numeric_limits<float>::max_digits10);
void* context;
uxsd::write_vpr_constraints_xml(reader, context, fp);
} else {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
"Unknown extension on output %s",
file_name);
}
}
12 changes: 12 additions & 0 deletions vpr/src/base/vpr_constraints_writer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* vpr_constraints_writer.h
*
* Author: khalid88
*/

#ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_
#define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_

void write_vpr_floorplan_constraints(const char* file_name, int expand, int subtile);

#endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */
Loading