P4C
The P4 Compiler
Loading...
Searching...
No Matches
greedy_allocator.h
1
19#ifndef BF_P4C_PHV_V2_GREEDY_ALLOCATOR_H_
20#define BF_P4C_PHV_V2_GREEDY_ALLOCATOR_H_
21
22#include "backends/tofino/bf-p4c/phv/utils/utils.h"
23#include "backends/tofino/bf-p4c/phv/v2/allocator_base.h"
24#include "backends/tofino/bf-p4c/phv/v2/kind_size_indexed_map.h"
25#include "backends/tofino/bf-p4c/phv/v2/phv_kit.h"
26#include "backends/tofino/bf-p4c/phv/v2/utils_v2.h"
27
28namespace PHV {
29namespace v2 {
30
32 // const PhvKit& kit_i;
33 PhvInfo &phv_i;
35 const int pipe_id_i;
37 const int max_slicing_tries_i = 256;
38
39 private:
41 ContainerGroupsBySize make_container_groups_by_size() const;
42
43 struct PreSliceResult {
44 std::list<SuperCluster *> clusters;
46 };
47
51 PreSliceResult pre_slice_all(const Allocation &empty_alloc,
52 const std::list<SuperCluster *> &clusters,
53 ordered_set<const SuperCluster *> &invalid_clusters,
54 AllocatorMetrics &alloc_metrics) const;
55
60 struct RefinedSuperClusterSet {
61 std::list<PHV::SuperCluster *> normal;
62 std::list<PHV::SuperCluster *> deparser_zero;
63 std::list<PHV::SuperCluster *> strided;
64
66 std::deque<std::pair<int, const PHV::SuperCluster *>> normal_sc_que() const;
67 };
68
70 void sort_normal_clusters(std::list<PHV::SuperCluster *> &clusters) const;
71
74 RefinedSuperClusterSet prepare_refined_set(const std::list<SuperCluster *> &clusters) const;
75
80 struct AllocResultWithSlicingDetails {
81 AllocResult rst;
82 TxScore *best_score = nullptr;
83 std::list<PHV::SuperCluster *> best_slicing;
84 int best_slicing_idx = 0; // valid index starts from 1.
87 explicit AllocResultWithSlicingDetails(const Transaction &tx) : rst(tx) {}
88 explicit AllocResultWithSlicingDetails(AllocError *err) : rst(err) {}
89 };
90 friend std::ostream &operator<<(std::ostream &, const AllocResultWithSlicingDetails &);
91
93 AllocResultWithSlicingDetails slice_and_allocate_sc(
94 const ScoreContext &ctx, const Allocation &alloc, const PHV::SuperCluster *sc,
95 const ContainerGroupsBySize &container_groups, AllocatorMetrics &alloc_metrics,
96 const int max_slicings = 128) const;
97
98 public:
99 GreedyAllocator(const PhvKit &kit, PhvInfo &phv, int pipe_id)
100 : AllocatorBase(kit), phv_i(phv), pipe_id_i(pipe_id){};
101
105 bool allocate(std::list<SuperCluster *> clusters, AllocatorMetrics &alloc_metrics);
106};
107
108std::ostream &operator<<(std::ostream &, const GreedyAllocator::AllocResultWithSlicingDetails &);
109
110} // namespace v2
111} // namespace PHV
112
113#endif /* BF_P4C_PHV_V2_GREEDY_ALLOCATOR_H_ */
Definition ordered_map.h:32
Definition ordered_set.h:32
Definition phv/utils/utils.h:117
Definition phv/utils/utils.h:1049
Definition phv/utils/utils.h:561
Definition allocator_base.h:77
AllocatorMetrics contains metrics useful in tracking Allocator efficiency and debug.
Definition allocator_metrics.h:30
Definition greedy_allocator.h:31
bool allocate(std::list< SuperCluster * > clusters, AllocatorMetrics &alloc_metrics)
Definition greedy_allocator.cpp:494
ScoreContext is the allocation context that is updated and passed down during allocation.
Definition utils_v2.h:178
TxScore is the interface of an allocation score.
Definition tx_score.h:28
Definition phv_fields.h:1095
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Definition utils_v2.h:92
Definition utils_v2.h:120
Definition phv_kit.h:46