Skip to content

Commit 041e0f1

Browse files
Merge pull request #2034 from verilog-to-routing/re_clustering_api
Refactoring clustering/packing code and building re-cluster API
2 parents e8b1b04 + bf943cb commit 041e0f1

30 files changed

+4759
-3907
lines changed

vpr/src/base/read_netlist.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static size_t mark_constant_generators_rec(const t_pb* pb, const t_pb_routes& pb
6060
static t_pb_routes alloc_pb_route(t_pb_graph_node* pb_graph_node);
6161

6262
static void load_atom_pin_mapping(const ClusteredNetlist& clb_nlist);
63-
static void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist, const AtomBlockId atom_blk, const AtomPortId atom_port, const t_pb_graph_pin* gpin);
6463

6564
/**
6665
* @brief Initializes the clb_nlist with info from a netlist
@@ -1219,7 +1218,7 @@ static void load_atom_pin_mapping(const ClusteredNetlist& clb_nlist) {
12191218
}
12201219
}
12211220

1222-
static void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist, const AtomBlockId atom_blk, const AtomPortId atom_port, const t_pb_graph_pin* gpin) {
1221+
void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist, const AtomBlockId atom_blk, const AtomPortId atom_port, const t_pb_graph_pin* gpin) {
12231222
auto& atom_ctx = g_vpr_ctx.mutable_atom();
12241223

12251224
VTR_ASSERT(atom_ctx.nlist.port_block(atom_port) == atom_blk);

vpr/src/base/read_netlist.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ ClusteredNetlist read_netlist(const char* net_file,
1717
bool verify_file_digests,
1818
int verbosity);
1919

20+
void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist,
21+
const AtomBlockId atom_blk,
22+
const AtomPortId atom_port,
23+
const t_pb_graph_pin* gpin);
24+
2025
#endif

vpr/src/base/vpr_api.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a
348348
}
349349

350350
fflush(stdout);
351+
352+
auto& helper_ctx = g_vpr_ctx.mutable_helper();
353+
helper_ctx.lb_type_rr_graphs = vpr_setup->PackerRRGraph;
351354
}
352355

353356
bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
@@ -382,6 +385,14 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
382385
{ //Analysis
383386
vpr_analysis_flow(vpr_setup, arch, route_status);
384387
}
388+
389+
//clean packing-placement data
390+
if (vpr_setup.PackerOpts.doPacking == STAGE_DO) {
391+
auto& helper_ctx = g_vpr_ctx.mutable_helper();
392+
free_cluster_placement_stats(helper_ctx.cluster_placement_stats);
393+
}
394+
395+
//close the graphics
385396
vpr_close_graphics(vpr_setup);
386397

387398
return route_status.success();

vpr/src/base/vpr_context.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ struct AtomContext : public Context {
5555
/********************************************************************
5656
* Atom Netlist
5757
********************************************************************/
58-
58+
AtomContext()
59+
: list_of_pack_molecules(nullptr, free_pack_molecules) {}
5960
///@brief Atom netlist
6061
AtomNetlist nlist;
6162

6263
///@brief Mappings to/from the Atom Netlist to physically described .blif models
6364
AtomLookup lookup;
65+
66+
///@brief The molecules associated with each atom block
67+
std::multimap<AtomBlockId, t_pack_molecule*> atom_molecules;
68+
69+
std::unique_ptr<t_pack_molecule, decltype(&free_pack_molecules)> list_of_pack_molecules;
6470
};
6571

6672
/**
@@ -259,6 +265,26 @@ struct ClusteringContext : public Context {
259265
*/
260266
std::map<ClusterBlockId, std::map<int, ClusterNetId>> post_routing_clb_pin_nets;
261267
std::map<ClusterBlockId, std::map<int, int>> pre_routing_net_pin_mapping;
268+
269+
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
270+
};
271+
272+
struct ClusteringHelperContext : public Context {
273+
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
274+
t_cluster_placement_stats* cluster_placement_stats;
275+
int num_models;
276+
int max_cluster_size;
277+
t_pb_graph_node** primitives_list;
278+
279+
bool enable_pin_feasibility_filter;
280+
int feasible_block_array_size;
281+
282+
int total_clb_num;
283+
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
284+
285+
~ClusteringHelperContext() {
286+
free(primitives_list);
287+
}
262288
};
263289

264290
/**
@@ -446,6 +472,9 @@ class VprContext : public Context {
446472
const ClusteringContext& clustering() const { return clustering_; }
447473
ClusteringContext& mutable_clustering() { return clustering_; }
448474

475+
const ClusteringHelperContext& helper() const { return helper_; }
476+
ClusteringHelperContext& mutable_helper() { return helper_; }
477+
449478
const PlacementContext& placement() const { return placement_; }
450479
PlacementContext& mutable_placement() { return placement_; }
451480

@@ -464,6 +493,8 @@ class VprContext : public Context {
464493
PowerContext power_;
465494

466495
ClusteringContext clustering_;
496+
ClusteringHelperContext helper_;
497+
467498
PlacementContext placement_;
468499
RoutingContext routing_;
469500
FloorplanningContext constraints_;

vpr/src/base/vpr_types.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cmath>
22
#include "vpr_types.h"
3+
#include "globals.h"
34

45
t_ext_pin_util_targets::t_ext_pin_util_targets(float default_in_util, float default_out_util) {
56
defaults_.input_pin_util = default_in_util;
@@ -213,3 +214,53 @@ BitIndex t_pb::atom_pin_bit_index(const t_pb_graph_pin* gpin) const {
213214
void t_pb::set_atom_pin_bit_index(const t_pb_graph_pin* gpin, BitIndex atom_pin_bit_idx) {
214215
pin_rotations_[gpin] = atom_pin_bit_idx;
215216
}
217+
218+
void free_pack_molecules(t_pack_molecule* list_of_pack_molecules) {
219+
t_pack_molecule* cur_pack_molecule = list_of_pack_molecules;
220+
while (cur_pack_molecule != nullptr) {
221+
cur_pack_molecule = list_of_pack_molecules->next;
222+
delete list_of_pack_molecules;
223+
list_of_pack_molecules = cur_pack_molecule;
224+
}
225+
}
226+
227+
/**
228+
* Free linked lists found in cluster_placement_stats_list
229+
*/
230+
void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_stats_list) {
231+
t_cluster_placement_primitive *cur, *next;
232+
auto& device_ctx = g_vpr_ctx.device();
233+
234+
for (const auto& type : device_ctx.logical_block_types) {
235+
int index = type.index;
236+
cur = cluster_placement_stats_list[index].tried;
237+
while (cur != nullptr) {
238+
next = cur->next_primitive;
239+
free(cur);
240+
cur = next;
241+
}
242+
cur = cluster_placement_stats_list[index].in_flight;
243+
while (cur != nullptr) {
244+
next = cur->next_primitive;
245+
free(cur);
246+
cur = next;
247+
}
248+
cur = cluster_placement_stats_list[index].invalid;
249+
while (cur != nullptr) {
250+
next = cur->next_primitive;
251+
free(cur);
252+
cur = next;
253+
}
254+
for (int j = 0; j < cluster_placement_stats_list[index].num_pb_types; j++) {
255+
cur = cluster_placement_stats_list[index].valid_primitives[j]->next_primitive;
256+
while (cur != nullptr) {
257+
next = cur->next_primitive;
258+
free(cur);
259+
cur = next;
260+
}
261+
free(cluster_placement_stats_list[index].valid_primitives[j]);
262+
}
263+
free(cluster_placement_stats_list[index].valid_primitives);
264+
}
265+
free(cluster_placement_stats_list);
266+
}

vpr/src/base/vpr_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,4 +1654,9 @@ class RouteStatus {
16541654

16551655
typedef vtr::vector<ClusterBlockId, std::vector<std::vector<int>>> t_clb_opins_used; //[0..num_blocks-1][0..class-1][0..used_pins-1]
16561656

1657+
typedef std::vector<std::map<int, int>> t_arch_switch_fanin;
1658+
1659+
void free_pack_molecules(t_pack_molecule* list_of_pack_molecules);
1660+
void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_stats);
1661+
16571662
#endif

0 commit comments

Comments
 (0)