P4C
The P4 Compiler
Loading...
Searching...
No Matches
PHV::v2::TrivialAllocator Class Reference

#include <trivial_allocator.h>

Inheritance diagram for PHV::v2::TrivialAllocator:
[legend]

Classes

struct  PartialAllocResult
 
class  PhvStatus
 PhvStatus bookkeeper for containers. More...
 
struct  PreSlicingResult
 

Public Member Functions

 TrivialAllocator (const PhvKit &kit, PhvInfo &phv, int pipe_id)
 
bool allocate (const std::list< PHV::SuperCluster * > &clusters, AllocatorMetrics &alloc_metrics)
 run trivial PHV allocator to allocate all clusters and update phv_i.
 
bool can_be_allocated (const Allocation &empty_alloc, const PHV::SuperCluster *sc, AllocatorMetrics &alloc_metrics, const int max_slicings=128) const
 
PreSlicingResult pre_slice (const Allocation &empty_alloc, SuperCluster *sc, AllocatorMetrics &alloc_metrics, const int n_max_slicing=128, bool baseline_mode=false) const
 
const PartialAllocResultslice_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
 
- Public Member Functions inherited from PHV::v2::AllocatorBase
 AllocatorBase (const PhvKit &kit)
 
PHV::Transaction alloc_deparser_zero_cluster (const ScoreContext &ctx, const PHV::Allocation &alloc, const PHV::SuperCluster *sc, PhvInfo &phv) const
 
AllocResult alloc_strided_super_clusters (const ScoreContext &ctx, const Allocation &alloc, const SuperCluster *sc, const ContainerGroupsBySize &groups, AllocatorMetrics &alloc_metrics, const int max_n_slicings=64) const
 
AllocResult try_sliced_super_cluster (const ScoreContext &ctx, const Allocation &alloc, const SuperCluster *sc, const ContainerGroupsBySize &groups, AllocatorMetrics &alloc_metrics) const
 ALLOCATION functions common to trivial and greedy allocation.
 

Additional Inherited Members

- Protected Types inherited from PHV::v2::AllocatorBase
using DfsAllocCb = std::function<bool(const Transaction &)>
 internal type of callback.
 
- Protected Member Functions inherited from PHV::v2::AllocatorBase
AllocResult alloc_stride (const ScoreContext &ctx, const Allocation &alloc, const std::vector< FieldSlice > &stride, const ContainerGroupsBySize &groups, AllocatorMetrics &alloc_metrics) const
 
const AllocErrorcheck_container_scope_constraints (const Allocation &alloc, const std::vector< AllocSlice > &candidates, const Container &c) const
 
std::set< PHV::Sizecompute_valid_container_sizes (const SuperCluster *sc) const
 
const AllocErroris_container_bytes_ok (const Allocation &alloc, const std::vector< AllocSlice > &candidates, const Container &c) const
 
const AllocErroris_container_gress_ok (const Allocation &alloc, const AllocSlice &sl, const Container &c) const
 
const AllocErroris_container_solitary_ok (const Allocation &alloc, const AllocSlice &candidate, const Container &c) const
 
const AllocErroris_container_type_ok (const AllocSlice &sl, const Container &c) const
 CONSTRAINT CHECKING Functions common to trivial and greedy allocation.
 
const AllocErroris_container_write_mode_ok (const Allocation &alloc, const AllocSlice &sl, const Container &c) const
 
std::vector< const SuperCluster::SliceList * > * make_alloc_order (const ScoreContext &ctx, const SuperCluster *sc, const PHV::Size width) const
 
Transaction make_speculated_alloc (const ScoreContext &ctx, const Allocation &alloc, const SuperCluster *sc, const std::vector< AllocSlice > &candidates, const Container &candidates_cont) const
 
std::vector< int > make_start_positions (const ScoreContext &ctx, const SuperCluster::SliceList *sl, const PHV::Size width) const
 
std::optional< Transactiontry_hints (const ScoreContext &ctx, const Allocation &alloc, const ContainerGroup &group, const ActionSourceCoPackMap &action_hints_map, ordered_set< PHV::FieldSlice > &allocated, ScAllocAlignment &hint_enforced_alignments, AllocatorMetrics &alloc_metrics) const
 
SomeContScopeAllocResult try_slices_adapter (const ScoreContext &ctx, const Allocation &alloc, const FieldSliceAllocStartMap &fs_starts, const ContainerGroup &group, std::optional< Container > c, AllocatorMetrics &alloc_metrics) const
 
ContScopeAllocResult try_slices_to_container (const ScoreContext &ctx, const Allocation &alloc, const FieldSliceAllocStartMap &fs_starts, const Container &c, AllocatorMetrics &alloc_metrics, const bool skip_mau_checks=false) const
 
SomeContScopeAllocResult try_slices_to_container_group (const ScoreContext &ctx, const Allocation &alloc, const FieldSliceAllocStartMap &fs_starts, const ContainerGroup &group, AllocatorMetrics &alloc_metrics) const
 
AllocResult try_super_cluster_to_container_group (const ScoreContext &ctx, const Allocation &alloc, const SuperCluster *sc, const ContainerGroup &group, AllocatorMetrics &alloc_metrics) const
 
AllocResult try_wide_arith_slices_to_container_group (const ScoreContext &ctx, const Allocation &alloc, const ScAllocAlignment &alignment, const SuperCluster::SliceList *lo, const SuperCluster::SliceList *hi, const ContainerGroup &group, AllocatorMetrics &alloc_metrics) const
 
const AllocErrorverify_can_pack (const ScoreContext &ctx, const Allocation &alloc, const SuperCluster *sc, const std::vector< AllocSlice > &candidates, const Container &c, ActionSourceCoPackMap &co_pack_hints) const
 
- Protected Attributes inherited from PHV::v2::AllocatorBase
const PhvKitkit_i
 

Detailed Description

TrivialAllocator allocates PHV fields to an infinite long PHV. It is in two cases: (1) trivial allocation before table placement. (2) check whether all constraints can be satisfied.


Class Documentation

◆ PHV::v2::TrivialAllocator::PreSlicingResult

struct PHV::v2::TrivialAllocator::PreSlicingResult

result of pre-slicing will always have a set of sliced super cluster. If any sliced super cluster failed to pass can_be_allocated verification, the first one will be saved to invalid.

Class Members
ordered_map< SuperCluster *, KindSizeIndexedMap > baseline_cont_req
const SuperCluster * invalid = nullptr
list< SuperCluster * > sliced

Member Function Documentation

◆ can_be_allocated()

bool PHV::v2::TrivialAllocator::can_be_allocated ( const Allocation & empty_alloc,
const PHV::SuperCluster * sc,
AllocatorMetrics & alloc_metrics,
const int max_slicings = 128 ) const
Returns
true if sc can be allocated to empty_alloc, assuming there are infinite containers. Use this verify whether there is any unsat constraint in sc.

◆ pre_slice()

TrivialAllocator::PreSlicingResult PHV::v2::TrivialAllocator::pre_slice ( const Allocation & empty_alloc,
SuperCluster * sc,
AllocatorMetrics & alloc_metrics,
const int n_max_slicing = 128,
bool baseline_mode = false ) const
Returns
result of sliced cluster from sc with the minimal number of slicing (try to maximize packing). This function will try to ensure that all the returned super clusters can be allocated, without violating any constraints, by calling can_be_allocated to verify before return. However, there can by cases that either we are not lucky enough or there are conflicting constraints, the sc cannot be split to allocatable clusters. In those cases, we will just return the last slicing we found.

◆ slice_and_allocate_sc()

const TrivialAllocator::PartialAllocResult * PHV::v2::TrivialAllocator::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
Returns
a PartialAllocResult that contains alloc_slices of an updated phv status when allocation succeeded. If allocation failed, PartialResult of an error that contains the best effort diagnose result will be returned.