🐛 Describe the bug
Bug
There is a pointer arithmetic bug in src/libtorchaudio/cuctc/src/ctc_prefix_decoder_kernel_v2.cu (line 298) that causes out-of-bounds shared memory writes.
The bug is latent on most GPU architectures but produces incorrect results or crashes on NVIDIA H100 due to stricter shared memory bounds checking.
Location
float* block_topk_key =
reinterpret_cast<float*>(smem_buf_bytes + smem_result_byte_offset);
int* block_topk_value =
reinterpret_cast<int*>(block_topk_key + sizeof(float) * beam); // ← BUG
impact
- A10 / A100: The out-of-bounds write silently lands on physically present but unallocated shared memory regions. Tests pass, but results may be subtly incorrect.
- H100: Stricter shared memory bounds checking causes data corruption, leading to incorrect CTC decoding results or kernel failures.
Root Cause
block_topk_key is a float*. Pointer arithmetic operates in units of the pointed-to type, not bytes. Adding sizeof(float) * beam to a float* advances by sizeof(float) × sizeof(float) × beam = 16 × beam bytes, instead of the intended sizeof(float) × beam = 4 × beam bytes.
Solution
int* block_topk_value =
reinterpret_cast<int*>(block_topk_key + beam);
Versions
main
🐛 Describe the bug
Bug
There is a pointer arithmetic bug in
src/libtorchaudio/cuctc/src/ctc_prefix_decoder_kernel_v2.cu(line 298) that causes out-of-bounds shared memory writes.The bug is latent on most GPU architectures but produces incorrect results or crashes on NVIDIA H100 due to stricter shared memory bounds checking.
Location
impact
Root Cause
block_topk_key is a float*. Pointer arithmetic operates in units of the pointed-to type, not bytes. Adding sizeof(float) * beam to a float* advances by sizeof(float) × sizeof(float) × beam = 16 × beam bytes, instead of the intended sizeof(float) × beam = 4 × beam bytes.
Solution
Versions
main