Fix shared-memory value buffer offset in CUDA CTC top-k kernel - #4213
Conversation
…bitonic_topk_kernel` causes shared memory out-of-bounds write Closes pytorch#4181
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4213
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. |
|
Hi @saisharan0103! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Fixes #4181.
first_matrix__bitonic_topk_kernelcomputedblock_topk_valuefromblock_topk_keywithblock_topk_key + sizeof(float) * beam. Sinceblock_topk_keyis afloat*, that pointer addition was scaled again bysizeof(float), placing the int value buffer16 * beambytes after the key buffer instead of the intended4 * beambytes.The shared-memory allocation only reserves space for
beamfloat keys followed bybeamint values, soqueue.storecould write top-k values beyond the allocated result region and corrupt output or fail on architectures with stricter shared-memory bounds checking.This changes the value buffer pointer to start immediately after the
beamfloat keys while keeping the fix local tofirst_matrix__bitonic_topk_kernel, so the existingsmem_sizecalculation inCTC_prob_first_step_V2remains consistent.Coverage was added to the CUDA CTC decoder test with a deterministic decode path that exercises the first-step top-k kernel and checks stable CUDA decoder output shape/content.
ruff check src/libtorchaudio/cuctc/src/ctc_prefix_decoder_kernel_v2.cu test/torchaudio_unittest/models/decoder/cuda_ctc_decoder_test.pyreports no new findings on the changed files.Ran
pytest -xlocally with no new failures.