Skip to content

Commit

Permalink
Merge pull request verilog-to-routing#2546 from verilog-to-routing/no…
Browse files Browse the repository at this point in the history
…c_pack_part

NoC-aware packing optimization and NoC-biased centroid move type
  • Loading branch information
vaughnbetz committed May 23, 2024
2 parents 29760b4 + 80dcdeb commit 28e7960
Show file tree
Hide file tree
Showing 66 changed files with 1,143 additions and 503 deletions.
5 changes: 3 additions & 2 deletions libs/libvtrutil/src/vtr_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdexcept>
#include <string>
#include <utility>

/**
* @file
Expand Down Expand Up @@ -34,9 +35,9 @@ namespace vtr {
class VtrError : public std::runtime_error {
public:
///@brief VtrError constructor
VtrError(std::string msg = "", std::string new_filename = "", size_t new_linenumber = -1)
VtrError(const std::string& msg = "", std::string new_filename = "", size_t new_linenumber = -1)
: std::runtime_error(msg)
, filename_(new_filename)
, filename_(std::move(new_filename))
, linenumber_(new_linenumber) {}

/**
Expand Down
29 changes: 12 additions & 17 deletions libs/libvtrutil/src/vtr_expr_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ static bool is_char_number(const char ch);
static bool is_operator(const char ch);

// returns true if the specified name is a known function operator
static bool is_function(std::string name);
static bool is_function(const std::string& name);

// returns true if the specified name is a known compound operator
t_compound_operator is_compound_op(const char* ch);

// returns true if the specified name is a known variable
static bool is_variable(std::string var);
static bool is_variable(const std::string& var);

// returns the length of any identifier (e.g. name, function) starting at the beginning of str
static int identifier_length(const char* str);
Expand All @@ -76,14 +76,14 @@ static bool goto_next_char(int* str_ind, const string& pw_formula, char ch);
bool same_string(std::string str1, std::string str2);

//checks if the block indicated by the user was one of the moved blocks in the last perturbation
int in_blocks_affected(std::string expression_left);
int in_blocks_affected(const std::string& expression_left);

//the function of += operator
bool additional_assignment_op(int arg1, int arg2);

/**** Function Implementations ****/
/* returns integer result according to specified non-piece-wise formula and data */
int FormulaParser::parse_formula(std::string formula, const t_formula_data& mydata, bool is_breakpoint) {
int FormulaParser::parse_formula(const std::string& formula, const t_formula_data& mydata, bool is_breakpoint) {
int result = -1;

/* output in reverse-polish notation */
Expand Down Expand Up @@ -150,7 +150,7 @@ int FormulaParser::parse_piecewise_formula(const char* formula, const t_formula_
}
tmp_ind_count = str_ind - tmp_ind_start; /* range start is between { and : */
substr = pw_formula.substr(tmp_ind_start, tmp_ind_count);
range_start = parse_formula(substr.c_str(), mydata);
range_start = parse_formula(substr, mydata);

/* get the end of the range */
tmp_ind_start = str_ind + 1;
Expand All @@ -160,7 +160,7 @@ int FormulaParser::parse_piecewise_formula(const char* formula, const t_formula_
}
tmp_ind_count = str_ind - tmp_ind_start; /* range end is between : and } */
substr = pw_formula.substr(tmp_ind_start, tmp_ind_count);
range_end = parse_formula(substr.c_str(), mydata);
range_end = parse_formula(substr, mydata);

if (range_start > range_end) {
throw vtr::VtrError(vtr::string_fmt("parse_piecewise_formula: range_start, %d, is bigger than range end, %d\n", range_start, range_end), __FILE__, __LINE__);
Expand Down Expand Up @@ -287,8 +287,6 @@ static void formula_to_rpn(const char* formula, const t_formula_data& mydata, ve
rpn_output.push_back(fobj_dummy);
op_stack.pop();
}

return;
}

/* Fills the formula object fobj according to specified character and mydata,
Expand Down Expand Up @@ -352,7 +350,7 @@ static void get_formula_object(const char* ch, int& ichar, const t_formula_data&
}
ichar--;
fobj->type = E_FML_NUMBER;
fobj->data.num = vtr::atoi(ss.str().c_str());
fobj->data.num = vtr::atoi(ss.str());
} else if (is_compound_op(ch) != E_COM_OP_UNDEFINED) {
fobj->type = E_FML_OPERATOR;
t_compound_operator comp_op_code = is_compound_op(ch);
Expand Down Expand Up @@ -415,8 +413,6 @@ static void get_formula_object(const char* ch, int& ichar, const t_formula_data&
break;
}
}

return;
}

/* returns integer specifying precedence of passed-in operator. higher integer
Expand Down Expand Up @@ -562,7 +558,6 @@ static void handle_bracket(const Formula_Object& fobj, vector<Formula_Object>& r
}
} while (keep_going);
}
return;
}

/* used by the shunting-yard formula parser to deal with commas, ie ','. These occur in function calls*/
Expand Down Expand Up @@ -770,7 +765,7 @@ static bool is_operator(const char ch) {
}

//returns true if string signifies a function e.g max, min
static bool is_function(std::string name) {
static bool is_function(const std::string& name) {
if (name == "min"
|| name == "max"
|| name == "gcd"
Expand Down Expand Up @@ -801,7 +796,7 @@ t_compound_operator is_compound_op(const char* ch) {
}

//checks if the entered string is a known variable name
static bool is_variable(std::string var_name) {
static bool is_variable(const std::string& var_name) {
if (same_string(var_name, "from_block") || same_string(var_name, "temp_count") || same_string(var_name, "move_num") || same_string(var_name, "route_net_id") || same_string(var_name, "in_blocks_affected") || same_string(var_name, "router_iter")) {
return true;
}
Expand Down Expand Up @@ -849,11 +844,11 @@ bool same_string(std::string str1, std::string str2) {
str1.erase(remove(str1.begin(), str1.end(), ' '), str1.end());
str2.erase(remove(str2.begin(), str2.end(), ' '), str2.end());

//converting both strings to lower case to eliminate case sensivity
//converting both strings to lower case to eliminate case sensitivity
std::transform(str1.begin(), str1.end(), str1.begin(), ::tolower);
std::transform(str2.begin(), str2.end(), str2.begin(), ::tolower);

return (str1.compare(str2) == 0);
return (str1 == str2);
}

//the += operator
Expand All @@ -870,7 +865,7 @@ bool additional_assignment_op(int arg1, int arg2) {
//recognizes the block_id to look for (entered by the user)
//then looks for that block_id in all the blocks moved in the last perturbation.
//returns the block id if found, else just -1
int in_blocks_affected(std::string expression_left) {
int in_blocks_affected(const std::string& expression_left) {
int wanted_block = -1;
int found_block;
std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion libs/libvtrutil/src/vtr_expr_eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class FormulaParser {
FormulaParser& operator=(const FormulaParser&) = delete;

///@brief returns integer result according to specified formula and data
int parse_formula(std::string formula, const t_formula_data& mydata, bool is_breakpoint = false);
int parse_formula(const std::string& formula, const t_formula_data& mydata, bool is_breakpoint = false);

///@brief returns integer result according to specified piece-wise formula and data
int parse_piecewise_formula(const char* formula, const t_formula_data& mydata);
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/base/CheckSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
const t_server_opts& ServerOpts,
const t_det_routing_arch& RoutingArch,
const std::vector<t_segment_inf>& Segments,
const t_timing_inf Timing,
const t_timing_inf& Timing,
const t_chan_width_dist Chans) {
int i;
int Tmp;
Expand Down Expand Up @@ -79,7 +79,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
for (i = 0; i < (int)Segments.size(); ++i) {
Tmp = Segments[i].arch_opin_switch;
auto& device_ctx = g_vpr_ctx.device();
if (false == device_ctx.arch_switch_inf[Tmp].buffered()) {
if (!device_ctx.arch_switch_inf[Tmp].buffered()) {
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
"arch_opin_switch (#%d) of segment type #%d is not buffered.\n", Tmp, i);
}
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/CheckSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
const t_server_opts& ServerOpts,
const t_det_routing_arch& RoutingArch,
const std::vector<t_segment_inf>& Segments,
const t_timing_inf Timing,
const t_timing_inf& Timing,
const t_chan_width_dist Chans);

#endif
9 changes: 5 additions & 4 deletions vpr/src/base/SetupGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void set_grid_block_type(int priority,
const t_metadata_dict* meta);

///@brief Create the device grid based on resource requirements
DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_def>& grid_layouts, const std::map<t_logical_block_type_ptr, size_t>& minimum_instance_counts, float target_device_utilization) {
DeviceGrid create_device_grid(const std::string& layout_name, const std::vector<t_grid_def>& grid_layouts, const std::map<t_logical_block_type_ptr, size_t>& minimum_instance_counts, float target_device_utilization) {
if (layout_name == "auto") {
//Auto-size the device
//
Expand Down Expand Up @@ -78,9 +78,9 @@ DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_
}

///@brief Create the device grid based on dimensions
DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_def>& grid_layouts, size_t width, size_t height) {
DeviceGrid create_device_grid(const std::string& layout_name, const std::vector<t_grid_def>& grid_layouts, size_t width, size_t height) {
if (layout_name == "auto") {
VTR_ASSERT(grid_layouts.size() > 0);
VTR_ASSERT(!grid_layouts.empty());
//Auto-size
if (grid_layouts[0].grid_type == GridDefType::AUTO) {
//Auto layout of the specified dimensions
Expand Down Expand Up @@ -145,7 +145,7 @@ DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_
* If an auto grid layouts are specified, the smallest dynamicly sized grid is picked
*/
static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layouts, const std::map<t_logical_block_type_ptr, size_t>& minimum_instance_counts, float maximum_device_utilization) {
VTR_ASSERT(grid_layouts.size() > 0);
VTR_ASSERT(!grid_layouts.empty());

DeviceGrid grid;

Expand Down Expand Up @@ -281,6 +281,7 @@ static std::vector<t_logical_block_type_ptr> grid_overused_resources(const Devic

//Sort so we allocate logical blocks with the fewest equivalent sites first (least flexible)
std::vector<const t_logical_block_type*> logical_block_types;
logical_block_types.reserve(device_ctx.logical_block_types.size());
for (auto& block_type : device_ctx.logical_block_types) {
logical_block_types.push_back(&block_type);
}
Expand Down
7 changes: 5 additions & 2 deletions vpr/src/base/SetupGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#include "physical_types.h"

///@brief Find the device satisfying the specified minimum resources
DeviceGrid create_device_grid(std::string layout_name,
DeviceGrid create_device_grid(const std::string& layout_name,
const std::vector<t_grid_def>& grid_layouts,
const std::map<t_logical_block_type_ptr, size_t>& minimum_instance_counts,
float target_device_utilization);

///@brief Find the device close in size to the specified dimensions
DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_def>& grid_layouts, size_t min_width, size_t min_height);
DeviceGrid create_device_grid(const std::string& layout_name,
const std::vector<t_grid_def>& grid_layouts,
size_t min_width,
size_t min_height);

/**
* @brief Calculate the device utilization
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static void SetupRoutingArch(const t_arch& Arch,
RoutingArch->R_minW_pmos = Arch.R_minW_pmos;
RoutingArch->Fs = Arch.Fs;
RoutingArch->directionality = BI_DIRECTIONAL;
if (Arch.Segments.size()) {
if (!Arch.Segments.empty()) {
RoutingArch->directionality = Arch.Segments[0].directionality;
}

Expand Down Expand Up @@ -744,6 +744,7 @@ static void SetupNocOpts(const t_options& Options, t_noc_opts* NocOpts) {
NocOpts->noc_latency_weighting = Options.noc_latency_weighting;
NocOpts->noc_congestion_weighting = Options.noc_congestion_weighting;
NocOpts->noc_swap_percentage = Options.noc_swap_percentage;
NocOpts->noc_centroid_weight = Options.noc_centroid_weight;
NocOpts->noc_placement_file_name = Options.noc_placement_file_name;
}

Expand Down
10 changes: 5 additions & 5 deletions vpr/src/base/atom_netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ AtomBlockId AtomNetlist::find_atom_pin_driver(const AtomBlockId blk_id, const t_
return AtomBlockId::INVALID();
}

std::unordered_set<std::string> AtomNetlist::net_aliases(const std::string net_name) const {
std::unordered_set<std::string> AtomNetlist::net_aliases(const std::string& net_name) const {
auto net_id = find_net(net_name);
VTR_ASSERT(net_id != AtomNetId::INVALID());

Expand All @@ -137,7 +137,7 @@ std::unordered_set<std::string> AtomNetlist::net_aliases(const std::string net_n
* Mutators
*
*/
AtomBlockId AtomNetlist::create_block(const std::string name, const t_model* model, const TruthTable truth_table) {
AtomBlockId AtomNetlist::create_block(const std::string& name, const t_model* model, const TruthTable& truth_table) {
AtomBlockId blk_id = Netlist::create_block(name);

//Initialize the data
Expand Down Expand Up @@ -205,7 +205,7 @@ AtomPinId AtomNetlist::create_pin(const AtomPortId port_id, BitIndex port_bit, c
return pin_id;
}

AtomNetId AtomNetlist::create_net(const std::string name) {
AtomNetId AtomNetlist::create_net(const std::string& name) {
AtomNetId net_id = Netlist::create_net(name);

//Check post-conditions: size
Expand All @@ -214,11 +214,11 @@ AtomNetId AtomNetlist::create_net(const std::string name) {
return net_id;
}

AtomNetId AtomNetlist::add_net(const std::string name, AtomPinId driver, std::vector<AtomPinId> sinks) {
AtomNetId AtomNetlist::add_net(const std::string& name, AtomPinId driver, std::vector<AtomPinId> sinks) {
return Netlist::add_net(name, driver, sinks);
}

void AtomNetlist::add_net_alias(const std::string net_name, const std::string alias_net_name) {
void AtomNetlist::add_net_alias(const std::string& net_name, const std::string& alias_net_name) {
auto net_id = find_net(net_name);
VTR_ASSERT(net_id != AtomNetId::INVALID());

Expand Down
10 changes: 5 additions & 5 deletions vpr/src/base/atom_netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
*
* @param net_name name of the net from which the aliases are extracted
*/
std::unordered_set<std::string> net_aliases(const std::string net_name) const;
std::unordered_set<std::string> net_aliases(const std::string& net_name) const;

public: //Public Mutators
/*
Expand All @@ -173,7 +173,7 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
* The truth_table is optional and only relevant for LUTs (where it describes the logic function)
* and Flip-Flops/latches (where it consists of a single entry defining the initial state).
*/
AtomBlockId create_block(const std::string name, const t_model* model, const TruthTable truth_table = TruthTable());
AtomBlockId create_block(const std::string& name, const t_model* model, const TruthTable& truth_table = TruthTable());

/**
* @brief Create or return an existing port in the netlist
Expand All @@ -199,7 +199,7 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
*
* @param name The unique name of the net
*/
AtomNetId create_net(const std::string name); //An empty or existing net
AtomNetId create_net(const std::string& name); //An empty or existing net

/**
* @brief Create a completely specified net from specified driver and sinks
Expand All @@ -208,7 +208,7 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
* @param driver The net's driver pin
* @param sinks The net's sink pins
*/
AtomNetId add_net(const std::string name, AtomPinId driver, std::vector<AtomPinId> sinks);
AtomNetId add_net(const std::string& name, AtomPinId driver, std::vector<AtomPinId> sinks);

/**
* @brief Adds a value to the net aliases set for a given net name in the net_aliases_map.
Expand All @@ -218,7 +218,7 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
* @param net_name The net to be added to the map
* @param alias_net_name The alias of the assigned clock net id
*/
void add_net_alias(const std::string net_name, std::string alias_net_name);
void add_net_alias(const std::string& net_name, const std::string& alias_net_name);

private: //Private members
/*
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/constraints_load.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "constraints_load.h"

void echo_constraints(char* filename, VprConstraints constraints) {
void echo_constraints(char* filename, const VprConstraints& constraints) {
FILE* fp;
fp = vtr::fopen(filename, "w");

Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/constraints_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
#include "vtr_vector.h"

///@brief Used to print vpr's floorplanning constraints to an echo file "vpr_constraints.echo"
void echo_constraints(char* filename, VprConstraints constraints);
void echo_constraints(char* filename, const VprConstraints& constraints);

#endif
Loading

0 comments on commit 28e7960

Please sign in to comment.