---
title: Cgemm
description: "| 硬件型号 | 支持情况 |"
url: "https://www.hiascend.com/document/detail/zh/canncommercial/900/API/SiP/SIP_API_0010.html"
---

# Cgemm

#### 产品支持情况

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


#### 功能说明

接口功能：

- asdBlasMakeCgemmPlan：初始化该句柄对应的Cgemm算子配置。
- asdBlasCgemm：矩阵乘法运算中的一种，用于计算两个复数矩阵的乘积。

计算公式

- asdBlasCgemm的计算公式：
  其中，


- 示例：
  输入“inTensorA”为：

```
[   [ 1+i, 1+2i ],
[ 1+3i, 1+4i ]  ]
```


  输入“inTensorB”为：

```
[   [ 2+i, 2+2i ],
[ 2+3i, 2+4i ]  ]
```


  输入“inTensorC”为：

```
[   [ 3+i, 3+2i ],
[ 3+3i, 3+4i ]  ]
```


  输入“transa”为： N，输入“transb”为：T。

  输入“m”为：2，输入“n”为： 2，输入“k”为：2，输入“alpha”为：1+i，“beta”为：2+2i。

  输入“lda”为： 2，输入“ldb”为：2，输入“ldc”为：2。

  调用“Cgemm”算子后，输出“outTensor”为：

```
[   [ -15+19i, -27+19i ],
[ -37+21i, -57+13i ]  ]
```


#### 函数原型

- AspbStatus asdBlasMakeCgemmPlan(asdBlasHandle handle, asdBlasOperation_t transa, asdBlasOperation_t transb, int64_t m,int64_t n, int64_t k, int64_t lda, int64_t ldb, int64_t ldc)
- AspbStatus asdBlasCgemm(asdBlasHandle handle, asdBlasOperation_t transa, asdBlasOperation_t transb, const int64_t m,const int64_t n, const int64_t k, const std::complex<float> *alpha, aclTensor *A,const int64_t lda, aclTensor *B, const int64_t ldb, const std::complex<float> *beta,aclTensor *C, const int64_t ldc)


#### 参数说明

- asdBlasMakeCgemmPlan| 参数名称 | Input/Output | 类型 | 描述 |
| --- | --- | --- | --- |
| handle | Input | asdBlasHandle | Cgemm算子的句柄。 |
| transa | Input | asdBlasOperation\_t | 指定矩阵A是否需要转置。 ASDBLAS\_OP\_N // 不转置 ASDBLAS\_OP\_T // 转置 ASDBLAS\_OP\_C // 共轭转置 |
| transb | Input | asdBlasOperation\_t | 指定矩阵B是否需要转置。 ASDBLAS\_OP\_N // 不转置 ASDBLAS\_OP\_T // 转置 ASDBLAS\_OP\_C // 共轭转置 |
| m | Input | const int64\_t | 矩阵A和C的行数。 |
| n | Input | const int64\_t | 矩阵B和C的列数。 |
| k | Input | const int64\_t | 矩阵A和B的公共维度。 |
| lda | Input | const int64\_t | A左右相邻元素间的内存地址偏移量（当前约束为m）。 |
| ldb | Input | const int64\_t | B左右相邻元素间的内存地址偏移量（当前约束为k）。 |
| ldc | Input | const int64\_t | C左右相邻元素间的内存地址偏移量（当前约束为m）。 |


- asdBlasCgemm| 参数名称 | Input/Output | 类型 | 描述 |
| --- | --- | --- | --- |
| handle | Input | asdBlasHandle | cgemm算子的句柄。 |
| transa | Input | asdBlasOperation\_t | 指定矩阵A是否需要转置。 ASDBLAS\_OP\_N // 不转置 ASDBLAS\_OP\_T // 转置 ASDBLAS\_OP\_C // 共轭转置 |
| transb | Input | asdBlasOperation\_t | 指定矩阵B是否需要转置。 ASDBLAS\_OP\_N // 不转置 ASDBLAS\_OP\_T // 转置 ASDBLAS\_OP\_C // 共轭转置 |
| m | Input | const int64\_t | 矩阵C的行数。 |
| n | Input | const int64\_t | 矩阵C的列数。 |
| k | Input | const int64\_t | 矩阵A和B的公共维度。 |
| alpha | Input | const std::complex<float> \* | 公式中的alpha，复数标量，用于乘以矩阵乘法的结果。 |
| A | Input | aclTensor \* | 公式中的A，列主序，Device侧的Tensor，数据类型仅支持COMPLEX64，数据格式支持ND，shape为[m，k]。 |
| lda | Input | const int64\_t | A左右相邻元素间的内存地址偏移量（当前约束为m）。 |
| B | Input | aclTensor \* | 公式中的B，Device侧的Tensor，数据类型仅支持COMPLEX64，数据格式支持ND，shape为[k，n]。 |
| ldb | Input | const int64\_t | B左右相邻元素间的内存地址偏移量（当前约束为k）。 |
| beta | Input | const std::complex<float> \* | 公式中的beta，复数标量，用于乘以矩阵C。 |
| C | Input/Output | aclTensor \* | 公式中的C，Device侧的Tensor，数据类型仅支持COMPLEX64，数据格式支持ND，shape为[m，n]。 |
| ldc | Input | const int64\_t | C左右相邻元素间的内存地址偏移量（当前约束为m）。 |


#### 返回值说明

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


#### 约束说明

- asdBlasMakeCgemmPlan：无。
- asdBlasCgemm

  - 输入的元素个数m，n，k当前覆盖支持[1，8192]。
  - 算子输入数据为列主序，输入shape为[m，k]、[k，n]、[m，n]，输出shape为[m，n]。

  - 算子实际计算时，不支持ND高维度运算（不支持维度≥3的运算）。


#### 调用示例

算子的调用示例参见Cgemm。
