Skip to content

cuda: quantize_rowwise_i8_convrot_cuda in registers + template scaling - #1

Open
dfriehs wants to merge 1 commit into
leejet:int8_convrotfrom
dfriehs:int8_convrot
Open

cuda: quantize_rowwise_i8_convrot_cuda in registers + template scaling#1
dfriehs wants to merge 1 commit into
leejet:int8_convrotfrom
dfriehs:int8_convrot

Conversation

@dfriehs

@dfriehs dfriehs commented Aug 19, 2026

Copy link
Copy Markdown

Overview

Rewrite of quantize_rowwise_i8_convrot_cuda to work without the large shared memory required to store intermediates, instead does all of the H256 rotation via warp shuffles. This was quite a bit better than the previous kernel in Nsight Compute for me, but I don't expect much of an end-to-end speed up unless on cards with very little shared memory that weren't able to use the rowwise kernel before.

I tested and profiled Krea2 shapes (k=6144/16384, rows=1042/4114) on a RTX 3090, and also built stable-diffusion.cpp with the changes applied and generated a test image.

If you would rather wait with this PR and have me bring it up on mainline after yours is merged just tell me, that's fine by me.

Additional information

rows x k Duration [ms] (old) Duration [ms] (new) Speedup Compute Throughput [%] (old) Compute Throughput [%] (new) Memory Throughput [%] (old) Memory Throughput [%] (new) Registers (old) Registers (new)
1042 x 6144 0.0867 0.0401 2.16x 41.4 51.1 41.4 86.7 28 38
1042 x 16384 0.1729 0.1043 1.66x 51.3 42.7 54.5 89.4 28 51
4114 x 6144 0.3147 0.1481 2.12x 44.5 51.2 45.2 93.4 28 38
4114 x 16384 0.6034 0.3913 1.54x 57.6 44.0 61.4 94.4 28 51

Are there any models to test that require even higher k? The kernel scales via templating to even higher row sizes at the cost of more registers per thread, but I only special cased for up to k=32768. With bigger k you might see more of an improvement as 32768 should have already been over the shared memory limit for a lot of consumer GPUs on the old kernel.

The scales == nullptr special case to store scales after each row looked like dead code so I removed it and asserted instead, all callers seem to pass scales right now. I'm not sure about the asserts for alignment, but the kernel requires that alignment for coalesced 128-bit loads.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, to talk through the shuffles and find further optimizations (Gemma 4 31B, Qwen 3.8 27B). I wrote all code myself.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant