P4C
The P4 Compiler
Loading...
Searching...
No Matches
determine_power_usage.h
1
19#ifndef BF_P4C_MAU_DETERMINE_POWER_USAGE_H_
20#define BF_P4C_MAU_DETERMINE_POWER_USAGE_H_
21
22#include <map>
23
24#include "backends/tofino/bf-p4c/device.h"
25#include "backends/tofino/bf-p4c/logging/manifest.h"
26#include "backends/tofino/bf-p4c/mau/build_power_graph.h"
27#include "backends/tofino/bf-p4c/mau/finalize_mau_pred_deps_power.h"
28#include "backends/tofino/bf-p4c/mau/mau_power.h"
29#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
30#include "backends/tofino/bf-p4c/mau/resource.h"
31#include "backends/tofino/bf-p4c/mau/table_dependency_graph.h"
32#include "lib/error.h"
33#include "lib/json.h"
34#include "power_schema.h"
35
36namespace MauPower {
37
38using namespace P4;
39
40class MauFeatures;
41
49 // map from match table UniqueId to tuple of memory accesses
50 // A match table will also include any attached table's memory accesses used.
51 std::map<UniqueId, PowerMemoryAccess> &table_memory_access_;
52
53 // map from attached table's UniqueId to memory access struct.
54 // Only populated with stats, meters, stateful, selector, action data.
55 // This is needed because a shared attached table is only attached to one
56 // of its match tables, but each match table that accesses shared table
57 // needs to factor in power used by its attached.
58 std::map<UniqueId, PowerMemoryAccess> attached_memory_usage_ = {};
59
60 // Need to update these to include accesses from 'attached_memory_usage'
61 // once that information is found.
62 IR::Vector<IR::MAU::Table> match_tables_with_unattached_;
63
64 // map from table to Boolean indicating if the table accesses mocha containers
65 // in the match input crossbar.
66 std::map<UniqueId, bool> table_uses_mocha_container_ = {};
67
68 /* --------------------------------------------------------
69 * Function definitions.
70 * --------------------------------------------------------*/
71 void end_apply(const IR::Node *root) override;
72 void postorder(const IR::BFN::Pipe *p) override;
73 void postorder(const IR::MAU::Table *t) override;
74 bool preorder(const IR::MAU::Meter *m) override;
75 bool preorder(const IR::MAU::Counter *c) override;
76 bool preorder(const IR::MAU::Selector *sel) override;
77
78 private:
85 void add_unattached_memory_accesses();
86
91 void find_stage_dependencies();
92
98 void update_stage_dependencies_for_min_latency();
99
104 bool uses_mocha_containers_in_ixbar(const IR::MAU::Table *t) const;
105
106 const PhvInfo &phv_;
107 DependencyGraph &dep_graph_;
108 BuildPowerGraph *graphs_;
109 const BFN_Options &options_;
114 MauFeatures *mau_features_;
115 bool &exceeds_stages_;
116
117 public:
118 explicit DeterminePowerUsage(const PhvInfo &phv, DependencyGraph &dep_graph,
119 BuildPowerGraph *control_graphs, const BFN_Options &options,
120 MauFeatures *mau_features, bool &exceeds_stages,
121 std::map<UniqueId, PowerMemoryAccess> &table_memory_access)
122 : table_memory_access_(table_memory_access),
123 phv_(phv),
124 dep_graph_(dep_graph),
125 graphs_(control_graphs),
126 options_(options),
127 mau_features_(mau_features),
128 exceeds_stages_(exceeds_stages) {
129 force_match_dependency_ = options_.force_match_dependency;
130 if (Device::currentDevice() != Device::TOFINO) {
131 // This will not be necessary when turn on MPR by default.
132 // force_match_dependency_ = true;
133 }
134 }
135
136 private:
137 // Temporarily use this variable until can turn MPR on by default.
138 bool force_match_dependency_ = false;
139};
140
141} // end namespace MauPower
142
143#endif /* BF_P4C_MAU_DETERMINE_POWER_USAGE_H_ */
Definition bf-p4c-options.h:28
Definition mau_visitor.h:29
Definition build_power_graph.h:38
Definition determine_power_usage.h:48
Definition mau_power.h:64
Definition node.h:94
Definition vector.h:59
Definition phv_fields.h:1095
Definition mau/asm_output.h:39
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition table_dependency_graph.h:52