P4C
The P4 Compiler
Loading...
Searching...
No Matches
trivial_allocator.h
1
19#ifndef BF_P4C_PHV_V2_TRIVIAL_ALLOCATOR_H_
20#define BF_P4C_PHV_V2_TRIVIAL_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
35 public:
37 class PhvStatus {
38 std::unordered_map<PHV::Size, int> next_container_idx;
39
40 public:
41 PhvStatus();
42 PHV::Container next_container(PHV::Size) const;
43 void inc_next_container(PHV::Size);
44 };
45
49 const AllocError *err = nullptr;
50 std::vector<AllocSlice> alloc_slices;
51 PhvStatus phv_status;
52 bool ok() const { return err == nullptr; };
53 PartialAllocResult(const std::vector<AllocSlice> &alloc_slices, PhvStatus phv_status)
54 : alloc_slices(alloc_slices), phv_status(phv_status) {}
55 explicit PartialAllocResult(const AllocError *err) : err(err) {}
56 };
57
58 private:
59 // const PhvKit& kit_i;
60 PhvInfo &phv_i;
61 const int pipe_id_i;
62
64 ContainerGroupsBySize make_container_groups_merged_by_size() const;
65
69 std::vector<PHV::AllocSlice> gen_alloc_slices_from_tx(const PHV::Transaction &tx,
70 PhvStatus &phv_status) const;
71
75 void bind_alloc_slices(const std::vector<PHV::AllocSlice> &slices);
76
79 const AllocError *diagnose_invalid_cluster(const Allocation &empty_alloc,
80 const PHV::SuperCluster *sc,
81 const ContainerGroupsBySize &container_groups,
82 AllocatorMetrics &alloc_metrics) const;
83
85 cstring make_error_msg(const SuperCluster *sc, const AllocError *err) const;
86
87 public:
88 TrivialAllocator(const PhvKit &kit, PhvInfo &phv, int pipe_id);
89
94 const Allocation &empty_alloc, const PHV::SuperCluster *sc, PhvStatus phv_status,
95 const ContainerGroupsBySize &container_groups, AllocatorMetrics &alloc_metrics,
96 bool homogeneous_sizes = false, bool minimal_packing_slicing = true,
97 const int max_slicings = 128, std::ostream *history = nullptr) const;
98
100 bool allocate(const std::list<PHV::SuperCluster *> &clusters, AllocatorMetrics &alloc_metrics);
101
104 bool can_be_allocated(const Allocation &empty_alloc, const PHV::SuperCluster *sc,
105 AllocatorMetrics &alloc_metrics, const int max_slicings = 128) const;
106
111 std::list<SuperCluster *> sliced;
112 const SuperCluster *invalid = nullptr;
114 };
115
122 PreSlicingResult pre_slice(const Allocation &empty_alloc, SuperCluster *sc,
123 AllocatorMetrics &alloc_metrics, const int n_max_slicing = 128,
124 bool baseline_mode = false) const;
125};
126
127} // namespace v2
128} // namespace PHV
129
130#endif /* BF_P4C_PHV_V2_TRIVIAL_ALLOCATOR_H_ */
Definition cstring.h:85
Definition ordered_map.h:32
Definition phv/utils/utils.h:117
Definition phv.h:176
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
PhvStatus bookkeeper for containers.
Definition trivial_allocator.h:37
Definition trivial_allocator.h:34
bool can_be_allocated(const Allocation &empty_alloc, const PHV::SuperCluster *sc, AllocatorMetrics &alloc_metrics, const int max_slicings=128) const
Definition trivial_allocator.cpp:436
bool allocate(const std::list< PHV::SuperCluster * > &clusters, AllocatorMetrics &alloc_metrics)
run trivial PHV allocator to allocate all clusters and update phv_i.
Definition trivial_allocator.cpp:339
const PartialAllocResult * slice_and_allocate_sc(const Allocation &empty_alloc, const PHV::SuperCluster *sc, PhvStatus phv_status, const ContainerGroupsBySize &container_groups, AllocatorMetrics &alloc_metrics, bool homogeneous_sizes=false, bool minimal_packing_slicing=true, const int max_slicings=128, std::ostream *history=nullptr) const
Definition trivial_allocator.cpp:253
PreSlicingResult pre_slice(const Allocation &empty_alloc, SuperCluster *sc, AllocatorMetrics &alloc_metrics, const int n_max_slicing=128, bool baseline_mode=false) const
Definition trivial_allocator.cpp:142
Definition trivial_allocator.h:110
Definition phv_fields.h:1095
The namespace encapsulating PHV-related stuff.
Definition gateway.h:32
Size
all possible PHV container sizes in BFN devices
Definition phv.h:110
Definition utils_v2.h:92
Definition phv_kit.h:46
Definition trivial_allocator.h:48