Skip to content

asc_get_saturation_flag

产品支持情况

  • Ascend 950PR/Ascend 950DT:支持
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
  • Atlas 200I/500 A2 推理产品:不支持
  • Atlas 推理系列产品AI Core:不支持
  • Atlas 推理系列产品Vector Core:不支持
  • Atlas 训练系列产品:不支持

功能说明

头文件路径为:"c_api/spr/spr.h"

按饱和模式类型读取当前是否开启饱和,并返回布尔类型的结果。

函数原型

C
__aicore__ inline bool asc_get_saturation_flag(asc_saturation_mode saturation_mode)

参数说明

表1 参数说明

参数名输入/输出描述
saturation_mode输入饱和模式类型,取值见asc_saturation_mode

返回值说明

true表示当前该模式下饱和已开启;false表示未开启(对INT为截断;对FLOAT/FLOAT8/CAST为非饱和或截断)。

流水类型

PIPE_S

约束说明

  • 返回值是API语义层结果:true表示该模式下饱和已开启,false表示未开启(对INT为截断;对FLOAT/FLOAT8/CAST为非饱和或截断)。各模式语义差异见asc_set_saturation_flag表1。
  • CAST模式,即使本接口返回true,也需同时满足饱和策略为USE_GLOBAL,CAST饱和配置才会在精度转换中真正生效。详见asc_set_saturation_strategy

调用示例

场景:动态量化场景,溢出需饱和到±MAX而非截断。须先将策略设为USE_GLOBAL并开启CAST饱和。

C++
// SIMD_VF外:asc_get_saturation_flag查询当前CAST饱和开关
bool cast_sat_enabled = asc_get_saturation_flag(asc_saturation_mode::CAST);
asc_override_strategy old_strategy = asc_get_saturation_strategy();

if (!cast_sat_enabled) {
    asc_set_saturation_strategy(asc_override_strategy::USE_GLOBAL);
    asc_set_saturation_flag(asc_saturation_mode::CAST, true);
}

asc_copy_gm2ub_align(act_ub, act_gm, act_burst_bytes);
asc_copy_gm2ub_align(bias_ub, bias_gm, bias_burst_bytes);
asc_sync_notify(PIPE_MTE2, PIPE_V, EVENT_ID0);
asc_sync_wait(PIPE_MTE2, PIPE_V, EVENT_ID0);

// 矢量计算循环内:激活+bias加法后float→int32(全局CAST饱和生效)

// SIMD_VF外:若本段临时开启过CAST饱和,则恢复进入本段前的配置
if (!cast_sat_enabled) {
    asc_set_saturation_flag(asc_saturation_mode::CAST, false);
    asc_set_saturation_strategy(old_strategy);
}

数据搬运与Reg cast模式可参考Cast样例

免责声明:本站内容由 asc-devkit 仓 master 分支自动编译生成,属于持续开发版本,可能存在缺陷,仅供预览与参考。如需稳定及商用资料,请查阅官方 昇腾社区