Skip to content

Commit 4cb2cd9

Browse files
author
MohamedElgammal
committed
More commenting
1 parent 6b88b4b commit 4cb2cd9

File tree

7 files changed

+79
-72
lines changed

7 files changed

+79
-72
lines changed

vpr/src/base/vpr_context.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ struct ClusteringContext : public Context {
289289
};
290290

291291
/**
292-
* @brief State relating to helper data structure using in clustering
292+
* @brief State relating to helper data structure using in the clustering stage
293293
*
294-
* This should contain helper data structures that is useful in clustering/packing.
294+
* This should contain helper data structures that are useful in the clustering/packing stage.
295295
* They are encapsulated here as they are useful in clustering and reclustering algorithms that may be used
296296
* in packing or placement stages.
297297
*/
@@ -314,10 +314,10 @@ struct ClusteringHelperContext : public Context {
314314
// total number of CLBs
315315
int total_clb_num;
316316

317-
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types
317+
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
318318
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
319319

320-
// the utilization of external input/output pins during packing
320+
// the utilization of external input/output pins during packing (between 0 and 1)
321321
t_ext_pin_util_targets target_external_pin_util;
322322

323323
~ClusteringHelperContext() {

vpr/src/base/vpr_types.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,6 @@ const t_pb* t_pb::find_pb_for_model(const std::string& blif_model) const {
147147
return nullptr; //Not found
148148
}
149149

150-
/**
151-
* @brief Deep copy function for t_pb class
152-
*
153-
* This funcion deeply copies some data members of
154-
* t_pb class to be used to retrieve pb.
155-
*
156-
* This function is currently used in re-clustering API.
157-
*/
158-
void t_pb::pb_deep_copy(const t_pb* rhs) {
159-
name = rhs->name;
160-
pb_graph_node = rhs->pb_graph_node;
161-
mode = rhs->mode;
162-
parent_pb = rhs->parent_pb;
163-
pb_stats = rhs->pb_stats;
164-
clock_net = rhs->clock_net;
165-
pin_rotations_ = rhs->pin_rotations_;
166-
}
167-
168150
/**
169151
* @brief Returns the root pb containing this pb
170152
*/
@@ -281,4 +263,4 @@ void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_s
281263
free(cluster_placement_stats_list[index].valid_primitives);
282264
}
283265
free(cluster_placement_stats_list);
284-
}
266+
}

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,6 @@ class t_pb {
277277

278278
// Member functions
279279

280-
/**
281-
* @brief Deep copy function for t_pb class
282-
*
283-
* This funcion deeply copies some data members of
284-
* t_pb class to be used to retrieve pb.
285-
*
286-
* This function is currently used in re-clustering API.
287-
*/
288-
void pb_deep_copy(const t_pb* rhs);
289-
290280
///@brief Returns true if this block has not parent pb block
291281
bool is_root() const { return parent_pb == nullptr; }
292282

vpr/src/pack/re_cluster.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3737

3838
//remove the molecule from its current cluster
3939
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
40-
if(old_clb_atoms.size() == 1) {
40+
if (old_clb_atoms.size() == 1) {
4141
VTR_LOGV(verbosity > 4, "Atom: %zu move failed. This is the last atom in its cluster.\n");
4242
return false;
4343
}
@@ -109,7 +109,7 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
109109

110110
//remove the molecule from its current cluster
111111
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
112-
if(old_clb_atoms.size() == 1) {
112+
if (old_clb_atoms.size() == 1) {
113113
VTR_LOGV(verbosity > 4, "Atom: %zu move failed. This is the last atom in its cluster.\n");
114114
return false;
115115
}
@@ -128,7 +128,7 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
128128

129129
//Add the atom to the new cluster
130130
t_lb_router_data* new_router_data = nullptr;
131-
is_added = pack_mol_in_existing_cluster(molecule, new_clb, new_clb_atoms, during_packing, clustering_data, false, new_router_data);
131+
is_added = pack_mol_in_existing_cluster(molecule, new_clb, new_clb_atoms, during_packing, false, clustering_data, new_router_data);
132132

133133
//Commit or revert the move
134134
if (is_added) {
@@ -184,23 +184,21 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
184184
std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms(clb_1);
185185
std::vector<AtomBlockId> clb_2_atoms = cluster_to_atoms(clb_2);
186186

187-
if(clb_1_atoms.size() == 1 || clb_2_atoms.size() == 1) {
187+
if (clb_1_atoms.size() == 1 || clb_2_atoms.size() == 1) {
188188
VTR_LOGV(verbosity > 4, "Atom: %zu, %zu swap failed. This is the last atom in its cluster.\n", molecule_1->atom_block_ids[molecule_1->root], molecule_2->atom_block_ids[molecule_2->root]);
189189
return false;
190190
}
191191

192192
//remove the molecule from its current cluster
193193
remove_mol_from_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, old_1_router_data);
194194
commit_mol_removal(molecule_1, molecule_1_size, clb_1, during_packing, old_1_router_data, clustering_data);
195-
195+
196196
remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, old_2_router_data);
197-
commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
198-
197+
commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
199198

200199
//Add the atom to the new cluster
201-
mol_1_success = pack_mol_in_existing_cluster(molecule_1, clb_2, clb_2_atoms, during_packing, clustering_data, true, old_2_router_data);
202-
mol_2_success = pack_mol_in_existing_cluster(molecule_2, clb_1, clb_1_atoms, during_packing, clustering_data, true, old_1_router_data);
203-
200+
mol_1_success = pack_mol_in_existing_cluster(molecule_1, clb_2, clb_2_atoms, during_packing, true, clustering_data, old_2_router_data);
201+
mol_2_success = pack_mol_in_existing_cluster(molecule_2, clb_1, clb_1_atoms, during_packing, true, clustering_data, old_1_router_data);
204202

205203
//commit the move if succeeded or revert if failed
206204
if (mol_1_success && mol_2_success) {
@@ -211,7 +209,6 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
211209
VTR_LOGV(verbosity > 4, "Molecules swap failed\n");
212210
}
213211

214-
215212
//If the move is done after packing not during it, some fixes need to be done on the clustered netlist
216213
if (mol_1_success && mol_2_success && !during_packing) {
217214
fix_clustered_netlist(molecule_1, molecule_1_size, clb_1, clb_2);
@@ -221,4 +218,4 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
221218
//return the move result
222219
return (mol_1_success && mol_2_success);
223220
}
224-
#endif
221+
#endif

vpr/src/pack/re_cluster.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
#include "cluster_util.h"
1616

1717
/**
18-
* @brief This function moves a molecule out of its cluster and create a new cluster for it
18+
* @brief This function moves a molecule out of its cluster and creates a new cluster for it
1919
*
2020
* This function can be called from 2 spots in the vpr flow.
2121
* - First, during packing to optimize the initial clustered netlist
2222
* (during_packing variable should be true.)
23-
* - Second, during placement (during_packing variable should be false)
23+
* - Second, during placement (during_packing variable should be false). In this case, the clustered
24+
* netlist is updated.
2425
*/
2526
bool move_mol_to_new_cluster(t_pack_molecule* molecule,
2627
bool during_packing,
@@ -33,7 +34,8 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3334
* This function can be called from 2 spots in the vpr flow.
3435
* - First, during packing to optimize the initial clustered netlist
3536
* (during_packing variable should be true.)
36-
* - Second, during placement (during_packing variable should be false)
37+
* - Second, during placement (during_packing variable should be false). In this case, the clustered
38+
* netlist is updated.
3739
*/
3840
bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
3941
const ClusterBlockId& new_clb,
@@ -47,11 +49,12 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
4749
* This function can be called from 2 spots in the vpr flow.
4850
* - First, during packing to optimize the initial clustered netlist
4951
* (during_packing variable should be true.)
50-
* - Second, during placement (during_packing variable should be false)
52+
* - Second, during placement (during_packing variable should be false). In this case, the clustered
53+
* netlist is updated.
5154
*/
5255
bool swap_two_molecules(t_pack_molecule* molecule_1,
5356
t_pack_molecule* molecule_2,
5457
bool during_packing,
5558
int verbosity,
5659
t_clustering_data& clustering_data);
57-
#endif
60+
#endif

vpr/src/pack/re_cluster_util.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ void remove_mol_from_cluster(const t_pack_molecule* molecule,
5858
t_lb_router_data*& router_data) {
5959
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
6060

61-
//Determine the cluster ID
62-
old_clb = atom_to_cluster(molecule->atom_block_ids[molecule->root]);
63-
//std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
64-
6561
//re-build router_data structure for this cluster
6662
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, old_clb, old_clb_atoms);
6763

@@ -80,6 +76,7 @@ void commit_mol_move(const ClusterBlockId& old_clb,
8076
bool new_clb_created) {
8177
auto& device_ctx = g_vpr_ctx.device();
8278

79+
//Place the new cluster if this function called during placement (after the initial placement is done)
8380
if (!during_packing && new_clb_created) {
8481
int imacro;
8582
g_vpr_ctx.mutable_placement().block_locs.resize(g_vpr_ctx.placement().block_locs.size() + 1);
@@ -166,6 +163,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
166163
clb_index = cluster_ctx.clb_nlist.create_block(new_name.c_str(), pb, type);
167164
helper_ctx.total_clb_num++;
168165

166+
//If you are still in packing, update the clustering data. Otherwise, update the clustered netlist.
169167
if (during_packing) {
170168
clustering_data.intra_lb_routing.push_back((*router_data)->saved_lb_nets);
171169
(*router_data)->saved_lb_nets = nullptr;
@@ -188,8 +186,8 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
188186
const ClusterBlockId new_clb,
189187
const std::vector<AtomBlockId>& new_clb_atoms,
190188
bool during_packing,
191-
t_clustering_data& clustering_data,
192189
bool is_swap,
190+
t_clustering_data& clustering_data,
193191
t_lb_router_data*& router_data) {
194192
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
195193
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
@@ -204,7 +202,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
204202
rebuild_cluster_placemet_stats(new_clb, new_clb_atoms, cluster_ctx.clb_nlist.block_type(new_clb)->index, cluster_ctx.clb_nlist.block_pb(new_clb)->mode);
205203

206204
//re-build router_data structure for this cluster
207-
if(!is_swap)
205+
if (!is_swap)
208206
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
209207

210208
pack_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_type->index]),
@@ -225,6 +223,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
225223

226224
// If clustering succeeds, add it to the clb netlist
227225
if (pack_result == BLK_PASSED) {
226+
//If you are still in packing, update the clustering data. Otherwise, update the clustered netlist.
228227
if (during_packing) {
229228
free_intra_lb_nets(clustering_data.intra_lb_routing[new_clb]);
230229
clustering_data.intra_lb_routing[new_clb] = router_data->saved_lb_nets;
@@ -235,12 +234,12 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
235234
}
236235
}
237236

238-
if(pack_result == BLK_PASSED || !is_swap ) {
237+
if (pack_result == BLK_PASSED || !is_swap) {
239238
//Free clustering router data
240239
free_router_data(router_data);
241240
router_data = nullptr;
242241
}
243-
242+
244243
return (pack_result == BLK_PASSED);
245244
}
246245

@@ -277,6 +276,7 @@ void revert_mol_move(const ClusterBlockId& old_clb,
277276
temp_cluster_pr_original);
278277

279278
VTR_ASSERT(pack_result == BLK_PASSED);
279+
//If you are still in packing, update the clustering data. Otherwise, update the clustered netlist.
280280
if (during_packing) {
281281
free_intra_lb_nets(clustering_data.intra_lb_routing[old_clb]);
282282
clustering_data.intra_lb_routing[old_clb] = old_router_data->saved_lb_nets;
@@ -384,8 +384,10 @@ static void fix_cluster_pins_after_moving(const ClusterBlockId clb_index) {
384384
int iport, ipb_pin, ipin, rr_node_index;
385385

386386
ipin = 0;
387+
// iterating over input ports
387388
for (iport = 0; iport < num_input_ports; iport++) {
388389
ClusterPortId input_port_id = cluster_ctx.clb_nlist.find_port(clb_index, block_type->pb_type->ports[iport].name);
390+
// iterating over physical block pins of each input port
389391
for (ipb_pin = 0; ipb_pin < pb->pb_graph_node->num_input_pins[iport]; ipb_pin++) {
390392
pb_graph_pin = &pb->pb_graph_node->input_pins[iport][ipb_pin];
391393
rr_node_index = pb_graph_pin->pin_count_in_cluster;
@@ -408,8 +410,10 @@ static void fix_cluster_pins_after_moving(const ClusterBlockId clb_index) {
408410
}
409411
}
410412

413+
// iterating over output ports
411414
for (iport = 0; iport < num_output_ports; iport++) {
412415
ClusterPortId output_port_id = cluster_ctx.clb_nlist.find_port(clb_index, block_type->pb_type->ports[num_input_ports + iport].name);
416+
// iterating over physical block pins of each output port
413417
for (ipb_pin = 0; ipb_pin < pb->pb_graph_node->num_output_pins[iport]; ipb_pin++) {
414418
pb_graph_pin = &pb->pb_graph_node->output_pins[iport][ipb_pin];
415419
rr_node_index = pb_graph_pin->pin_count_in_cluster;
@@ -437,8 +441,10 @@ static void fix_cluster_pins_after_moving(const ClusterBlockId clb_index) {
437441
}
438442
}
439443

444+
// iterating over clock ports
440445
for (iport = 0; iport < num_clock_ports; iport++) {
441446
ClusterPortId clock_port_id = cluster_ctx.clb_nlist.find_port(clb_index, block_type->pb_type->ports[num_input_ports + num_output_ports + iport].name);
447+
// iterating over physical block pins of each clock port
442448
for (ipb_pin = 0; ipb_pin < pb->pb_graph_node->num_clock_pins[iport]; ipb_pin++) {
443449
pb_graph_pin = &pb->pb_graph_node->clock_pins[iport][ipb_pin];
444450
rr_node_index = pb_graph_pin->pin_count_in_cluster;
@@ -651,6 +657,7 @@ void commit_mol_removal(const t_pack_molecule* molecule,
651657

652658
cleanup_pb(cluster_ctx.clb_nlist.block_pb(old_clb));
653659

660+
//If you are still in packing, update the clustering data. Otherwise, update the clustered netlist.
654661
if (during_packing) {
655662
free_intra_lb_nets(clustering_data.intra_lb_routing[old_clb]);
656663
clustering_data.intra_lb_routing[old_clb] = router_data->saved_lb_nets;
@@ -679,4 +686,4 @@ bool check_type_and_mode_compitability(const ClusterBlockId& old_clb,
679686
}
680687

681688
return true;
682-
}
689+
}

0 commit comments

Comments
 (0)