Skip to content

Commit 4ccc910

Browse files
add more comments
1 parent 6d722f3 commit 4ccc910

File tree

4 files changed

+43
-51
lines changed

4 files changed

+43
-51
lines changed

vpr/src/base/blk_loc_registry.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class BlkLocRegistry {
3737
///@brief Clustered pin placement mapping with physical pin
3838
vtr::vector_map<ClusterPinId, int> physical_pins_;
3939

40+
/**
41+
* @brief Contains information about placement macros.
42+
* A placement macro is a set of clustered blocks that must be placed
43+
* in a way that is compliant with relative locations specified by the macro.
44+
*/
4045
PlaceMacros place_macros_;
4146

4247
public:
@@ -55,8 +60,10 @@ class BlkLocRegistry {
5560
///@brief Returns the physical pin of the tile, related to the given ClusterNedId, and the net pin index.
5661
int net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const;
5762

63+
///@brief Returns a constant reference to placement macros.
5864
const PlaceMacros& place_macros() const;
5965

66+
///@brief Returns a mutable reference to placement macros.
6067
PlaceMacros& mutable_place_macros();
6168

6269
/**

vpr/src/place/place_macro.cpp

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,16 @@ void PlaceMacros::alloc_and_load_placement_macros(const std::vector<t_direct_inf
6666
* the amount of memory required for the actual variables.
6767
* 2) Allocate the actual variables with the exact amount of
6868
* memory. Then loads the data from the temporary data
69-
* structures before freeing them.
70-
*
71-
* For pl_macro_member_blk_num, allocate for the first dimension
72-
* only at first. Allocate for the second dimension when I know
73-
* the size. Otherwise, the array is going to be of size
74-
* cluster_ctx.clb_nlist.blocks().size()^2 (There are big
75-
* benchmarks VPR that have cluster_ctx.clb_nlist.blocks().size()
76-
* in the 100k's range).
77-
*
78-
* The placement macro array is freed by the caller(s).
69+
* structures before freeing them.
7970
*/
80-
auto& cluster_ctx = g_vpr_ctx.clustering();
71+
const auto& cluster_ctx = g_vpr_ctx.clustering();
8172

8273
// Allocate maximum memory for temporary variables.
8374
std::vector<int> pl_macro_idirect(cluster_ctx.clb_nlist.blocks().size());
8475
std::vector<int> pl_macro_num_members(cluster_ctx.clb_nlist.blocks().size());
76+
/* For pl_macro_member_blk_num, Allocate for the first dimension only at first. Allocate for the second dimension
77+
* when I know the size. Otherwise, the array is going to be of size cluster_ctx.clb_nlist.blocks().size()^2 */
8578
std::vector<std::vector<ClusterBlockId>> pl_macro_member_blk_num(cluster_ctx.clb_nlist.blocks().size());
86-
std::vector<ClusterBlockId> pl_macro_member_blk_num_of_this_blk(cluster_ctx.clb_nlist.blocks().size());
8779

8880
alloc_and_load_idirect_from_blk_pin_(directs);
8981

@@ -94,8 +86,7 @@ void PlaceMacros::alloc_and_load_placement_macros(const std::vector<t_direct_inf
9486
* Head - blocks with to_pin OPEN and from_pin connected
9587
* Tail - blocks with to_pin connected and from_pin OPEN
9688
*/
97-
int num_macro = find_all_the_macro_(pl_macro_member_blk_num_of_this_blk,
98-
pl_macro_idirect, pl_macro_num_members, pl_macro_member_blk_num);
89+
const int num_macro = find_all_the_macro_(pl_macro_idirect, pl_macro_num_members, pl_macro_member_blk_num);
9990

10091
// Allocate the memories for the macro.
10192
pl_macros_.resize(num_macro);
@@ -133,8 +124,7 @@ ClusterBlockId PlaceMacros::macro_head(ClusterBlockId blk) const {
133124
}
134125
}
135126

136-
int PlaceMacros::find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_member_blk_num_of_this_blk,
137-
std::vector<int>& pl_macro_idirect,
127+
int PlaceMacros::find_all_the_macro_(std::vector<int>& pl_macro_idirect,
138128
std::vector<int>& pl_macro_num_members,
139129
std::vector<std::vector<ClusterBlockId>>& pl_macro_member_blk_num) {
140130
/* Compute required size: *
@@ -143,30 +133,26 @@ int PlaceMacros::find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_membe
143133
* as the number macros) and also the length of each macro *
144134
* Head - blocks with to_pin OPEN and from_pin connected *
145135
* Tail - blocks with to_pin connected and from_pin OPEN */
146-
147-
int from_iblk_pin, to_iblk_pin, from_idirect, to_idirect,
148-
from_src_or_sink, to_src_or_sink;
149-
ClusterNetId to_net_id, from_net_id, next_net_id, curr_net_id;
150-
ClusterBlockId next_blk_id;
151-
int num_blk_pins, num_macro;
152-
int imember;
153-
auto& cluster_ctx = g_vpr_ctx.clustering();
136+
const auto& cluster_ctx = g_vpr_ctx.clustering();
137+
std::vector<ClusterBlockId> pl_macro_member_blk_num_of_this_blk(cluster_ctx.clb_nlist.blocks().size());
154138

155139
// Hash table holding the unique cluster ids and the macro id it belongs to
156140
std::unordered_map<ClusterBlockId, int> clusters_macro;
157141

158-
num_macro = 0;
159-
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
160-
auto logical_block = cluster_ctx.clb_nlist.block_type(blk_id);
161-
auto physical_tile = pick_physical_type(logical_block);
142+
// counts the total number of macros
143+
int num_macro = 0;
144+
145+
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
146+
t_logical_block_type_ptr logical_block = cluster_ctx.clb_nlist.block_type(blk_id);
147+
t_physical_tile_type_ptr physical_tile = pick_physical_type(logical_block);
162148

163-
num_blk_pins = cluster_ctx.clb_nlist.block_type(blk_id)->pb_type->num_pins;
164-
for (to_iblk_pin = 0; to_iblk_pin < num_blk_pins; to_iblk_pin++) {
149+
int num_blk_pins = cluster_ctx.clb_nlist.block_type(blk_id)->pb_type->num_pins;
150+
for (int to_iblk_pin = 0; to_iblk_pin < num_blk_pins; to_iblk_pin++) {
165151
int to_physical_pin = get_physical_pin(physical_tile, logical_block, to_iblk_pin);
166152

167-
to_net_id = cluster_ctx.clb_nlist.block_net(blk_id, to_iblk_pin);
168-
to_idirect = idirect_from_blk_pin_[physical_tile->index][to_physical_pin];
169-
to_src_or_sink = direct_type_from_blk_pin_[physical_tile->index][to_physical_pin];
153+
ClusterNetId to_net_id = cluster_ctx.clb_nlist.block_net(blk_id, to_iblk_pin);
154+
int to_idirect = idirect_from_blk_pin_[physical_tile->index][to_physical_pin];
155+
int to_src_or_sink = direct_type_from_blk_pin_[physical_tile->index][to_physical_pin];
170156

171157
// Identify potential macro head blocks (i.e. start of a macro)
172158
//
@@ -177,16 +163,14 @@ int PlaceMacros::find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_membe
177163
// Note that the restriction that constant nets are not driven from another direct ensures that
178164
// blocks in the middle of a chain with internal constant signals are not detected as potential
179165
// head blocks.
180-
if (to_src_or_sink == SINK && to_idirect != OPEN
181-
&& (to_net_id == ClusterNetId::INVALID()
182-
|| (is_constant_clb_net(to_net_id)
183-
&& !net_is_driven_by_direct_(to_net_id)))) {
184-
for (from_iblk_pin = 0; from_iblk_pin < num_blk_pins; from_iblk_pin++) {
166+
if (to_src_or_sink == SINK && to_idirect != OPEN &&
167+
(to_net_id == ClusterNetId::INVALID() || (is_constant_clb_net(to_net_id) && !net_is_driven_by_direct_(to_net_id)))) {
168+
for (int from_iblk_pin = 0; from_iblk_pin < num_blk_pins; from_iblk_pin++) {
185169
int from_physical_pin = get_physical_pin(physical_tile, logical_block, from_iblk_pin);
186170

187-
from_net_id = cluster_ctx.clb_nlist.block_net(blk_id, from_iblk_pin);
188-
from_idirect = idirect_from_blk_pin_[physical_tile->index][from_physical_pin];
189-
from_src_or_sink = direct_type_from_blk_pin_[physical_tile->index][from_physical_pin];
171+
ClusterNetId from_net_id = cluster_ctx.clb_nlist.block_net(blk_id, from_iblk_pin);
172+
int from_idirect = idirect_from_blk_pin_[physical_tile->index][from_physical_pin];
173+
int from_src_or_sink = direct_type_from_blk_pin_[physical_tile->index][from_physical_pin];
190174

191175
// Confirm whether this is a head macro
192176
//
@@ -204,12 +188,12 @@ int PlaceMacros::find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_membe
204188
// there are at least 2 members - 1 head and 1 tail.
205189

206190
// Initialize the variables
207-
next_net_id = from_net_id;
208-
next_blk_id = blk_id;
191+
ClusterNetId next_net_id = from_net_id;
192+
ClusterBlockId next_blk_id = blk_id;
209193

210194
// Start finding the other members
211195
while (next_net_id != ClusterNetId::INVALID()) {
212-
curr_net_id = next_net_id;
196+
ClusterNetId curr_net_id = next_net_id;
213197

214198
// Assume that carry chains only has 1 sink - direct connection
215199
VTR_ASSERT(cluster_ctx.clb_nlist.net_sinks(curr_net_id).size() == 1);
@@ -221,7 +205,7 @@ int PlaceMacros::find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_membe
221205
next_net_id = cluster_ctx.clb_nlist.block_net(next_blk_id, from_iblk_pin);
222206

223207
// Mark down this block as a member of the macro
224-
imember = pl_macro_num_members[num_macro];
208+
int imember = pl_macro_num_members[num_macro];
225209
pl_macro_member_blk_num_of_this_blk[imember] = next_blk_id;
226210

227211
// Increment the num_member count.
@@ -233,7 +217,7 @@ int PlaceMacros::find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_membe
233217
pl_macro_member_blk_num[num_macro].resize(pl_macro_num_members[num_macro]);
234218
int matching_macro = -1;
235219
// Copy the data from the temporary array to the newly allocated array.
236-
for (imember = 0; imember < pl_macro_num_members[num_macro]; imember++) {
220+
for (int imember = 0; imember < pl_macro_num_members[num_macro]; imember++) {
237221
auto cluster_id = pl_macro_member_blk_num_of_this_blk[imember];
238222
pl_macro_member_blk_num[num_macro][imember] = cluster_id;
239223
// check if this cluster block was in a previous macro
@@ -382,7 +366,7 @@ static bool try_combine_macros(std::vector<std::vector<ClusterBlockId>>& pl_macr
382366
int PlaceMacros::get_imacro_from_iblk(ClusterBlockId iblk) const {
383367
int imacro;
384368
if (iblk != ClusterBlockId::INVALID()) {
385-
/* Return the imacro for the block. */
369+
// Return the imacro for the block.
386370
imacro = imacro_from_iblk_[iblk];
387371
} else {
388372
imacro = OPEN; //No valid block, so no valid macro
@@ -619,7 +603,7 @@ void PlaceMacros::write_place_macros_(std::string filename, const std::vector<t_
619603
}
620604

621605
static bool is_constant_clb_net(ClusterNetId clb_net) {
622-
auto& atom_ctx = g_vpr_ctx.atom();
606+
const auto& atom_ctx = g_vpr_ctx.atom();
623607
AtomNetId atom_net = atom_ctx.lookup.atom_net(clb_net);
624608

625609
return atom_ctx.nlist.net_is_constant(atom_net);

vpr/src/place/place_macro.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ class PlaceMacros {
223223
std::vector<t_pl_macro> pl_macros_;
224224

225225
private:
226-
int find_all_the_macro_(std::vector<ClusterBlockId>& pl_macro_member_blk_num_of_this_blk,
227-
std::vector<int>& pl_macro_idirect,
226+
int find_all_the_macro_(std::vector<int>& pl_macro_idirect,
228227
std::vector<int>& pl_macro_num_members,
229228
std::vector<std::vector<ClusterBlockId>>& pl_macro_member_blk_num);
230229

vpr/src/place/weighted_centroid_move_generator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
* @brief Weighted Centroid move generator
88
*
99
* This move generator is inspired by analytical placers: model net connections as springs and
10-
* calculate the force equilibrium location.
10+
* calculate the force equilibrium location.
11+
*
12+
* @details This class inherits from CentroidMoveGenerator to avoid code duplication.
1113
*
1214
* For more details, please refer to:
1315
* "Learn to Place: FPGA Placement using Reinforcement Learning and Directed Moves", ICFPT2020

0 commit comments

Comments
 (0)