Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized BFV/BFV operations involving plaintexts #730

Merged
merged 5 commits into from
Apr 8, 2024

Conversation

yspolyakov
Copy link
Contributor

@yspolyakov yspolyakov commented Apr 5, 2024

  • Optimized ctxt/ptxt Core* operations for BFV (the extra logic with adjustments, which was implemented for BGV and CKKS, is not needed in this case)
  • Optimized private ctxt/ptxt operations for BFV/BGV to reduce the number of memory allocations
  • Optimized the encoding for BFV/BGV plaintexts to only do required steps for DCRTPoly
  • Changed encoded plaintexts for DCRTPoly to EVALUATION representation (instead of the COEFFICIENT one)

The runtime of ctxt/ptxt is now 1.5-3x faster than before (depending on the machine used for measurements). The packing now takes more time because it calls NTTs at the end rather than during subsequent ctxt/ptxt operations.

@yspolyakov yspolyakov added the optimization Improves performance label Apr 5, 2024
@yspolyakov yspolyakov added this to the Release 1.1.5 milestone Apr 5, 2024
@yspolyakov yspolyakov linked an issue Apr 5, 2024 that may be closed by this pull request
// ilVector coefficients are packed and resulting ilVector is in
// COEFFICIENT form.
this->Pack(&this->GetElement<NativePoly>(), this->encodingParams->GetPlaintextModulus());
// Calls the inverse NTT mod plaintext modulus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the code below (lines 90, 92-95) be executed first in this block? Also 2 brackets around OPENFHE_THROW should improve readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branches are quite different and work with different data members (encodedNativeVector vs encodedVectorDCRT). I do not think it is a good idea to merge them. The code will be hard to read and follow.

Sure, feel free to add the extra brackets around OPENFHE_THROW

}
else {
// Calls the inverse NTT mod plaintext modulus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the code below (lines 102-107) be executed first in this block? Also 2 brackets around OPENFHE_THROW should improve readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, please add extra parentheses around OPENFHE_THROW

Copy link
Collaborator

@andreea-alexandru andreea-alexandru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@dsuponitskiy dsuponitskiy merged commit c7384bf into dev Apr 8, 2024
8 of 9 checks passed
@dsuponitskiy dsuponitskiy deleted the polyakov-optimize-ctxt-ptxt branch May 10, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Improves performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize BFV/BGV operations related to plaintexts
4 participants