---
title: ConcatOperation
description: "| 硬件型号 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendtb/ascendtb_01_0054.html
sourcePath: /source/zh/canncommercial/900/API/ascendtb/ascendtb_01_0054.html
indexId: c5359e5ed9cefae4dc4ce99679e0ed287fc6c96beaa4d488538ab29bd406952d64
---
# ConcatOperation

#### 产品支持情况

| 硬件型号 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 推理系列产品 / Atlas A3 训练系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |


#### 功能说明

将两个输入张量在指定维度拼接成一个输出张量。

图1 Concat算子实现原理


#### 算子上下文

图2 ConcatOperation


#### 定义

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


#### 参数列表

| 成员名称 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
| concatDim | int | 0 | 指定拼接的维度索引。 假设拼接的维度索引为k，x的维度数为dimNum： 当concatDim为负数时，其含义是从最高维度开始访问，k=dimNum+concatDim。例如concatDim = \-1，则拼接维度k为dimNum \- 1。 否则k=concatDim。 |
| rsv[12] | uint8\_t | {0} | 预留参数。 |


#### 输入

| 参数 | 维度 | 数据类型 | 格式 | 描述 |
| --- | --- | --- | --- | --- |
| x | [x\_dim\_0, x\_dim\_1, ... ，x\_dim\_n] | float16/bf16 | ND | 需要被拼接的tensor。 |
| y | [y\_dim\_0, y\_dim\_1, ... ，y\_dim\_n] | float16/bf16 | ND | 需要被拼接的tensor。除了y\_dim\_k之外，其余维度与x相同。 |


#### 输出

| 参数 | 维度 | 数据类型 | 格式 | 描述 |
| --- | --- | --- | --- | --- |
| output | [dim\_0, dim\_1, ..., dim\_n] | float16/bf16 | ND | 拼接后的tensor。 |


#### 约束说明

- Param参数约束

  - dimNum为被拼接tensor的维数。
  - -dimNum ≤ concatDim ≤ dimNum - 1。

- 输入约束

  - 输入x和y的维数相等。
  - 输入x和y的维度大小，除了concatDim维之外，其他维度要求相同。


#### 接口调用示例

- 输入

```
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（或-2）
```


- 输出

```
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]]]
```
