---
title: Swap
description: "| 硬件型号 | 支持情况 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/SiP/SIP_API_0026.html
sourcePath: /source/zh/canncommercial/900/API/SiP/SIP_API_0026.html
indexId: 02495120d572633988b5c845f6810e47d4a2344ed4737c6dab7c315afdc0363155
---
# Swap

#### 产品支持情况

| 硬件型号 | 支持情况 |
| --- | --- |
| Atlas 200I/500 A2 推理产品 | 不支持 |
| Atlas 推理系列产品 | 不支持 |
| Atlas 训练系列产品 | 不支持 |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | 支持 |
| Atlas A3 推理系列产品 / Atlas A3 训练系列产品 | 支持 |


#### 功能描述

接口功能

- asdBlasMakeSwapPlan：初始化该句柄对应的Swap算子配置。
- asdBlasSswap：交换两个实数向量。

- asdBlasCswap：交换两个复数向量。

计算公式

- asdBlasSswap的计算公式：

  - 示例：
    输入“x”为：

```
[1.0, 2.0]
```


    输入“y”为：

```
[3.0, 4.0]
```


    调用“Sswap”算子后，输出“x”为：

```
[3.0, 4.0]
```


    输出“y”为：

```
[1.0, 2.0]
```


- asdBlasCswap的计算公式：

  - 示例：
    输入“x”为：

```
[1.0 + 1.0i, 2.0 + 2.0i]
```


    输入“y”为：

```
[3.0 + 3.0i, 4.0 + 4.0i]
```


    调用“Cswap”算子后，输出“x”为：

```
[3.0 + 3.0i, 4.0 + 4.0i]
```


    输出“y”为：

```
[1.0 + 1.0i, 2.0 + 2.0i]
```


#### 函数原型

- AspbStatus asdBlasMakeSwapPlan(asdBlasHandle handle)
- AspbStatus asdBlasSswap(asdBlasHandle handle, const int64_t n, aclTensor *x, const int64_t incx, aclTensor *y, const int64_t incy)
- AspbStatus asdBlasCswap(asdBlasHandle handle, const int64_t n, aclTensor *x, const int64_t incx, aclTensor *y,const int64_t incy)


#### 参数说明

- asdBlasMakeSwapPlan| 参数名称 | Input/Output | 类型 | 描述 |
| --- | --- | --- | --- |
| handle | Input | asdBlasHandle | swap算子的句柄。 |


- asdBlasSswap & asdBlasCswap| 参数名称 | Input/Output | 类型 | 描述 |
| --- | --- | --- | --- |
| handle | Input | asdBlasHandle | swap算子的句柄。 |
| n | Input | const int64\_t | 向量x（y）中元素的个数。 |
| x | Input/Output | aclTensor \* | 公式中的x，Device侧的Tensor，数据格式支持ND，shape为[n]。 Sswap下数据类型支持FLOAT32。 Cswap下数据类型支持COMPLEX64。 |
| incx | Input | const int64\_t | x相邻元素间的内存地址偏移量（当前约束为1）。 |
| y | Input /Output | aclTensor \* | 公式中的y，Device侧的Tensor，数据格式支持ND，shape为[n]。 Sswap下数据类型支持FLOAT32。 Cswap下数据类型支持COMPLEX64。 |
| incy | Input | const int64\_t | y相邻元素间的内存地址偏移量（当前约束为1）。 |


#### 返回值说明

返回值相关说明参见返回值。


#### 约束说明

- asdBlasMakeSwapPlan：无。
- asdBlasSswap

  - 输入和输出数据格式、数据类型、shape保持一致。
  - 输入的元素个数n当前覆盖支持[1，6.71e+07]。
  - 算子输入shape为[n]、[n]，输出shape为[n]、[n]。
  - 算子实际计算时，不支持ND高维度运算（不支持维度≥3的运算）。

- asdBlasCswap

  - 输入和输出数据格式、数据类型、shape保持一致。
  - 输入的元素个数n当前覆盖支持[1，6.71e+07]。
  - 算子输入shape为[n]、[n]，输出shape为[n]、[n]。
  - 算子实际计算时，不支持ND高维度运算（不支持维度≥3的运算）。


#### 调用示例

算子的调用示例参见Swap。
