已合并
【fix】constexpr函数内部调用函数加__callee__支撑编译器修改 #4977
好好说话95号创建于 8月10日
【fix】constexpr函数内部调用函数加__callee__支撑编译器修改 #4977
已合并
好好说话95号创建于 8月10日
好好说话95号
好好说话95号成员
8月10日

描述

此 PR 主要针对编译器Werror更新后对 constexpr 函数的约束变化进行适配:在 constexpr 函数内部调用的内联函数需添加constexpr,使用 __callee__替代部分场景下的 aicore 属性

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 好好说话95号 的贡献)
好好说话95号好好说话95号成员
8月10日 创建了 pull request,commit 978cc4db
atomgit-bot
atomgit-bot
8月10日 评论:

变更摘要

此 PR 主要针对编译器更新后对 constexpr 函数的约束变化进行适配:在 constexpr 函数内部调用的内联函数需添加 __callee__ 属性(替代部分场景下的 __aicore__),同时将一批原本仅标记为 inline 的工具函数补充 constexpr 关键字,使其可在编译期上下文正确求值。改动覆盖数学工具函数、浮点类型转换函数、tuple 基础设施以及 union 位码转换辅助结构。

主要改动

  • Union 构造函数属性从 __aicore__ 改为 __callee__:在 GetScalarBitcodeValueGetScalarBitcodeToHalfkernel_utils_struct_norm_sort.h)以及 get_scalar_bitcode_valueasc_type_conversion_utils.h)等 constexpr 函数内部的 ScalarBitcode union 中,将默认构造函数标注由 __aicore__ 替换为 __callee__,以适配编译器对 constexpr 上下文中被调用函数的属性要求。

  • 补充 constexpr 至数值工具函数CeilCeilAlignmatmul_utils.h)以及 Ceilkernel_utils_ceil_oom_que.h)由 __aicore__ inline 改为 __aicore__ constexpr inline,使其可在编译期参与常量表达式计算。

  • 浮点转换函数添加 constexprasc_type_conversion_utils.hfp32_constructorhif8_to_fp32fp8e5m2_to_fp32fp8e4m3_to_fp32fp4e2m1_to_bfloatfp4e1m2_to_bfloatbf16_to_fp32 及其配套的提取/判断辅助函数(fp8e5m2_is_nanextract_fp8 等)均由 __aicore__ inline 改为 __aicore__ constexpr inline

  • tuple 基础设施补充 constexprtuple_impl.htuple 的默认构造、参数构造以及 tuple_static_assertget 访问函数均添加 constexprtuple.h 中的 get 声明同步更新,使 tuple 可在编译期上下文中使用。

likedislike
不准确?
atomgit-bot
atomgit-bot
8月10日 评论:

代码审查

关闭总结

按优先级统计发现数量:

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 2

整体风险评估:低风险

此 PR 对 6 个文件做了统一修改:为 constexpr 函数内部调用的辅助函数添加 constexpr__callee__ 标记以支撑编译器修改。变更本身是一致的、低风险的——constexpr 是向后兼容的修饰符,添加后运行时行为保持不变。唯一值得关注的问题是两个调试/类型转换函数(extract_fp8e5m2extract_fp8)中存在收窄转换,这会在严格的 constexpr 求值中引发问题;不过由于实际值域安全且是 AscendC 编译器扩展语境,严重度设为 P3。

各文件审查结果:

  • impl/adv_api/detail/matmul/utils/matmul_utils.h — 无问题(Ceil/CeilAlign 添加 constexpr)
  • impl/basic_api/utils/kernel_utils_ceil_oom_que.h — 无问题(Ceil 添加 constexpr)
  • impl/basic_api/utils/kernel_utils_struct_norm_sort.h — 无问题(__aicore____callee__
  • impl/utils/debug/npu_arch_3510/asc_type_conversion_utils.h — 2 个 P3 发现(收窄转换)
  • impl/utils/std/tuple/tuple_impl.h — 无问题(构造函数/get 添加 constexpr)
  • include/utils/std/tuple.h — 无问题(get 声明添加 constexpr)
类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
不准确?
CANN-robotCANN-robot成员
8月10日 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
8月10日 添加了label:cann-cla/yes
此处折叠了379条消息 查看更多
wuzhaolin成员
15 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
15 天前 添加了label:approved
CANN-robot
CANN-robot成员
15 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
好好说话95号好好说话95号成员
15 天前 解决了最后一个问题
CANN-robotCANN-robot成员
15 天前 合入了pull request