Faster matrix multiplication mod p <= 255 - #2812
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds dedicated matrix multiplication code modulo$p \le 255$ :
nmod_mat_mul_u8, called fromnmod_mat_mulwhen applicable_nmod_mat_mul_u8acting directly on byte arrays, called internally (with conversion) fromnmod_mat_mul_u8, and directly fromgr_mat_mulwith thenmod8contextThere are three internal algorithms, all of which beat
nmod_mat_mul_blas; small GF(p) now reach teraop/second-equivalent speeds on my humble Zen3 laptop.uint16fallback) + Strassen withuint8modular additionsflint_sgemm+ block accumulation + Strassen withuint8modular additionsI considered bit-packing for GF(5) and GF(7) too but preliminary tests didn't show this to be competitive with the byte-shuffling approach, so I've dropped this idea for now.
Single-threaded performance, n is the matrix dimension:
Multithreaded performance (8 threads):
Note that the
nmod_mat_mul"old" timings are withflint_sgemm/flint_dgemmfrom #2810 enabled, so the speedups are essentially versusnmod_mat_mul_blas. The much higher speedup ratios fornmod8are indicative of the improvement of the newnmod_mat_mulover the oldnmod_mat_mulwithout a BLAS backend.Note that
gr_mat_mulwithnmod8coefficients now always beatsnmod_mat_mul, as it should be. For GF(2), the cost of streamingulongcoefficients in and out of memory is virtually as high as that of actually multiplying in packed representation.Developed using Claude Fable 5 and Opus 5.