TensorRT 8.6.0
nvinfer1::ITopKLayer Class Reference

Layer that represents a TopK reduction. More...

#include <NvInfer.h>

Inheritance diagram for nvinfer1::ITopKLayer:
nvinfer1::ILayer nvinfer1::INoCopy

Public Member Functions

void setOperation (TopKOperation op) noexcept
 Set the operation for the layer. More...
 
TopKOperation getOperation () const noexcept
 Get the operation for the layer. More...
 
void setK (int32_t k) noexcept
 Set the static k value for the layer. More...
 
int32_t getK () const noexcept
 Get the k value for the layer. More...
 
void setReduceAxes (uint32_t reduceAxes) noexcept
 Set which axes to reduce for the layer. More...
 
uint32_t getReduceAxes () const noexcept
 Get the axes to reduce for the layer. More...
 
void setInput (int32_t index, ITensor &tensor) noexcept
 Append or replace an input of this layer with a specific tensor. More...
 
- Public Member Functions inherited from nvinfer1::ILayer
LayerType getType () const noexcept
 Return the type of a layer. More...
 
void setName (char const *name) noexcept
 Set the name of a layer. More...
 
char const * getName () const noexcept
 Return the name of a layer. More...
 
int32_t getNbInputs () const noexcept
 Get the number of inputs of a layer. More...
 
ITensorgetInput (int32_t index) const noexcept
 Get the layer input corresponding to the given index. More...
 
int32_t getNbOutputs () const noexcept
 Get the number of outputs of a layer. More...
 
ITensorgetOutput (int32_t index) const noexcept
 Get the layer output corresponding to the given index. More...
 
void setInput (int32_t index, ITensor &tensor) noexcept
 Replace an input of this layer with a specific tensor. More...
 
void setPrecision (DataType dataType) noexcept
 Set the computational precision of this layer. More...
 
DataType getPrecision () const noexcept
 get the computational precision of this layer More...
 
bool precisionIsSet () const noexcept
 whether the computational precision has been set for this layer More...
 
void resetPrecision () noexcept
 reset the computational precision for this layer More...
 
void setOutputType (int32_t index, DataType dataType) noexcept
 Set the output type of this layer. More...
 
DataType getOutputType (int32_t index) const noexcept
 get the output type of this layer More...
 
bool outputTypeIsSet (int32_t index) const noexcept
 whether the output type has been set for this layer More...
 
void resetOutputType (int32_t index) noexcept
 reset the output type for this layer More...
 
void setMetadata (char const *metadata) noexcept
 Set the metadata for this layer. More...
 
char const * getMetadata () const noexcept
 Get the metadata of the layer. More...
 

Protected Member Functions

virtual ~ITopKLayer () noexcept=default
 
- Protected Member Functions inherited from nvinfer1::ILayer
virtual ~ILayer () noexcept=default
 
- Protected Member Functions inherited from nvinfer1::INoCopy
 INoCopy ()=default
 
virtual ~INoCopy ()=default
 
 INoCopy (INoCopy const &other)=delete
 
INoCopyoperator= (INoCopy const &other)=delete
 
 INoCopy (INoCopy &&other)=delete
 
INoCopyoperator= (INoCopy &&other)=delete
 

Protected Attributes

apiv::VTopKLayer * mImpl
 
- Protected Attributes inherited from nvinfer1::ILayer
apiv::VLayer * mLayer
 

Detailed Description

Layer that represents a TopK reduction.

This layer can accept both static and dynamic k. Static k can be set through the addTopK() API function, or accessed using the getK() and setK() functions after layer creation. For dynamic k, use the setInput() method to pass in k as a tensor with index 1, which overrides the static k value in calculations.

Warning
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.

Constructor & Destructor Documentation

◆ ~ITopKLayer()

virtual nvinfer1::ITopKLayer::~ITopKLayer ( )
protectedvirtualdefaultnoexcept

Member Function Documentation

◆ getK()

int32_t nvinfer1::ITopKLayer::getK ( ) const
inlinenoexcept

Get the k value for the layer.

This function will return the static k value passed into addTopK(), or the value passed into setK().

If a second layer input is present and non-null, this function returns -1.

See also
setK()

◆ getOperation()

TopKOperation nvinfer1::ITopKLayer::getOperation ( ) const
inlinenoexcept

Get the operation for the layer.

See also
setOperation(), TopKOperation

◆ getReduceAxes()

uint32_t nvinfer1::ITopKLayer::getReduceAxes ( ) const
inlinenoexcept

Get the axes to reduce for the layer.

See also
setReduceAxes()

◆ setInput()

void nvinfer1::ILayer::setInput ( int32_t  index,
ITensor tensor 
)
inlinenoexcept

Append or replace an input of this layer with a specific tensor.

Parameters
indexThe index of the input to modify.
tensorThe new input tensor.

For a TopK layer, the values 0-1 are valid. The indices are as follows:

  • 0: Input data tensor.
  • 1: A scalar Int32 tensor containing a positive value corresponding to the number of top elements to retrieve. Values larger than 3840 will result in a runtime error. If provided, this will override the static k value in calculations.

◆ setK()

void nvinfer1::ITopKLayer::setK ( int32_t  k)
inlinenoexcept

Set the static k value for the layer.

Currently only values up to 3840 are supported.

If a second input to this layer has been set, it will be reset to null by this method.

See also
getK()

◆ setOperation()

void nvinfer1::ITopKLayer::setOperation ( TopKOperation  op)
inlinenoexcept

Set the operation for the layer.

See also
getOperation(), TopKOperation

◆ setReduceAxes()

void nvinfer1::ITopKLayer::setReduceAxes ( uint32_t  reduceAxes)
inlinenoexcept

Set which axes to reduce for the layer.

See also
getReduceAxes()

Member Data Documentation

◆ mImpl

apiv::VTopKLayer* nvinfer1::ITopKLayer::mImpl
protected

The documentation for this class was generated from the following file: