P4C
The P4 Compiler
Loading...
Searching...
No Matches
optimize_phv.h
1
19#ifndef BF_P4C_PHV_OPTIMIZE_PHV_H_
20#define BF_P4C_PHV_OPTIMIZE_PHV_H_
21
22#include <optional>
23
24#include "bf-p4c/phv/allocate_phv.h"
25#include "bf-p4c/phv/phv_fields.h"
26#include "bf-p4c/phv/utils/utils.h"
27
29 // Mapping table of Transaction -> SuperCluster
30 std::unordered_map<PHV::Transaction *, PHV::SuperCluster *> tr_to_sc_i;
31 // Mapping table of Transaction -> Unique Transaction ID
32 std::unordered_map<PHV::Transaction *, int> tr_to_tr_id_i;
33 // Ordered Mapping table of Unique Transaction ID -> Transaction
34 std::map<int, PHV::Transaction *> tr_id_to_tr_i;
35 // Ordered Mapping table of Container -> Set of Unique Transaction ID
36 std::map<PHV::Container, std::set<int>> container_to_tr_ids_i;
37 // Next Transaction ID to use. Removed Transaction ID are never re-used
38 int next_tr_id = 0;
39
40 // Mapping table of Unique Transaction ID -> Diff for logging purpose
41 std::map<int, const cstring> tr_id_to_diff;
42};
43
65 // Limit the number of dependant transactions when trying to replace a transaction.
66 static constexpr int MAX_PRUNED_TRANSACTIONS = 16;
67 // Limit the number of passes we spend on trying to optimize the solution. One pass is equal
68 // to the number of transaction eligible to be replaced.
69 static constexpr int MAX_OPT_PASS = 2;
70 // Number of passes that try to optimize the solution without any dark spilling. This is to
71 // help Table Allocation fitting.
72 static constexpr int MAX_OPT_PASS_WO_DARK = 1;
73 // Only apply this optimization process if the solution have at least 32 Transactions. This is
74 // to avoid trying to optimize the pounding rounds except if that one is huge and have
75 // potential to be swapped differently.
76 static constexpr int MIN_TR_SIZE = 32;
77 // Largest SuperCluster to optimize. If at least one SuperCluster is larger than that, cancel
78 // the optimization process since we don't have much chance to find a solution.
79 static constexpr size_t MAX_SC_BIT = 64;
80 // Maximum number of bits to place through the optimization process.
81 static constexpr size_t MAX_TOTAL_SC_BIT = 256;
82
83 // Required to call the BruteForceAllocationStrategy allocation services.
84 BruteForceAllocationStrategy &alloc_strategy_i;
85 const std::list<PHV::ContainerGroup *> &container_groups_i;
86 const ScoreContext &score_ctx_i;
87
88 // Transaction Data that is continuously updated to increase the solution score.
89 TransactData *data;
90
91 // Build a sequence of Transaction In/Out if tr_id is removed.
92 bool buildSeqWithout(int tr_id, std::list<int> &tr_in, std::list<int> &tr_out);
93
94 // Play a sequence on top of a particular Transaction.
95 BruteForceOptimizationStrategy playSeq(std::list<int> &tr_in, PHV::Transaction &partial_alloc);
96
97 public:
99 BruteForceAllocationStrategy &alloc_strategy_i,
100 const std::list<PHV::ContainerGroup *> &container_groups, const ScoreContext &score_ctx)
101 : alloc_strategy_i(alloc_strategy_i),
102 container_groups_i(container_groups),
103 score_ctx_i(score_ctx) {
104 data = new TransactData();
105 }
106
107 // Insert a Transaction/SuperCluster to the optimization strategy.
108 void addTransaction(PHV::Transaction &transaction, PHV::SuperCluster &sc, int tr_id = -1);
109
110 // Start the optimization process.
111 std::list<PHV::SuperCluster *> optimize(std::list<PHV::SuperCluster *> &unallocated_sc,
112 PHV::Transaction &rst);
113
114 // Print the Container to Transaction Dependencies.
115 void printContDependency();
116};
117
118#endif /* BF_P4C_PHV_OPTIMIZE_PHV_H_ */
Definition allocate_phv.h:694
Definition optimize_phv.h:64
void addTransaction(PHV::Transaction &transaction, PHV::SuperCluster &sc, int tr_id=-1)
Definition optimize_phv.cpp:29
std::list< PHV::SuperCluster * > optimize(std::list< PHV::SuperCluster * > &unallocated_sc, PHV::Transaction &rst)
Definition optimize_phv.cpp:177
void printContDependency()
Definition optimize_phv.cpp:391
Definition phv/utils/utils.h:1049
Definition phv/utils/utils.h:561
ScoreContext can compute a alloc score for an PHV::Transaction.
Definition allocate_phv.h:306
Definition optimize_phv.h:28