P4C
The P4 Compiler
Loading...
Searching...
No Matches
device.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_DEVICE_H_
20#define BACKENDS_TOFINO_BF_P4C_DEVICE_H_
21
22#include "arch/arch_spec.h"
23#include "ir/gress.h"
24#include "lib/cstring.h"
25#include "lib/exceptions.h"
26#include "lib/range.h"
27#include "mau/mau_spec.h"
28#include "mau/power_spec.h"
29#include "parde/parde_spec.h"
30#include "phv/phv_spec.h"
31
32class Device {
33 public:
34 enum Device_t {
35 TOFINO,
36 JBAY,
37 };
45 static void init(cstring name);
46
47 static const Device &get() {
48 BUG_CHECK(instance_ != nullptr, "Target device not initialized!");
49 return *instance_;
50 }
51
52 static Device_t currentDevice() { return Device::get().device_type(); }
53 static cstring name() { return Device::get().get_name(); }
54
55 static const PhvSpec &phvSpec() { return Device::get().getPhvSpec(); }
56 static const PardeSpec &pardeSpec() { return Device::get().getPardeSpec(); }
57 struct GatewaySpec;
58 static const GatewaySpec &gatewaySpec() { return Device::get().getGatewaySpec(); }
59 struct StatefulAluSpec;
60 static const StatefulAluSpec &statefulAluSpec() { return Device::get().getStatefulAluSpec(); }
61 static const ArchSpec &archSpec() { return Device::get().getArchSpec(); }
62 static const MauPowerSpec &mauPowerSpec() { return Device::get().getMauPowerSpec(); }
63 static const MauSpec &mauSpec() { return Device::get().getMauSpec(); }
64 static const IXBarSpec &ixbarSpec() { return Device::get().getMauSpec().getIXBarSpec(); }
65 static const IMemSpec &imemSpec() { return Device::get().getMauSpec().getIMemSpec(); }
66 static int numPipes() { return Device::get().getNumPipes(); }
67 static int numStages() {
68 return numStagesRuntimeOverride_ ? numStagesRuntimeOverride_ : Device::get().getNumStages();
69 }
70 static void overrideNumStages(int num);
71 static int numLongBranchTags() { return Device::get().getLongBranchTags(); }
72 static bool hasLongBranches() { return numLongBranchTags() > 0; }
73 static int alwaysRunIMemAddr() { return Device::get().getAlwaysRunIMemAddr(); }
74 static bool hasAlwaysRunInstr() { return alwaysRunIMemAddr() >= 0; }
75 static unsigned maxCloneId(gress_t gress) { return Device::get().getMaxCloneId(gress); }
76 static gress_t maxGress() { return Device::get().getMaxGress(); }
77 static RangeIter<gress_t> allGresses() { return Range(INGRESS, maxGress()); }
78 static unsigned maxResubmitId() { return Device::get().getMaxResubmitId(); }
79 static unsigned maxDigestId() { return Device::get().getMaxDigestId(); }
80 /* type is 'int' because width_bits() is defined as 'int' in ir/base.def */
81 static int mirrorTypeWidth() { return Device::get().getMirrorTypeWidth(); }
82 static int cloneSessionIdWidth() { return Device::get().getCloneSessionIdWidth(); }
83 static int queueIdWidth() { return Device::get().getQueueIdWidth(); }
84 static int portBitWidth() { return Device::get().getPortBitWidth(); }
85 static int maxParserMatchBits() { return Device::get().getMaxParserMatchBits(); }
86 static unsigned maxDigestSizeInBytes() { return Device::get().getMaxDigestSizeInBytes(); }
87 static int numParsersPerPipe() { return 18; }
88 static int numMaxChannels() { return Device::get().getNumMaxChannels(); }
89 static int numClots() { return pardeSpec().numClotsPerGress(); }
90 static int isMemoryCoreSplit() { return Device::get().getIfMemoryCoreSplit(); }
91 static bool hasCompareInstructions() { return Device::get().getHasCompareInstructions(); }
92 static int numLogTablesPerStage() { return Device::get().getNumLogTablesPerStage(); }
93 static bool hasIngressDeparser() { return Device::get().getHasIngressDeparser(); }
94 static bool hasEgressParser() { return Device::get().getHasEgressParser(); }
95 static bool hasGhostThread() { return Device::get().getHasGhostThread(); }
96 static bool threadsSharePipe(gress_t a, gress_t b) {
97 return Device::get().getThreadsSharePipe(a, b);
98 }
99 static bool hasMirrorIOSelect() { return Device::get().getHasMirrorIOSelect(); }
100 static bool hasMetadataPOV() { return Device::get().getHasMetadataPOV(); }
101 static int sramMinPackEntries() { return Device::get().getSramMinPackEntries(); }
102 static int sramMaxPackEntries() { return Device::get().getSramMaxPackEntries(); }
103 static int sramMaxPackEntriesPerRow() { return Device::get().getSramMaxPackEntriesPerRow(); }
104 /* sramColumnAdjust is applicable for Tofino targets where the left and right side columns in
105 * SRAMs are different. The columns are still present in address space but not actually usable.
106 * This results in an adjustment required for column numbering.
107 */
108 static int sramColumnAdjust() { return Device::get().getSramColumnAdjust(); }
109 static int metaGlobalTimestampStart() { return Device::get().getMetaGlobalTimestampStart(); }
110 static int metaGlobalTimestampLen() { return Device::get().getMetaGlobalTimestampLen(); }
111 static int metaGlobalVersionStart() { return Device::get().getMetaGlobalVersionStart(); }
112 static int metaGlobalVersionLen() { return Device::get().getMetaGlobalVersionLen(); }
113 static unsigned int egressIntrinsicMetadataMinLen() {
114 return Device::get().getEgressIntrinsicMetadataMinLen();
115 }
116
117 protected:
118 explicit Device(cstring name) : name_(name) {}
119
120 virtual Device_t device_type() const = 0;
121 virtual cstring get_name() const = 0;
122
123 virtual const PhvSpec &getPhvSpec() const = 0;
124 virtual const PardeSpec &getPardeSpec() const = 0;
125 virtual const GatewaySpec &getGatewaySpec() const = 0;
126 virtual const StatefulAluSpec &getStatefulAluSpec() const = 0;
127 virtual const MauPowerSpec &getMauPowerSpec() const = 0;
128 virtual const MauSpec &getMauSpec() const = 0;
129 virtual const ArchSpec &getArchSpec() const = 0;
130 virtual int getNumPipes() const = 0;
131 virtual int getNumPortsPerPipe() const = 0;
132 virtual int getNumChannelsPerPort() const = 0;
133 virtual int getNumStages() const = 0;
134 virtual int getLongBranchTags() const = 0;
135 virtual int getAlwaysRunIMemAddr() const = 0;
136 virtual unsigned getMaxCloneId(gress_t) const = 0;
137 virtual gress_t getMaxGress() const = 0;
138 virtual unsigned getMaxResubmitId() const = 0;
139 virtual unsigned getMaxDigestId() const = 0;
140 virtual unsigned getMaxDigestSizeInBytes() const = 0;
141 virtual int getMirrorTypeWidth() const = 0;
142 virtual int getCloneSessionIdWidth() const = 0;
143 virtual int getQueueIdWidth() const = 0;
144 virtual int getPortBitWidth() const = 0;
145 virtual int getMaxParserMatchBits() const = 0;
146 virtual int getNumMaxChannels() const = 0;
147 virtual bool getIfMemoryCoreSplit() const = 0;
148 virtual bool getHasCompareInstructions() const = 0;
149 virtual int getNumLogTablesPerStage() const = 0;
150 virtual bool getHasIngressDeparser() const = 0;
151 virtual bool getHasEgressParser() const = 0;
152 virtual bool getHasGhostThread() const = 0;
153 virtual bool getThreadsSharePipe(gress_t a, gress_t b) const = 0;
154 virtual bool getHasMirrorIOSelect() const = 0;
155 virtual bool getHasMetadataPOV() const = 0;
156 virtual int getSramMinPackEntries() const = 0;
157 virtual int getSramMaxPackEntries() const = 0;
158 virtual int getSramMaxPackEntriesPerRow() const = 0;
159 virtual int getSramColumnAdjust() const = 0;
160 virtual int getMetaGlobalTimestampStart() const = 0;
161 virtual int getMetaGlobalTimestampLen() const = 0;
162 virtual int getMetaGlobalVersionStart() const = 0;
163 virtual int getMetaGlobalVersionLen() const = 0;
164 virtual unsigned int getEgressIntrinsicMetadataMinLen() const = 0;
165
166 private:
167 static Device *instance_;
168 static int numStagesRuntimeOverride_;
169 cstring name_;
170};
171
172class TofinoDevice : public Device {
173 const TofinoPhvSpec phv_;
174 const TofinoPardeSpec parde_;
175 const TofinoMauPowerSpec mau_power_;
176 const TofinoMauSpec mau_;
177 const TofinoArchSpec arch_;
178
179 public:
180 TofinoDevice() : Device("Tofino"_cs), parde_() {}
181 Device::Device_t device_type() const override { return Device::TOFINO; }
182 cstring get_name() const override { return "Tofino"_cs; }
183 int getNumPipes() const override { return 4; }
184 int getNumPortsPerPipe() const override { return 4; }
185 int getNumChannelsPerPort() const override { return 18; }
186 int getNumStages() const override { return 12; }
187 int getLongBranchTags() const override { return 0; }
188 int getAlwaysRunIMemAddr() const override { return -1; }
189 unsigned getMaxCloneId(gress_t gress) const override {
190 switch (gress) {
191 case INGRESS:
192 return 7; // one id reserved for IBuf
193 case EGRESS:
194 return 8;
195 default:
196 return 8;
197 }
198 }
199 gress_t getMaxGress() const override { return EGRESS; }
200 unsigned getMaxResubmitId() const override { return 8; }
201 unsigned getMaxDigestId() const override { return 8; }
202 int getMirrorTypeWidth() const override { return 3; }
203 int getCloneSessionIdWidth() const override { return 10; }
204 int getQueueIdWidth() const override { return 5; }
205 int getPortBitWidth() const override { return 9; }
206 int getMaxParserMatchBits() const override { return 32; }
207 int getNumMaxChannels() const override {
208 return getNumPipes() * getNumPortsPerPipe() * getNumChannelsPerPort();
209 }
210 unsigned getMaxDigestSizeInBytes() const override { return (384 / 8); }
211
212 const PhvSpec &getPhvSpec() const override { return phv_; }
213 const PardeSpec &getPardeSpec() const override { return parde_; }
214 const GatewaySpec &getGatewaySpec() const override;
215 const StatefulAluSpec &getStatefulAluSpec() const override;
216 const MauPowerSpec &getMauPowerSpec() const override { return mau_power_; }
217 const MauSpec &getMauSpec() const override { return mau_; }
218 const ArchSpec &getArchSpec() const override { return arch_; }
219 bool getIfMemoryCoreSplit() const override { return false; }
220 bool getHasCompareInstructions() const override { return false; }
221 int getNumLogTablesPerStage() const override { return 16; }
222 bool getHasIngressDeparser() const override { return true; }
223 bool getHasEgressParser() const override { return true; }
224 bool getHasGhostThread() const override { return false; };
225 bool getThreadsSharePipe(gress_t, gress_t) const override { return true; }
226 bool getHasMirrorIOSelect() const override { return false; }
227 bool getHasMetadataPOV() const override { return false; }
228 int getSramMinPackEntries() const override { return 1; }
229 int getSramMaxPackEntries() const override { return 9; }
230 int getSramMaxPackEntriesPerRow() const override { return 5; }
231 int getMetaGlobalTimestampStart() const override { return 432; }
232 int getMetaGlobalTimestampLen() const override { return 48; }
233 int getMetaGlobalVersionStart() const override { return 480; }
234 int getMetaGlobalVersionLen() const override { return 32; }
235 int getSramColumnAdjust() const override { return 2; }
236 unsigned int getEgressIntrinsicMetadataMinLen() const override { return 2; }
237};
238
239class JBayDevice : public Device {
240 const JBayPhvSpec phv_;
241 const JBayPardeSpec parde_;
242 const JBayMauPowerSpec mau_power_;
243 const JBayMauSpec mau_;
244 const JBayArchSpec arch_;
245
246 protected:
247#ifdef EMU_OVERRIDE_STAGE_COUNT
248 const int NUM_MAU_STAGES = EMU_OVERRIDE_STAGE_COUNT;
249#else
250 const int NUM_MAU_STAGES = 20;
251#endif
252
253 public:
254 JBayDevice() : Device("Tofino2"_cs), parde_() {}
255 Device::Device_t device_type() const override { return Device::JBAY; }
256 cstring get_name() const override { return "Tofino2"_cs; }
257 int getNumPipes() const override { return 4; }
258 int getNumPortsPerPipe() const override { return 4; }
259 int getNumChannelsPerPort() const override { return 18; }
260 int getNumStages() const override { return NUM_MAU_STAGES; }
261 int getLongBranchTags() const override { return 8; }
262 int getAlwaysRunIMemAddr() const override { return 63; }
263 unsigned getMaxCloneId(gress_t /* gress */) const override { return 16; }
264 gress_t getMaxGress() const override { return GHOST; }
265 unsigned getMaxResubmitId() const override { return 8; }
266 unsigned getMaxDigestId() const override { return 8; }
267 unsigned getMaxDigestSizeInBytes() const override { return (384 / 8); }
268 int getMirrorTypeWidth() const override { return 4; }
269 int getCloneSessionIdWidth() const override { return 8; }
270 int getQueueIdWidth() const override { return 7; }
271 int getPortBitWidth() const override { return 9; }
272 int getMaxParserMatchBits() const override { return 32; }
273 int getNumMaxChannels() const override {
274 return getNumPipes() * getNumPortsPerPipe() * getNumChannelsPerPort();
275 }
276
277 const PhvSpec &getPhvSpec() const override { return phv_; }
278 const PardeSpec &getPardeSpec() const override { return parde_; }
279 const GatewaySpec &getGatewaySpec() const override;
280 const StatefulAluSpec &getStatefulAluSpec() const override;
281 const MauSpec &getMauSpec() const override { return mau_; }
282 const MauPowerSpec &getMauPowerSpec() const override { return mau_power_; }
283 const ArchSpec &getArchSpec() const override { return arch_; }
284 bool getIfMemoryCoreSplit() const override { return true; }
285 bool getHasCompareInstructions() const override { return true; }
286 int getNumLogTablesPerStage() const override { return 16; }
287 bool getHasIngressDeparser() const override { return true; }
288 bool getHasEgressParser() const override { return true; }
289 bool getHasGhostThread() const override { return true; };
290 bool getThreadsSharePipe(gress_t, gress_t) const override { return true; }
291 bool getHasMirrorIOSelect() const override { return true; }
292 bool getHasMetadataPOV() const override { return true; }
293 int getSramMinPackEntries() const override { return 1; }
294 int getSramMaxPackEntries() const override { return 9; }
295 int getSramMaxPackEntriesPerRow() const override { return 5; }
296 int getMetaGlobalTimestampStart() const override { return 400; }
297 int getMetaGlobalTimestampLen() const override { return 48; }
298 int getMetaGlobalVersionStart() const override { return 448; }
299 int getMetaGlobalVersionLen() const override { return 32; }
300 int getSramColumnAdjust() const override { return 2; }
301 unsigned int getEgressIntrinsicMetadataMinLen() const override { return 8; }
302};
303
306#if BAREFOOT_INTERNAL
307class JBayHDevice : public JBayDevice {
308 public:
309 int getNumStages() const override { return 6; }
310 cstring get_name() const override { return "Tofino2H"_cs; }
311};
312#endif /* BAREFOOT_INTERNAL */
313
314class JBayMDevice : public JBayDevice {
315 public:
316 int getNumStages() const override { return 12; }
317 cstring get_name() const override { return "Tofino2M"_cs; }
318};
319
320class JBayUDevice : public JBayDevice {
321 public:
322 int getNumStages() const override { return 20; }
323 cstring get_name() const override { return "Tofino2U"_cs; }
324};
325
326class JBayA0Device : public JBayDevice {
327 public:
328 const JBayA0PardeSpec parde_{};
329 const PardeSpec &getPardeSpec() const override { return parde_; }
330 cstring get_name() const override { return "Tofino2A0"_cs; }
331};
332
333#endif /* BACKENDS_TOFINO_BF_P4C_DEVICE_H_ */
Definition tofino/bf-p4c/arch/arch_spec.h:47
Definition device.h:32
static void init(cstring name)
Definition device.cpp:28
Definition gateway.h:38
Definition mau_spec.h:27
Definition mau_spec.h:44
Definition device.h:326
Definition parde_spec.h:670
Definition tofino/bf-p4c/arch/arch_spec.h:155
Definition device.h:239
Definition device.h:314
Definition power_spec.h:149
Definition mau_spec.h:178
Definition parde_spec.h:575
Definition phv_spec.h:353
Definition device.h:320
Definition power_spec.h:32
Definition mau_spec.h:95
Definition range.h:25
Definition cstring.h:85
Definition parde_spec.h:378
virtual unsigned numClotsPerGress() const =0
The number of CLOTs available for allocation in each gress.
Definition phv_spec.h:42
Definition tofino/bf-p4c/arch/arch_spec.h:150
Definition device.h:172
const GatewaySpec & getGatewaySpec() const override
Definition gateway.cpp:31
const StatefulAluSpec & getStatefulAluSpec() const override
Definition mau/stateful_alu.cpp:32
Definition power_spec.h:93
Definition mau_spec.h:168
Definition parde_spec.h:503
Definition phv_spec.h:315
Definition mau/stateful_alu.h:106