SetSaturationStrategy
产品支持情况
- Ascend 950PR&950DT系列产品:支持
- Atlas A3系列产品:不支持
- Atlas A2系列产品:不支持
- Atlas 200I/500 A2推理产品:不支持
- Atlas推理系列产品AI Core:不支持
- Atlas推理系列产品Vector Core:不支持
- Atlas训练系列产品:不支持
- Kirin X90处理器系列产品:不支持
- Kirin 9030处理器系列产品:不支持
功能说明
头文件路径为:"basic_api/kernel_operator_common_intf.h"。
设置精度转换接口使用的饱和模式配置策略。该配置主要与Memory矢量计算的Cast和Reg矢量计算的Cast配合使用,两类Cast的配置方式如下:
- 使用单接口饱和配置时,Reg矢量计算Cast通过
CastTrait::satMode配置单接口的饱和或非饱和模式;Memory矢量计算Cast不提供单接口饱和模式参数,其单接口配置为饱和模式。 - 使用全局饱和配置时,两类Cast均使用SetSaturationFlag设置的全局饱和模式。
具体支持的数据类型和转换组合以各Cast接口资料为准,可通过GetSaturationStrategy查询当前使用的配置策略。
函数原型
template <OverrideStrategy strategy>
__aicore__ inline void SetSaturationStrategy()
参数说明
表1 模板参数说明
| 参数名 | 描述 |
|---|---|
| strategy | 饱和模式配置策略,取值如下: • OverrideStrategy::USE_API:使用精度转换接口自身的饱和配置。• OverrideStrategy::USE_GLOBAL:使用SetSaturationFlag设置的全局饱和配置,系统默认采用该策略。模板参数无默认值,调用本接口时必须显式指定。 |
返回值说明
无
约束说明
无
调用示例
以下示例通过Memory矢量计算Cast体现两种配置策略的效果。假设int16_t类型的srcLocal中各元素均为257,两个输出Tensor的数据类型均为uint8_t,count表示参与转换的元素个数。示例关闭全局精度转换饱和模式,使接口自身配置与全局配置产生不同结果。
// 关闭整数精度转换的全局饱和模式。
AscendC::SetSaturationFlag<AscendC::SaturationMode::CAST>(false);
// 使用Memory矢量计算Cast自身的饱和配置,转换结果为255。
AscendC::SetSaturationStrategy<AscendC::OverrideStrategy::USE_API>();
AscendC::PipeBarrier<PIPE_ALL>();
AscendC::Cast(apiDstLocal, srcLocal, AscendC::RoundMode::CAST_NONE, count);
// 使用全局非饱和配置,转换结果为1。
AscendC::SetSaturationStrategy<AscendC::OverrideStrategy::USE_GLOBAL>();
AscendC::PipeBarrier<PIPE_ALL>();
AscendC::Cast(globalDstLocal, srcLocal, AscendC::RoundMode::CAST_NONE, count);