Pull Request已成功合入, 合并人@CANN-robot
(感谢 rk 的贡献)变更摘要
本 PR 对 norm 系列算子的 arch35 路径做去硬编码清理:将代码中写死的 32 字节 UB block(及 256 字节向量寄存器)常量,统一替换为平台查询接口(host 侧 Ops::Base::GetUbBlockSize(context)/commonParams.blockSize,kernel 侧 platform::GetUbBlockSize()/Ops::Base::GetVRegSize()),涉及 add_layer_norm_quant、layer_norm_grad、layer_norm_grad_v3、layer_norm_v3、layer_norm_v4 等算子的 tiling 与 kernel 代码,使 UB/VL block 大小随平台自适应。
主要改动
- kernel 侧 block 常量改为平台接口:在
layer_norm_v3_common.h、layer_norm_v4_regbase_common.h、layer_norm_v4_welford.h中将constexpr static int64_t BLOCK_SIZE = 32改为platform::GetUbBlockSize();layer_norm_grad_api.h中BLOCK_SIZE改为Ops::Base::GetUbBlockSize(),VREG_SIZE = 256改为VECTOR_LENGTH = Ops::Base::GetVRegSize()。 - host 侧 tiling 使用
commonParams.blockSize:layer_norm_v3_regbase_no_reduce_tiling.cpp、layer_norm_v3_regbase_norm_not_equal_params_tiling.cpp、layer_norm_v3_regbase_two_pass_perf_tiling.cpp、layer_norm_v3_welford_multi_reduce_tiling.cpp、layer_norm_v4_regbase_two_pass_perf_tiling.cpp删除*_BLOCK_SIZE = 32/*_B32_ALIGN_NUM等常量,改用commonParams.blockSize / sizeof(float)计算 B32 对齐数。 add_layer_norm_quant去硬编码:host 侧add_layer_norm_quant_tiling_arch35.cpp删除BLOCK_SIZE,colsAligned_及blkFp32Nums、constTmpBufSize改用this->blockSize_;kernel 侧add_layer_norm_quant_regbase_helper.h中FLOAT_BLOCK_ELEM = 8改为blockSize_ / sizeof(float)。layer_norm_grad/layer_norm_grad_v3统一 block 获取方式:layer_norm_grad_base.h删除自定义返回 32U 的GetUbBlockSize(),相关调用改用 API 中定义的BLOCK_SIZE;layer_norm_grad_v3_base.h的GetUbBlockSize()改为返回Ops::Base::GetUbBlockSize()。- 对齐函数参数化:
layer_norm_v3_regbase_norm_not_equal_params_tiling.cpp的AlignB32(val)改为AlignB32(val, alignNum),由调用方基于commonParams.blockSize传入对齐数,去除对固定 32B 对齐的假设。


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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| norm | ✅ 任如海, 钱泽洪 (2/2) | ✅ 钱泽洪 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
wangpengbo26, thanks for your pull request. All authors of the commits have signed the CLA. 👍


描述
本 PR 对 norm 系列算子 arch35 路径下的 VL/UB block size 处理进行代码清理,去除散落在各算子中的硬编码常量
32,统一改用平台 API 在运行时获取,消除魔法数字,提升代码可维护性与跨硬件适配能力。改动原因
arch35 路径下 add_layer_norm_quant、layer_norm_grad/grad_v3、layer_norm_v3、layer_norm_v4 等算子的 host tiling 与 kernel 侧多处使用
constexpr ... = 32表示 UB block 字节数(部分派生出B32_ALIGN_NUM = 32/sizeof(float)等常量)。这些魔法数字:BLOCK_SIZE/BLOCK_BYTES/B32_ALIGN_NUM)与 kernel 侧(自定义GetUbBlockSize()、BLOCK_SIZE)重复定义,缺乏单一数据源。改动方法
统一替换为平台 API:
BLOCK_SIZE/BLOCK_BYTES/B32_ALIGN_NUM等常量,改用Ops::Base::GetUbBlockSize(context_)(新增#include "op_common/op_host/util/platform_util.h"),或复用类成员this->blockSize_;constexpr static int64_t BLOCK_SIZE = 32→platform::GetUbBlockSize()(新增#include "../../inc/platform.h");GetUbBlockSize()内联函数,统一使用 AscendC 框架的BLOCK_SIZE。涉及算子:add_layer_norm_quant、layer_norm_grad、layer_norm_grad_v3、layer_norm_v3、layer_norm_v4。
关联的Issue
测试
文档更新
无
类型标签
AI/Agent生成声明