Skip to content

Commit fca017a

Browse files
authored
Merge pull request #2396 from verilog-to-routing/placement_move_primitive
Placement Refactoring
2 parents 31f60a5 + d000874 commit fca017a

15 files changed

+2510
-2072
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,10 @@ struct t_logical_block_type {
924924
std::vector<t_physical_tile_type_ptr> equivalent_tiles; ///>List of physical tiles at which one could
925925
///>place this type of netlist block.
926926

927-
std::unordered_map<int, t_pb_graph_pin*> pin_logical_num_to_pb_pin_mapping; /* pin_logical_num_to_pb_pin_mapping[pin logical number] -> pb_graph_pin ptr} */
928-
std::unordered_map<const t_pb_graph_pin*, int> primitive_pb_pin_to_logical_class_num_mapping; /* primitive_pb_pin_to_logical_class_num_mapping[pb_graph_pin ptr] -> class logical number */
929-
std::vector<t_class> primitive_logical_class_inf; /* primitive_logical_class_inf[class_logical_number] -> class */
930-
std::unordered_map<const t_pb_graph_node*, t_class_range> pb_graph_node_class_range;
927+
std::unordered_map<int, t_pb_graph_pin*> pin_logical_num_to_pb_pin_mapping; /* pin_logical_num_to_pb_pin_mapping[pin logical number] -> pb_graph_pin ptr} */
928+
std::unordered_map<const t_pb_graph_pin*, int> primitive_pb_pin_to_logical_class_num_mapping; /* primitive_pb_pin_to_logical_class_num_mapping[pb_graph_pin ptr] -> class logical number */
929+
std::vector<t_class> primitive_logical_class_inf; /* primitive_logical_class_inf[class_logical_number] -> class */
930+
std::unordered_map<const t_pb_graph_node*, t_class_range> primitive_pb_graph_node_class_range; /* primitive_pb_graph_node_class_range[primitive_pb_graph_node ptr] -> class range for that primitive*/
931931

932932
// Is this t_logical_block_type empty?
933933
bool is_empty() const;
@@ -1239,6 +1239,12 @@ class t_pb_graph_node {
12391239

12401240
int placement_index;
12411241

1242+
/*
1243+
* There is a root-level pb_graph_node assigned to each logical type. Each logical type can contain multiple primitives.
1244+
* If this pb_graph_node is associated with a primitive, a unique number is assigned to it within the logical block level.
1245+
*/
1246+
int primitive_num = OPEN;
1247+
12421248
/* Contains a collection of mode indices that cannot be used as they produce conflicts during VPR packing stage
12431249
*
12441250
* Illegal modes do arise when children of a graph_node do have inconsistent `edge_modes` with respect to

libs/libarchfpga/src/physical_types_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ t_class_range get_pb_graph_node_class_physical_range(t_physical_tile_type_ptr /*
965965
const t_pb_graph_node* pb_graph_node) {
966966
VTR_ASSERT(pb_graph_node->is_primitive());
967967

968-
t_class_range class_range = logical_block->pb_graph_node_class_range.at(pb_graph_node);
968+
t_class_range class_range = logical_block->primitive_pb_graph_node_class_range.at(pb_graph_node);
969969
int logical_block_class_offset = sub_tile->primitive_class_range[sub_tile_relative_cap].at(logical_block).low;
970970

971971
class_range.low += logical_block_class_offset;

libs/libvtrutil/src/vtr_vec_id_set.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define VTR_SET_H
33

44
#include <vector>
5+
#include <algorithm>
56

67
namespace vtr {
78

vpr/src/base/vpr_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,4 +1919,10 @@ void free_pack_molecules(t_pack_molecule* list_of_pack_molecules);
19191919
*/
19201920
void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_stats);
19211921

1922+
struct pair_hash {
1923+
std::size_t operator()(const std::pair<ClusterBlockId, ClusterBlockId>& p) const noexcept {
1924+
return std::hash<ClusterBlockId>()(p.first) ^ (std::hash<ClusterBlockId>()(p.second) << 1);
1925+
}
1926+
};
1927+
19221928
#endif

vpr/src/pack/pb_type_graph.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
5050
const int index,
5151
const int flat_index,
5252
bool load_power_structures,
53-
int& pin_count_in_cluster);
53+
int& pin_count_in_cluster,
54+
int& primitive_num);
5455

5556
static void alloc_and_load_pb_graph_pin_sinks(t_pb_graph_node* pb_graph_node);
5657

@@ -153,13 +154,15 @@ void alloc_and_load_all_pb_graphs(bool load_power_structures, bool is_flat) {
153154
if (type.pb_type) {
154155
type.pb_graph_head = new t_pb_graph_node();
155156
int pin_count_in_cluster = 0;
157+
int primitive_num = 0;
156158
alloc_and_load_pb_graph(type.pb_graph_head,
157159
nullptr,
158160
type.pb_type,
159161
0,
160162
0,
161163
load_power_structures,
162-
pin_count_in_cluster);
164+
pin_count_in_cluster,
165+
primitive_num);
163166
type.pb_graph_head->total_pb_pins = pin_count_in_cluster;
164167
load_pin_classes_in_pb_graph_head(type.pb_graph_head);
165168
if (is_flat) {
@@ -233,7 +236,8 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
233236
const int index,
234237
const int flat_index,
235238
bool load_power_structures,
236-
int& pin_count_in_cluster) {
239+
int& pin_count_in_cluster,
240+
int& primitive_num) {
237241
int i, j, k, i_input, i_output, i_clockport;
238242

239243
pb_graph_node->placement_index = index;
@@ -350,6 +354,11 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
350354
pb_graph_node->pb_node_power->transistor_cnt_pb_children = 0.;
351355
}
352356

357+
if (pb_graph_node->is_primitive()) {
358+
pb_graph_node->primitive_num = primitive_num;
359+
primitive_num++;
360+
}
361+
353362
/* Allocate and load child nodes for each mode and create interconnect in each mode */
354363

355364
pb_graph_node->child_pb_graph_nodes = (t_pb_graph_node***)vtr::calloc(pb_type->num_modes, sizeof(t_pb_graph_node**));
@@ -368,7 +377,8 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
368377
k,
369378
child_flat_index,
370379
load_power_structures,
371-
pin_count_in_cluster);
380+
pin_count_in_cluster,
381+
primitive_num);
372382
}
373383
}
374384
}
@@ -384,6 +394,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
384394
load_power_structures);
385395
}
386396

397+
387398
// update the total number of primitives of that type
388399
if (pb_graph_node->is_primitive()) {
389400
int total_count = 1;
@@ -549,8 +560,8 @@ static void add_primitive_logical_classes(t_logical_block_type* logical_block) {
549560
}
550561
num_added_classes += add_port_logical_classes(logical_block, pb_graph_pins, num_ports, num_pins);
551562
}
552-
logical_block->pb_graph_node_class_range.insert(std::make_pair(pb_graph_node, t_class_range(first_class_num,
553-
first_class_num + num_added_classes - 1)));
563+
logical_block->primitive_pb_graph_node_class_range.insert(std::make_pair(pb_graph_node, t_class_range(first_class_num,
564+
first_class_num + num_added_classes - 1)));
554565
}
555566
}
556567

vpr/src/pack/re_cluster.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
200200
}
201201

202202
t_pb* clb_pb_1 = cluster_ctx.clb_nlist.block_pb(clb_1);
203-
std::string clb_pb_1_name = (std::string)clb_pb_1->name;
203+
std::string clb_pb_1_name = static_cast<std::string>(clb_pb_1->name);
204204
t_pb* clb_pb_2 = cluster_ctx.clb_nlist.block_pb(clb_2);
205-
std::string clb_pb_2_name = (std::string)clb_pb_2->name;
205+
std::string clb_pb_2_name = static_cast<std::string>(clb_pb_2->name);
206206

207207
//remove the molecule from its current cluster
208208
remove_mol_from_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, false, old_1_router_data);

vpr/src/pack/re_cluster_util.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "re_cluster_util.h"
2-
32
#include "clustered_netlist_utils.h"
43
#include "cluster_util.h"
54
#include "cluster_router.h"
@@ -8,7 +7,6 @@
87
#include "initial_placement.h"
98
#include "read_netlist.h"
109

11-
1210
// The name suffix of the new block (if exists)
1311
// This suffix is useful in preventing duplicate high-level cluster block names
1412
const char* name_suffix = "_m";

vpr/src/place/move_transactions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void clear_move_blocks(t_pl_blocks_to_be_moved& blocks_affected) {
128128

129129
//For run-time, we just reset num_moved_blocks to zero, but do not free the blocks_affected
130130
//array to avoid memory allocation
131+
131132
blocks_affected.num_moved_blocks = 0;
132133

133134
blocks_affected.affected_pins.clear();

vpr/src/place/move_transactions.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
* old_loc: the location the block is moved from *
1010
* new_loc: the location the block is moved to */
1111
struct t_pl_moved_block {
12+
t_pl_moved_block() = default;
13+
t_pl_moved_block(ClusterBlockId block_num_, const t_pl_loc& old_loc_, const t_pl_loc& new_loc_)
14+
: block_num(block_num_)
15+
, old_loc(old_loc_)
16+
, new_loc(new_loc_) {}
1217
ClusterBlockId block_num;
1318
t_pl_loc old_loc;
1419
t_pl_loc new_loc;
1520
};
1621

17-
/* Stores the list of blocks to be moved in a swap during *
22+
/* Stores the list of cluster blocks to be moved in a swap during *
1823
* placement. *
1924
* Store the information on the blocks to be moved in a swap during *
2025
* placement, in the form of array of structs instead of struct with *
@@ -29,7 +34,7 @@ struct t_pl_moved_block {
2934
* incrementally invalidate parts of the timing *
3035
* graph. */
3136
struct t_pl_blocks_to_be_moved {
32-
t_pl_blocks_to_be_moved(size_t max_blocks)
37+
explicit t_pl_blocks_to_be_moved(size_t max_blocks)
3338
: moved_blocks(max_blocks) {}
3439

3540
int num_moved_blocks = 0;

vpr/src/place/move_utils.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ void report_aborted_moves();
9595

9696
e_create_move create_move(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId b_from, t_pl_loc to);
9797

98+
/**
99+
* @brief Find the blocks that will be affected by a move of b_from to to_loc
100+
* @param blocks_affected Loaded by this routine and returned via reference; it lists the blocks etc. moved
101+
* @param b_from Id of the cluster-level block to be moved
102+
* @param to Where b_from will be moved to
103+
* @return e_block_move_result ABORT if either of the the moving blocks are already stored, or either of the blocks are fixed, to location is not
104+
* compatible, etc. INVERT if the "from" block is a single block and the "to" block is a macro. VALID otherwise.
105+
*/
98106
e_block_move_result find_affected_blocks(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId b_from, t_pl_loc to);
99107

100108
e_block_move_result record_single_block_swap(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId b_from, t_pl_loc to);
@@ -109,6 +117,12 @@ e_block_move_result record_macro_move(t_pl_blocks_to_be_moved& blocks_affected,
109117
e_block_move_result identify_macro_self_swap_affected_macros(std::vector<int>& macros, const int imacro, t_pl_offset swap_offset);
110118
e_block_move_result record_macro_self_swaps(t_pl_blocks_to_be_moved& blocks_affected, const int imacro, t_pl_offset swap_offset);
111119

120+
/**
121+
* @brief Check whether the "to" location is legal for the given "blk"
122+
* @param blk
123+
* @param to
124+
* @return True if this would be a legal move, false otherwise
125+
*/
112126
bool is_legal_swap_to_location(ClusterBlockId blk, t_pl_loc to);
113127

114128
std::set<t_pl_loc> determine_locations_emptied_by_move(t_pl_blocks_to_be_moved& blocks_affected);

0 commit comments

Comments
 (0)