Skip to content

Commit 90c3579

Browse files
[Prepacking] Re-Designed Prepacker API
The original Prepacker API created a lot of global variables which were confusing to work with and hard to maintain. Created a Prepacker class which maintains the state of the Prepacker and provides methods to access prepacking information. I also tried to remove the accesses to the global scope from within the prepacker to isolate it from the rest of VTR. This is in an attempt to make it easier to work with.
1 parent 79a5bc8 commit 90c3579

15 files changed

+468
-391
lines changed

vpr/src/base/vpr_context.h

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66
#include <mutex>
77

8+
#include "prepack.h"
89
#include "vpr_types.h"
910
#include "vtr_ndmatrix.h"
1011
#include "vtr_optional.h"
@@ -72,34 +73,17 @@ struct AtomContext : public Context {
7273
/********************************************************************
7374
* Atom Netlist
7475
********************************************************************/
75-
/**
76-
* @brief constructor
77-
*
78-
* In the constructor initialize the list of pack molecules to nullptr and defines a custom deletor for it
79-
*/
80-
AtomContext()
81-
: list_of_pack_molecules(nullptr, free_pack_molecules) {}
82-
83-
///@brief Atom netlist
76+
/// @brief Atom netlist
8477
AtomNetlist nlist;
8578

86-
///@brief Mappings to/from the Atom Netlist to physically described .blif models
79+
/// @brief Mappings to/from the Atom Netlist to physically described .blif models
8780
AtomLookup lookup;
8881

89-
/**
90-
* @brief The molecules associated with each atom block.
91-
*
92-
* This map is loaded in the pre-packing stage and freed at the very end of vpr flow run.
93-
* The pointers in this multimap is shared with list_of_pack_molecules.
94-
*/
95-
std::multimap<AtomBlockId, t_pack_molecule*> atom_molecules;
96-
97-
/**
98-
* @brief A linked list of all the packing molecules that are loaded in pre-packing stage.
99-
*
100-
* Is is useful in freeing the pack molecules at the destructor of the Atom context using free_pack_molecules.
101-
*/
102-
std::unique_ptr<t_pack_molecule, decltype(&free_pack_molecules)> list_of_pack_molecules;
82+
/// @brief Prepacker object which performs prepacking and stores the pack
83+
/// molecules. Has a method to get the pack molecule of an AtomBlock.
84+
/// TODO: This is mainly only used in the clusterer. It can probably be
85+
/// removed from the AtomContext entirely.
86+
Prepacker prepacker;
10387
};
10488

10589
/**

vpr/src/base/vpr_types.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,6 @@ void t_pb::set_atom_pin_bit_index(const t_pb_graph_pin* gpin, BitIndex atom_pin_
452452
pin_rotations_[gpin] = atom_pin_bit_idx;
453453
}
454454

455-
void free_pack_molecules(t_pack_molecule* list_of_pack_molecules) {
456-
t_pack_molecule* cur_pack_molecule = list_of_pack_molecules;
457-
while (cur_pack_molecule != nullptr) {
458-
cur_pack_molecule = list_of_pack_molecules->next;
459-
delete list_of_pack_molecules;
460-
list_of_pack_molecules = cur_pack_molecule;
461-
}
462-
}
463-
464455
/**
465456
* Free linked lists found in cluster_placement_stats_list
466457
*/

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,11 +1847,6 @@ typedef vtr::vector<ClusterBlockId, std::vector<std::vector<RRNodeId>>> t_clb_op
18471847

18481848
typedef std::vector<std::map<int, int>> t_arch_switch_fanin;
18491849

1850-
/**
1851-
* @brief Free the linked list that saves all the packing molecules.
1852-
*/
1853-
void free_pack_molecules(t_pack_molecule* list_of_pack_molecules);
1854-
18551850
/**
18561851
* @brief Free the linked lists to placement locations based on status of primitive inside placement stats data structure.
18571852
*/

vpr/src/pack/cluster.cpp

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,28 @@
3333
* The output of clustering is 400 t_pb of type BLE which represent the clustered user netlist.
3434
* Each of the 400 t_pb will reference one of the 4 BLE-type t_pb_graph_nodes.
3535
*/
36+
#include "cluster.h"
37+
38+
#include <algorithm>
3639
#include <cstdio>
3740
#include <cstdlib>
3841
#include <cstring>
3942
#include <ctime>
4043
#include <map>
41-
#include <algorithm>
42-
#include <fstream>
43-
44-
#include "vtr_assert.h"
45-
#include "vtr_log.h"
46-
#include "vtr_math.h"
47-
#include "vtr_memory.h"
4844

49-
#include "vpr_types.h"
50-
#include "vpr_error.h"
51-
52-
#include "globals.h"
45+
#include "PreClusterDelayCalculator.h"
5346
#include "atom_netlist.h"
54-
#include "pack_types.h"
55-
#include "cluster.h"
56-
#include "cluster_util.h"
57-
#include "output_clustering.h"
58-
#include "SetupGrid.h"
59-
#include "read_xml_arch_file.h"
60-
#include "vpr_utils.h"
61-
#include "cluster_placement.h"
62-
#include "echo_files.h"
6347
#include "cluster_router.h"
64-
#include "lb_type_rr_graph.h"
65-
66-
#include "timing_info.h"
67-
#include "timing_reports.h"
68-
#include "PreClusterDelayCalculator.h"
69-
#include "PreClusterTimingGraphResolver.h"
70-
#include "tatum/echo_writer.hpp"
71-
#include "tatum/report/graphviz_dot_writer.hpp"
72-
#include "tatum/TimingReporter.hpp"
73-
74-
#include "re_cluster_util.h"
48+
#include "cluster_util.h"
7549
#include "constraints_report.h"
50+
#include "globals.h"
51+
#include "pack_types.h"
52+
#include "prepack.h"
53+
#include "timing_info.h"
54+
#include "vpr_types.h"
55+
#include "vpr_utils.h"
56+
#include "vtr_assert.h"
57+
#include "vtr_log.h"
7658

7759
/*
7860
* When attraction groups are created, the purpose is to pack more densely by adding more molecules
@@ -87,10 +69,9 @@ static constexpr int ATTRACTION_GROUPS_MAX_REPEATED_MOLECULES = 500;
8769
std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& packer_opts,
8870
const t_analysis_opts& analysis_opts,
8971
const t_arch* arch,
90-
t_pack_molecule* molecule_head,
72+
Prepacker& prepacker,
9173
const std::unordered_set<AtomNetId>& is_clock,
9274
const std::unordered_set<AtomNetId>& is_global,
93-
const std::unordered_map<AtomBlockId, t_pb_graph_node*>& expected_lowest_cost_pb_gnode,
9475
bool allow_unrelated_clustering,
9576
bool balance_block_type_utilization,
9677
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,
@@ -173,11 +154,11 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
173154
helper_ctx.max_cluster_size = 0;
174155
max_pb_depth = 0;
175156

176-
const t_molecule_stats max_molecule_stats = calc_max_molecules_stats(molecule_head);
157+
const t_molecule_stats max_molecule_stats = prepacker.calc_max_molecule_stats(atom_ctx.nlist);
177158

178-
mark_all_molecules_valid(molecule_head);
159+
prepacker.mark_all_molecules_valid();
179160

180-
cluster_stats.num_molecules = count_molecules(molecule_head);
161+
cluster_stats.num_molecules = prepacker.get_num_molecules();
181162

182163
get_max_cluster_size_and_pb_depth(helper_ctx.max_cluster_size, max_pb_depth);
183164

@@ -193,7 +174,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
193174
check_for_duplicate_inputs ();
194175
#endif
195176
alloc_and_init_clustering(max_molecule_stats,
196-
&(helper_ctx.cluster_placement_stats), &(helper_ctx.primitives_list), molecule_head,
177+
&(helper_ctx.cluster_placement_stats), &(helper_ctx.primitives_list), prepacker,
197178
clustering_data, net_output_feeds_driving_block_input,
198179
unclustered_list_head_size, cluster_stats.num_molecules);
199180

@@ -213,7 +194,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
213194
vtr::vector<AtomBlockId, float> atom_criticality(atom_ctx.nlist.blocks().size(), 0.);
214195

215196
if (packer_opts.timing_driven) {
216-
calc_init_packing_timing(packer_opts, analysis_opts, expected_lowest_cost_pb_gnode,
197+
calc_init_packing_timing(packer_opts, analysis_opts, prepacker,
217198
clustering_delay_calc, timing_info, atom_criticality);
218199
}
219200

vpr/src/pack/cluster.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef CLUSTER_H
22
#define CLUSTER_H
3-
#include <unordered_map>
3+
44
#include <unordered_set>
55
#include <map>
66
#include <vector>
@@ -11,13 +11,14 @@
1111
#include "attraction_groups.h"
1212
#include "cluster_util.h"
1313

14+
class Prepacker;
15+
1416
std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& packer_opts,
1517
const t_analysis_opts& analysis_opts,
1618
const t_arch* arch,
17-
t_pack_molecule* molecule_head,
19+
Prepacker& prepacker,
1820
const std::unordered_set<AtomNetId>& is_clock,
1921
const std::unordered_set<AtomNetId>& is_global,
20-
const std::unordered_map<AtomBlockId, t_pb_graph_node*>& expected_lowest_cost_pb_gnode,
2122
bool allow_unrelated_clustering,
2223
bool balance_block_type_utilization,
2324
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,

0 commit comments

Comments
 (0)