P4C
The P4 Compiler
Loading...
Searching...
No Matches
AllocScore Struct Reference

#include <allocate_phv.h>

Public Types

using ContainerAllocStatus = PHV::Allocation::ContainerAllocStatus
 
using IsBetterFunc = std::function<bool(const AllocScore &left, const AllocScore &right)>
 IsBetterFunc returns true if left is better than right.
 
typedef cstring MetricName
 type of the name of a metric.
 

Public Member Functions

 AllocScore (const PHV::Transaction &alloc, const PhvInfo &phv, const ClotInfo &clot, const PhvUse &uses, const MapFieldToParserStates &field_to_parser_states, const CalcParserCriticalPath &parser_critical_path, const TableFieldPackOptimization &tablePackOpt, FieldPackingOpportunity *packing, const int bitmasks)
 
AllocScore operator- (const AllocScore &other) const
 
AllocScoreoperator= (const AllocScore &other)=default
 

Static Public Member Functions

static AllocScore make_lowest ()
 

Public Attributes

ordered_map< PHV::Kind, ordered_map< MetricName, int > > by_kind
 
ordered_map< MetricName, int > general
 

Static Public Attributes

static const std::vector< MetricNameg_by_kind_metrics
 container-kind-specific scores.
 
static const std::vector< MetricNameg_general_metrics
 general metrics
 

Detailed Description

The score of an Allocation .

This score is used in 3 places where decisions have to be made. From bottom to top, they are:

  1. Inside tryAllocSliceList, we use this score to find a best container for a slice list.
  2. Inside tryAlloc, to find the best starting position for slices from a aligned_cluster.
  3. Inside BestScoreStrategy, to find the best container_group for a SuperCluster.

Constructor & Destructor Documentation

◆ AllocScore()

AllocScore::AllocScore ( const PHV::Transaction & alloc,
const PhvInfo & phv,
const ClotInfo & clot,
const PhvUse & uses,
const MapFieldToParserStates & field_to_parser_states,
const CalcParserCriticalPath & parser_critical_path,
const TableFieldPackOptimization & tablePackOpt,
FieldPackingOpportunity * packing_opportunities,
const int bitmasks )

Construct a score from a Transaction.

alloc: new allocation group: the container group where allocations were made to.

The metrics are calculated:

  • is_tphv: type of group.
  • n_set_gress: number of containers which set their gress to ingress/egress from std::nullopt.
  • n_overlay_bits: container bits already used in parent alloc get overlaid.
  • n_field_packing_score: container bits that share the same byte for two or more slices used as a condition in a match table.
  • n_packing_bits: use bits that ContainerAllocStatus is PARTIAL in parent.
  • n_inc_containers: the number of container used that was EMPTY.
  • n_wasted_bits: if field is solitary, container.size() - slice.width().

Member Data Documentation

◆ g_by_kind_metrics

const std::vector< MetricName > AllocScore::g_by_kind_metrics
static
Initial value:
= {
n_set_gress,
n_set_parser_group_gress,
n_set_deparser_group_gress,
n_set_parser_extract_group_source,
n_overlay_bits,
n_packing_bits,
n_packing_priority,
n_inc_containers,
n_wasted_bits,
n_inc_small_containers,
n_clot_bits,
n_field_packing_score,
n_mismatched_deparser_gress,
}

container-kind-specific scores.

◆ g_general_metrics

const std::vector< MetricName > AllocScore::g_general_metrics
static
Initial value:
= {
n_tphv_on_phv_bits, n_mocha_on_phv_bits, n_dark_on_phv_bits, n_dark_on_mocha_bits,
n_prefer_bits, n_bitmasked_set, n_wasted_pov_bits, parser_extractor_balance,
n_inc_tphv_collections,
}

general metrics