Adaptive encoding reduces matrix multiplication steps on Nvidia tensor cores
AWE: Adaptive Weight Encoding for Exact Integer Matrix Products with Fewer GEMMs on FP4 Tensor Cores
Mathematical SoftwareHardware Architecture
Summary
Multiplying big integer matrices exactly can be slow when using very low precision floating-point units like FP4, which are fast but limited in number size. The authors found a way to represent the numbers with flexible weights, reducing the number of smaller fast multiplications needed from 9 to 6 for 8-bit integers. This new method also applies to other settings and can speed up accurate matrix calculations on hardware like Nvidia B200 and B300 GPUs. They provide the detailed encodings to help others use these improvements.
What this means in practice
- •For gpu software engineers: Implement faster exact integer matrix multiplications on Nvidia B200 and B300 GPUs using reduced FP4 tensor core calls.
- •For cryptography developers: Improve performance of computations requiring exact integer matrix products and residue arithmetic by applying adaptive weight encoding.
Authors
Shun-ichiro Hayashi, Daichi Mukunoki, Tetsuya Hoshino, Takahiro Katagiri
Abstract
Emulation of high-accuracy floating-point matrix multiplication, as in the Ozaki scheme, splits the inputs into low-precision components and multiplies them pairwise. These products must be error-free, and each is an integer matrix product times a scale factor. FP4 Tensor Cores are the fastest on the NVIDIA B200 and B300 but cannot hold INT8 operands. The FP4 values scaled by 2 form the set $S = \{0, \pm1, \pm2, \pm3, \pm4, \pm6, \pm8, \pm12\}$, which contains every residue modulo 13, so with carries any integer splits into base-13 digits that FP4 can store. Prior work splits each INT8 operand into 3 such digits (limbs) with weights $(1, 13, 169)$ and multiplies them pairwise, 9 FP4 matrix multiplications (GEMMs) for INT8$\times$INT8. The classical ways to reduce products, such as the Karatsuba and Toom--Cook methods, do not apply as they stand: sums of limbs reach $\pm 24$ and leave $S$. This paper asks how many FP4 GEMMs are needed for one integer matrix product. We propose Adaptive Weight Encoding (AWE): the limbs take freely chosen integer weights, the stored planes are linear combinations of limbs, and the exact product is the sum of the FP4 GEMMs scaled by reconstruction coefficients. For each input range, we searched these choices for encodings with fewer products and found INT8$\times$INT8 in 6 products and INT4$\times$INT8 in 4. The formulation also holds modulo $m$, which covers the residue number systems of Ozaki scheme II: for the FP64 significand, the 75 products of prior work are reduced to 59. The boundary in product count between encodings with and without residues lies near input width 15. We release the encodings found.