W4A16 matmul
Decode multiplies a few activation rows by every weight matrix in the model, so it is limited by how fast the weights stream from DRAM. Storing weights as 4-bit integers (8 per int32, fp16 scale and zero per group of 128) cuts those bytes ~3.6x. The kernel dequantizes in registers and feeds tensor cores. For decode, split-K spreads one small matmul over the whole GPU. A CUDA C++ version of the decode case is compared side by side.
Triton kernel
kernels/w4a16.py: _w4a16_kernel (67 lines, click to show)
@triton.jit
def _w4a16_kernel(
a_ptr, q_ptr, s_ptr, z_ptr, bias_ptr, c_ptr,
M, N, K,
stride_am, stride_ak, stride_qk, stride_qn, stride_sg, stride_sn, stride_cm, stride_cn,
M_KEY, # only used as an autotune key (M rounded up to a power of 2)
GROUP_SIZE: tl.constexpr,
HAS_BIAS: tl.constexpr,
BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,
SPLIT_K: tl.constexpr, GROUP_M: tl.constexpr,
):
# Grouped tile order so neighbouring programs share A rows / B columns in L2 (prefill).
pid = tl.program_id(0)
pid_k = tl.program_id(1)
num_pid_m = tl.cdiv(M, BLOCK_M)
num_pid_n = tl.cdiv(N, BLOCK_N)
group_id = pid // (GROUP_M * num_pid_n)
first_m = group_id * GROUP_M
group_rows = min(num_pid_m - first_m, GROUP_M)
pid_m = first_m + (pid % group_rows)
pid_n = (pid % (GROUP_M * num_pid_n)) // group_rows
offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)
offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)
mask_m = offs_m < M
mask_n = offs_n < N
offs_pk = tl.arange(0, BLOCK_K // 8) # packed rows in one K tile
shifts = (tl.arange(0, 8) * 4)[None, :, None]
# This program's K range, aligned to BLOCK_K (BLOCK_K divides GROUP_SIZE divides K).
k_tiles = K // BLOCK_K
tiles_per_split = tl.cdiv(k_tiles, SPLIT_K)
t_start = pid_k * tiles_per_split
t_end = min(t_start + tiles_per_split, k_tiles)
acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
for t in range(t_start, t_end):
k0 = t * BLOCK_K
offs_k = k0 + tl.arange(0, BLOCK_K)
a = tl.load(
a_ptr + offs_m[:, None] * stride_am + offs_k[None, :] * stride_ak,
mask=mask_m[:, None], other=0.0,
)
packed = tl.load(
q_ptr + (k0 // 8 + offs_pk)[:, None] * stride_qk + offs_n[None, :] * stride_qn,
mask=mask_n[None, :], other=0,
)
# [BK/8, BN] int32 -> [BK/8, 8, BN] nibbles -> [BK, BN], row k = 8 * packed_row + i
q = (packed[:, None, :] >> shifts) & 0xF
q = tl.reshape(q, (BLOCK_K, BLOCK_N))
g = k0 // GROUP_SIZE
s = tl.load(s_ptr + g * stride_sg + offs_n * stride_sn, mask=mask_n, other=0.0)
z = tl.load(z_ptr + g * stride_sg + offs_n * stride_sn, mask=mask_n, other=0.0)
b = (q.to(tl.float16) - z[None, :]) * s[None, :]
acc = tl.dot(a, b, acc)
if HAS_BIAS:
if pid_k == 0:
bias = tl.load(bias_ptr + offs_n, mask=mask_n, other=0.0)
acc += bias.to(tl.float32)[None, :]
c_ptrs = c_ptr + offs_m[:, None] * stride_cm + offs_n[None, :] * stride_cn
c_mask = mask_m[:, None] & mask_n[None, :]
if SPLIT_K == 1:
tl.store(c_ptrs, acc.to(c_ptr.dtype.element_ty), mask=c_mask)
else:
tl.atomic_add(c_ptrs, acc, mask=c_mask, sem="relaxed")CUDA C++ decode kernel (inner loop)
kernels/cuda/w4a16_decode.cu: w4a16_decode_kernel (70 lines, click to show)
__global__ void __launch_bounds__(kThreads) w4a16_decode_kernel(
const half* __restrict__ x, const int* __restrict__ qweight, const half* __restrict__ scales,
const half* __restrict__ zeros, const half* __restrict__ bias, half* __restrict__ out_f16,
float* __restrict__ out_f32, int M, int N, int K, int group_size, int k_per_split) {
__shared__ float xs[MT][kTileK];
__shared__ float xsum8[MT][kTileK / 8]; // sum of each run of 8 activations (one packed row)
__shared__ float red[MT][kColsPerBlock];
const int lane = threadIdx.x % 32;
const int warp = threadIdx.x / 32;
const int n0 = blockIdx.x * kColsPerBlock + lane * kColsPerThread;
const bool cols_ok = n0 < N; // host checks N % 4 == 0, so a lane's 4 columns are all in or out
const int k_begin = blockIdx.y * k_per_split;
const int k_end = min(k_begin + k_per_split, K);
for (int i = threadIdx.x; i < MT * kColsPerBlock; i += kThreads) (&red[0][0])[i] = 0.f;
float acc[MT][kColsPerThread];
#pragma unroll
for (int m = 0; m < MT; ++m)
#pragma unroll
for (int c = 0; c < kColsPerThread; ++c) acc[m][c] = 0.f;
for (int kt = k_begin; kt < k_end; kt += kTileK) {
const int klen = min(kTileK, k_end - kt); // multiple of 8
__syncthreads();
for (int i = threadIdx.x; i < MT * kTileK; i += kThreads) {
const int m = i / kTileK, k = i % kTileK;
xs[m][k] = (m < M && k < klen) ? __half2float(x[(size_t)m * K + kt + k]) : 0.f;
}
__syncthreads();
for (int i = threadIdx.x; i < MT * (kTileK / 8); i += kThreads) {
const int m = i / (kTileK / 8), r = i % (kTileK / 8);
float sum = 0.f;
#pragma unroll
for (int j = 0; j < 8; ++j) sum += xs[m][r * 8 + j];
xsum8[m][r] = sum;
}
__syncthreads();
if (!cols_ok) continue;
for (int r = warp; r < klen / 8; r += kWarps) {
const int krow = kt / 8 + r;
const int4 q = *reinterpret_cast<const int4*>(qweight + (size_t)krow * N + n0);
const int g = (kt + r * 8) / group_size;
const uint2 s2 = *reinterpret_cast<const uint2*>(scales + (size_t)g * N + n0);
const uint2 z2 = *reinterpret_cast<const uint2*>(zeros + (size_t)g * N + n0);
const half* sh = reinterpret_cast<const half*>(&s2);
const half* zh = reinterpret_cast<const half*>(&z2);
const int qs[kColsPerThread] = {q.x, q.y, q.z, q.w};
#pragma unroll
for (int c = 0; c < kColsPerThread; ++c) {
const float s = __half2float(sh[c]);
const float z = __half2float(zh[c]);
float xq[MT];
#pragma unroll
for (int m = 0; m < MT; ++m) xq[m] = 0.f;
#pragma unroll
for (int i = 0; i < 8; ++i) {
const float qv = static_cast<float>((qs[c] >> (4 * i)) & 0xF);
#pragma unroll
for (int m = 0; m < MT; ++m) xq[m] += qv * xs[m][r * 8 + i];
}
#pragma unroll
for (int m = 0; m < MT; ++m) acc[m][c] += s * (xq[m] - z * xsum8[m][r]);
}
}
}
Triton or CUDA?
Both kernels compute the same thing on the same weight format (int4 packed 8 per int32, fp16 scale and zero per group of 128), use the same factored dequantization, and pass the same tests. Numbers are from the final L4 runs (CUDA-graph timing, median of 3 sweeps); H100 numbers are on the site.
Speed. At batch 1 the Triton GEMV path reaches a median of 77% of peak bandwidth across six layer shapes, against 70% for the CUDA kernel (82% vs 74% on Qwen's gate_up layer). That was not true in the first round: the CUDA kernel led at batch 1 until both kernels got the factored dequantization and the Triton path picker stopped timing in eager mode (see DECISIONS). At batch 16 the gap is large: Triton holds 62% while CUDA drops to 29%. The CUDA kernel does its multiply-adds on CUDA cores, so 16 rows mean 16 times the arithmetic per weight and it becomes compute-bound; Triton switches to its tl.dot path on tensor cores. In the full model at batch 1: 118.2 tokens/s with Triton, 114.4 with the CUDA decode kernel. On the H100 the ranking is the same and the gap wider (batch 1: 25% vs 17% of peak, median; Qwen2.5 decode 398 vs 339 tokens/s): there, unpacking work rather than memory limits both kernels, and the CUDA kernel does more of it per byte.
Code. The Triton GEMM kernel is 58 lines and the batch-1 GEMV kernel 48. The CUDA kernel is 85 lines plus a 52-line host launcher with manual shape checks, alignment rules (N must be a multiple of 4 for 16-byte loads) and template dispatch on the batch size (scripts/loc.py). Triton's autotuner picked tile sizes, warps, pipeline depth, split-K and the dequant variant for every shape; for CUDA we tuned only split-K and hand-picked the rest. The Triton GEMM also covers prefill (batch 2048), which the CUDA kernel does not do at all.
When each is worth it. - Triton first: one kernel family for decode and prefill, autotuning for free, tensor cores without writing MMA code, and quick to iterate on. Here it ended up faster at every shape we measured. - CUDA C++ when you need control Triton does not give you: exact register tiling, vector widths, warp-level tricks, or a layout Triton cannot express. Our CUDA kernel would need a hand-written tensor-core (MMA) path to compete at batch 16, which is much more code. The CUDA version was still worth writing: an independent second implementation to check the numbers against, and for a while the faster one at batch 1, which is what pushed the Triton kernel to improve.
L4
| shape | triton (us) | cuda (us) | fp16 (us) | torchao (us) | compile (us) | naive (us) | speedup vs fp16 | triton % peak bw |
|---|---|---|---|---|---|---|---|---|
| layer=qwen_qkv, M=1 | 10.3 | 11.9 | 26.4 | 12.7 | 36.3 | 196.1 | 2.55x | 54% |
| layer=qwen_qkv, M=2 | 13.6 | 13.3 | 26.5 | 13.7 | 38.7 | 200.9 | 1.95x | 41% |
| layer=qwen_qkv, M=4 | 13.8 | 16.0 | 26.6 | 14.0 | 39.1 | 201.3 | 1.93x | 41% |
| layer=qwen_qkv, M=8 | 14.2 | 21.7 | 26.9 | 15.3 | 39.6 | 201.4 | 1.89x | 41% |
| layer=qwen_qkv, M=16 | 14.8 | 34.0 | 27.4 | 21.4 | 40.9 | 202.6 | 1.85x | 40% |
| layer=qwen_o, M=1 | 8.9 | 10.1 | 21.3 | 10.1 | 8.5 | 138.1 | 2.39x | 47% |
| layer=qwen_o, M=2 | 11.3 | 11.3 | 20.5 | 11.3 | 24.1 | 144.7 | 1.82x | 37% |
| layer=qwen_o, M=4 | 11.4 | 13.7 | 20.6 | 11.5 | 27.2 | 145.0 | 1.82x | 38% |
| layer=qwen_o, M=8 | 11.7 | 18.7 | 20.8 | 12.1 | 25.9 | 145.6 | 1.78x | 37% |
| layer=qwen_o, M=16 | 13.0 | 29.3 | 21.2 | 16.9 | 25.9 | 150.4 | 1.64x | 35% |
| layer=qwen_gate_up, M=1 | 59.9 | 65.7 | 207.8 | 78.5 | 82.6 | 4662.9 | 3.47x | 82% |
| layer=qwen_gate_up, M=2 | 73.7 | 69.1 | 221.2 | 80.2 | 461.6 | 4698.7 | 3.00x | 66% |
| layer=qwen_gate_up, M=4 | 70.8 | 77.1 | 222.2 | 81.0 | 464.9 | 4700.5 | 3.14x | 70% |
| layer=qwen_gate_up, M=8 | 74.3 | 110.6 | 223.7 | 91.7 | 465.6 | 4699.6 | 3.01x | 67% |
| layer=qwen_gate_up, M=16 | 79.2 | 164.9 | 226.5 | 141.5 | 443.3 | 4718.6 | 2.86x | 64% |
| layer=qwen_down, M=1 | 33.6 | 37.6 | 102.8 | 34.1 | 44.3 | 2126.6 | 3.06x | 73% |
| layer=qwen_down, M=2 | 39.3 | 39.9 | 109.1 | 34.7 | 158.8 | 2136.2 | 2.77x | 62% |
| layer=qwen_down, M=4 | 39.9 | 45.5 | 109.4 | 35.8 | 195.9 | 2151.0 | 2.74x | 62% |
| layer=qwen_down, M=8 | 40.8 | 61.1 | 109.8 | 41.2 | 199.4 | 2150.1 | 2.69x | 61% |
| layer=qwen_down, M=16 | 42.1 | 95.7 | 111.2 | 81.9 | 167.4 | 2141.2 | 2.64x | 61% |
| layer=8b_up, M=1 | 123.9 | 131.7 | 429.9 | 123.3 | 144.2 | 10081.9 | 3.47x | 84% |
| layer=8b_up, M=2 | 149.3 | 136.1 | 459.4 | 124.0 | 1156.4 | 10203.1 | 3.08x | 70% |
| layer=8b_up, M=4 | 154.0 | 158.5 | 454.3 | 125.8 | 1139.7 | 10202.6 | 2.95x | 68% |
| layer=8b_up, M=8 | 156.3 | 207.1 | 458.0 | 161.2 | 1143.5 | 10209.0 | 2.93x | 67% |
| layer=8b_up, M=16 | 160.9 | 313.9 | 464.4 | 282.4 | 1152.5 | 10214.7 | 2.89x | 66% |
| layer=8b_down, M=1 | 126.5 | 131.1 | 427.5 | 129.6 | 141.1 | 10111.7 | 3.38x | 82% |
| layer=8b_down, M=2 | 142.6 | 136.7 | 450.8 | 128.3 | 1125.1 | 10216.9 | 3.16x | 73% |
| layer=8b_down, M=4 | 151.7 | 157.6 | 451.3 | 135.4 | 1130.1 | 10220.0 | 2.98x | 69% |
| layer=8b_down, M=8 | 155.4 | 215.2 | 452.8 | 165.5 | 1135.9 | 10219.8 | 2.91x | 68% |
| layer=8b_down, M=16 | 162.0 | 329.5 | 455.8 | 291.3 | 1144.5 | 10222.2 | 2.81x | 65% |
| layer=qwen_qkv, M=128 | 37.7 | - | 35.7 | 110.5 | 54.1 | 217.7 | 0.95x | 23% |
| layer=qwen_qkv, M=512 | 103.4 | - | 93.2 | 422.5 | 112.1 | 275.1 | 0.90x | 17% |
| layer=qwen_qkv, M=2048 | 357.5 | - | 314.9 | 1661.8 | 321.1 | 486.3 | 0.88x | 15% |
| layer=qwen_o, M=128 | 27.5 | - | 26.9 | 85.6 | 37.9 | 159.3 | 0.98x | 25% |
| layer=qwen_o, M=512 | 70.9 | - | 59.0 | 326.8 | 67.3 | 183.7 | 0.83x | 21% |
| layer=qwen_o, M=2048 | 242.5 | - | 243.2 | 1277.8 | 244.1 | 357.3 | 1.00x | 19% |
| layer=qwen_gate_up, M=128 | 223.8 | - | 300.4 | 895.5 | 569.3 | 4770.6 | 1.34x | 29% |
| layer=qwen_gate_up, M=512 | 638.4 | - | 617.3 | 3516.4 | 917.6 | 4913.3 | 0.97x | 18% |
| layer=qwen_gate_up, M=2048 | 2485.1 | - | 2083.7 | 14076.1 | 2372.4 | 6131.3 | 0.84x | 13% |
| layer=qwen_down, M=128 | 144.2 | - | 146.8 | 486.5 | 213.2 | 2177.1 | 1.02x | 23% |
| layer=qwen_down, M=512 | 389.6 | - | 316.5 | 1891.2 | 410.9 | 2308.8 | 0.81x | 15% |
| layer=qwen_down, M=2048 | 1320.1 | - | 1284.1 | 7906.2 | 1435.3 | 2996.3 | 0.97x | 13% |
| layer=8b_up, M=128 | 356.4 | - | 531.4 | 1806.9 | 1176.9 | 10299.1 | 1.49x | 34% |
| layer=8b_up, M=512 | 1272.5 | - | 1337.7 | 7028.9 | 2045.1 | 10552.3 | 1.05x | 13% |
| layer=8b_up, M=2048 | 5025.5 | - | 4472.1 | 28082.2 | 5152.9 | 12973.1 | 0.89x | 7% |
| layer=8b_down, M=128 | 541.5 | - | 567.8 | 1878.4 | 1264.8 | 10319.4 | 1.05x | 22% |
| layer=8b_down, M=512 | 1714.5 | - | 1290.0 | 7467.3 | 2015.2 | 10581.6 | 0.75x | 10% |
| layer=8b_down, M=2048 | 5348.8 | - | 4674.9 | 29777.9 | 5393.9 | 13124.1 | 0.87x | 7% |
Profile on L4
| launch | time (ns) | DRAM % peak | SM % peak | occupancy % | regs/thread |
|---|---|---|---|---|---|
| w4a16_triton_gate_up_M1 | 59904 | 92.74 | 18.31 | 19.91 | 61 |
| w4a16_cuda_gate_up_M1 | 60576 | 90.84 | 32.98 | 78.28 | 48 |
| w4a16_cuda_gate_up_M1 | 2400 | 11.90 | 0.28 | 7.96 | 30 |
| w4a16_triton_gate_up_M16 | 61568 | 90.30 | 42.21 | 39.49 | 71 |
| w4a16_cuda_gate_up_M16 | 129056 | 43.74 | 45.40 | 19.80 | 152 |
| w4a16_triton_down_M1 | 31040 | 88.83 | 20.06 | 26.66 | 64 |
| w4a16_triton_down_M1 | 2112 | 1.99 | 0.07 | 8.27 | 30 |
| w4a16_cuda_down_M1 | 33888 | 80.55 | 28.63 | 27.38 | 48 |
| w4a16_cuda_down_M1 | 2176 | 1.96 | 0.06 | 8.27 | 30 |
| w4a16_triton_down_M16 | 34624 | 83.78 | 36.86 | 26.75 | 71 |
| w4a16_triton_down_M16 | 2432 | 15.68 | 0.34 | 8.08 | 30 |
| w4a16_cuda_down_M16 | 80992 | 36.44 | 36.69 | 13.75 | 152 |
| w4a16_cuda_down_M16 | 2624 | 14.48 | 0.31 | 8.07 | 30 |
Power on L4
Sustained decode matmuls hold the card at its power cap (reason 0x4 = software power cap) and the SM clock drops well below its maximum. That is why sustained numbers sit below single-launch Nsight Compute numbers, and why cutting ALU work in the dequantization (the factored GEMV) raised bandwidth.
| kernel (gate_up, M=1) | us per call | SM clock (MHz) | power (W) | throttle reasons |
|---|---|---|---|---|
| triton | 60.3 | 1328 | 72 / 72 | 0x0000000000000004 |
| cuda | 66.6 | 1200 | 72 / 72 | 0x0000000000000004 |
| fp16 | 209.0 | 1328 | 72 / 72 | 0x0000000000000004 |
H100
| shape | triton (us) | cuda (us) | fp16 (us) | torchao (us) | compile (us) | naive (us) | speedup vs fp16 | triton % peak bw |
|---|---|---|---|---|---|---|---|---|
| layer=qwen_qkv, M=1 | 6.6 | 8.4 | 5.4 | 7.4 | 5.0 | 65.6 | 0.82x | 8% |
| layer=qwen_qkv, M=2 | 7.3 | 9.5 | 5.5 | 8.1 | 10.5 | 65.6 | 0.75x | 7% |
| layer=qwen_qkv, M=4 | 7.4 | 11.7 | 5.5 | 8.4 | 10.6 | 65.6 | 0.74x | 7% |
| layer=qwen_qkv, M=8 | 7.4 | 16.6 | 5.5 | 9.2 | 10.5 | 65.7 | 0.74x | 7% |
| layer=qwen_qkv, M=16 | 7.6 | 26.8 | 5.6 | 11.7 | 10.6 | 65.4 | 0.73x | 7% |
| layer=qwen_o, M=1 | 6.6 | 8.2 | 5.2 | 7.3 | 5.0 | 54.0 | 0.78x | 6% |
| layer=qwen_o, M=2 | 7.1 | 9.4 | 5.2 | 8.0 | 9.4 | 54.2 | 0.73x | 5% |
| layer=qwen_o, M=4 | 7.1 | 11.6 | 5.2 | 8.3 | 9.4 | 54.2 | 0.73x | 5% |
| layer=qwen_o, M=8 | 7.2 | 16.6 | 5.2 | 9.1 | 9.4 | 54.2 | 0.72x | 5% |
| layer=qwen_o, M=16 | 7.3 | 26.7 | 5.2 | 11.7 | 9.4 | 54.3 | 0.72x | 6% |
| layer=qwen_gate_up, M=1 | 12.7 | 18.6 | 23.0 | 16.3 | 21.2 | 534.3 | 1.80x | 34% |
| layer=qwen_gate_up, M=2 | 19.8 | 22.8 | 23.1 | 17.4 | 61.6 | 534.5 | 1.17x | 22% |
| layer=qwen_gate_up, M=4 | 20.0 | 29.2 | 23.3 | 20.7 | 61.6 | 533.3 | 1.16x | 22% |
| layer=qwen_gate_up, M=8 | 20.3 | 49.5 | 23.5 | 30.1 | 61.6 | 534.5 | 1.16x | 22% |
| layer=qwen_gate_up, M=16 | 20.4 | 75.8 | 23.8 | 46.6 | 61.7 | 534.4 | 1.16x | 22% |
| layer=qwen_down, M=1 | 14.7 | 21.4 | 14.4 | 12.4 | 10.8 | 279.8 | 0.98x | 15% |
| layer=qwen_down, M=2 | 14.7 | 23.1 | 14.5 | 13.4 | 43.2 | 279.2 | 0.99x | 15% |
| layer=qwen_down, M=4 | 14.7 | 26.5 | 14.5 | 14.3 | 43.2 | 279.2 | 0.99x | 15% |
| layer=qwen_down, M=8 | 14.7 | 35.3 | 14.7 | 19.0 | 43.3 | 279.7 | 1.00x | 15% |
| layer=qwen_down, M=16 | 14.8 | 54.1 | 14.9 | 28.0 | 43.6 | 279.0 | 1.00x | 15% |
| layer=8b_up, M=1 | 20.8 | 30.4 | 42.4 | 20.3 | 33.5 | 1098.4 | 2.04x | 45% |
| layer=8b_up, M=2 | 32.0 | 36.4 | 42.4 | 21.1 | 125.7 | 1098.3 | 1.33x | 29% |
| layer=8b_up, M=4 | 32.1 | 48.6 | 42.5 | 27.0 | 125.7 | 1098.2 | 1.33x | 29% |
| layer=8b_up, M=8 | 32.4 | 73.3 | 42.6 | 42.5 | 125.9 | 1098.5 | 1.32x | 29% |
| layer=8b_up, M=16 | 33.0 | 135.9 | 43.0 | 69.7 | 126.1 | 1099.1 | 1.31x | 29% |
| layer=8b_down, M=1 | 24.6 | 35.6 | 44.5 | 20.8 | 31.3 | 1120.1 | 1.81x | 38% |
| layer=8b_down, M=2 | 34.6 | 40.2 | 43.1 | 21.5 | 129.7 | 1119.8 | 1.25x | 27% |
| layer=8b_down, M=4 | 34.6 | 48.1 | 43.2 | 27.6 | 129.6 | 1120.1 | 1.25x | 27% |
| layer=8b_down, M=8 | 34.6 | 68.1 | 43.5 | 42.9 | 129.7 | 1120.2 | 1.26x | 27% |
| layer=8b_down, M=16 | 35.0 | 119.8 | 44.1 | 69.9 | 129.6 | 1120.5 | 1.26x | 27% |
| layer=qwen_qkv, M=128 | 17.2 | - | 5.9 | 44.6 | 12.4 | 66.4 | 0.34x | 5% |
| layer=qwen_qkv, M=512 | 19.9 | - | 8.1 | 154.9 | 13.9 | 69.9 | 0.41x | 8% |
| layer=qwen_qkv, M=2048 | 43.4 | - | 22.0 | 591.5 | 26.2 | 81.6 | 0.51x | 11% |
| layer=qwen_o, M=128 | 17.1 | - | 5.7 | 37.6 | 10.1 | 54.7 | 0.33x | 4% |
| layer=qwen_o, M=512 | 19.7 | - | 7.3 | 119.1 | 11.8 | 57.1 | 0.37x | 7% |
| layer=qwen_o, M=2048 | 42.8 | - | 17.1 | 452.3 | 20.6 | 65.5 | 0.40x | 10% |
| layer=qwen_gate_up, M=128 | 42.9 | - | 25.2 | 324.2 | 64.2 | 535.5 | 0.59x | 14% |
| layer=qwen_gate_up, M=512 | 109.7 | - | 50.8 | 1264.2 | 89.4 | 554.3 | 0.46x | 9% |
| layer=qwen_gate_up, M=2048 | 345.8 | - | 177.0 | 5034.3 | 219.6 | 667.8 | 0.51x | 8% |
| layer=qwen_down, M=128 | 87.7 | - | 16.7 | 134.9 | 47.8 | 283.0 | 0.19x | 3% |
| layer=qwen_down, M=512 | 99.9 | - | 31.2 | 505.6 | 60.8 | 296.1 | 0.31x | 5% |
| layer=qwen_down, M=2048 | 232.9 | - | 83.0 | 2002.5 | 116.6 | 340.6 | 0.36x | 6% |
| layer=8b_up, M=128 | 65.4 | - | 45.3 | 501.3 | 124.4 | 1098.6 | 0.69x | 16% |
| layer=8b_up, M=512 | 216.8 | - | 105.4 | 1994.7 | 172.9 | 1137.7 | 0.49x | 7% |
| layer=8b_up, M=2048 | 743.7 | - | 346.5 | 7909.4 | 436.5 | 1360.7 | 0.47x | 4% |
| layer=8b_down, M=128 | 140.4 | - | 51.4 | 523.7 | 134.7 | 1122.4 | 0.37x | 8% |
| layer=8b_down, M=512 | 225.3 | - | 92.7 | 2031.4 | 168.1 | 1151.1 | 0.41x | 7% |
| layer=8b_down, M=2048 | 741.4 | - | 335.4 | 8068.2 | 426.3 | 1368.1 | 0.45x | 4% |
Profile on H100
| launch | time (ns) | DRAM % peak | SM % peak | occupancy % | regs/thread |
|---|---|---|---|---|---|
| w4a16_triton_gate_up_M1 | 10816 | 40.64 | 49.29 | 38.91 | 55 |
| w4a16_triton_gate_up_M1 | 2912 | 0.80 | 0.15 | 5.75 | 32 |
| w4a16_cuda_gate_up_M1 | 17312 | 25.40 | 54.28 | 42.50 | 48 |
| w4a16_cuda_gate_up_M1 | 2848 | 0.82 | 0.15 | 5.89 | 32 |
| w4a16_triton_gate_up_M16 | 22080 | 19.87 | 38.96 | 24.52 | 83 |
| w4a16_cuda_gate_up_M16 | 73408 | 6.45 | 35.51 | 12.99 | 153 |
| w4a16_cuda_gate_up_M16 | 3264 | 10.72 | 1.87 | 11.50 | 32 |
| w4a16_triton_down_M1 | 13344 | 16.45 | 33.37 | 17.47 | 82 |
| w4a16_triton_down_M1 | 2848 | 0.12 | 0.03 | 5.94 | 32 |
| w4a16_cuda_down_M1 | 20160 | 10.90 | 21.54 | 9.10 | 48 |
| w4a16_cuda_down_M1 | 2848 | 0.12 | 0.03 | 6.03 | 32 |
| w4a16_triton_down_M16 | 13184 | 17.44 | 33.53 | 17.45 | 82 |
| w4a16_triton_down_M16 | 2752 | 1.13 | 0.19 | 5.58 | 32 |
| w4a16_cuda_down_M16 | 53120 | 4.34 | 26.32 | 9.15 | 153 |
| w4a16_cuda_down_M16 | 2880 | 1.09 | 0.18 | 6.09 | 32 |
Power on H100
Sustained decode matmuls hold the card at its power cap (reason 0x4 = software power cap) and the SM clock drops well below its maximum. That is why sustained numbers sit below single-launch Nsight Compute numbers, and why cutting ALU work in the dequantization (the factored GEMV) raised bandwidth.
| kernel (gate_up, M=1) | us per call | SM clock (MHz) | power (W) | throttle reasons |
|---|---|---|---|---|
| triton | 11.6 | 1980 | 468 / 700 | 0x0000000000000000 |
| cuda | 17.8 | 1980 | 439 / 700 | 0x0000000000000000 |
| fp16 | 22.2 | 1980 | 485 / 700 | 0x0000000000000000 |