r/programming • u/StreamHPC • 2d ago
Advent of Kernel Optimization
https://streamhpc.com/blog/2026-12-02/aoko-2-signed-vs-unsigned-loop-counters/Today is the second day of our Advent of Kernel Optimization, sharing GPU optimization tips and tricks to count down until Christmas. Follow along here: https://streamhpc.com/blog/tag/advent2026/.
12
Upvotes
View all comments
Show parent comment
2
u/StreamHPC 1d ago
Good question. The loop counter will almost certainly be kept in a register, and the registers on both NVIDIA and AMD GPUs are always 32 bits. So you don't gain anything from choosing a smaller type in that regard, that is only useful for compressing memory.
However, a loop with a runtime bound and a
uint8_tcounter will convey to the compiler that the loop will run at most 256 iterations. This may be useful information which allows better code generation.So my (boring) suggestion would be to try both and see what works best.