4
4
#include " cluster_placement.h"
5
5
#include " cluster_router.h"
6
6
7
-
8
7
bool move_mol_to_new_cluster (t_pack_molecule* molecule,
9
8
t_clustering_data& clustering_data,
10
9
bool during_packing) {
11
10
auto & cluster_ctx = g_vpr_ctx.clustering ();
12
11
auto & helper_ctx = g_vpr_ctx.mutable_cl_helper ();
13
12
auto & device_ctx = g_vpr_ctx.device ();
14
- auto & atom_ctx = g_vpr_ctx.mutable_atom ();
15
13
16
14
bool is_removed, is_created;
17
- ClusterBlockId old_clb;
15
+ ClusterBlockId old_clb = atom_to_cluster (molecule->atom_block_ids [molecule->root ]);
16
+ ;
18
17
int molecule_size = get_array_size_of_molecule (molecule);
19
18
20
- // Backup the original pb of the molecule before the move
21
- std::vector<t_pb*> mol_pb_backup;
22
- for (int i_atom = 0 ; i_atom < molecule_size; i_atom++) {
23
- if (molecule->atom_block_ids [i_atom]) {
24
- t_pb* atom_pb_backup = new t_pb;
25
- atom_pb_backup->pb_deep_copy (atom_ctx.lookup .atom_pb (molecule->atom_block_ids [i_atom]));
26
- mol_pb_backup.push_back (atom_pb_backup);
27
- }
28
- }
29
-
30
19
PartitionRegion temp_cluster_pr;
31
20
t_lb_router_data* old_router_data = nullptr ;
32
21
t_lb_router_data* router_data = nullptr ;
33
22
34
23
// Check that there is a place for a new cluster of the same type
35
- old_clb = atom_to_cluster (molecule->atom_block_ids [molecule->root ]);
36
24
t_logical_block_type_ptr block_type = cluster_ctx.clb_nlist .block_type (old_clb);
37
25
int block_mode = cluster_ctx.clb_nlist .block_pb (old_clb)->mode ;
38
26
@@ -48,7 +36,7 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
48
36
}
49
37
50
38
// remove the molecule from its current cluster and check the cluster legality after
51
- is_removed = remove_mol_from_cluster (molecule, molecule_size, old_clb, old_router_data);
39
+ is_removed = remove_mol_from_cluster (molecule, molecule_size, old_clb, old_router_data, clustering_data, during_packing );
52
40
53
41
if (!is_removed) {
54
42
VTR_LOG (" Atom: %zu move failed. Can't remove it from the old cluster\n " , molecule->atom_block_ids [molecule->root ]);
@@ -70,31 +58,22 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
70
58
71
59
// Commit or revert the move
72
60
if (is_created) {
73
- commit_mol_move (old_clb, new_clb, mol_pb_backup, old_router_data, clustering_data, during_packing, true );
61
+ commit_mol_move (old_clb, new_clb, during_packing, true );
74
62
VTR_LOG (" Atom:%zu is moved to a new cluster\n " , molecule->atom_block_ids [molecule->root ]);
75
63
} else {
76
- int atom_idx = 0 ;
77
- for (int i_atom = 0 ; i_atom < molecule_size; i_atom++) {
78
- if (molecule->atom_block_ids [i_atom]) {
79
- atom_ctx.lookup .set_atom_clb (molecule->atom_block_ids [i_atom], old_clb);
80
- atom_ctx.lookup .set_atom_pb (molecule->atom_block_ids [i_atom], mol_pb_backup[atom_idx]);
81
- atom_idx++;
82
- }
83
- }
64
+ revert_mol_move (old_clb, molecule, old_router_data, during_packing, clustering_data);
84
65
VTR_LOG (" Atom:%zu move failed. Can't start a new cluster of the same type and mode\n " , molecule->atom_block_ids [molecule->root ]);
85
66
}
86
67
68
+ free_router_data (old_router_data);
69
+ old_router_data = nullptr ;
70
+
87
71
// If the move is done after packing not during it, some fixes need to be done on the
88
72
// clustered netlist
89
73
if (is_created && !during_packing) {
90
74
fix_clustered_netlist (molecule, molecule_size, old_clb, new_clb);
91
75
}
92
76
93
- for (auto atom_pb_backup : mol_pb_backup) {
94
- cleanup_pb (atom_pb_backup);
95
- delete atom_pb_backup;
96
- }
97
-
98
77
return (is_created);
99
78
}
100
79
@@ -104,7 +83,6 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
104
83
t_clustering_data& clustering_data) {
105
84
// define required contexts
106
85
auto & cluster_ctx = g_vpr_ctx.clustering ();
107
- auto & atom_ctx = g_vpr_ctx.mutable_atom ();
108
86
109
87
// define local variables
110
88
bool is_removed, is_added;
@@ -128,56 +106,39 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
128
106
return false ;
129
107
}
130
108
131
- // Backup the original pb of the atom before the move
132
- std::vector<t_pb*> mol_pb_backup;
133
- for (int i_atom = 0 ; i_atom < molecule_size; i_atom++) {
134
- if (molecule->atom_block_ids [i_atom]) {
135
- t_pb* atom_pb_backup = new t_pb;
136
- atom_pb_backup->pb_deep_copy (atom_ctx.lookup .atom_pb (molecule->atom_block_ids [i_atom]));
137
- mol_pb_backup.push_back (atom_pb_backup);
138
- }
139
- }
140
-
141
109
// remove the molecule from its current cluster and check the cluster legality
142
- is_removed = remove_mol_from_cluster (molecule, molecule_size, old_clb, old_router_data);
110
+ is_removed = remove_mol_from_cluster (molecule, molecule_size, old_clb, old_router_data, clustering_data, during_packing );
143
111
if (!is_removed) {
144
112
VTR_LOG (" Atom: %zu move failed. Can't remove it from the old cluster\n " , root_atom_id);
145
113
return false ;
146
114
}
147
115
116
+ 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 );
148
117
// Add the atom to the new cluster
149
118
is_added = pack_mol_in_existing_cluster (molecule, new_clb, new_clb_atoms, during_packing, clustering_data);
150
119
151
120
// Commit or revert the move
152
121
if (is_added) {
153
- commit_mol_move (old_clb, new_clb, mol_pb_backup, old_router_data, clustering_data, during_packing, false );
122
+ commit_mol_move (old_clb, new_clb, during_packing, false );
154
123
VTR_LOG (" Atom:%zu is moved to a new cluster\n " , molecule->atom_block_ids [molecule->root ]);
155
124
} else {
156
- int atom_idx = 0 ;
157
- for (int i_atom = 0 ; i_atom < molecule_size; i_atom++) {
158
- if (molecule->atom_block_ids [i_atom]) {
159
- atom_ctx.lookup .set_atom_clb (molecule->atom_block_ids [i_atom], old_clb);
160
- atom_ctx.lookup .set_atom_pb (molecule->atom_block_ids [i_atom], mol_pb_backup[atom_idx]);
161
- atom_idx++;
162
- }
163
- }
125
+ revert_mol_move (old_clb, molecule, old_router_data, during_packing, clustering_data);
164
126
VTR_LOG (" Atom:%zu move failed. Can't start a new cluster of the same type and mode\n " , molecule->atom_block_ids [molecule->root ]);
165
127
}
166
128
129
+ free_router_data (old_router_data);
130
+ old_router_data = nullptr ;
131
+
167
132
// If the move is done after packing not during it, some fixes need to be done on the
168
133
// clustered netlist
169
134
if (is_added && !during_packing) {
170
135
fix_clustered_netlist (molecule, molecule_size, old_clb, new_clb);
171
136
}
172
137
173
- for (auto atom_pb_backup : mol_pb_backup) {
174
- cleanup_pb (atom_pb_backup);
175
- delete atom_pb_backup;
176
- }
177
-
178
138
return (is_added);
179
139
}
180
140
141
+ #if 0
181
142
bool swap_two_molecules(t_pack_molecule* molecule_1,
182
143
t_pack_molecule* molecule_2,
183
144
bool during_packing,
@@ -262,8 +223,8 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
262
223
}
263
224
264
225
//add the molecules to their new clusters
265
- pack_1_result = try_pack_molecule (&(helper_ctx.cluster_placement_stats [block_1_type->index ]),
266
- molecule_1 ,
226
+ pack_2_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_1_type->index]),
227
+ molecule_2 ,
267
228
helper_ctx.primitives_list,
268
229
cluster_ctx.clb_nlist.block_pb(clb_1),
269
230
helper_ctx.num_models,
@@ -277,8 +238,8 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
277
238
target_ext_pin_util,
278
239
temp_cluster_pr_1);
279
240
280
- pack_2_result = try_pack_molecule (&(helper_ctx.cluster_placement_stats [block_2_type->index ]),
281
- molecule_2 ,
241
+ pack_1_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_2_type->index]),
242
+ molecule_1 ,
282
243
helper_ctx.primitives_list,
283
244
cluster_ctx.clb_nlist.block_pb(clb_2),
284
245
helper_ctx.num_models,
@@ -292,6 +253,8 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
292
253
target_ext_pin_util,
293
254
temp_cluster_pr_2);
294
255
256
+
257
+
295
258
//commit the move if succeeded or revert if failed
296
259
if (pack_1_result == BLK_PASSED && pack_2_result == BLK_PASSED) {
297
260
if(during_packing) {
@@ -308,8 +271,8 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
308
271
309
272
}
310
273
311
- commit_mol_move (clb_1, clb_2, mol_1_pb_backup, old_1_router_data, clustering_data, during_packing, false );
312
- commit_mol_move (clb_2, clb_1, mol_2_pb_backup, old_2_router_data, clustering_data, during_packing, false );
274
+ commit_mol_move(clb_1, clb_2, during_packing, false);
275
+ commit_mol_move(clb_2, clb_1, during_packing, false);
313
276
314
277
} else {
315
278
int atom_idx = 0;
@@ -357,4 +320,5 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
357
320
358
321
//return the move result
359
322
return (pack_1_result == BLK_PASSED && pack_2_result == BLK_PASSED);
360
- }
323
+ }
324
+ #endif
0 commit comments