Skip to content

Commit e853ae3

Browse files
Merge branch 'master' into tileable_rr_graph_write
2 parents ed36ab2 + b7a5c77 commit e853ae3

35 files changed

+414
-467
lines changed

vpr/src/base/clustered_netlist.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
#include "vtr_assert.h"
44
#include "vpr_error.h"
55

6+
#include <utility>
7+
68
/**
79
* @file
810
* @brief ClusteredNetlist Class Implementation
911
*/
1012

1113
ClusteredNetlist::ClusteredNetlist(std::string name, std::string id)
12-
: Netlist<ClusterBlockId, ClusterPortId, ClusterPinId, ClusterNetId>(name, id) {}
14+
: Netlist<ClusterBlockId, ClusterPortId, ClusterPinId, ClusterNetId>(std::move(name), std::move(id)) {}
1315

1416
/*
1517
*
@@ -28,11 +30,16 @@ t_logical_block_type_ptr ClusteredNetlist::block_type(const ClusterBlockId id) c
2830
return block_types_[id];
2931
}
3032

31-
std::vector<ClusterBlockId> ClusteredNetlist::blocks_per_type(const t_logical_block_type blk_type) const {
33+
const std::vector<ClusterBlockId>& ClusteredNetlist::blocks_per_type(const t_logical_block_type& blk_type) const {
34+
// empty vector is declared static to avoid re-allocation every time the function is called
35+
static std::vector<ClusterBlockId> empty_vector;
3236
if (blocks_per_type_.count(blk_type.index) == 0) {
33-
std::vector<ClusterBlockId> empty_vector;
3437
return empty_vector;
3538
}
39+
40+
// the vector is returned as const reference to avoid unnecessary copies,
41+
// especially that returned vectors may be very large as they contain
42+
// all clustered blocks with a specific block type
3643
return blocks_per_type_.at(blk_type.index);
3744
}
3845

@@ -132,7 +139,7 @@ ClusterBlockId ClusteredNetlist::create_block(const char* name, t_pb* pb, t_logi
132139
return blk_id;
133140
}
134141

135-
ClusterPortId ClusteredNetlist::create_port(const ClusterBlockId blk_id, const std::string name, BitIndex width, PortType type) {
142+
ClusterPortId ClusteredNetlist::create_port(const ClusterBlockId blk_id, const std::string& name, BitIndex width, PortType type) {
136143
ClusterPortId port_id = find_port(blk_id, name);
137144
if (!port_id) {
138145
port_id = Netlist::create_port(blk_id, name, width, type);
@@ -163,7 +170,7 @@ ClusterPinId ClusteredNetlist::create_pin(const ClusterPortId port_id, BitIndex
163170
return pin_id;
164171
}
165172

166-
ClusterNetId ClusteredNetlist::create_net(const std::string name) {
173+
ClusterNetId ClusteredNetlist::create_net(const std::string& name) {
167174
//Check if the net has already been created
168175
StringId name_id = create_string(name);
169176
ClusterNetId net_id = find_net(name_id);
@@ -292,9 +299,9 @@ ClusterBlockId ClusteredNetlist::find_block_by_name_fragment(const std::string&
292299
ClusterBlockId blk_id = ClusterBlockId::INVALID();
293300
std::regex name_to_match(name_pattern);
294301

295-
for (auto compatible_block_id = cluster_block_candidates.begin(); compatible_block_id != cluster_block_candidates.end(); compatible_block_id++) {
296-
if (std::regex_match(Netlist::block_name(*compatible_block_id), name_to_match)) {
297-
blk_id = *compatible_block_id;
302+
for (auto cluster_block_candidate : cluster_block_candidates) {
303+
if (std::regex_match(Netlist::block_name(cluster_block_candidate), name_to_match)) {
304+
blk_id = cluster_block_candidate;
298305
break;
299306
}
300307
}

vpr/src/base/clustered_netlist.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ClusteredNetlist : public Netlist<ClusterBlockId, ClusterPortId, ClusterPi
135135
t_logical_block_type_ptr block_type(const ClusterBlockId id) const;
136136

137137
///@brief Returns the blocks with the specific block types in the netlist
138-
std::vector<ClusterBlockId> blocks_per_type(const t_logical_block_type blk_type) const;
138+
const std::vector<ClusterBlockId>& blocks_per_type(const t_logical_block_type& blk_type) const;
139139

140140
///@brief Returns the net of the block attached to the specific pin index
141141
ClusterNetId block_net(const ClusterBlockId blk_id, const int pin_index) const;
@@ -194,7 +194,7 @@ class ClusteredNetlist : public Netlist<ClusterBlockId, ClusterPortId, ClusterPi
194194
* @param width The width (number of bits) of the port
195195
* @param type The type of the port (INPUT, OUTPUT, or CLOCK)
196196
*/
197-
ClusterPortId create_port(const ClusterBlockId blk_id, const std::string name, BitIndex width, PortType type);
197+
ClusterPortId create_port(const ClusterBlockId blk_id, const std::string& name, BitIndex width, PortType type);
198198
/**
199199
* @brief Create or return an existing pin in the netlist
200200
*
@@ -212,7 +212,7 @@ class ClusteredNetlist : public Netlist<ClusterBlockId, ClusterPortId, ClusterPi
212212
*
213213
* @param name The unique name of the net
214214
*/
215-
ClusterNetId create_net(const std::string name);
215+
ClusterNetId create_net(const std::string& name);
216216

217217
/**
218218
* @brief Given a name of a block and vector of possible cluster blocks

vpr/src/base/read_options.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ struct ParsePlaceAgentSpace {
465465
ConvertedValue<e_agent_space> from_str(std::string str) {
466466
ConvertedValue<e_agent_space> conv_value;
467467
if (str == "move_type")
468-
conv_value.set_value(MOVE_TYPE);
468+
conv_value.set_value(e_agent_space::MOVE_TYPE);
469469
else if (str == "move_block_type")
470-
conv_value.set_value(MOVE_BLOCK_TYPE);
470+
conv_value.set_value(e_agent_space::MOVE_BLOCK_TYPE);
471471
else {
472472
std::stringstream msg;
473473
msg << "Invalid conversion from '" << str << "' to e_agent_space (expected one of: " << argparse::join(default_choices(), ", ") << ")";
@@ -478,10 +478,10 @@ struct ParsePlaceAgentSpace {
478478

479479
ConvertedValue<std::string> to_str(e_agent_space val) {
480480
ConvertedValue<std::string> conv_value;
481-
if (val == MOVE_TYPE)
481+
if (val == e_agent_space::MOVE_TYPE)
482482
conv_value.set_value("move_type");
483483
else {
484-
VTR_ASSERT(val == MOVE_BLOCK_TYPE);
484+
VTR_ASSERT(val == e_agent_space::MOVE_BLOCK_TYPE);
485485
conv_value.set_value("move_block_type");
486486
}
487487
return conv_value;

vpr/src/base/vpr_context.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,6 @@ struct PlacementContext : public Context {
396396
* Used for unique identification and consistency checking
397397
*/
398398
std::string placement_id;
399-
400-
/**
401-
* @brief Map physical block type to RL-agent block type
402-
*
403-
* RL-agent block types are the physical block types that are used in the netlist (at least one logical block in the netlist maps to).
404-
* As an example:
405-
* Having physical block types (EMPTY, LAB, DSP, IO),
406-
* agent block types would be (LAB,IO) if netlist doesn't contain DSP blocks.
407-
* Key : physical (agent) block type index
408-
* Value : agent (physical) block type index
409-
*/
410-
std::unordered_map<int, int> phys_blk_type_to_agent_blk_type_map;
411-
std::unordered_map<int, int> agent_blk_type_to_phys_blk_type_map;
412399
};
413400

414401
/**

vpr/src/base/vpr_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ enum e_agent_algorithm {
10501050
* can be based on (block_type, move_type) pair.
10511051
*
10521052
*/
1053-
enum e_agent_space {
1053+
enum class e_agent_space {
10541054
MOVE_TYPE,
10551055
MOVE_BLOCK_TYPE
10561056
};

vpr/src/draw/manual_moves.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#ifndef NO_GRAPHICS
1818

19-
void draw_manual_moves_window(std::string block_id) {
19+
void draw_manual_moves_window(const std::string& block_id) {
2020
t_draw_state* draw_state = get_draw_state_vars();
2121

2222
if (!draw_state->manual_moves_state.manual_move_window_is_open) {
@@ -249,7 +249,7 @@ void manual_move_cost_summary_dialog() {
249249
//If the user accepts the manual move
250250
case GTK_RESPONSE_ACCEPT:
251251
draw_state->manual_moves_state.manual_move_info.user_move_outcome = ACCEPTED;
252-
application.update_message(msg.c_str());
252+
application.update_message(msg);
253253
break;
254254
//If the user rejects the manual move
255255
case GTK_RESPONSE_REJECT:
@@ -282,14 +282,8 @@ void close_manual_moves_window() {
282282
draw_state->manual_moves_state.manual_move_window_is_open = false;
283283
}
284284

285-
bool string_is_a_number(std::string block_id) {
286-
for (size_t i = 0; i < block_id.size(); i++) {
287-
//Returns 0 if the string does not have characters from 0-9
288-
if (isdigit(block_id[i]) == 0) {
289-
return false;
290-
}
291-
}
292-
return true;
285+
bool string_is_a_number(const std::string& block_id) {
286+
return std::all_of(block_id.begin(), block_id.end(), isdigit);
293287
}
294288

295289
//Updates ManualMovesInfo cost and placer move outcome variables. User_move_outcome is also updated.
@@ -311,8 +305,8 @@ e_create_move manual_move_display_and_propose(ManualMoveGenerator& manual_move_g
311305
draw_manual_moves_window("");
312306
update_screen(ScreenUpdatePriority::MAJOR, " ", PLACEMENT, nullptr);
313307
move_type = e_move_type::MANUAL_MOVE;
314-
t_logical_block_type blk_type; //no need to specify block type in manual move "propose_move" function
315-
return manual_move_generator.propose_move(blocks_affected, move_type, blk_type, rlim, placer_opts, criticalities);
308+
t_propose_action proposed_action{move_type, -1}; //no need to specify block type in manual move "propose_move" function
309+
return manual_move_generator.propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
316310
}
317311

318312
#endif /*NO_GRAPHICS*/

vpr/src/draw/manual_moves.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool manual_move_is_selected();
9393
* Window prompts the user for input: block id/name used as the from block in the move generator, x position, y position, and subtile position.
9494
* @param block_id: The block id is passed in if the user decides to highlight the block in the UI. If the user decides to manually input the block ID in the manual move window, the string will be empty and the block ID will later be assigned to ManualMovesState struct.
9595
*/
96-
void draw_manual_moves_window(std::string block_id);
96+
void draw_manual_moves_window(const std::string& block_id);
9797

9898
/**
9999
* @brief Evaluates if the user input is valid and allowed.
@@ -139,7 +139,7 @@ void close_manual_moves_window();
139139
*
140140
* @return True if the string only contains numbers, false otherwise.
141141
*/
142-
bool string_is_a_number(std::string block_id);
142+
bool string_is_a_number(const std::string& block_id);
143143

144144
/**
145145
* @brief Updates the ManualMovesState variable members.

vpr/src/place/RL_agent_util.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include "manual_move_generator.h"
33

44
void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std::unique_ptr<MoveGenerator>& move_generator2, const t_placer_opts& placer_opts, int move_lim) {
5-
//extract available physical block types in the netlist
6-
determine_agent_block_types();
7-
85
if (placer_opts.RL_agent_placement == false) {
96
if (placer_opts.place_algorithm.is_timing_driven()) {
107
VTR_LOG("Using static probabilities for choosing each move type\n");
@@ -45,7 +42,6 @@ void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std:
4542
* only move type. *
4643
* This state is activated late in the anneal and in the Quench */
4744

48-
auto& place_ctx = g_vpr_ctx.placement();
4945
int num_1st_state_avail_moves = placer_opts.place_algorithm.is_timing_driven() ? NUM_PL_1ST_STATE_MOVE_TYPES : NUM_PL_NONTIMING_MOVE_TYPES;
5046
int num_2nd_state_avail_moves = placer_opts.place_algorithm.is_timing_driven() ? NUM_PL_MOVE_TYPES : NUM_PL_NONTIMING_MOVE_TYPES;
5147

@@ -55,17 +51,20 @@ void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std:
5551
if (placer_opts.place_agent_space == e_agent_space::MOVE_BLOCK_TYPE) {
5652
VTR_LOG("Using simple RL 'Epsilon Greedy agent' for choosing move and block types\n");
5753
karmed_bandit_agent1 = std::make_unique<EpsilonGreedyAgent>(num_1st_state_avail_moves,
58-
place_ctx.agent_blk_type_to_phys_blk_type_map.size(),
54+
e_agent_space::MOVE_BLOCK_TYPE,
5955
placer_opts.place_agent_epsilon);
6056
} else {
6157
VTR_LOG("Using simple RL 'Epsilon Greedy agent' for choosing move types\n");
6258
karmed_bandit_agent1 = std::make_unique<EpsilonGreedyAgent>(num_1st_state_avail_moves,
59+
e_agent_space::MOVE_TYPE,
6360
placer_opts.place_agent_epsilon);
6461
}
6562
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
6663
move_generator = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent1);
6764
//agent's 2nd state
68-
karmed_bandit_agent2 = std::make_unique<EpsilonGreedyAgent>(num_2nd_state_avail_moves, placer_opts.place_agent_epsilon);
65+
karmed_bandit_agent2 = std::make_unique<EpsilonGreedyAgent>(num_2nd_state_avail_moves,
66+
e_agent_space::MOVE_TYPE,
67+
placer_opts.place_agent_epsilon);
6968
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
7069
move_generator2 = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent2);
7170
} else {
@@ -74,15 +73,17 @@ void create_move_generators(std::unique_ptr<MoveGenerator>& move_generator, std:
7473
if (placer_opts.place_agent_space == e_agent_space::MOVE_BLOCK_TYPE) {
7574
VTR_LOG("Using simple RL 'Softmax agent' for choosing move and block types\n");
7675
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(num_1st_state_avail_moves,
77-
place_ctx.agent_blk_type_to_phys_blk_type_map.size());
76+
e_agent_space::MOVE_BLOCK_TYPE);
7877
} else {
7978
VTR_LOG("Using simple RL 'Softmax agent' for choosing move types\n");
80-
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(num_1st_state_avail_moves);
79+
karmed_bandit_agent1 = std::make_unique<SoftmaxAgent>(num_1st_state_avail_moves,
80+
e_agent_space::MOVE_TYPE);
8181
}
8282
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
8383
move_generator = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent1);
8484
//agent's 2nd state
85-
karmed_bandit_agent2 = std::make_unique<SoftmaxAgent>(num_2nd_state_avail_moves);
85+
karmed_bandit_agent2 = std::make_unique<SoftmaxAgent>(num_2nd_state_avail_moves,
86+
e_agent_space::MOVE_TYPE);
8687
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
8788
move_generator2 = std::make_unique<SimpleRLMoveGenerator>(karmed_bandit_agent2);
8889
}
@@ -115,22 +116,4 @@ void update_move_generator(std::unique_ptr<MoveGenerator>& move_generator, std::
115116
else
116117
move_generator2 = std::move(current_move_generator);
117118
}
118-
}
119-
120-
void determine_agent_block_types() {
121-
//Loop through all available logical block types and store the ones that exist in the netlist
122-
auto& device_ctx = g_vpr_ctx.device();
123-
auto& cluster_ctx = g_vpr_ctx.clustering();
124-
auto& place_ctx = g_vpr_ctx.mutable_placement();
125-
int agent_type_index = 0;
126-
for (auto itype : device_ctx.logical_block_types) {
127-
if (itype.index == 0) //ignore empty type
128-
continue;
129-
auto blk_per_type = cluster_ctx.clb_nlist.blocks_per_type(itype);
130-
if (blk_per_type.size() != 0) {
131-
place_ctx.phys_blk_type_to_agent_blk_type_map.insert(std::pair<int, int>(agent_type_index, itype.index));
132-
place_ctx.agent_blk_type_to_phys_blk_type_map.insert(std::pair<int, int>(itype.index, agent_type_index));
133-
agent_type_index++;
134-
}
135-
}
136119
}

vpr/src/place/RL_agent_util.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,4 @@ void assign_current_move_generator(std::unique_ptr<MoveGenerator>& move_generato
3030
* @ brief move the updated current_move_generator to its original move_Generator structure based on he placer_options and the agent state
3131
*/
3232
void update_move_generator(std::unique_ptr<MoveGenerator>& move_generator, std::unique_ptr<MoveGenerator>& move_generator2, e_agent_state agent_state, const t_placer_opts& placer_opts, bool in_quench, std::unique_ptr<MoveGenerator>& current_move_generator);
33-
34-
/**
35-
* @ brief determine which block types used by the netlist and create a map between physical block types and agent block types (the ones that are used in the netlist)
36-
*/
37-
void determine_agent_block_types();
38-
3933
#endif

vpr/src/place/centroid_move_generator.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "place_constraints.h"
66
#include "move_utils.h"
77

8-
e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, e_move_type& /*move_type*/, t_logical_block_type& blk_type, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* /*criticalities*/) {
8+
e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected, t_propose_action& proposed_action, float rlim, const t_placer_opts& placer_opts, const PlacerCriticalities* /*criticalities*/) {
99
//Find a movable block based on blk_type
10-
ClusterBlockId b_from = propose_block_to_move(blk_type, false, NULL, NULL);
10+
ClusterBlockId b_from = propose_block_to_move(proposed_action.logical_blk_type_index, false, nullptr, nullptr);
1111

1212
if (!b_from) { //No movable block found
1313
return e_create_move::ABORT;
@@ -23,15 +23,14 @@ e_create_move CentroidMoveGenerator::propose_move(t_pl_blocks_to_be_moved& block
2323
auto grid_from_type = device_ctx.grid.get_physical_type({from.x, from.y, from.layer});
2424
VTR_ASSERT(is_tile_compatible(grid_from_type, cluster_from_type));
2525

26-
t_range_limiters range_limiters;
27-
range_limiters.original_rlim = rlim;
28-
range_limiters.dm_rlim = placer_opts.place_dm_rlim;
29-
range_limiters.first_rlim = place_move_ctx.first_rlim;
26+
t_range_limiters range_limiters{rlim,
27+
place_move_ctx.first_rlim,
28+
placer_opts.place_dm_rlim};
3029

3130
t_pl_loc to, centroid;
3231

3332
/* Calculate the centroid location*/
34-
calculate_centroid_loc(b_from, false, centroid, NULL);
33+
calculate_centroid_loc(b_from, false, centroid, nullptr);
3534

3635
/* Find a location near the weighted centroid_loc */
3736
if (!find_to_loc_centroid(cluster_from_type, from, centroid, range_limiters, to, b_from)) {

0 commit comments

Comments
 (0)