fix: fix CUDA elementwise dynamic block shared memory#172
Merged
Conversation
kilinchange
reviewed
Jun 10, 2026
Collaborator
|
另外 commit message 麻烦修正下: |
7a8cae6 to
e5dd6de
Compare
kilinchange
approved these changes
Jun 11, 2026
Collaborator
|
e5dd6de to
41dd2a8
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


概要
修复 CUDA elementwise backward 在动态选择 block size 后,共享内存大小仍使用旧的模板参数
BLOCK_SIZE计算的问题。问题背景
LaunchKernel已经改为根据 tensor size 通过ChooseBlockSize()动态选择 block size。但部分 elementwise backward launch 逻辑仍然使用模板参数BLOCK_SIZE来计算 dynamic shared memory。这会导致实际 launch 配置和共享内存分配发生分歧:大 tensor 下运行时 block size 可能选择 512,但 shared memory 仍按
BLOCK_SIZE == 256计算。bf16/half broadcast backward 的 block-reduction kernel 内部按blockDim.x访问 shared memory,最终 shared memory 分配不足,出现越界写。修复方案
BLOCK_SIZE模板参数,新增ChooseBlockDims(),统一根据ChooseBlockSize()生成实际 launch block。block.x计算。回归测试
新增测试:
AutogradElementwiseBackwardTest.BFloat16MulBroadcastBackwardLargeBlock覆盖场景:
a:[512, 8192], bf16b:[8192], bf16 broadcastgrad:[512, 8192], bf16.62机器测试结果:

