19#ifndef BF_P4C_MAU_MEMORIES_H_
20#define BF_P4C_MAU_MEMORIES_H_
24#include "bf-p4c/common/alloc.h"
25#include "bf-p4c/mau/action_format.h"
26#include "bf-p4c/mau/attached_entries.h"
27#include "bf-p4c/mau/input_xbar.h"
29#include "lib/safe_vector.h"
34template <
class C,
class Pred>
35inline bool any_of(C c, Pred pred) {
36 return std::any_of(std::begin(c), std::end(c), pred);
41 static constexpr int SRAM_ROWS = 8;
42 static constexpr int SRAM_COLUMNS = 10;
43 static constexpr int STASH_UNITS = 2;
44 static constexpr int LOGICAL_TABLES = 16;
45 static constexpr int LEFT_SIDE_COLUMNS = 4;
46 static constexpr int RIGHT_SIDE_COLUMNS = SRAM_COLUMNS - LEFT_SIDE_COLUMNS;
47 static constexpr int LEFT_SIDE_RAMS = LEFT_SIDE_COLUMNS * SRAM_ROWS;
48 static constexpr int RIGHT_SIDE_RAMS = RIGHT_SIDE_COLUMNS * SRAM_ROWS;
49 static constexpr int TOTAL_SRAMS = SRAM_ROWS * SRAM_COLUMNS;
50 static constexpr int MAPRAM_COLUMNS = 6;
51 static constexpr int MAPRAM_MASK = (1U << MAPRAM_COLUMNS) - 1;
52 static constexpr int LAMB_DEPTH = 64;
53 static constexpr int TOTAL_LAMBS = 8;
57 static constexpr int TCAM_DEPTH = 512;
58 static constexpr int LOCAL_TIND_DEPTH = 64;
59 static constexpr int TOTAL_LOCAL_TIND = 16;
60 static constexpr int TABLES_MAX = 16;
61 static constexpr int TERNARY_TABLES_MAX = 8;
62 static constexpr int ACTION_TABLES_MAX = 16;
63 static constexpr int GATEWAYS_PER_ROW = 2;
64 static constexpr int BUS_COUNT = 2;
65 static constexpr int PAYLOAD_COUNT = 2;
66 static constexpr int STATS_ALUS = 4;
67 static constexpr int METER_ALUS = 4;
68 static constexpr int MAX_DATA_SWBOX_ROWS = 5;
69 static constexpr int COLOR_MAPRAM_PER_ROW = 4;
70 static constexpr int IMEM_ADDRESS_BITS = 6;
71 static constexpr int IMEM_LOOKUP_BITS = 3;
72 static constexpr int NUM_IDLETIME_BUS = 10;
73 static constexpr int MAX_PARTITION_RAMS_PER_ROW = 5;
74 static constexpr int MATCH_CENTRAL_ROW = 4;
75 static constexpr int MAX_STATS_ROW_PER_ALU = 3;
76 static constexpr int MAX_STATS_RAM_PER_ALU = MAPRAM_COLUMNS * MAX_STATS_ROW_PER_ALU;
78 static constexpr int LOGICAL_ROW_MISSING_OFLOW = 8;
95 bool is_twoport()
const {
96 return type == COUNTER || type == METER || type == SELECTOR || type == STATEFUL;
102 int row, bus, result_bus, word, alloc;
103 int stash_unit, stash_col;
113 explicit Row(
int r,
int b = -1,
int w = -1,
int a = -1)
121 void dbprint(std::ostream &out)
const { out <<
"Row " << row <<
" with bus " << bus; }
126 unsigned select_mask;
129 explicit Way(
int s,
unsigned sm) : size(s), select_mask(sm) {}
131 friend std::ostream &operator<<(std::ostream &out,
const Way &w);
134 uint64_t payload_value = 0ULL;
135 int payload_match_address = -1;
136 int payload_row = -1;
137 int payload_unit = -1;
139 type_t bus_type = EXACT;
141 payload_value = 0ULL;
142 payload_match_address = -1;
155 int tind_result_bus = -1;
156 IR::MAU::ColorMapramAddress cma = IR::MAU::ColorMapramAddress::NOT_SET;
159 enum h_bus_t { NONE, LEFT_HBUS1, LEFT_HBUS2, RIGHT_HBUS1, RIGHT_HBUS2 };
166 bool operator==(
const ScmLoc &scm_loc)
const {
167 return stage == scm_loc.stage && row == scm_loc.row;
169 bool operator!=(
const ScmLoc &scm_loc)
const {
return !(*
this == scm_loc); }
170 bool operator<(
const ScmLoc &scm_loc)
const {
171 if (stage != scm_loc.stage)
return stage < scm_loc.stage;
172 if (row != scm_loc.row)
return row < scm_loc.row;
175 ScmLoc() : stage(-1), row(-1) {}
176 explicit ScmLoc(
int s,
int r) : stage(s), row(r) {}
182 std::map<ScmLoc, std::pair<int, h_bus_t>> loc_to_gb;
199 int get_way(
int row,
int col) {
200 for (
size_t i = 0; i < ways.size(); i++) {
202 for (
auto ram : w.rams) {
203 if ((ram.first == row) && (ram.second == col))
return i;
209 void clear_allocation() {
211 color_mapram.clear();
214 cma = IR::MAU::ColorMapramAddress::NOT_SET;
231 int rams_required()
const;
236 int local_stage = -1;
240 virtual bool allocate_all() = 0;
241 virtual bool allocate_all_dummies() {
return true; }
242 virtual void update(
cstring table_name,
const Use &alloc) = 0;
243 virtual void update(
const std::map<UniqueId, Use> &alloc) = 0;
244 virtual void remove(
cstring table_name,
const Use &alloc) = 0;
245 virtual void remove(
const std::map<UniqueId, Use> &alloc) = 0;
246 virtual void clear() = 0;
247 virtual void add_table(
const IR::MAU::Table *t,
const IR::MAU::Table *gw,
251 virtual void shrink_allowed_lts() = 0;
252 virtual void fill_placed_scm_table(
const IR::MAU::Table *,
const TableResourceAlloc *) = 0;
253 virtual void printOn(std::ostream &)
const = 0;
254 cstring last_failure()
const {
return failure_reason ? failure_reason :
""_cs; }
255 virtual void init_shared(
int stage) { local_stage = stage; }
271 virtual void visitUse(
const Use &, std::function<
void(
cstring &, update_type_t)> fn) = 0;
276 friend std::ostream &operator<<(std::ostream &out,
const Memories &m) {
282template <
int R,
int C>
284 for (
int i = 0; i < R; i++) {
285 for (
int j = 0; j < C; j++) {
287 if (!val) val =
"-"_cs;
288 out << std::setw(10) << val <<
" ";
Definition table_layout.h:34
Definition ordered_map.h:32
Definition safe_vector.h:27
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition memories.h:133
Definition memories.h:101
Definition memories.h:160
Definition memories.h:124
bool separate_search_and_result_bus() const
Definition memories.cpp:45
std::map< UniqueId, ordered_set< UniqueId > > unattached_tables
Definition memories.h:195
static constexpr int SRAM_DEPTH
Definition memories.h:54