P4C
The P4 Compiler
Loading...
Searching...
No Matches
resources.h
1
19#ifndef _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_H_
20#define _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_H_
21
22/* clang-format off */
23#include <set>
24#include <string>
25#include <utility>
26#include <vector>
27
28#include "ir/ir.h"
29#include "ir/gress.h"
30#include "lib/cstring.h"
31#include "lib/ordered_map.h"
32#include "resources_schema.h"
33#include "bf-p4c/mau/instruction_memory.h"
34#include "bf-p4c/mau/tofino/input_xbar.h"
35/* clang-format on */
36using Logging::Resources_Schema_Logger;
37class ClotInfo; // Forward declaration
38
39namespace BFN {
40
41namespace Resources {
53 std::string usedBy;
54 std::string usedFor;
56
57 XbarByteResource(const std::string &ub, const std::string &uf, const IXBar::Use::Byte &b);
58
59 bool operator<(const XbarByteResource &other) const {
60 return std::tie(usedBy, usedFor, byte) < std::tie(other.usedBy, other.usedFor, other.byte);
61 }
62};
63
64// Each hash bit is reserved to a single table or side effect. However, because the
65// same bit can be the select bits/RAM line bit for two different ways in the same
66// table, then they can be shared
68 enum class UsageType { WaySelect = 0, WayLineSelect, SelectionBit, DistBit, Gateway };
69
70 struct Usage {
71 int value;
72 std::string fieldName;
73 UsageType type;
74
75 bool operator<(const Usage &other) const {
76 return std::tie(type, value, fieldName) <
77 std::tie(other.type, other.value, other.fieldName);
78 }
79 };
80
81 std::string usedBy;
82 std::string usedFor;
83 std::set<Usage> usages;
84
85 void append(std::string ub, std::string uf, UsageType type, int value,
86 const std::string &fieldName = "");
87};
88
89// This represents the 48 bits of hash distribution before the hash distribution units
90// are expanded, masked and shifted
91// Hash Distribution units can be used for multiple purposes (i.e. two wide addresses
92// between tables
94 std::set<std::string> usedBy;
95 std::set<std::string> usedFor;
96
97 void append(const std::string &ub, const std::string &uf);
98};
99
101 std::set<std::string> usedBy;
102
103 void append(const std::string &ub);
104};
105
107 const IR::MAU::Table *table;
108 std::string tableName;
109 std::string gatewayName;
110 const TableResourceAlloc *use;
111
112 MemoriesResource(const IR::MAU::Table *table, const std::string &name,
113 const std::string &gwname, const TableResourceAlloc *use)
114 : table(table), tableName(name), gatewayName(gwname), use(use) {}
115};
116
118 unsigned int color = 0;
119 gress_t gress = INGRESS;
120
121 // Key is used_by, value is list of action names
123};
124
126 ordered_map<int, cstring> logicalIds; // Map table logical ids to table names
128 // key is (hashBitNumber, hashFunction)
130 // key is (hashId, unitId)
134 std::vector<MemoriesResource> memories;
135};
136} // end namespace Resources
137
153 public:
154 using ActionDataResourceUsage = Resources_Schema_Logger::ActionDataResourceUsage;
155 using ClotResourceUsage = Resources_Schema_Logger::ClotResourceUsage;
156 using ElementUsage = Resources_Schema_Logger::ElementUsage;
157 using ExactMatchResultBusResourceUsage =
158 Resources_Schema_Logger::ExactMatchResultBusResourceUsage;
159 using ExactMatchSearchBusResourceUsage =
160 Resources_Schema_Logger::ExactMatchSearchBusResourceUsage;
161 using HashBitsResourceUsage = Resources_Schema_Logger::HashBitsResourceUsage;
162 using HashDistResourceUsage = Resources_Schema_Logger::HashDistributionResourceUsage;
163 using LogicalTableResourceUsage = Resources_Schema_Logger::LogicalTableResourceUsage;
164 using MapRamResourceUsage = Resources_Schema_Logger::MapRamResourceUsage;
165 using MauStageResourceUsage = Resources_Schema_Logger::MauStageResourceUsage;
166 using MeterAluResourceUsage = Resources_Schema_Logger::MeterAluResourceUsage;
167 using ParserResources = Resources_Schema_Logger::ParserResources;
168 using PhvResourceUsage = Resources_Schema_Logger::PhvResourceUsage;
169 using RamResourceUsage = Resources_Schema_Logger::RamResourceUsage;
170 using ResourceUsage = Resources_Schema_Logger::ResourceUsage;
171 using GatewayResourceUsage = Resources_Schema_Logger::GatewayResourceUsage;
172 using StashResourceUsage = Resources_Schema_Logger::StashResourceUsage;
173 using StatisticAluResourceUsage = Resources_Schema_Logger::StatisticAluResourceUsage;
174 using TcamResourceUsage = Resources_Schema_Logger::TcamResourceUsage;
175 using TindResultBusResourceUsage = Resources_Schema_Logger::TindResultBusResourceUsage;
176 using VliwResourceUsage = Resources_Schema_Logger::VliwResourceUsage;
177 using XbarResourceUsage = Resources_Schema_Logger::XbarResourceUsage;
178
179 protected:
180 const ClotInfo &clotInfo; // ClotInfo reference is only passed to CLOT resource logger
181 std::string filePath; // path to logged file
182 std::string manifestPath; // path from manifest to logged file
183 std::vector<Resources::StageResources> stageResources; // Data for logging are collected here
184 const ParserResources *parserResources = nullptr; // Logged data for parser
185 std::vector<ClotResourceUsage *> clotResources; // Logged data for clots
186
190 bool preorder(const IR::BFN::Pipe *p) override;
191
196 bool preorder(const IR::MAU::Table *tbl) override;
197
203 void end_apply(const IR::Node *root) override;
204
205 void collectTableUsage(cstring name, const IR::MAU::Table *table);
206
207 void collectXbarBytesUsage(unsigned int stage, const IXBar::Use *alloc);
208
209 void collectHashDistUsage(unsigned int stage, const Tofino::IXBar::HashDistUse &hd_use);
210
211 void collectActionBusBytesUsage(unsigned int stage, const TableResourceAlloc *res,
212 cstring tableName);
213
214 void collectVliwUsage(unsigned int stage, const InstructionMemory::Use &alloc, gress_t gress,
215 cstring tableName);
216
217 XbarResourceUsage *logXbarBytes(unsigned stageNo) const;
218
219 HashBitsResourceUsage *logHashBits(unsigned stageNo) const;
220
221 HashDistResourceUsage *logHashDist(unsigned stageNo) const;
222
223 void logMemories(unsigned int stage, RamResourceUsage *ramsRes, MapRamResourceUsage *mapRamsRes,
224 GatewayResourceUsage *gatewaysRes, StashResourceUsage *stashesRes,
225 MeterAluResourceUsage *meterRes, StatisticAluResourceUsage *statisticsRes,
226 TcamResourceUsage *tcamsRes) const;
227
228 LogicalTableResourceUsage *logLogicalTables(int stageNo) const;
229
230 ActionDataResourceUsage *logActionBusBytes(unsigned int stageNo) const;
231
232 void logActionSlots(MauStageResourceUsage *msru) const;
233
234 VliwResourceUsage *logVliw(unsigned int stageNo) const;
235
236 ExactMatchSearchBusResourceUsage *logExactMemSearchBuses(unsigned int stageNo) const;
237
238 ExactMatchResultBusResourceUsage *logExactMemResultBuses(unsigned int stageNo) const;
239
240 TindResultBusResourceUsage *logTindResultBuses(unsigned int stageNo) const;
241
242 MauStageResourceUsage *logStage(int stageNo);
243
244 public:
245 // Only need this for public interface, rest is done in preorder and end_apply
246 ResourcesLogging(const ClotInfo &clotInfo, const std::string &filename,
247 const std::string &outdir)
248 : clotInfo(clotInfo), filePath(filename) {
249 manifestPath = filename.substr(outdir.size() + 1);
250 }
251};
252
253} // namespace BFN
254
255#endif /* _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_H_ */
Class for generating resources.json logfile.
Definition resources.h:152
bool preorder(const IR::BFN::Pipe *p) override
Definition resources.cpp:215
void end_apply(const IR::Node *root) override
Definition resources.cpp:245
Definition clot_info.h:41
Definition node.h:95
Definition visitor.h:400
Definition cstring.h:85
Definition ordered_map.h:32
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition resources.h:100
Definition resources.h:67
Definition resources.h:93
Definition resources.h:117
Definition resources.h:106
Definition resources.h:125
Definition resources.h:52
Definition input_xbar.h:230
Definition input_xbar.h:191
Definition instruction_memory.h:111
Definition resource.h:37
Definition tofino/input_xbar.h:379