已合并
[bugfix] 将精度校验规则调整为混合精度模式 #285
justsheldon创建于 7月17日
[bugfix] 将精度校验规则调整为混合精度模式 #285
已合并
justsheldon创建于 7月17日
justsheldon成员
7月17日

描述

将syr,syr2,trsv,gbmv,tpsv,getrs_batched,gemv_batched,matinv_batched,gels_batched,getrf_batched,getri_batched算子精度校验规则调整为混合精度模式

关联的Issue

https://gitcode.com/cann/ops-blas/issues/319

测试

image.png

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 justsheldon 的贡献)
atomgit-bot
atomgit-bot
7月17日 评论:

变更摘要

此 PR 将多个 BLAS 测试文件中的精度校验方式统一调整为混合精度模式。原来各测试手动设置 VerifyConfig 的 mode(如 MERE_MARE、COMBINED)、mereThreshold、mareMultiplier、absTol、relTol 等字段,现在全部替换为调用 applyMixedTolerance 辅助函数,由其根据数据类型和参考数据自动推导合适的容差配置。同时移除了一些验证函数中冗余的阈值参数,并在部分测试中补充了数据类型判定和对角线元素处理逻辑。

主要改动

  • 引入 applyMixedTolerance 统一精度配置:在 sgbmv、syr、syr2、trsv、strsv 等测试中,原先手动配置 VerifyConfig 的 mode、mereThreshold、mareMultiplier 等字段的代码被替换为单次 applyMixedTolerance(cfg, ACL_FLOAT, ...) 调用,实现混合精度容差自动推导。
  • 简化验证函数签名:sgetri_batched 的 VerifyInverseMatrices、getrs_batched 的 VerifySolutions 等函数移除了 mereThreshold 和 mareMultiplier 参数,内部改用 applyMixedTolerance 代替原来的手动配置逻辑。
  • gemv_batched 测试增加输出数据类型判定:新增根据 p.dtype 值推导 outDtype 的逻辑(0 → ACL_FLOAT16,3 → ACL_BF16,其他 → ACL_FLOAT),并将该类型传入 applyMixedTolerance。
  • tpsv 测试增强矩阵对角线处理:新增对 ACLBLAS_UNIT 对角类型的支持——当 p.diag == ACLBLAS_UNIT 时对所有元素按比例缩放,否则按矩阵维度动态增大对角线元素(boost = max(5.0, n)),同时将精度校验也迁移到 applyMixedTolerance。
likedislike
不准确?
atomgit-bot
atomgit-bot
7月17日 评论:

代码审查

Now I have all the information needed. Let me write the closing summary.


审查总结

已逐一审查全部 14 个变更文件:

文件 结论
test/gbmv/sgbmv/arch35/sgbmv_test.cpp 无问题
test/gels_batched/sgels_batched/arch35/sgels_batched_test.cpp 无问题
test/gemv_batched/arch35/gemv_batched_test.cpp P2 — 早期返回守卫 p.mereThreshold <= 0.0 语义与新的 applyMixedTolerance 脱节
test/gemv_batched/arch35/gemv_batched_test.csv P3 — 数据生成方式变更(RANDOM_100→RANDOM)与精度模式变更无关
test/getrf_batched/sgetrf_batched/arch35/sgetrf_batched_test.cpp 无问题
test/getri_batched/sgetri_batched/arch35/sgetri_batched_test.cpp 无问题
test/getrs_batched/CMakeLists.txt 无问题(测试目标重命名一致)
test/getrs_batched/arch35/getrs_batched_test.cpp 无问题
test/getrs_batched/arch35/getrs_batched_test.csv 无问题(仅重命名,内容未变)
test/matinv_batched/arch35/matinv_batched_test.cpp P3 — VerifyInverseMatrices 保留已失效的 mereThreshold/mareMultiplier 参数
test/syr/ssyr/arch35/ssyr_test.cpp 无问题
test/syr2/ssyr2/arch35/ssyr2_test.cpp 无问题
test/tpsv/stpsv/arch35/stpsv_test.cpp 无问题(对角调优变更合理)
test/trsv/strsv/arch35/strsv_test.cpp 无问题

发现统计:P2 × 1,P3 × 2,合计 3 个问题。

整体风险判断:低风险。核心精度模式变更(MERE_MARE/COMBINED → MIXED_TOLERANCE)在各文件中执行一致。主要遗留问题是 gemv_batched 中 p.mereThreshold 早期返回的语义不一致,以及 matinv_batched 中已过时的参数签名,均属于可后续清理的维护性问题,不影响当前功能正确性。CSV 数据生成变更需作者确认是否为有意改动。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
不准确?
CANN-robotCANN-robot成员
7月17日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月17日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/ops-blas ✅ 宋恺, xutianze (2/2) ✅ 宋恺, xutianze (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

justsheldon, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
7月17日 将chenbinbin199309,luowen203_gg123,QK_25415,MaskHunter2008,songkai111,xutianze,wangzitao_leo,nino888,zhaoyingchao2,demoauguste,zizhongchen设为评审人
CANN-robotCANN-robot成员
7月17日 将chenbinbin199309,luowen203_gg123,QK_25415,MaskHunter2008,songkai111,xutianze,wangzitao_leo,nino888,zhaoyingchao2,demoauguste,zizhongchen设为审查人
Jjustsheldon成员
7月17日 修改了pull request 的描述
atomgit-bot
atomgit-bot7月17日进行代码检视2
test/gemv_batched/arch35/gemv_batched_test.cpp
已过期
@@ -297,1 +297,4 @@
297297 
298+ aclDataType outDtype = ACL_FLOAT;
299+ if (p.dtype == 0) outDtype = ACL_FLOAT16;
300+ else if (p.dtype == 3) outDtype = ACL_BF16;
atomgit-bot
atomgit-bot7月17日评论:

🟡 Medium Priority

gemv_batched_test.cpp 新增的 dtype→aclDataType 映射(第 298–300 行)遗漏了 dtype=2(HSS,FP16 计算)和 dtype=4(TSS,BF16 计算)两个 case。当前映射:

HSS 使用 FP16 算术,TSS 使用 BF16 算术。applyMixedTolerance 根据 dtype 选择不同的容差默认值:ACL_FLOAT16 的 atol=0.001953125,而 ACL_FLOAT 的 atol=1.53e-5(约 128 倍更严格)。对 HSS/TSS 测试用例使用 FP32 容差会导致合法的 FP16/BF16 计算结果被误判为失败。CSV 中受影响的用例包括 TC_L1_012–014、TC_L1_042(dtype=2)和 TC_L1_044、TC_L1_050–054(dtype=4)。

建议:为 dtype=2 (HSS) 映射 ACL_FLOAT16,为 dtype=4 (TSS) 映射 ACL_BF16:将 if (p.dtype == 0) 改为 if (p.dtype == 0 || p.dtype == 2),将 else if (p.dtype == 3) 改为 else if (p.dtype == 3 || p.dtype == 4)。

改动建议
300
+ aclDataType outDtype = ACL_FLOAT;
301
+ if (p.dtype == 0 || p.dtype == 2) outDtype = ACL_FLOAT16;
300
- else if (p.dtype == 3) outDtype = ACL_BF16;
302
+ else if (p.dtype == 3 || p.dtype == 4) outDtype = ACL_BF16;
应用建议
likedislike
不准确?
System
系统消息系统
7月17日 评论:

changed this line on 71541a56 view diff detail

justsheldon成员
7月17日 评论:

compile

likedislike
CANN-robotCANN-robot成员
7月17日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月17日 评论:

流水线任务触发成功
任务链接 [79143d4cbe5c4797acacb35c038e2175][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
codecheck ❌ FAILED >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
codecheck_codestyle ⚠️ WARNING >>>>>
precommit ⚠️ WARNING >>>>> >>>>>
likedislike
CANN-robotCANN-robot成员
7月17日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月17日 添加了label:ci-pipeline-failed
justsheldon成员
7月17日 评论:

compile

likedislike
Jjustsheldon成员
7月17日 强制推送  1 个提交:71541a56-[bugfix] 将精度校验规则调整为混合精度模式
Jjustsheldon成员
7月17日 解决了最后一个问题
CANN-robotCANN-robot成员
7月17日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月17日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月17日 评论:

流水线任务触发成功
任务链接 [c6f370800d2049d1bc7bb6223f416720][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
codecheck ❌ FAILED >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
codecheck_codestyle ⚠️ WARNING >>>>>
precommit ⚠️ WARNING >>>>> >>>>>
likedislike
CANN-robotCANN-robot成员
7月17日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月17日 添加了label:ci-pipeline-failed
Jjustsheldon成员
7月17日 强制推送  1 个提交:bac0b316-[bugfix] 将精度校验规则调整为混合精度模式
justsheldon成员
7月17日 评论:

compile

likedislike
CANN-robotCANN-robot成员
7月17日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月17日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月17日 评论:

流水线任务触发成功
任务链接 [098b4595cf934ea096ccc084d3ca86bf][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
codecheck_codestyle ⚠️ WARNING >>>>>
precommit ⚠️ WARNING >>>>> >>>>>
PreSmoke_A900_npupool ✅ SUCCESS >>>>>

[2026-07-17 16:14:02]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月17日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月17日 添加了label:ci-pipeline-passed
Jjustsheldon成员
7月17日 修改了pull request 的描述
Jjustsheldon成员
7月17日 修改了pull request 的描述
Jjustsheldon成员
7月17日 修改了pull request 的描述
justsheldon成员
7月20日 评论:

compile

likedislike
CANN-robotCANN-robot成员
7月20日 删除了label:ci-pipeline-passed
CANN-robotCANN-robot成员
7月20日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月20日 评论:

流水线任务触发成功
任务链接 [04b1c4af7bfe442dbb0c61634e59ed8e][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
codecheck_codestyle ⚠️ WARNING >>>>>
precommit ⚠️ WARNING >>>>> >>>>>
PreSmoke_A900_npupool ✅ SUCCESS >>>>>

[2026-07-20 09:23:28]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月20日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月20日 添加了label:ci-pipeline-passed
songkai111成员
7月20日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
7月20日 添加了label:approved
xutianze
xutianze成员
7月20日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月20日 添加了label:lgtm
CANN-robotCANN-robot成员
7月20日 关闭了关联的issue
CANN-robotCANN-robot成员
7月20日 合入了pull request