Skip to content

Use biased u8*i8 dot products in the small-M 4-bit MatMul kernel. - #1106

Open
copybara-service[bot] wants to merge 1 commit into
devfrom
test_1031331410
Open

copybara-service[bot] wants to merge 1 commit into
devfrom
test_1031331410

Conversation

@copybara-service

Copy link
Copy Markdown

Use biased u8*i8 dot products in the small-M 4-bit MatMul kernel.

Unpack 4-bit weights as unsigned-biased uint8_t (Q4_0 [0, 15], bias 8; MxFp4
2E2M1+12 in [0, 24], bias 12), precompute kBias * sum(q_a_block), and subtract
in int32_t inside TransposeReduce4 before float scaling (bit-exact). Since q_a
is in [-127, 127], paired int16_t sums stay <= 12192 < 32767, enabling
non-saturating pmaddubsw + pmaddwd (x86 SSSE3..AVX3) and 1x vpdpbusd (AVX3_DL+),
with BitCast i8
i8 elsewhere. Zen 3 bench_matmul (M=1..16): 1.19x-1.28x (AVX2),
1.27x-1.70x (SSE4).

Unpack 4-bit weights as unsigned-biased uint8_t (Q4_0 [0, 15], bias 8; MxFp4
2*E2M1+12 in [0, 24], bias 12), precompute kBias * sum(q_a_block), and subtract
in int32_t inside TransposeReduce4 before float scaling (bit-exact). Since q_a
is in [-127, 127], paired int16_t sums stay <= 12192 < 32767, enabling
non-saturating pmaddubsw + pmaddwd (x86 SSSE3..AVX3) and 1x vpdpbusd (AVX3_DL+),
with BitCast i8*i8 elsewhere. Zen 3 bench_matmul (M=1..16): 1.19x-1.28x (AVX2),
1.27x-1.70x (SSE4).

PiperOrigin-RevId: 1031331410
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