concat

Description

Reconcatenates multiple input tensors along a specified axis.

raw_tensors indicates input tensors of the same data type.

If raw_tensors[i].shape = [D0, D1, ... Daxis(i), ... Dn], the concatenated tensor is with shape [D0, D1, ... Raxis, ... Dn].

where Raxis = sum(Daxis(i)).

See the following example.

t1 = [[1, 2, 3], [4, 5, 6]] 
t2 = [[7, 8, 9], [10, 11, 12]] 
concat([t1, t2], 0)  # [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] 
concat([t1, t2], 1)  # [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]  

# Tensor t1 with shape [2, 3]
# Tensor t2 with shape [2, 3]
concat([t1, t2], 0).shape  # [4, 3] 
concat([t1, t2], 1).shape  # [2, 6]

The parameter axis can also be a negative integer, indicating the axis indexed axis+len(shape), which is indexed from the end.

See the following example.

t1 = [[[1, 2], [2, 3]], [[4, 4], [5, 3]]] 
t2 = [[[7, 4], [8, 4]], [[2, 10], [15, 11]]] 
concat([t1, t2], -1)

The output is as follows:

[[[ 1,  2,  7,  4],
  [ 2,  3,  8,  4]], 

 [[ 4,  4,  2, 10], 
  [ 5,  3, 15, 11]]]

Prototype

concat(raw_tensors, axis)

Parameters

  • raw_tensors: a list of tensors of type tvm.tensor. The last dimension of the tensor must be 32-byte aligned.

    The supported data types include: int8, uint8, int16, int32, float16, and float32.

    For input tensors, the axes except axis must have the same dimensions.

  • axis: axis along which concatenation is performed. The value range is [–d, d – 1]. The parameter d indicates the dimension count of raw_tensor.

Returns

res_tensor: a tvm.tensor for the result tensor

Restrictions

This API cannot be used in conjunction with other TBE DSL APIs.

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Example

from tbe import tvm
from tbe import dsl
shape1 = (64,128) 
shape2 = (64,128) 
input_dtype = "float16"
data1 = tvm.placeholder(shape1, name="data1", dtype=input_dtype) 
data2 = tvm.placeholder(shape2, name="data1", dtype=input_dtype) 
data = [data1, data2] 
res = dsl.concat(data, 0) 
# res.shape = (128,128)