Skip to content

Commit 28e7960

Browse files
authored
Merge pull request #2546 from verilog-to-routing/noc_pack_part
NoC-aware packing optimization and NoC-biased centroid move type
2 parents 29760b4 + 80dcdeb commit 28e7960

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1143
-503
lines changed

libs/libvtrutil/src/vtr_error.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stdexcept>
55
#include <string>
6+
#include <utility>
67

78
/**
89
* @file
@@ -34,9 +35,9 @@ namespace vtr {
3435
class VtrError : public std::runtime_error {
3536
public:
3637
///@brief VtrError constructor
37-
VtrError(std::string msg = "", std::string new_filename = "", size_t new_linenumber = -1)
38+
VtrError(const std::string& msg = "", std::string new_filename = "", size_t new_linenumber = -1)
3839
: std::runtime_error(msg)
39-
, filename_(new_filename)
40+
, filename_(std::move(new_filename))
4041
, linenumber_(new_linenumber) {}
4142

4243
/**

libs/libvtrutil/src/vtr_expr_eval.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ static bool is_char_number(const char ch);
5858
static bool is_operator(const char ch);
5959

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

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

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

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

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

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

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

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

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

165165
if (range_start > range_end) {
166166
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__);
@@ -287,8 +287,6 @@ static void formula_to_rpn(const char* formula, const t_formula_data& mydata, ve
287287
rpn_output.push_back(fobj_dummy);
288288
op_stack.pop();
289289
}
290-
291-
return;
292290
}
293291

294292
/* Fills the formula object fobj according to specified character and mydata,
@@ -352,7 +350,7 @@ static void get_formula_object(const char* ch, int& ichar, const t_formula_data&
352350
}
353351
ichar--;
354352
fobj->type = E_FML_NUMBER;
355-
fobj->data.num = vtr::atoi(ss.str().c_str());
353+
fobj->data.num = vtr::atoi(ss.str());
356354
} else if (is_compound_op(ch) != E_COM_OP_UNDEFINED) {
357355
fobj->type = E_FML_OPERATOR;
358356
t_compound_operator comp_op_code = is_compound_op(ch);
@@ -415,8 +413,6 @@ static void get_formula_object(const char* ch, int& ichar, const t_formula_data&
415413
break;
416414
}
417415
}
418-
419-
return;
420416
}
421417

422418
/* returns integer specifying precedence of passed-in operator. higher integer
@@ -562,7 +558,6 @@ static void handle_bracket(const Formula_Object& fobj, vector<Formula_Object>& r
562558
}
563559
} while (keep_going);
564560
}
565-
return;
566561
}
567562

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

772767
//returns true if string signifies a function e.g max, min
773-
static bool is_function(std::string name) {
768+
static bool is_function(const std::string& name) {
774769
if (name == "min"
775770
|| name == "max"
776771
|| name == "gcd"
@@ -801,7 +796,7 @@ t_compound_operator is_compound_op(const char* ch) {
801796
}
802797

803798
//checks if the entered string is a known variable name
804-
static bool is_variable(std::string var_name) {
799+
static bool is_variable(const std::string& var_name) {
805800
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")) {
806801
return true;
807802
}
@@ -849,11 +844,11 @@ bool same_string(std::string str1, std::string str2) {
849844
str1.erase(remove(str1.begin(), str1.end(), ' '), str1.end());
850845
str2.erase(remove(str2.begin(), str2.end(), ' '), str2.end());
851846

852-
//converting both strings to lower case to eliminate case sensivity
847+
//converting both strings to lower case to eliminate case sensitivity
853848
std::transform(str1.begin(), str1.end(), str1.begin(), ::tolower);
854849
std::transform(str2.begin(), str2.end(), str2.begin(), ::tolower);
855850

856-
return (str1.compare(str2) == 0);
851+
return (str1 == str2);
857852
}
858853

859854
//the += operator
@@ -870,7 +865,7 @@ bool additional_assignment_op(int arg1, int arg2) {
870865
//recognizes the block_id to look for (entered by the user)
871866
//then looks for that block_id in all the blocks moved in the last perturbation.
872867
//returns the block id if found, else just -1
873-
int in_blocks_affected(std::string expression_left) {
868+
int in_blocks_affected(const std::string& expression_left) {
874869
int wanted_block = -1;
875870
int found_block;
876871
std::stringstream ss;

libs/libvtrutil/src/vtr_expr_eval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class FormulaParser {
214214
FormulaParser& operator=(const FormulaParser&) = delete;
215215

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

219219
///@brief returns integer result according to specified piece-wise formula and data
220220
int parse_piecewise_formula(const char* formula, const t_formula_data& mydata);

vpr/src/base/CheckSetup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
1313
const t_server_opts& ServerOpts,
1414
const t_det_routing_arch& RoutingArch,
1515
const std::vector<t_segment_inf>& Segments,
16-
const t_timing_inf Timing,
16+
const t_timing_inf& Timing,
1717
const t_chan_width_dist Chans) {
1818
int i;
1919
int Tmp;
@@ -79,7 +79,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
7979
for (i = 0; i < (int)Segments.size(); ++i) {
8080
Tmp = Segments[i].arch_opin_switch;
8181
auto& device_ctx = g_vpr_ctx.device();
82-
if (false == device_ctx.arch_switch_inf[Tmp].buffered()) {
82+
if (!device_ctx.arch_switch_inf[Tmp].buffered()) {
8383
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
8484
"arch_opin_switch (#%d) of segment type #%d is not buffered.\n", Tmp, i);
8585
}

vpr/src/base/CheckSetup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void CheckSetup(const t_packer_opts& PackerOpts,
1111
const t_server_opts& ServerOpts,
1212
const t_det_routing_arch& RoutingArch,
1313
const std::vector<t_segment_inf>& Segments,
14-
const t_timing_inf Timing,
14+
const t_timing_inf& Timing,
1515
const t_chan_width_dist Chans);
1616

1717
#endif

vpr/src/base/SetupGrid.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void set_grid_block_type(int priority,
4646
const t_metadata_dict* meta);
4747

4848
///@brief Create the device grid based on resource requirements
49-
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) {
49+
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) {
5050
if (layout_name == "auto") {
5151
//Auto-size the device
5252
//
@@ -78,9 +78,9 @@ DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_
7878
}
7979

8080
///@brief Create the device grid based on dimensions
81-
DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_def>& grid_layouts, size_t width, size_t height) {
81+
DeviceGrid create_device_grid(const std::string& layout_name, const std::vector<t_grid_def>& grid_layouts, size_t width, size_t height) {
8282
if (layout_name == "auto") {
83-
VTR_ASSERT(grid_layouts.size() > 0);
83+
VTR_ASSERT(!grid_layouts.empty());
8484
//Auto-size
8585
if (grid_layouts[0].grid_type == GridDefType::AUTO) {
8686
//Auto layout of the specified dimensions
@@ -145,7 +145,7 @@ DeviceGrid create_device_grid(std::string layout_name, const std::vector<t_grid_
145145
* If an auto grid layouts are specified, the smallest dynamicly sized grid is picked
146146
*/
147147
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) {
148-
VTR_ASSERT(grid_layouts.size() > 0);
148+
VTR_ASSERT(!grid_layouts.empty());
149149

150150
DeviceGrid grid;
151151

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

282282
//Sort so we allocate logical blocks with the fewest equivalent sites first (least flexible)
283283
std::vector<const t_logical_block_type*> logical_block_types;
284+
logical_block_types.reserve(device_ctx.logical_block_types.size());
284285
for (auto& block_type : device_ctx.logical_block_types) {
285286
logical_block_types.push_back(&block_type);
286287
}

vpr/src/base/SetupGrid.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
#include "physical_types.h"
1414

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

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

2427
/**
2528
* @brief Calculate the device utilization

vpr/src/base/SetupVPR.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ static void SetupRoutingArch(const t_arch& Arch,
403403
RoutingArch->R_minW_pmos = Arch.R_minW_pmos;
404404
RoutingArch->Fs = Arch.Fs;
405405
RoutingArch->directionality = BI_DIRECTIONAL;
406-
if (Arch.Segments.size()) {
406+
if (!Arch.Segments.empty()) {
407407
RoutingArch->directionality = Arch.Segments[0].directionality;
408408
}
409409

@@ -744,6 +744,7 @@ static void SetupNocOpts(const t_options& Options, t_noc_opts* NocOpts) {
744744
NocOpts->noc_latency_weighting = Options.noc_latency_weighting;
745745
NocOpts->noc_congestion_weighting = Options.noc_congestion_weighting;
746746
NocOpts->noc_swap_percentage = Options.noc_swap_percentage;
747+
NocOpts->noc_centroid_weight = Options.noc_centroid_weight;
747748
NocOpts->noc_placement_file_name = Options.noc_placement_file_name;
748749
}
749750

vpr/src/base/atom_netlist.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ AtomBlockId AtomNetlist::find_atom_pin_driver(const AtomBlockId blk_id, const t_
115115
return AtomBlockId::INVALID();
116116
}
117117

118-
std::unordered_set<std::string> AtomNetlist::net_aliases(const std::string net_name) const {
118+
std::unordered_set<std::string> AtomNetlist::net_aliases(const std::string& net_name) const {
119119
auto net_id = find_net(net_name);
120120
VTR_ASSERT(net_id != AtomNetId::INVALID());
121121

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

143143
//Initialize the data
@@ -205,7 +205,7 @@ AtomPinId AtomNetlist::create_pin(const AtomPortId port_id, BitIndex port_bit, c
205205
return pin_id;
206206
}
207207

208-
AtomNetId AtomNetlist::create_net(const std::string name) {
208+
AtomNetId AtomNetlist::create_net(const std::string& name) {
209209
AtomNetId net_id = Netlist::create_net(name);
210210

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

217-
AtomNetId AtomNetlist::add_net(const std::string name, AtomPinId driver, std::vector<AtomPinId> sinks) {
217+
AtomNetId AtomNetlist::add_net(const std::string& name, AtomPinId driver, std::vector<AtomPinId> sinks) {
218218
return Netlist::add_net(name, driver, sinks);
219219
}
220220

221-
void AtomNetlist::add_net_alias(const std::string net_name, const std::string alias_net_name) {
221+
void AtomNetlist::add_net_alias(const std::string& net_name, const std::string& alias_net_name) {
222222
auto net_id = find_net(net_name);
223223
VTR_ASSERT(net_id != AtomNetId::INVALID());
224224

vpr/src/base/atom_netlist.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class AtomNetlist : public Netlist<AtomBlockId, AtomPortId, AtomPinId, AtomNetId
157157
*
158158
* @param net_name name of the net from which the aliases are extracted
159159
*/
160-
std::unordered_set<std::string> net_aliases(const std::string net_name) const;
160+
std::unordered_set<std::string> net_aliases(const std::string& net_name) const;
161161

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

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

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

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

223223
private: //Private members
224224
/*

vpr/src/base/constraints_load.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "constraints_load.h"
22

3-
void echo_constraints(char* filename, VprConstraints constraints) {
3+
void echo_constraints(char* filename, const VprConstraints& constraints) {
44
FILE* fp;
55
fp = vtr::fopen(filename, "w");
66

vpr/src/base/constraints_load.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
#include "vtr_vector.h"
99

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

1313
#endif

0 commit comments

Comments
 (0)