fix(transformer): use correct stride in Transpose_Kernel shared memory indexing to eliminate bank conflicts#8055
Merged
Conversation
Signed-off-by: xjx <493337577@qq.com>
8501668 to
91c41f5
Compare
Contributor
Author
|
Sorry to bother you, but could you please help me merge this PR file? This solved the problem. If there's anything else I can do, I'll continue. I'm very happy to hear your response. |
1 similar comment
Contributor
Author
|
Sorry to bother you, but could you please help me merge this PR file? This solved the problem. If there's anything else I can do, I'll continue. I'm very happy to hear your response. |
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.
PR Title
fix(transformer): use correct stride in Transpose_Kernel shared memory indexing to eliminate bank conflicts
PR Description
Summary
Fix a shared memory bank conflict bug in
Transpose_Kernelwhere the +1padding declared in the shared memory array was not used in the indexing.
Problem
The shared memory is declared with padding to avoid bank conflicts:
But both write and read indices use
cols_trans(16) as stride instead ofcols_trans + 1(17), making the padding ineffective and causing bankconflicts on column-wise reads during transpose.
Fix
Change indexing stride from
cols_transto(cols_trans + 1)in boththe write and read loops. 2 lines changed.
Benchmark (NVIDIA L20, 1024×1024 float32)
nsys profile (1101 kernel calls):
CUDA Event timing (1000 iterations):
The kernel is already near DRAM bandwidth peak on L20 (~80% utilization),
partially masking the bank conflict overhead. Larger gains are expected on
GPUs with lower memory bandwidth.
Testing
Correctness was verified with a standalone CUDA A/B test (see below).
Both original and fixed kernels produce identical results (PASS, 0 errors).
No pytest unit test is added because
Transpose_Kernelis not exposed toPython via pybind11 — it is called internally by other C++ transformer
functions in
ds_transformer_cuda.cpp. Adding a Python-level test wouldrequire introducing a new pybind binding solely for this kernel, which is
disproportionate for a 2-line bugfix.
Standalone CUDA test script
Build and run: