Optimize non-transposed int8 GEMV kernel #559
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously the non-transposed int8 GEMV kernel iterated over the B matrix in blocks of
I32_VEC_LEN
columns, 4 rows. At each step it loadedI32_VEC_LEN
int8 values and sign-extended to i32. These were interleaved to give a 4x4 transposed tile of B and two dot product instructions were used to updateI32_VEC_LEN
dot products and column sums. This version reduces the number of loads from B by loading 4 rows ofI8_VEC_LEN
columns at a time, interleaving to giveI32_VEC_LEN
x 4x4 transposed tiles and usingI32_VEC_LEN * 2
dot product instructions to updateI8_VEC_LEN
dot products and column sums.On M3 Pro (5 perf cores) this improves GEMV performance for the non-transposed case from 45 GF -> 61 GF. This compares to 90 GF for the case where B is transposed. For wasmtime (single core) this goes from 6.8 -> 16.6 GF compared to 28 when transposed.
A downside of this change is that the number of tail columns is now much larger (up to 15, 31, or 63 on AVX512). This could possibly be handled by using masked loads for the tail.
SimdInt::{zip_lo_i8, zip_hi_i8, zip_lo_i16, zip_hi_i16}
methods for interleaving packed 8 and 16-bit intsTODO: