Skip to content

[TOPI][CUDA] Fix topk/sort gridDim overflow by remapping grid axes in sort_ir - #19900

Open
cchung100m wants to merge 2 commits into
apache:mainfrom
cchung100m:issue-19549
Open

[TOPI][CUDA] Fix topk/sort gridDim overflow by remapping grid axes in sort_ir#19900
cchung100m wants to merge 2 commits into
apache:mainfrom
cchung100m:issue-19549

Conversation

@cchung100m

Copy link
Copy Markdown
Contributor

Hi Committers,

This PR addresses issue #19549. Any suggestions would be appreciated if you are available.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the GPU merge sort implementation in python/tvm/topi/gpu/sort.py by introducing a separate blockIdx.z thread axis (bz) instead of packing dimensions into blockIdx.y and manually unpacking them using division and modulo. Feedback on this change highlights a potential CUDA overflow issue: since blockIdx.z has a limit of 65,535, sorting arrays larger than ~8.38 million elements will cause kernel launch failures. To resolve this, the reviewer suggested swapping the thread axis mappings so that bz is bound to blockIdx.x (which has a much higher limit) and bx is bound to blockIdx.z, safely extending the maximum supported size to approximately 268 million elements.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/tvm/topi/gpu/sort.py Outdated
@cchung100m cchung100m changed the title [TOPI][CUDA] Fix topk/sort gridDim.y overflow by moving the width-block dim to blockIdx.z [TOPI][CUDA] Fix topk/sort gridDim overflow by remapping grid axes in sort_ir Jun 29, 2026
@cchung100m
cchung100m marked this pull request as ready for review June 29, 2026 15:41
@cchung100m

Copy link
Copy Markdown
Contributor Author

cc @mshr-h @tlopex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant