Skip to content

Faster CKKS multiply#346

Merged
WeiDaiWD merged 4 commits intomicrosoft:contribfrom
fboemer:fboemer/faster-ckks-mult
Jun 8, 2021
Merged

Faster CKKS multiply#346
WeiDaiWD merged 4 commits intomicrosoft:contribfrom
fboemer:fboemer/faster-ckks-mult

Conversation

@fboemer
Copy link
Contributor

@fboemer fboemer commented May 28, 2021

Speeds up CKKS Multiply by ~1.2x - 2.1x. Several optimizations improve the default implementation:

  • Avoid the add_poly_coeffmod step when not needed
  • Use as much in-place computation as possible
  • Process 256-coefficient tiles at a time rather than entire polynomials at a time.
  • Also runs pre-commit for some whitespace changes

I imagine a similar approach could be used to optimize the BEHZ ciphertext product in BFV multiply.

If this approach turns out to improve performance on more evaluator functions, perhaps a better implementation would be to add another iterator layer beyond the CoeffIterator, e.g. "TileIterator", which performs the tiling iteration more cleanly.

On ICX compiled with gcc-10, running CKKS / EvaluateMulCt benchmark for 1000 iterations yields:

n=4096

HEXL Time before (us) Time after (us) Speedup
OFF 148 120 1.23x
ON 52.6 39.1 1.34x

n=8192

HEXL Time before (us) Time after (us) Speedup
OFF 640 493 1.30x.
ON 209 116 1.82x.

n=16384

HEXL Time before (us) Time after (us) Speedup
OFF 2656 2008 1.32x
ON 891 414 2.15x

n=32768

HEXL Time before (us) Time after (us) Speedup
OFF 10054 7634 1.31x
ON 3963 2509 1.57x

@fionser
Copy link
Contributor

fionser commented May 28, 2021

Typos in the comments

 // Given input pairs of polynomials x = (x[0], x[1], x[2]), y = (y[0], y[1])

Should it be x = (x[0], x[1]) ?

@fboemer
Copy link
Contributor Author

fboemer commented May 28, 2021

Typos in the comments

 // Given input pairs of polynomials x = (x[0], x[1], x[2]), y = (y[0], y[1])

Should it be x = (x[0], x[1]) ?

The input to CKKS multiply would be x = (x[0], x[1]), but after encrypted1.resize(context_, context_data.parms_id(), dest_size);, x = (x[0], x[1], x[2]). So I suppose x = (x[0], x[1], x[2]) is a tuple, rather than a pair, of polynomials. Hopefully that makes it more clear.

@WeiDaiWD
Copy link
Contributor

WeiDaiWD commented Jun 8, 2021

This is quite nice! Thanks a lot. I'm gonna make slight modifications before release (3.6.6).

@WeiDaiWD WeiDaiWD merged commit a44ca9a into microsoft:contrib Jun 8, 2021
@fboemer fboemer mentioned this pull request Jun 12, 2021
WeiDaiWD pushed a commit that referenced this pull request Jun 15, 2021
@fboemer fboemer deleted the fboemer/faster-ckks-mult branch November 3, 2021 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants