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

Composite Scaling CKKS Bootstrapping (#910 phase 3) #931

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update error conditions.
  • Loading branch information
fdiasmor committed Dec 21, 2024
commit fde39d701345f01ebf6b82ec23791b05e4d9cf71
4 changes: 2 additions & 2 deletions src/pke/lib/scheme/ckksrns/ckksrns-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ void CryptoParametersCKKSRNS::ConfigureCompositeDegree(uint32_t scalingModSize)
static_cast<uint32_t>(std::ceil(static_cast<float>(scalingModSize) / registerWordSize));
// Assert minimum allowed moduli size on composite scaling mode
// @fdiasmor TODO: make it more robust for a range of multiplicative depth
if (static_cast<float>(scalingModSize) / compositeDegree < 22) {
if (static_cast<float>(scalingModSize) / compositeDegree < 20) {
OPENFHE_THROW(
config_error,
"Moduli size is too short (< 22) for target multiplicative depth. Consider increasing the scaling factor or the register word size.");
"Moduli size is too short (< 20) for target multiplicative depth. Consider increasing the scaling factor or the register word size. Otherwise set those parameters manually using COMPOSITESCALINGMANUAL at your own risk.");
}
m_compositeDegree = compositeDegree;
} // else composite degree remains set to 1
Expand Down
21 changes: 10 additions & 11 deletions src/pke/lib/scheme/ckksrns/ckksrns-parametergeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ bool ParameterGenerationCKKSRNS::ParamsGenCKKSRNS(std::shared_ptr<CryptoParamete
uint32_t registerWordSize = cryptoParamsCKKSRNS->GetRegisterWordSize();

if (scalTech == COMPOSITESCALINGAUTO || scalTech == COMPOSITESCALINGMANUAL) {
// if (compositeDegree > 2 && (firstModSize <= 68 || scalingModSize <= 67)) {
// OPENFHE_THROW(
// config_error,
// "This COMPOSITESCALING* version does not fully support composite degree > 2 for small prime moduli. Prime moduli size must generally be greater than 22.");
// }
// else
if (compositeDegree == 1 && registerWordSize < 32) {
if (compositeDegree > 2 && numPrimes > 4 && (firstModSize <= 68 || scalingModSize <= 67)) {
OPENFHE_THROW(
config_error,
"COMPOSITESCALING Warning: There will probably not be enough prime moduli for composite degree > 2 and too small prime moduli. Prime moduli size must generally be greater than 22 for larger multiplicative depth. Feel free to try it using COMPOSITESCALINGMANUAL at your own risk.");
}
else if (compositeDegree == 1 && registerWordSize < 32) {
OPENFHE_THROW(config_error, "This COMPOSITESCALING* version does not support composite degree == 1.");
}
else if (compositeDegree < 1) {
Expand All @@ -106,8 +105,10 @@ bool ParameterGenerationCKKSRNS::ParamsGenCKKSRNS(std::shared_ptr<CryptoParamete
//// HE Standards compliance logic/check
SecurityLevel stdLevel = cryptoParamsCKKSRNS->GetStdLevel();
uint32_t auxBits = (scalTech == COMPOSITESCALINGAUTO || scalTech == COMPOSITESCALINGMANUAL) ? 30 : AUXMODSIZE;
uint32_t n = cyclOrder / 2;
uint32_t qBound = firstModSize + (numPrimes - 1) * scalingModSize + extraModSize;
// Alternative way to calculate auxBits for composite scaling mode
// ((registerWordSize < 30) ? registerWordSize : 30) : AUXMODSIZE;
uint32_t n = cyclOrder / 2;
uint32_t qBound = firstModSize + (numPrimes - 1) * scalingModSize + extraModSize;

// we add an extra bit to account for the alternating logic of selecting the RNS moduli in CKKS
// ignore the case when there is only one max size modulus
Expand Down Expand Up @@ -168,8 +169,6 @@ bool ParameterGenerationCKKSRNS::ParamsGenCKKSRNS(std::shared_ptr<CryptoParamete

if (scalTech == COMPOSITESCALINGAUTO || scalTech == COMPOSITESCALINGMANUAL) {
numPrimes *= compositeDegree;
std::cout << __FUNCTION__ << "::" << __LINE__ << " numPrimes: " << numPrimes << " qBound: " << qBound
<< std::endl;
}

uint32_t vecSize = (extraModSize == 0) ? numPrimes : numPrimes + 1;
Expand Down