P4C
The P4 Compiler
Loading...
Searching...
No Matches
walk_power_graph.h
1
19#ifndef BF_P4C_MAU_WALK_POWER_GRAPH_H_
20#define BF_P4C_MAU_WALK_POWER_GRAPH_H_
21
22#include <map>
23#include <ostream>
24#include <set>
25
26#include "backends/tofino/bf-p4c/bf-p4c-options.h"
27#include "backends/tofino/bf-p4c/mau/build_power_graph.h"
28#include "backends/tofino/bf-p4c/mau/determine_power_usage.h"
29#include "backends/tofino/bf-p4c/mau/jbay_next_table.h"
30#include "backends/tofino/bf-p4c/mau/mau_power.h"
31#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
32#include "backends/tofino/bf-p4c/mau/table_dependency_graph.h"
33#include "backends/tofino/bf-p4c/phv/phv_fields.h"
34#include "ir/gress.h"
35#include "power_schema.h"
36
37namespace MauPower {
38
47 public:
48 using PowerLogging = Logging::Power_Schema_Logger;
49 bool preorder(const IR::MAU::Table *t) override;
50 void end_apply(const IR::Node *root) override;
51 WalkPowerGraph(const NextTable *next_table_properties, BuildPowerGraph *graphs,
52 const bool &exceeds_stages,
53 const std::map<UniqueId, PowerMemoryAccess> &table_memory_access,
54 const BFN_Options &options, MauFeatures *mau_features,
55 std::map<gress_t, MprSettings *> &mpr_settings)
56 : next_table_properties_(next_table_properties),
57 graphs_(graphs),
58 exceeds_stages_(exceeds_stages),
59 options_(options),
60 table_memory_access_(table_memory_access),
61 mau_features_(mau_features),
62 mpr_settings_(mpr_settings) {
63 disable_mpr_config_ = options.disable_mpr_config;
64 if (Device::currentDevice() != Device::TOFINO) {
65 // This will not be necessary when turn on MPR by default.
66 // disable_mpr_config_ = true;
67 }
68 }
69
70 private:
71 // inputs
72 const NextTable *next_table_properties_;
73 BuildPowerGraph *graphs_;
74 const bool &exceeds_stages_;
75 const BFN_Options &options_;
76 const std::map<UniqueId, PowerMemoryAccess> &table_memory_access_;
77 // modified
78 MauFeatures *mau_features_;
79 std::map<gress_t, MprSettings *> &mpr_settings_;
80 // created
81 PowerLogging *logger_ = nullptr;
82 // Temporarily use this variable until can turn MPR on by default.
83 bool disable_mpr_config_ = false;
87 std::map<gress_t, double> gress_powers_real_ = {};
92 std::map<gress_t, double> gress_powers_ = {};
97 std::map<UniqueId, bool> on_critical_path_ = {};
103 std::map<UniqueId, bool> always_powered_on_ = {};
104 /*
105 * Powered on due to latency difference between ingress & egress
106 * JBAY-2889 HW Issue
107 */
108 std::map<UniqueId, bool> always_powered_on_latency_ = {};
112 std::map<UniqueId, cstring> external_names_ = {};
116 std::map<UniqueId, int> stages_ = {};
120 std::map<UniqueId, gress_t> gress_map_ = {};
124 size_t longest_table_name_ = 0;
125
132 void clear_mpr_settings();
133 void compute_mpr();
134 bool check_mpr_conflict(); // check for ingress/egress match/action conflict
138 double estimate_power();
142 double estimate_power_tofino();
146 double estimate_power_non_tofino();
147
154 bool is_mpr_powered_on(gress_t g, int stage, const IR::MAU::Table *t) const;
155
159 double traffic_limit_scaling(double pwr) const;
160
164 void create_mau_power_json(const IR::Node *root);
165 void produce_json_tables();
166 void produce_json_total_power(int pipe_id);
167 void produce_json_total_latency(int pipe_id);
168 void produce_json_stage_characteristics();
169
173 void create_mau_power_log(const IR::Node *root) const;
174 void print_features(std::ofstream &out) const;
175 void print_latency(std::ofstream &out) const;
176 void print_mpr_settings(std::ofstream &out) const;
177 void print_worst_power(std::ofstream &out) const;
178};
179
180} // end namespace MauPower
181
182#endif /* BF_P4C_MAU_WALK_POWER_GRAPH_H_ */
Definition bf-p4c-options.h:28
Definition mau_visitor.h:29
Definition build_power_graph.h:38
Definition mau_power.h:64
Definition walk_power_graph.h:46
void end_apply(const IR::Node *root) override
Definition walk_power_graph.cpp:68
Definition next_table.h:26
Definition node.h:94
Definition mau/asm_output.h:39