19#ifndef BF_P4C_MAU_RESOURCE_ESTIMATE_H_
20#define BF_P4C_MAU_RESOURCE_ESTIMATE_H_
22#include "bf-p4c/mau/attached_entries.h"
23#include "bf-p4c/mau/table_layout.h"
24#include "lib/algorithm.h"
25#include "lib/safe_vector.h"
30 static constexpr int MIN_WAYS = 1;
31 static constexpr int MAX_WAYS = 8;
32 static constexpr int MAX_METER_ALUS = 4;
33 static constexpr int MAX_STATS_ALUS = 4;
34 static constexpr int MAX_LOCAL_TINDS = 16;
36 static constexpr int MAX_DLEFT_HASH_SIZE = 23;
37 static constexpr int COMPILER_DEFAULT_SELECTOR_POOLS = 4;
38 static constexpr int SINGLE_RAMLINE_POOL_SIZE = 120;
39 static constexpr int MAX_MOD = 31;
40 static constexpr int MAX_MOD_SHIFT = 5;
41 static constexpr int MAX_POOL_RAMLINES = MAX_MOD << MAX_MOD_SHIFT;
42 static constexpr int MOD_INPUT_BITS = 10;
49 int exact_ixbar_bytes = 0;
50 int ternary_ixbar_groups = 0;
54 int hash_bits_masked = 0;
69 size_t preferred_index = 0;
72 logical_ids += a.logical_ids;
75 local_tinds += a.local_tinds;
77 exact_ixbar_bytes += a.exact_ixbar_bytes;
78 ternary_ixbar_groups += a.ternary_ixbar_groups;
79 meter_alus += a.meter_alus;
80 stats_alus += a.stats_alus;
84 bool prev_placed,
bool gateway_attached,
bool disable_split,
PhvInfo &phv);
93 rv.logical_ids = StageUse::MAX_LOGICAL_IDS;
94 rv.srams = StageUse::MAX_SRAMS;
95 rv.tcams = StageUse::MAX_TCAMS;
96 rv.local_tinds = MAX_LOCAL_TINDS;
97 rv.maprams = StageUse::MAX_MAPRAMS;
98 rv.exact_ixbar_bytes = StageUse::MAX_IXBAR_BYTES;
99 rv.ternary_ixbar_groups = StageUse::MAX_TERNARY_GROUPS;
100 rv.meter_alus = MAX_METER_ALUS;
101 rv.stats_alus = MAX_STATS_ALUS;
105 return logical_ids <= a.logical_ids && srams <= a.srams && tcams <= a.tcams &&
106 maprams <= a.maprams && exact_ixbar_bytes <= a.exact_ixbar_bytes &&
107 ternary_ixbar_groups <= a.ternary_ixbar_groups && meter_alus < a.meter_alus &&
108 stats_alus <= a.stats_alus && local_tinds <= a.local_tinds;
115 exact_ixbar_bytes = 0;
116 ternary_ixbar_groups = 0;
123 void options_to_ways(
const IR::MAU::Table *tbl,
int entries);
124 void options_to_rams(
const IR::MAU::Table *tbl,
const attached_entries_t &att_entries);
125 void select_best_option(
const IR::MAU::Table *tbl);
126 void options_to_ternary_entries(
const IR::MAU::Table *tbl,
int entries);
127 void select_best_option_ternary();
130 void calculate_attached_rams(
const IR::MAU::Table *tbl,
const attached_entries_t &att_entries,
132 void fill_estimate_from_option(
int &entries);
133 void remove_invalid_option() {
134 erase_if(layout_options, [](
const LayoutOption &lo) {
return lo.entries == 0; });
137 if (layout_options.empty())
140 return &layout_options[preferred_index];
144 auto option = preferred();
145 if (option ==
nullptr)
return nullptr;
146 return &action_formats[option->action_format_index];
151 void determine_initial_layout_option(
const IR::MAU::Table *tbl,
int &entries,
155 bool calculate_for_leftover_srams(
const IR::MAU::Table *tbl,
int &srams_left,
int &entries,
157 void calculate_for_leftover_tcams(
const IR::MAU::Table *tbl,
int srams_left,
int tcams_left,
159 void calculate_for_leftover_atcams(
const IR::MAU::Table *tbl,
int srams_left,
int &entries,
161 void shrink_preferred_srams_lo(
const IR::MAU::Table *tbl,
int &entries,
163 void shrink_preferred_tcams_lo(
const IR::MAU::Table *tbl,
int &entries,
165 void shrink_preferred_atcams_lo(
const IR::MAU::Table *tbl,
int &entries,
169 void unknown_srams_needed(
const IR::MAU::Table *tbl,
LayoutOption *lo,
int srams_left);
170 void unknown_tcams_needed(
const IR::MAU::Table *tbl,
LayoutOption *lo,
int tcams_left,
177 void srams_left_best_option(
int srams_left);
178 void max_entries_best_option();
179 void tcams_left_best_option();
185 RAM_counter() : per_word(0), width(0), need_srams(
false), need_maprams(
false) {}
187 : per_word(p), width(w), need_srams(ns), need_maprams(nm) {}
192 int stages_required()
const;
195int CounterPerWord(
const IR::MAU::Counter *ctr);
196int CounterWidth(
const IR::MAU::Counter *ctr);
197int RegisterPerWord(
const IR::MAU::StatefulAlu *reg);
198int ActionDataPerWord(
const IR::MAU::Table::Layout *layout,
int *width);
199int ActionDataHuffmanVPNBits(
const IR::MAU::Table::Layout *layout);
200int ActionDataVPNStartPosition(
const IR::MAU::Table::Layout *layout);
201int ActionDataVPNIncrement(
const IR::MAU::Table::Layout *layout);
202int LocalTernaryIndirectPerWord(
const IR::MAU::Table::Layout *layout,
const IR::MAU::Table *tbl);
203int TernaryIndirectPerWord(
const IR::MAU::Table::Layout *layout,
const IR::MAU::Table *tbl);
204int IdleTimePerWord(
const IR::MAU::IdleTime *idletime);
205int SelectorRAMLinesPerEntry(
const IR::MAU::Selector *sel);
206int SelectorModBits(
const IR::MAU::Selector *sel);
207int SelectorShiftBits(
const IR::MAU::Selector *sel);
208int SelectorHashModBits(
const IR::MAU::Selector *sel);
209int SelectorLengthShiftBits(
const IR::MAU::Selector *sel);
210int SelectorLengthBits(
const IR::MAU::Selector *sel);
213 static constexpr int MULTIRANGE_DISTRIBUTION_LIMIT = 8;
214 static constexpr int RANGE_ENTRY_PERCENTAGE = 25;
219 int total_TCAM_lines = 0;
220 int max_entry_TCAM_lines = 1;
222 bool preorder(
const IR::MAU::TableSeq *)
override {
return false; }
223 bool preorder(
const IR::MAU::Action *)
override {
return false; }
224 bool preorder(
const IR::MAU::BackendAttached *)
override {
return false; }
225 bool preorder(
const IR::MAU::TableKey *)
override;
226 void postorder(
const IR::MAU::Table *)
override;
229 int TCAM_lines() {
return total_TCAM_lines; }
Definition table_layout.h:83
Definition table_layout.h:34
Definition mau_visitor.h:29
Definition safe_vector.h:27
Definition phv_fields.h:1095
Definition resource_estimate.h:212
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition resource_estimate.h:180
Definition resource_estimate.h:29
void calculate_way_sizes(const IR::MAU::Table *tbl, LayoutOption *lo, int &calculated_depth)
Definition resource_estimate.cpp:571
void options_to_dleft_entries(const IR::MAU::Table *tbl, const attached_entries_t &att_entries)
Definition resource_estimate.cpp:773
void calculate_partition_sizes(const IR::MAU::Table *tbl, LayoutOption *lo, int ram_depth)
Definition resource_estimate.cpp:727
void options_to_atcam_entries(const IR::MAU::Table *tbl, int entries)
Definition resource_estimate.cpp:750
void unknown_atcams_needed(const IR::MAU::Table *tbl, LayoutOption *lo, int srams_left)
Definition resource_estimate.cpp:1445
bool ways_provided(const IR::MAU::Table *tbl, LayoutOption *lo, int &calculated_depth)
Definition resource_estimate.cpp:383
bool can_be_identity_hash(const IR::MAU::Table *tbl, LayoutOption *lo, int &calculated_depth)
Definition resource_estimate.cpp:482