TensorRT 8.4.3
nvinfer1::IGatherLayer Class Reference

A Gather layer in a network definition. Supports several kinds of gathering. More...

#include <NvInfer.h>

Inheritance diagram for nvinfer1::IGatherLayer:
nvinfer1::ILayer nvinfer1::INoCopy

Public Member Functions

void setGatherAxis (int32_t axis) noexcept
 Set the axis used by GatherMode::kELEMENTS and GatherMode::kDEFAULT The axis must be less than the number of dimensions in the data input. The axis defaults to 0. More...
 
int32_t getGatherAxis () const noexcept
 Get the axis to gather on. More...
 
void setNbElementWiseDims (int32_t elementWiseDims) noexcept
 Set the number of leading dimensions of indices tensor to be handled elementwise. The gathering of indexing starts from the dimension of data[NbElementWiseDims:]. The NbElementWiseDims must be less than the Rank of the data input. More...
 
int32_t getNbElementWiseDims () const noexcept
 Get the number of leading dimensions of indices tensor to be handled elementwise. More...
 
void setMode (GatherMode mode) noexcept
 Set the gather mode. More...
 
GatherMode getMode () const noexcept
 Get the gather mode. 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...
 

Protected Member Functions

virtual ~IGatherLayer () 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::VGatherLayer * mImpl
 
- Protected Attributes inherited from nvinfer1::ILayer
apiv::VLayer * mLayer
 

Detailed Description

A Gather layer in a network definition. Supports several kinds of gathering.

The Gather layer has two input tensors, Data and Indices, and an output tensor Output. Additionally, there are three parameters: mode, nbElementwiseDims, and axis that control how the indices are interpreted.

The dimensions of the output likewise depends on the mode:

GatherMode::kDEFAULT:

    First nbElementwiseDims of output are computed by applying broadcast rules to
    first nbElementwiseDims of indices and data. Note that nbElementwiseDims <= 1.
    Rest of dimensions are computed by copying dimensions of Data, and replacing
    the dimension for axis gatherAxis with the dimensions of indices.

GatherMode::kND:
    If indices.d[q-1] = r - nbElementwiseDims
        output.d = [indices.d[0], ... , indices.d[q-2]]
    Else if indices.d[q-1] < r - nbElementWiseDims
        output.d = [indices.d[0], ... , indices.d[q-1], data.d[nbElementwiseDims + indices.d[q-1] + q],
        data.d[r-1]]
    Else
        This is build time error

GatherMode::kELEMENT:
    The output dimensions match the dimensions of the indices tensor.

The types of Data and Output must be the same, and Indices shall be DataType::kINT32.

How the elements of Data are gathered depends on the mode:

GatherMode::kDEFAULT:
    Each index in indices is used to index Data along axis gatherAxis.

GatherMode::kND:
    Indices is a rank q integer tensor, best thought of as a rank (q-1) tensor of
    indices into data, where each element defines a slice of data
    The operation can be formulated as output[i_1, ..., i_{q-1}] = data[indices[i_1, ..., i_{q-1}]]

GatherMode::kELEMENT:

    Here "axis" denotes the result of getGatherAxis().
    For each element X of indices:
        Let J denote a sequence for the subscripts of X
        Let K = sequence J with element [axis] replaced by X
        output[J] = data[K]

The handling of nbElementWiseDims depends on the mode:

  • GatherMode::kDEFAULT: nbElementWiseDims <= 1. Broadcast is supported across the elementwise dimension if present.
  • GatherMode::kND: 0 <= nbElementWiseDims < rank(Data)-1. Broadcast is not supported across the elementwise dimensions.
  • GatherMode::kELEMENT: nbElementWiseDims = 0

Notes:

  • For modes GatherMode::kND and GatherMode::kELEMENT, the first nbElementWiseDims dimensions of data and index must be equal. If not, an error will be reported at build time or run time.
  • Only mode GatherMode::kDEFAULT supports an implicit batch dimensions or broadcast on the elementwise dimensions.
  • If an axis of Data has dynamic length, using a negative index for it has undefined behavior.
  • No DLA support
  • Zero will be stored for OOB access
Warning
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.

Constructor & Destructor Documentation

◆ ~IGatherLayer()

virtual nvinfer1::IGatherLayer::~IGatherLayer ( )
protectedvirtualdefaultnoexcept

Member Function Documentation

◆ getGatherAxis()

int32_t nvinfer1::IGatherLayer::getGatherAxis ( ) const
inlinenoexcept

Get the axis to gather on.

Warning
Undefined behavior when used with GatherMode::kND.
See also
setGatherAxis()

◆ getMode()

GatherMode nvinfer1::IGatherLayer::getMode ( ) const
inlinenoexcept

Get the gather mode.

See also
setMode()

◆ getNbElementWiseDims()

int32_t nvinfer1::IGatherLayer::getNbElementWiseDims ( ) const
inlinenoexcept

Get the number of leading dimensions of indices tensor to be handled elementwise.

See also
setNbElementWiseDims()

◆ setGatherAxis()

void nvinfer1::IGatherLayer::setGatherAxis ( int32_t  axis)
inlinenoexcept

Set the axis used by GatherMode::kELEMENTS and GatherMode::kDEFAULT The axis must be less than the number of dimensions in the data input. The axis defaults to 0.

Warning
Undefined behavior when used with GatherMode::kND.
See also
getGatherAxis()

◆ setMode()

void nvinfer1::IGatherLayer::setMode ( GatherMode  mode)
inlinenoexcept

Set the gather mode.

See also
getMode()

◆ setNbElementWiseDims()

void nvinfer1::IGatherLayer::setNbElementWiseDims ( int32_t  elementWiseDims)
inlinenoexcept

Set the number of leading dimensions of indices tensor to be handled elementwise. The gathering of indexing starts from the dimension of data[NbElementWiseDims:]. The NbElementWiseDims must be less than the Rank of the data input.

Parameters
elementWiseDimsnumber of dims to be handled as elementwise.

Default: 0

The value of nbElementWiseDims and GatherMode are checked during network validation:

GatherMode::kDEFAULT: nbElementWiseDims must be 0 if there is an implicit batch dimension. It can be 0 or 1 if there is not an implicit batch dimension. GatherMode::kND: nbElementWiseDims can be between 0 and one less than rank(data). GatherMode::kELEMENT: nbElementWiseDims must be 0

See also
getNbElementWiseDims()

Member Data Documentation

◆ mImpl

apiv::VGatherLayer* nvinfer1::IGatherLayer::mImpl
protected

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