P4C
The P4 Compiler
Loading...
Searching...
No Matches
greedy_tx_score.h
1
19#ifndef BF_P4C_PHV_V2_GREEDY_TX_SCORE_H_
20#define BF_P4C_PHV_V2_GREEDY_TX_SCORE_H_
21
22#include "bf-p4c/phv/v2/kind_size_indexed_map.h"
23#include "bf-p4c/phv/v2/phv_kit.h"
24#include "bf-p4c/phv/v2/tx_score.h"
25
26namespace PHV {
27namespace v2 {
28
30using ContainerByte = std::pair<Container, int>;
34using StageIxbarContBytesMap = ordered_map<int, ordered_set<ContainerByte>>;
35
39struct Vision {
41 enum class ContGress {
42 ingress,
43 egress,
44 unassigned,
45 };
46
56
57 // TODO: maybe a good idea to add learning quanta and pov bits limit here?
58 // ordered_map<gress_t, int> pov_bits_used;
59 // ordered_map<gress_t, int> pov_bits_unallocated;
60
61 // The direction of dataflow for table matching is
62 // phv-bytes ======> ixbar (groups) =======> search bus ========> SRAM/TCAM table.
63 // (1) (2)
64 // (1) Constraints are:
65 // + 32-bit container bytes must be mapped to same mod-4 bytes.
66 // + 16-bit container bytes must be mapped to same mod-2 bytes.
67 // + 8-bit container byte can be mapped to any bytes.
68 // (2) Constraints are:
69 // + search bus read from one of 8 (exact) or 12 (ternary) ixbar group.
70 // + For ternary, a group is of 5 + 1 (4bit of mid-byte) bytes group.
71 // + For sram, a group has 16 bytes.
72
81
83 int bits_demand(const PHV::Kind &k) const;
84 int bits_supply(const PHV::Kind &k) const;
85 bool has_more_than_enough(const PHV::Kind &k) const {
86 return bits_supply(k) >= bits_demand(k);
87 };
88};
89
90std::ostream &operator<<(std::ostream &, const ContainerByte &);
91std::ostream &operator<<(std::ostream &, const Vision &);
92
94 private:
95 const PhvKit &kit_i;
96
97 Vision vision_i;
98 std::set<const Field *> table_key_with_ranges;
99
100 friend class GreedyTxScore;
101 friend std::ostream &operator<<(std::ostream &, const Vision &);
102
103 public:
104 GreedyTxScoreMaker(const PhvKit &utils, const std::list<ContainerGroup *> &container_groups,
105 const std::list<SuperCluster *> &sorted_clusters,
107
108 TxScore *make(const Transaction &tx) const override;
109
111 void record_commit(const Transaction &tx, const SuperCluster *presliced_sc);
112
117 const ConcreteAllocation &curr_alloc,
118 const ordered_set<AllocSlice> &slices);
119
120 cstring status() const;
121
122 // algorithms
123 public:
132 static int ixbar_imbalanced_alignment(const ordered_set<ContainerByte> &cont_bytes);
133};
134
136class GreedyTxScore : public TxScore {
137 private:
138 const GreedyTxScoreMaker *maker_i = nullptr;
139 const Vision *vision_i;
140
143 int used_L1_bits() const;
144
146 int used_L2_bits() const;
147
148 friend class GreedyTxScoreMaker;
149
150 private:
159 KindSizeIndexedMap used_bits;
160
162 KindSizeIndexedMap used_containers;
163
165 KindSizeIndexedMap n_set_gress;
166 KindSizeIndexedMap n_set_parser_gress;
167 KindSizeIndexedMap n_set_deparser_gress;
168 KindSizeIndexedMap n_mismatched_deparser_gress;
169 // TODO
170 // {n_mismatched_deparser_gress, weighted_delta[n_mismatched_deparser_gress], false},
171
174 ordered_map<int, int> ixbar_bytes;
175
177 int n_size_overflow = 0;
178
187 int n_max_overflowed = 0;
188
191 int n_tphv_on_phv_bits = 0;
192
194 int n_inc_used_tphv_collection = 0;
195
198 int n_pov_deparser_read_bits = 0;
199
202 int n_deparser_read_learning_bytes = 0;
203
207 int n_table_new_ixbar_bytes = 0;
208
212 int n_stage_new_ixbar_bytes = 0;
213
214 // sum of the imbalanced alignment for all tables involved in this tx.
215 int n_table_ixbar_imbalanced_alignments = 0;
216
217 // sum of the imbalanced alignment of ixbar bytes,
218 // for all stages that are (1) involved in this tx and (2) the remaining bytes of the stage
219 // are less than threshold.
220 int n_overloaded_stage_ixbar_imbalanced_alignments = 0;
221
222 // For TCAM table match keys, amount of nibbles occupied, i.e. the width of the span
223 // between first and last nibble occupied.
224 int n_range_match_nibbles_occupied = 0;
225
226 public:
227 explicit GreedyTxScore(const Vision *vision) : vision_i(vision) {}
228
230 bool better_than(const TxScore *other) const override;
231
233 std::string str() const override;
234
236 bool has_mismatch_gress() const;
237};
238
239} // namespace v2
240} // namespace PHV
241
242#endif /* BF_P4C_PHV_V2_GREEDY_TX_SCORE_H_ */
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv/utils/utils.h:506
Definition phv/utils/utils.h:1049
Definition phv/utils/utils.h:561
GreedyTxScore is the default allocation heuristics.
Definition greedy_tx_score.h:136
std::string str() const override
Definition phv/v2/greedy_tx_score.cpp:634
bool has_mismatch_gress() const
Definition phv/v2/greedy_tx_score.cpp:630
bool better_than(const TxScore *other) const override
Definition phv/v2/greedy_tx_score.cpp:565
Definition greedy_tx_score.h:93
KindSizeIndexedMap record_deallocation(const SuperCluster *sc, const ConcreteAllocation &curr_alloc, const ordered_set< AllocSlice > &slices)
Definition phv/v2/greedy_tx_score.cpp:239
static int ixbar_imbalanced_alignment(const ordered_set< ContainerByte > &cont_bytes)
Definition phv/v2/greedy_tx_score.cpp:145
void record_commit(const Transaction &tx, const SuperCluster *presliced_sc)
update vision_i.
Definition phv/v2/greedy_tx_score.cpp:210
TxScore is the interface of an allocation score.
Definition tx_score.h:28
TxScoreMaker is the interface of the factory class of TxScore.
Definition tx_score.h:35
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Kind
Definition phv.h:44
Definition kind_size_indexed_map.h:30
Definition phv_kit.h:46
Definition greedy_tx_score.h:39
TableIxbarContBytesMap table_ixbar_cont_bytes
maps table to allocated match key positions.
Definition greedy_tx_score.h:74
ordered_map< ContGress, KindSizeIndexedMap > cont_available
Definition greedy_tx_score.h:55
StageIxbarContBytesMap stage_sram_ixbar_cont_bytes
Definition greedy_tx_score.h:77
ContGress
ContGress represents the hardware gress constraint of a container.
Definition greedy_tx_score.h:41
ordered_map< const SuperCluster *, KindSizeIndexedMap > sc_cont_required
Definition greedy_tx_score.h:49
ordered_map< gress_t, KindSizeIndexedMap > cont_required
Definition greedy_tx_score.h:52
StageIxbarContBytesMap stage_tcam_ixbar_cont_bytes
Definition greedy_tx_score.h:80
int bits_demand(const PHV::Kind &k) const
supply vs demand in terms of bits.
Definition phv/v2/greedy_tx_score.cpp:123