Repository navigation
Addition of 2,3,5 mixed radix NTT - #613
Open
czurnieden wants to merge 4 commits into
Open
czurnieden wants to merge 4 commits into
czurnieden wants to merge 4 commits into
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.
Somebody insisted on NTT instead of FFT (no non-optional floating points) so I did.
Tried van der Hoevens TFT first, looked really good but had a cutoff/threshold point near 2^30 bits. If we change the lengths to
size_tinstead ofintI can dust it off if you want.Normal radix-2 NTT was too "steppy", so I went to the middle-ground a mixed radix 2,3 NTT. Still too "steppy". An addition of a radix-5 butterfly was necessary. Which, I found out, is totally different from the 2 and 3 radices. So no radix 7 butterflies from my side.
The final result a 2, 3, 5 mixed radix NTT with Mongomery division and CRT (Garner) with three primes for 60-bit and four primes for 28 bit limbs. Works technically but probably needs some work to adhere to the LTM style. And whatever travis complains about.
MP_64BITwith 60 bit limbs andMP_32BITwith 28 bit limbs work,MP_16BITcould be made to work but the size of anintand therefore the maximum number size is below the NTT thresholds.MP_32BITwith 31 bit limbs does not work as it is organized now (we take all bits of the limb, we do not need to slice them. 31 bit would be too much for the current way NTT is implemented and slicing 31 bits would not only be expensive but also complicated because the slicing would be unbalanced).Here are some benchmarks (all with
MP_64BITon an i7-2600 @ 3.40GHz and 24 Gibibytes of RAM, only some of the benchmarks have been run undercsetisolation. Has not much influence to timing but the noise level is higher and the peaks of 5-smooth input are less visible. All benchmarks are against the full Toom-Cook (2-7) pipeline if not noted otherwise. Base multiplication is always in column 2 unless stated differently. The variablekis the size of the input. The x-axis shows the number of limbs of the first input, the y-axis shows time in seconds.)My apologies for the botched titles.
NTT multiplication with weights 1,2,6 against Toom-Cook 2-7 pipeline.
NTT squaring with weights 1,2,6 against Toom-Cook 2-7 pipeline and Toom-Cook 2-3 (develop) pipeline.
The three different butterflies have different runtimes, so the computed length of the input arrays sets different weights for the different radices. The difference is visible.

Influence of different weights.
The NTT algorithms works much better with unbalanced input. Our balancer only wins (that is, NTT is at the normal cutoff point) if the difference is small (
k + k/100). Once the difference gets larger (k + k/10) NTT wins. That behavior is stable for allnk + k/mwithn >= 1andm >= ~10. Calculating those cutoffs is not yet implemented, buttune.cwould have the means to do it.NTT multiplication
k + k/100NTT multiplication
k + k/10NTT multiplication
k + k/2NTT multiplication
2k - k/100NTT multiplication
2k - k/10And with a larger difference:
NTT multiplication
7kNTT multiplication
7k - k/10