Skip to content

Tell ptxas the largest block size a kernel can be launched with - #9284

Open
abadams wants to merge 3 commits into
mainfrom
abadams/ptx_block_size_metadata
Open

Tell ptxas the largest block size a kernel can be launched with#9284
abadams wants to merge 3 commits into
mainfrom
abadams/ptx_block_size_metadata

Conversation

@abadams

@abadams abadams commented Aug 5, 2026

Copy link
Copy Markdown
Member

Without it ptxas has to assume a block could hold the maximum number of threads, which caps it at 65536/1024 = 64 registers per thread. The kernel in apps/cuda_mat_mul is launched with 16x2 threads and wants 70 registers, so it spilled: 20 bytes of spill stores and 16 of spill loads. Giving ptxas the bound removes the spills, and the app goes from 0.314 ms to 0.233 ms.

I believe this is the underlying reason we found a benefit in manually messing with the number of registers with an env var - code that was backed out in #9260.

Without it ptxas has to assume a block could hold the maximum number of
threads, which caps it at 65536/1024 = 64 registers per thread. The kernel in
apps/cuda_mat_mul is launched with 16x2 threads and wants 70 registers, so it
spilled: 20 bytes of spill stores and 16 of spill loads. Giving ptxas the bound
removes the spills, and the app goes from 0.314 ms to 0.233 ms.

This has to be a function attribute. The equivalent nvvm.annotations entry,
which is how the kernel annotation just above is written, is upgraded to one of
these when a module is read from a file, but that never happens to a module we
built ourselves, and the backend only looks at the attribute.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@mcourteaux mcourteaux 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.

Nice!

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.

3 participants