[UPDATE] ffGEMM : finite field general matrix multiply
Not parallelization, not vectorization but a secret 3rd thing
Fileforma is an independent laboratory dedicated to researching custom binary formats for Artificial Intelligence. We research alternatives to FP32 and BF16 for AI. Our team consists of Yale-educated statisticians and ex-military physicists.
ffGEMM is a fixed-point arithmetic library for fast matrix multiplications on CPU. This article introduces the underlying mathematics for Fileforma’s ffGEMM library.
Introduction to Finite Fields
Finite fields, also known as Galois fields, are algebraic structures in which a finite set of elements is equipped with two operations: addition and multiplication. These operations satisfy the properties of a field, meaning every non-zero element has a multiplicative inverse, and both addition and multiplication are associative, commutative, and distributive over each other.
Introduction to Matrix Multiplication
To multiply two matrices, we use the rule that the element in the i-th row and j-th column of the resulting matrix is the dot product of the i-th row of the first matrix with the j-th column of the second matrix.
Here are two 3×3 matrices:
Matrix 1:
Matrix 2:
The product of these matrices would look like:
Introduction to the Chinese Remainder Theorem
The Chinese Remainder Theorem states that a unique integer represents sets of mods across different finite fields.
Formal Definition of the Chinese Remainder Theorem
Define a set of positive pairwise relatively prime integers
where
and
Let us define a set of integers
Then, there exists exactly one integer X such that:
that satisfies the conditions
Combining Finite Fields and Matrix Multiplication using the Chinese Remainder Theorem
From our introduction to matrix multiplications, we observe that matrix multiplications are linear combinations of columns. For the first column, we observe these elements contribute to the overall result.
From our introduction to the Chinese Remainder Theorem, we observe that we can combine integers using the Chinese Remainder Theorem.
To combine the integers A, D, and G using the Chinese Remainder Theorem, we assume that they correspond to solutions of the following system of congruences:
where
and
Using the Chinese Remainder Theorem we can find a unique solution
Therefore, we conclude
Our ffGEMM library builds upon the equivalence shown above.
Citations
Lidl, R., & Niederreiter, H. (1997). Finite Fields. Cambridge University Press.
Dummit, D. S., & Foote, R. M. (2004). Abstract Algebra (3rd ed.). Wiley.
Stinson, D. R. (2006). Cryptography: Theory and Practice (3rd ed.). CRC Press.
Omondi, A & Premkumar, B. (2007). Residue Number Systems : Theory and Implementation. Imperial College Press.