ConcatOperation

Description

Combines two input tensors into an output tensor at a specified dimension.

Operator Context

Figure 1 ConcatOperation

Operator Function Implementation

The Concat operator is used to concatenate two input tensors into one output tensor in a specified dimension.

Figure 2 Implementation principle of the Concat operator

Definition

struct ConcatParam {
    int concatDim = 0;
    uint8_t rsv[12] = {0};
};

Parameters

Member

Type

Default Value

Description

concatDim

int

0

Dimension index for concat.

When concatDim is a negative number, the access starts from the highest dimension.

For example, if concatDim is -1 and the dimension count of x is dimNum, the concat dimension is dimNum - 1.

rsv[12]

uint8_t

{0}

Reserved

Input

Parameter

Dimension

Data Type

Format

Description

x

[-1,…,-1]

The value -1 indicates that the size of the current dimension is not restricted.

float16/bf16

ND

Tensor to be concatenated.

y

[-1,…,-1]

The value -1 indicates that the size of the current dimension is not restricted.

float16/bf16

ND

Tensor to be concatenated.

Output

Parameter

Dimension

Data Type

Format

Description

output

[-1,…,-1]

The value -1 indicates that the size of the current dimension is not restricted.

float16/bf16

ND

Concatenated tensor.

Restrictions

  • Restrictions on the parameters:
    • dimNum: number of dimensions of the concatenated tensor.
    • -dimNum ≤ concatDim ≤ dimNum - 1.
  • Input constraints
    • The inputs x and y have the same dimensions.
    • Dimension size of the inputs x and y must be the same except the concatDim dimension.

API Calling Example

  • Input
    x shape = [3, 2, 3]:
    [[[1.0, 1.0, 1.0],
      [1.0, 1.0, 1.0]],
     [[1.0, 1.0, 1.0],
      [1.0, 1.0, 1.0]],
     [[1.0, 1.0, 1.0],
      [1.0, 1.0, 1.0]]]
    y shape = [3, 1, 3]:
    [[[2.0, 2.0, 2.0]],
     [[2.0, 2.0, 2.0]],
     [[2.0, 2.0, 2.0]]]
    param.concatDim = 1 (or -2)
  • Output
    output shape = [3, 3, 3]
    [[[1.0, 1.0, 1.0],
      [1.0, 1.0, 1.0],
      [2.0, 2.0, 2.0]],
     [[1.0, 1.0, 1.0],
      [1.0, 1.0, 1.0],
      [2.0, 2.0, 2.0]],
     [[1.0, 1.0, 1.0],
      [1.0, 1.0, 1.0],
      [2.0, 2.0, 2.0]]]