Skip to content

Commit

Permalink
Merge pull request #2703 from AlexandreSinger/feature-prepacker-rework
Browse files Browse the repository at this point in the history
[Prepacking] Re-Designed Prepacker API
  • Loading branch information
vaughnbetz authored Aug 27, 2024
2 parents b69fa0e + 0408e7d commit c7b9ce0
Show file tree
Hide file tree
Showing 16 changed files with 596 additions and 537 deletions.
32 changes: 8 additions & 24 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <mutex>

#include "prepack.h"
#include "vpr_types.h"
#include "vtr_ndmatrix.h"
#include "vtr_optional.h"
Expand Down Expand Up @@ -72,34 +73,17 @@ struct AtomContext : public Context {
/********************************************************************
* Atom Netlist
********************************************************************/
/**
* @brief constructor
*
* In the constructor initialize the list of pack molecules to nullptr and defines a custom deletor for it
*/
AtomContext()
: list_of_pack_molecules(nullptr, free_pack_molecules) {}

///@brief Atom netlist
/// @brief Atom netlist
AtomNetlist nlist;

///@brief Mappings to/from the Atom Netlist to physically described .blif models
/// @brief Mappings to/from the Atom Netlist to physically described .blif models
AtomLookup lookup;

/**
* @brief The molecules associated with each atom block.
*
* This map is loaded in the pre-packing stage and freed at the very end of vpr flow run.
* The pointers in this multimap is shared with list_of_pack_molecules.
*/
std::multimap<AtomBlockId, t_pack_molecule*> atom_molecules;

/**
* @brief A linked list of all the packing molecules that are loaded in pre-packing stage.
*
* Is is useful in freeing the pack molecules at the destructor of the Atom context using free_pack_molecules.
*/
std::unique_ptr<t_pack_molecule, decltype(&free_pack_molecules)> list_of_pack_molecules;
/// @brief Prepacker object which performs prepacking and stores the pack
/// molecules. Has a method to get the pack molecule of an AtomBlock.
/// TODO: This is mainly only used in the clusterer. It can probably be
/// removed from the AtomContext entirely.
Prepacker prepacker;
};

/**
Expand Down
9 changes: 0 additions & 9 deletions vpr/src/base/vpr_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,6 @@ void t_pb::set_atom_pin_bit_index(const t_pb_graph_pin* gpin, BitIndex atom_pin_
pin_rotations_[gpin] = atom_pin_bit_idx;
}

void free_pack_molecules(t_pack_molecule* list_of_pack_molecules) {
t_pack_molecule* cur_pack_molecule = list_of_pack_molecules;
while (cur_pack_molecule != nullptr) {
cur_pack_molecule = list_of_pack_molecules->next;
delete list_of_pack_molecules;
list_of_pack_molecules = cur_pack_molecule;
}
}

/**
* Free linked lists found in cluster_placement_stats_list
*/
Expand Down
5 changes: 0 additions & 5 deletions vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1847,11 +1847,6 @@ typedef vtr::vector<ClusterBlockId, std::vector<std::vector<RRNodeId>>> t_clb_op

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

/**
* @brief Free the linked list that saves all the packing molecules.
*/
void free_pack_molecules(t_pack_molecule* list_of_pack_molecules);

/**
* @brief Free the linked lists to placement locations based on status of primitive inside placement stats data structure.
*/
Expand Down
57 changes: 19 additions & 38 deletions vpr/src/pack/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,28 @@
* The output of clustering is 400 t_pb of type BLE which represent the clustered user netlist.
* Each of the 400 t_pb will reference one of the 4 BLE-type t_pb_graph_nodes.
*/
#include "cluster.h"

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <algorithm>
#include <fstream>

#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_math.h"
#include "vtr_memory.h"

#include "vpr_types.h"
#include "vpr_error.h"

#include "globals.h"
#include "PreClusterDelayCalculator.h"
#include "atom_netlist.h"
#include "pack_types.h"
#include "cluster.h"
#include "cluster_util.h"
#include "output_clustering.h"
#include "SetupGrid.h"
#include "read_xml_arch_file.h"
#include "vpr_utils.h"
#include "cluster_placement.h"
#include "echo_files.h"
#include "cluster_router.h"
#include "lb_type_rr_graph.h"

#include "timing_info.h"
#include "timing_reports.h"
#include "PreClusterDelayCalculator.h"
#include "PreClusterTimingGraphResolver.h"
#include "tatum/echo_writer.hpp"
#include "tatum/report/graphviz_dot_writer.hpp"
#include "tatum/TimingReporter.hpp"

#include "re_cluster_util.h"
#include "cluster_util.h"
#include "constraints_report.h"
#include "globals.h"
#include "pack_types.h"
#include "prepack.h"
#include "timing_info.h"
#include "vpr_types.h"
#include "vpr_utils.h"
#include "vtr_assert.h"
#include "vtr_log.h"

/*
* When attraction groups are created, the purpose is to pack more densely by adding more molecules
Expand All @@ -87,10 +69,9 @@ static constexpr int ATTRACTION_GROUPS_MAX_REPEATED_MOLECULES = 500;
std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& packer_opts,
const t_analysis_opts& analysis_opts,
const t_arch* arch,
t_pack_molecule* molecule_head,
Prepacker& prepacker,
const std::unordered_set<AtomNetId>& is_clock,
const std::unordered_set<AtomNetId>& is_global,
const std::unordered_map<AtomBlockId, t_pb_graph_node*>& expected_lowest_cost_pb_gnode,
bool allow_unrelated_clustering,
bool balance_block_type_utilization,
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,
Expand Down Expand Up @@ -173,11 +154,11 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
helper_ctx.max_cluster_size = 0;
max_pb_depth = 0;

const t_molecule_stats max_molecule_stats = calc_max_molecules_stats(molecule_head);
const t_molecule_stats max_molecule_stats = prepacker.calc_max_molecule_stats(atom_ctx.nlist);

mark_all_molecules_valid(molecule_head);
prepacker.mark_all_molecules_valid();

cluster_stats.num_molecules = count_molecules(molecule_head);
cluster_stats.num_molecules = prepacker.get_num_molecules();

get_max_cluster_size_and_pb_depth(helper_ctx.max_cluster_size, max_pb_depth);

Expand All @@ -193,7 +174,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
check_for_duplicate_inputs ();
#endif
alloc_and_init_clustering(max_molecule_stats,
&(helper_ctx.cluster_placement_stats), &(helper_ctx.primitives_list), molecule_head,
&(helper_ctx.cluster_placement_stats), &(helper_ctx.primitives_list), prepacker,
clustering_data, net_output_feeds_driving_block_input,
unclustered_list_head_size, cluster_stats.num_molecules);

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

if (packer_opts.timing_driven) {
calc_init_packing_timing(packer_opts, analysis_opts, expected_lowest_cost_pb_gnode,
calc_init_packing_timing(packer_opts, analysis_opts, prepacker,
clustering_delay_calc, timing_info, atom_criticality);
}

Expand Down
7 changes: 4 additions & 3 deletions vpr/src/pack/cluster.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef CLUSTER_H
#define CLUSTER_H
#include <unordered_map>

#include <unordered_set>
#include <map>
#include <vector>
Expand All @@ -11,13 +11,14 @@
#include "attraction_groups.h"
#include "cluster_util.h"

class Prepacker;

std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& packer_opts,
const t_analysis_opts& analysis_opts,
const t_arch* arch,
t_pack_molecule* molecule_head,
Prepacker& prepacker,
const std::unordered_set<AtomNetId>& is_clock,
const std::unordered_set<AtomNetId>& is_global,
const std::unordered_map<AtomBlockId, t_pb_graph_node*>& expected_lowest_cost_pb_gnode,
bool allow_unrelated_clustering,
bool balance_block_type_utilization,
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,
Expand Down
Loading

0 comments on commit c7b9ce0

Please sign in to comment.