---
title: SetBias
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendcopapi/atlasascendc_api_07_0635.html
sourcePath: /source/zh/canncommercial/900/API/ascendcopapi/atlasascendc_api_07_0635.html
indexId: 2bd1fafd9edc40066a20f46e89b6758052553a11b276b0fb5b57b85e2034d77d76
---
# SetBias

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |
| Atlas 推理系列产品 AI Core | √ |
| Atlas 推理系列产品 Vector Core | x |
| Atlas 训练系列产品 | x |


#### 功能说明

设置矩阵乘的Bias。


#### 函数原型

```
__aicore__ inline void SetBias(const GlobalTensor<BiasT>& biasGlobal)
```


```
__aicore__ inline void SetBias(const LocalTensor<BiasT>& inputBias)
```


#### 参数说明


**表1 参数说明**

| 参数名 | 输入/输出 | 描述 |
| --- | --- | --- |
| biasGlobal | 输入 | Bias矩阵。类型为GlobalTensor。 Atlas 350 加速卡，支持的数据类型为:half/bfloat16\_t/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas A3 训练系列产品 / Atlas A3 推理系列产品 ，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas 推理系列产品 AI Core，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas A2 训练系列产品 / Atlas A2 推理系列产品 ，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas 200I/500 A2 推理产品 ，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t A矩阵、B矩阵、Bias支持的数据类型组合可参考Matmul输入输出数据类型的组合说明；在MxMatmul场景，A矩阵、B矩阵、Bias支持的数据类型组合可参考MatmulTypeWithScale参数说明(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas\_ascendc\_10\_10029.html\#ZH\-CN\_TOPIC\_0000002562429869\_\_zh\-cn\_topic\_0000002270097206\_table14759942142014)。 |
| inputBias | 输入 | Bias矩阵。类型为LocalTensor，支持的TPosition为TSCM/VECOUT。 Atlas 350 加速卡，支持的数据类型为:half/bfloat16\_t/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas A3 训练系列产品 / Atlas A3 推理系列产品 ，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas 推理系列产品 AI Core，支持的数据类型为：half/float/int32\_t Atlas A2 训练系列产品 / Atlas A2 推理系列产品 ，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t Atlas 200I/500 A2 推理产品 ，支持的数据类型为：half/float/int32\_t，其中仅在A、B的数据类型为int8\_t时，Bias的数据类型可以设置为int32\_t A矩阵、B矩阵、Bias支持的数据类型组合可参考Matmul输入输出数据类型的组合说明；在MxMatmul场景，A矩阵、B矩阵、Bias支持的数据类型组合可参考MatmulTypeWithScale参数说明(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas\_ascendc\_10\_10029.html\#ZH\-CN\_TOPIC\_0000002562429869\_\_zh\-cn\_topic\_0000002270097206\_table14759942142014) 。 |


#### 返回值说明

无


#### 约束说明

- 在Matmul Tiling计算中，必须配置TCubeTiling结构中的  isBias
参数为1，即使能Bias后，才能调用本接口设置Bias矩阵。
- 传入的Bias地址空间大小需要保证不小于singleN。
- 对于Atlas 350 加速卡，Bias矩阵的内存逻辑位置为TSCM且数据类型为float或int32_t时，Bias矩阵的LocalTensor空间必须64字节对齐。


#### 调用示例

```
REGIST_MATMUL_OBJ(&pipe, GetSysWorkSpacePtr(), mm, &tiling);
mm.SetTensorA(gm_a);
mm.SetTensorB(gm_b);
if (tiling.isBias) {
    mm.SetBias(gmBias);  // 设置Bias
}
mm.IterateAll(gm_c);
mm.End();
```
