P4C
The P4 Compiler
Loading...
Searching...
No Matches
PhvSpec Class Referenceabstract
Inheritance diagram for PhvSpec:
[legend]

Classes

struct  MauGroupType
 
struct  RangeSpec
 

Public Types

using AddressSpec = std::map<PHV::Type, RangeSpec>
 
enum  ArchBlockType_t { PARSER , MAU , DEPARSER }
 

Public Member Functions

void applyGlobalPragmas (const std::vector< const IR::Annotation * > &global_pragmas) const
 apply global pragmas to cached info about available PHV containers
 
const std::set< PHV::Kind > & containerKinds () const
 
cstring containerSetToString (const bitvec &set) const
 
const std::set< PHV::Size > & containerSizes () const
 
unsigned containerToId (PHV::Container container) const
 
const std::vector< PHV::Type > & containerTypes () const
 
unsigned containerTypeToId (PHV::Type type) const
 
bitvec deparserGroup (unsigned id) const
 
virtual unsigned deparserGroupId (const PHV::Container &c) const =0
 
const std::pair< int, int > deparserGroupNumAndSize (const PHV::Type t) const
 
const bitvecegressOnly () const
 
bitvec filterContainerSet (const bitvec &set, PHV::Kind kind) const
 Filters a set of containers for a single container kind or type.
 
bitvec filterContainerSet (const bitvec &set, PHV::Type type) const
 
unsigned getNumPovBits () const
 
unsigned getNumTagalongCollections () const
 
unsigned getTagalongCollectionId (PHV::Container c) const
 
const std::map< PHV::Type, unsigned > getTagalongCollectionSpec () const
 
const std::map< PHV::Size, std::set< PHV::Type > > groupsToTypes () const
 
bool hasContainerKind (PHV::Kind kind) const
 Determines whether the device has the given kind of PHV container.
 
virtual bool hasParserExtractGroups () const =0
 
PHV::Container idToContainer (unsigned id) const
 
PHV::Type idToContainerType (unsigned id) const
 
virtual const bitvecindividuallyAssignedContainers () const =0
 
const bitvecingressOnly () const
 
bitvec ingressOrEgressOnlyContainers (const std::map< PHV::Size, std::vector< unsigned > > &gressOnlyMauGroupIds) const
 
bitvec mauGroup (unsigned container_id) const
 
virtual unsigned mauGroupId (const PHV::Container &c) const =0
 
const std::pair< int, int > mauGroupNumAndSize (const PHV::Type t) const
 
const std::map< PHV::Size, std::vector< bitvec > > & mauGroups () const
 
const std::vector< bitvec > & mauGroups (PHV::Size sz) const
 
unsigned numContainersInGroup () const
 
unsigned numContainerTypes () const
 
virtual bitvec parserExtractGroup (unsigned id) const =0
 
virtual bitvec parserGroup (unsigned id) const =0
 
virtual unsigned parserGroupId (const PHV::Container &c) const =0
 
unsigned physicalAddress (const PHV::Container &c, ArchBlockType_t interface) const
 
virtual unsigned physicalAddress (unsigned container_id, ArchBlockType_t interface) const =0
 
virtual AddressSpec & physicalAddressSpec (ArchBlockType_t interface) const =0
 
std::optional< PHV::ContainerphysicalAddressToContainer (unsigned address, ArchBlockType_t interface) const
 
const bitvecphysicalContainers () const
 
bitvec range (PHV::Type t, unsigned start, unsigned length) const
 
bitvec tagalongCollection (unsigned container_id) const
 
const std::vector< bitvec > & tagalongCollections () const
 

Protected Member Functions

void addType (PHV::Type t)
 
unsigned getContainersPerGroup (const std::map< PHV::Size, unsigned > &numContainersPerGroup) const
 Return the number of containers in an MAU group.
 

Protected Attributes

unsigned containersPerGroup = 0
 
std::set< PHV::KinddefinedKinds
 All kinds of containers supported by the device.
 
std::set< PHV::SizedefinedSizes
 All sizes of containers supported by the device.
 
std::vector< PHV::TypedefinedTypes
 All types of containers supported by the device.
 
std::map< PHV::Type, unsigned > deparserGroupSize
 
std::map< PHV::Type, std::pair< unsigned, unsigned > > deparserGroupSpec
 
bitvec egress_only_containers_i
 
std::map< PHV::Size, std::vector< unsigned > > egressOnlyMauGroupIds
 
bitvec individually_assigned_containers_i
 
bitvec ingress_only_containers_i
 
std::map< PHV::Size, std::vector< unsigned > > ingressOnlyMauGroupIds
 
std::map< PHV::Size, std::vector< bitvec > > mau_groups_i
 
std::map< PHV::Size, MauGroupTypemauGroupSpec
 
unsigned numPovBits = 0
 
unsigned numTagalongCollections = 0
 
bitvec physical_containers_i
 
std::map< PHV::Size, std::set< PHV::Type > > sizeToTypeMap
 
std::vector< bitvectagalong_collections_i
 
std::map< PHV::Type, unsigned > tagalongCollectionSpec
 
ordered_map< PHV::Type, unsigned > typeIdMap
 

Class Documentation

◆ PhvSpec::RangeSpec

struct PhvSpec::RangeSpec

Represents a range of container addresses Containers are organized by blocks of blockSize. The addresses start at 'start'. The next block address is current block start + incr The address of a regiser within a block is start + ((index << shl) >> shr)

Class Members
unsigned blocks
unsigned blockSize
unsigned incr
unsigned shl
unsigned shr
unsigned start

Member Function Documentation

◆ addType()

void PhvSpec::addType ( PHV::Type t)
protected

Add a PHV container type to the set of types which are available on this device. This should only be called inside the constructor of subclasses of PhvSpec; after a PhvSpec instance is constructed, its list of container types is considered immutable.

Copyright (C) 2024 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

◆ containerKinds()

const std::set< PHV::Kind > & PhvSpec::containerKinds ( ) const
Returns
the PHV container kinds available on this device.

◆ containerSetToString()

cstring PhvSpec::containerSetToString ( const bitvec & set) const
Returns
a string representation of the provided set of containers.

◆ containerSizes()

const std::set< PHV::Size > & PhvSpec::containerSizes ( ) const
Returns
the PHV container sizes available on this device.

◆ containerToId()

unsigned PhvSpec::containerToId ( PHV::Container container) const
Returns
a numeric id that uniquely specifies the given PHV container on this device. Different devices have different PHV containers, so ids are not consistent between devices.

◆ containerTypes()

const std::vector< PHV::Type > & PhvSpec::containerTypes ( ) const
Returns
the PHV container types available on this device.

◆ containerTypeToId()

unsigned PhvSpec::containerTypeToId ( PHV::Type type) const
Returns
a numeric id that uniquely specifies the given PHV container type on this device. Different devices may map the same type to different ids. This behaves the same as using std::find_if to find the index of the given type in containerTypes().

◆ deparserGroup()

bitvec PhvSpec::deparserGroup ( unsigned id) const
Returns
the ids of every container in the same deparser group as the provided container.

◆ deparserGroupId()

virtual unsigned PhvSpec::deparserGroupId ( const PHV::Container & c) const
pure virtual
Returns
the Deparser group id of the container

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ deparserGroupNumAndSize()

const std::pair< int, int > PhvSpec::deparserGroupNumAndSize ( const PHV::Type t) const
Returns
a pair <#groups, #containers per group> corresponding to the PHV Type t.

◆ egressOnly()

const bitvec & PhvSpec::egressOnly ( ) const
Returns
a bitvec of the containers which are hard-wired to egress.

◆ getNumPovBits()

unsigned PhvSpec::getNumPovBits ( ) const
inline
Returns
the number of POV bits available

◆ getTagalongCollectionId()

unsigned PhvSpec::getTagalongCollectionId ( PHV::Container c) const
Returns
the ID of tagalong collection that the container belongs to

◆ groupsToTypes()

const std::map< PHV::Size, std::set< PHV::Type > > PhvSpec::groupsToTypes ( ) const
Returns
the map from PHV groups to the types supported by that group.

◆ hasParserExtractGroups()

virtual bool PhvSpec::hasParserExtractGroups ( ) const
pure virtual

Does the device have extract groups where all extracts to the group must be of the same source type (e.g., packet vs non-packet)?

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ idToContainer()

PHV::Container PhvSpec::idToContainer ( unsigned id) const
Returns
the PHV container corresponding to the given numeric id on this device. Different devices have different PHV containers, so ids are not consistent between devices.

◆ idToContainerType()

PHV::Type PhvSpec::idToContainerType ( unsigned id) const
Returns
the PHV container type corresponding to the given numeric id. Different devices may map the same id to different types. Behaves the as containerTypes()[id].

◆ individuallyAssignedContainers()

virtual const bitvec & PhvSpec::individuallyAssignedContainers ( ) const
pure virtual
Returns
the ids of containers that can be assigned to a thread individually.

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ ingressOnly()

const bitvec & PhvSpec::ingressOnly ( ) const
Returns
a bitvec of the containers which are hard-wired to ingress.

◆ ingressOrEgressOnlyContainers()

bitvec PhvSpec::ingressOrEgressOnlyContainers ( const std::map< PHV::Size, std::vector< unsigned > > & gressOnlyMauGroupIds) const
Returns
containers that constraint to either ingress or egress

◆ mauGroup()

bitvec PhvSpec::mauGroup ( unsigned container_id) const
Returns
the ids of every container in the MAU group of container_id, or std::nullopt if container_id is not part of any MAU group.

◆ mauGroupId()

virtual unsigned PhvSpec::mauGroupId ( const PHV::Container & c) const
pure virtual
Returns
the MAU group id for the container

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ mauGroupNumAndSize()

const std::pair< int, int > PhvSpec::mauGroupNumAndSize ( const PHV::Type t) const
Returns
a pair <#groups, #containers per group> corresponding to the PHV Type t

◆ mauGroups() [1/2]

const std::map< PHV::Size, std::vector< bitvec > > & PhvSpec::mauGroups ( ) const
Returns
MAU groups of all types

◆ mauGroups() [2/2]

const std::vector< bitvec > & PhvSpec::mauGroups ( PHV::Size sz) const
Returns
MAU groups of a given size sz.

◆ numContainersInGroup()

unsigned PhvSpec::numContainersInGroup ( ) const
inline
Returns
the number of containers in a single MAU group. Assumption currently is that each group has the same number of containers (applicable to both Tofino and Tofino2).

◆ numContainerTypes()

unsigned PhvSpec::numContainerTypes ( ) const
Returns
the number of PHV container types available on this device. Behaves the same as containerTypes().size().

◆ parserExtractGroup()

virtual bitvec PhvSpec::parserExtractGroup ( unsigned id) const
pure virtual
Returns
the ids of every container in the same parser group as the provided container.

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ parserGroup()

virtual bitvec PhvSpec::parserGroup ( unsigned id) const
pure virtual

The JBay parser treats the PHV as 256 x 16b containers, where each extractor can write to the upper/lower/both 8b segments of each 16b container. MAU, on the other hand, views PHV as groups of 8b, 16b, and 32b containers.

As a result, if an even/odd pair of 8b PHV containers holds extracted fields, then they need to be assigned to the same thread.

Returns
the ids of every container in the same parser group as the provided container.

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ parserGroupId()

virtual unsigned PhvSpec::parserGroupId ( const PHV::Container & c) const
pure virtual
Returns
the Parser group id of the container

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ physicalAddress() [1/2]

unsigned PhvSpec::physicalAddress ( const PHV::Container & c,
ArchBlockType_t interface ) const
Returns
the target-specific address of c, for the specified interface in the pipeline: PARSER, MAU, DEPARSER.

◆ physicalAddress() [2/2]

virtual unsigned PhvSpec::physicalAddress ( unsigned container_id,
ArchBlockType_t interface ) const
pure virtual
Returns
the target-specific address of container_id, for the specified interface in the pipeline: PARSER, MAU, DEPARSER.

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ physicalAddressSpec()

virtual AddressSpec & PhvSpec::physicalAddressSpec ( ArchBlockType_t interface) const
pure virtual
Returns
the target-specific address specification for the specified interface

Implemented in JBayPhvSpec, and TofinoPhvSpec.

◆ physicalAddressToContainer()

std::optional< PHV::Container > PhvSpec::physicalAddressToContainer ( unsigned address,
ArchBlockType_t interface ) const
Returns
the target-specific container of address, for the specified interface in the pipeline: PARSER, MAU, DEPARSER.

◆ physicalContainers()

const bitvec & PhvSpec::physicalContainers ( ) const
Returns
the ids of all containers which actually exist on the Tofino hardware - i.e., all non-overflow containers.

◆ range()

bitvec PhvSpec::range ( PHV::Type t,
unsigned start,
unsigned length ) const

Generates a bitvec containing a range of containers. This kind of bitvec can be used to implement efficient set operations on large numbers of containers.

To generate the range [B10, B16), use range(Kind::B, 10, 6).

Parameters
tThe type of container.
startThe index of first container in the range.
lengthThe number of containers in the range. May be zero.

◆ tagalongCollection()

bitvec PhvSpec::tagalongCollection ( unsigned container_id) const
Returns
the ids of every container in the tagalong collection of container_id, or std::nullopt if container_id is not part of any collection.

◆ tagalongCollections()

const std::vector< bitvec > & PhvSpec::tagalongCollections ( ) const
Returns
a bitvec of available tagalong collections.

Member Data Documentation

◆ containersPerGroup

unsigned PhvSpec::containersPerGroup = 0
protected

Number of containers in a single MAU group.

◆ mauGroupSpec

std::map<PHV::Size, MauGroupType> PhvSpec::mauGroupSpec
protected

Describes PHV groups for MAU in the device. E.g. if a device has two types of MAU groups, corresponding to 32-bit and 8-bit containers, and each type of group has 16 normal PHV containers of a given size, the mauGroupSpec will be: { { PHV::Size::b8, MauGroupType(4, { PHV::Type::B, 16 }) }, { PHV::Size::b32, MauGroupType(4, { PHV::Type::W, 16 }) } }.