fix OOB in cuda_ctc_decoder (#3754)#4199
Closed
gilbsgilbs wants to merge 1 commit into
Closed
Conversation
`first_matrix__bitonic_topk_kernel` placed its top-k values array with: > int* block_topk_value = > reinterpret_cast<int*>(block_topk_key + sizeof(float) * beam); This is a classic pitfall with pointers arithmetic: `block_topk_key` is a `float*`, so `+ sizeof(float) * beam` advances `sizeof(float) * beam` (= 4*4*beam bytes) instead of `beam` "elements" (= 4*beam bytes). Therefore, the value is written and read 8*beam..12*beam bytes past the end of the kernel's allocated smem. On Hopper/Blackwell, the issue is systematic at the first synchronize after the kernel (probably because of tighter shared-memory bounds on newer architectures?). On Ampere/Ada, the issue only becomes apparent at higher beam sizes because it makes the overrun large enough. Advance by `beam` elements instead of `sizeof(float)*beam` elements. Add a regression test that decodes with beam_size=128, so that the overrun is large enough to fault on any GPU. Fixes pytorch#3754.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4199
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Author
|
Just realized #4198 by @lanarkite99 has the same fix. Closing this one (although I prefer my test case as it is less verbose and reuses the patterns of the other tests). |
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.
first_matrix__bitonic_topk_kernelplaced its top-k values array with:This is a classic pitfall with pointers arithmetic:
block_topk_keyis afloat*, so+ sizeof(float) * beamadvancessizeof(float) * beam(= 4*4*beam bytes) instead ofbeam"elements" (= 4*beam bytes). Therefore, the value is written and read 8*beam..12*beam bytes past the end of the kernel's allocated smem.On Hopper/Blackwell, the issue is systematic at the first synchronize after the kernel (probably because of tighter shared-memory bounds on newer architectures?). On Ampere/Ada, the issue only becomes apparent at higher beam sizes because it makes the overrun large enough.
Advance by
beamelements instead ofsizeof(float)*beamelements. Add a regression test that decodes with beam_size=128, so that the overrun is large enough to fault on any GPU.Fixes #3754.
For future reference:
compute-sanitizer --tool memcheckon the unpatched decoder yields the exact OOB line (at thequeue.store):Also, linters are usually able to catch such pointer arithmetic bugs statically.
PLEASE NOTE THAT THE TORCHAUDIO REPOSITORY IS NO LONGER ACTIVELY MONITORED. You may not get a response. For open discussions, visit https://discuss.pytorch.org/.