From 3f8bcbefaecd9468fc5ff7a78ec7a33fb382d2f6 Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Mon, 23 Dec 2024 11:05:48 -0500 Subject: [PATCH 1/7] udates to SwitchModulus --- src/core/lib/math/hal/intnat/mubintvecnat.cpp | 112 ++++++------------ 1 file changed, 39 insertions(+), 73 deletions(-) diff --git a/src/core/lib/math/hal/intnat/mubintvecnat.cpp b/src/core/lib/math/hal/intnat/mubintvecnat.cpp index c231f8028..68a505d6e 100644 --- a/src/core/lib/math/hal/intnat/mubintvecnat.cpp +++ b/src/core/lib/math/hal/intnat/mubintvecnat.cpp @@ -42,30 +42,30 @@ namespace intnat { template -NativeVectorT::NativeVectorT(usint length, const IntegerType& modulus, +NativeVectorT::NativeVectorT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs) noexcept : m_modulus{modulus}, m_data(length) { - const size_t len = (rhs.size() < m_data.size()) ? rhs.size() : m_data.size(); - for (size_t i = 0; i < len; ++i) + const uint32_t vlen = (rhs.size() < m_data.size()) ? rhs.size() : m_data.size(); + for (uint32_t i = 0; i < vlen; ++i) m_data[i] = *(rhs.begin() + i) % m_modulus; } template -NativeVectorT::NativeVectorT(usint length, const IntegerType& modulus, +NativeVectorT::NativeVectorT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs) noexcept : m_modulus{modulus}, m_data(length) { - const size_t len = (rhs.size() < m_data.size()) ? rhs.size() : m_data.size(); - for (size_t i = 0; i < len; ++i) + const uint32_t vlen = (rhs.size() < m_data.size()) ? rhs.size() : m_data.size(); + for (uint32_t i = 0; i < vlen; ++i) m_data[i].m_value = BasicInt(*(rhs.begin() + i)) % m_modulus.m_value; } template NativeVectorT& NativeVectorT::operator=(std::initializer_list rhs) noexcept { - const size_t len = rhs.size(); - if (m_data.size() < len) - m_data.resize(len); + const size_t vlen = rhs.size(); + if (m_data.size() < vlen) + m_data.resize(vlen); for (size_t i = 0; i < m_data.size(); ++i) { - if (i < len) { + if (i < vlen) { m_data[i] = *(rhs.begin() + i); if (m_modulus.m_value != 0) m_data[i].m_value = m_data[i].m_value % m_modulus.m_value; @@ -79,11 +79,11 @@ NativeVectorT& NativeVectorT::operator=(std::initializ template NativeVectorT& NativeVectorT::operator=(std::initializer_list rhs) noexcept { - const size_t len = rhs.size(); - if (m_data.size() < len) - m_data.resize(len); + const size_t vlen = rhs.size(); + if (m_data.size() < vlen) + m_data.resize(vlen); for (size_t i = 0; i < m_data.size(); ++i) { - if (i < len) { + if (i < vlen) { m_data[i].m_value = BasicInt(*(rhs.begin() + i)); if (m_modulus.m_value != 0) m_data[i].m_value = m_data[i].m_value % m_modulus.m_value; @@ -108,29 +108,17 @@ NativeVectorT& NativeVectorT::operator=(std::initializ template void NativeVectorT::SwitchModulus(const IntegerType& modulus) { // TODO: #ifdef NATIVEINT_BARRET_MOD - auto size{m_data.size()}; - auto halfQ{m_modulus.m_value >> 1}; - auto om{m_modulus.m_value}; - this->NativeVectorT::SetModulus(modulus); - auto nm{modulus.m_value}; - if (nm > om) { - auto diff{nm - om}; - for (size_t i = 0; i < size; ++i) { - auto& v = m_data[i].m_value; - if (v > halfQ) - v = v + diff; - } + IntegerType halfQ{m_modulus >> 1}; + IntegerType diff{(m_modulus > modulus) ? (m_modulus - modulus) : (modulus - m_modulus)}; + if (modulus > m_modulus) { + for (auto& v : m_data) + v.AddEqFast((v > halfQ) ? diff : 0); } else { - auto diff{nm - (om % nm)}; - for (size_t i = 0; i < size; ++i) { - auto& v = m_data[i].m_value; - if (v > halfQ) - v = v + diff; - if (v >= nm) - v = v % nm; - } + for (auto& v : m_data) + v.ModSubEq((v > halfQ) ? diff : 0, modulus); } + this->SetModulus(modulus); } template @@ -138,27 +126,16 @@ NativeVectorT NativeVectorT::Mod(const IntegerType& mo auto ans(*this); if (modulus.m_value == 2) return ans.ModByTwoEq(); - auto nm{modulus.m_value}; - auto halfQ{m_modulus.m_value >> 1}; - auto om{m_modulus.m_value}; - auto size{m_data.size()}; - if (nm > om) { - auto diff{nm - om}; - for (size_t i = 0; i < size; ++i) { - auto& v = ans.m_data[i].m_value; - if (v > halfQ) - v = v + diff; - } + IntegerType halfQ{m_modulus >> 1}; + IntegerType diff{(m_modulus > modulus) ? (m_modulus - modulus) : (modulus - m_modulus)}; + + if (modulus > m_modulus) { + for (auto& v : ans.m_data) + v.AddEqFast((v > halfQ) ? diff : 0); } else { - auto diff{nm - (om % nm)}; - for (size_t i = 0; i < size; ++i) { - auto& v = ans.m_data[i].m_value; - if (v > halfQ) - v = v + diff; - if (v >= nm) - v = v % nm; - } + for (auto& v : ans.m_data) + v.ModSubEq((v > halfQ) ? diff : 0, modulus); } return ans; } @@ -167,27 +144,16 @@ template NativeVectorT& NativeVectorT::ModEq(const IntegerType& modulus) { if (modulus.m_value == 2) return this->NativeVectorT::ModByTwoEq(); - auto nm{modulus.m_value}; - auto halfQ{m_modulus.m_value >> 1}; - auto om{m_modulus.m_value}; - auto size{m_data.size()}; - if (nm > om) { - auto diff{nm - om}; - for (size_t i = 0; i < size; ++i) { - auto& v = m_data[i].m_value; - if (v > halfQ) - v = v + diff; - } + IntegerType halfQ{m_modulus >> 1}; + IntegerType diff{(m_modulus > modulus) ? (m_modulus - modulus) : (modulus - m_modulus)}; + + if (modulus > m_modulus) { + for (auto& v : m_data) + v.AddEqFast((v > halfQ) ? diff : 0); } else { - auto diff{nm - (om % nm)}; - for (size_t i = 0; i < size; ++i) { - auto& v = m_data[i].m_value; - if (v > halfQ) - v = v + diff; - if (v >= nm) - v = v % nm; - } + for (auto& v : m_data) + v.ModSubEq((v > halfQ) ? diff : 0, modulus); } return *this; } @@ -470,7 +436,7 @@ NativeVectorT& NativeVectorT::DivideAndRoundEq(const I } template -NativeVectorT NativeVectorT::GetDigitAtIndexForBase(usint index, usint base) const { +NativeVectorT NativeVectorT::GetDigitAtIndexForBase(uint32_t index, uint32_t base) const { auto ans(*this); for (size_t i = 0; i < ans.m_data.size(); ++i) ans[i].m_value = static_cast(ans[i].GetDigitAtIndexForBase(index, base)); From a9260237360cddfa8167af80062885981786ef0c Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Mon, 23 Dec 2024 11:33:49 -0500 Subject: [PATCH 2/7] updates to ApproxSwitchCRTBasis and FastExpandCRTBasisPloverQ --- .../lattice/hal/default/dcrtpoly-impl.h | 207 +++++++----------- .../utbfvrns/UnitTestBFVrnsCRTOperations.cpp | 17 +- 2 files changed, 84 insertions(+), 140 deletions(-) diff --git a/src/core/include/lattice/hal/default/dcrtpoly-impl.h b/src/core/include/lattice/hal/default/dcrtpoly-impl.h index 3d00b236d..e47b4eb95 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly-impl.h +++ b/src/core/include/lattice/hal/default/dcrtpoly-impl.h @@ -129,12 +129,12 @@ template DCRTPolyImpl::DCRTPolyImpl(const DggType& dgg, const std::shared_ptr& dcrtParams, Format format) : m_params{dcrtParams}, m_format{format} { - const usint rdim = m_params->GetRingDimension(); + const uint32_t rdim = m_params->GetRingDimension(); const auto dggValues = dgg.GenerateIntVector(rdim); m_vectors.reserve(m_params->GetParams().size()); for (auto& p : m_params->GetParams()) { NativeVector ildv(rdim, p->GetModulus()); - for (usint j = 0; j < rdim; j++) { + for (uint32_t j = 0; j < rdim; j++) { NativeInteger::SignedNativeInt k = (dggValues.get())[j]; auto m = p->GetModulus().ConvertToInt(); auto dcrt_qmodulus = static_cast(m); @@ -190,12 +190,12 @@ template DCRTPolyImpl::DCRTPolyImpl(const TugType& tug, const std::shared_ptr& dcrtParams, Format format, uint32_t h) : m_params{dcrtParams}, m_format{format} { - const usint rdim = m_params->GetRingDimension(); + const uint32_t rdim = m_params->GetRingDimension(); const auto tugValues = tug.GenerateIntVector(rdim, h); m_vectors.reserve(m_params->GetParams().size()); for (auto& p : m_params->GetParams()) { NativeVector iltvs(rdim, p->GetModulus()); - for (usint j = 0; j < rdim; j++) { + for (uint32_t j = 0; j < rdim; j++) { NativeInteger::SignedNativeInt k = (tugValues.get())[j]; if (k < 0) { k *= (-1); @@ -236,7 +236,7 @@ DCRTPolyImpl DCRTPolyImpl::CloneTowers(uint32_t startTower, ui } template -std::vector> DCRTPolyImpl::BaseDecompose(usint baseBits, bool evalModeAnswer) const { +std::vector> DCRTPolyImpl::BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const { auto bdV(CRTInterpolate().BaseDecompose(baseBits, false)); std::vector> result; result.reserve(bdV.size()); @@ -306,15 +306,15 @@ std::vector> DCRTPolyImpl::CRTDecompose(uint32_t } template -std::vector> DCRTPolyImpl::PowersOfBase(usint baseBits) const { +std::vector> DCRTPolyImpl::PowersOfBase(uint32_t baseBits) const { // prepare for the calculations by gathering a big integer version of each of the little moduli std::vector mods; mods.reserve(m_params->GetParams().size()); for (auto& p : m_params->GetParams()) mods.emplace_back(p->GetModulus()); - usint nBits = m_params->GetModulus().GetLengthForBase(2); - usint nWindows = nBits / baseBits; + uint32_t nBits = m_params->GetModulus().GetLengthForBase(2); + uint32_t nWindows = nBits / baseBits; if (nBits % baseBits != 0) ++nWindows; @@ -322,7 +322,7 @@ std::vector> DCRTPolyImpl::PowersOfBase(usint bas result.reserve(nWindows); Integer twoPow(1); size_t size{m_vectors.size()}; - for (usint i = 0; i < nWindows; ++i) { + for (uint32_t i = 0; i < nWindows; ++i) { DCRTPolyImpl x(m_params, m_format); twoPow.LShiftEq(baseBits); for (size_t t = 0; t < size; ++t) @@ -824,7 +824,7 @@ typename DCRTPolyImpl::PolyLargeType DCRTPolyImpl::CRTInterpol * an Poly with zeros except at that single element */ template -typename DCRTPolyImpl::PolyLargeType DCRTPolyImpl::CRTInterpolateIndex(usint i) const { +typename DCRTPolyImpl::PolyLargeType DCRTPolyImpl::CRTInterpolateIndex(uint32_t i) const { if (m_format != Format::COEFFICIENT) OPENFHE_THROW(std::string(__func__) + ": Only available in COEFFICIENT format."); @@ -895,7 +895,7 @@ void DCRTPolyImpl::TimesQovert(const std::shared_ptr& paramsQ, uint32_t size(m_vectors.size()); uint32_t ringDim(m_params->GetRingDimension()); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(size)) - for (size_t i = 0; i < size; ++i) { + for (uint32_t i = 0; i < size; ++i) { auto q{m_vectors[i].GetModulus()}; auto mu{q.ComputeMu()}; for (uint32_t ri = 0; ri < ringDim; ++ri) { @@ -914,36 +914,15 @@ DCRTPolyImpl DCRTPolyImpl::ApproxSwitchCRTBasis( DCRTPolyImpl ans(paramsP, m_format, true); uint32_t sizeQ = (m_vectors.size() > paramsQ->GetParams().size()) ? paramsQ->GetParams().size() : m_vectors.size(); uint32_t sizeP = ans.m_vectors.size(); -#if defined(HAVE_INT128) && NATIVEINT == 64 - uint32_t ringDim = m_params->GetRingDimension(); - std::vector sum(sizeP); - #pragma omp parallel for firstprivate(sum) num_threads(OpenFHEParallelControls.GetThreadLimit(8)) - for (uint32_t ri = 0; ri < ringDim; ++ri) { - std::fill(sum.begin(), sum.end(), 0); - for (uint32_t i = 0; i < sizeQ; ++i) { - const auto& qi = m_vectors[i].GetModulus(); - const auto& xi = m_vectors[i][ri]; - const auto& QHatModpi = QHatModp[i]; - const auto xQHatInvModqi = - xi.ModMulFastConst(QHatInvModq[i], qi, QHatInvModqPrecon[i]).template ConvertToInt(); - for (uint32_t j = 0; j < sizeP; ++j) - sum[j] += Mul128(xQHatInvModqi, QHatModpi[j].ConvertToInt()); - } - for (uint32_t j = 0; j < sizeP; ++j) { - const auto& pj = ans.m_vectors[j].GetModulus(); - ans.m_vectors[j][ri] = BarrettUint128ModUint64(sum[j], pj.ConvertToInt(), modpBarrettMu[j]); - } - } -#else for (uint32_t i = 0; i < sizeQ; ++i) { auto xQHatInvModqi = m_vectors[i] * QHatInvModq[i]; +#pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeP)) for (uint32_t j = 0; j < sizeP; ++j) { - auto temp = xQHatInvModqi; - temp.SwitchModulus(ans.m_vectors[j].GetModulus(), ans.m_vectors[j].GetRootOfUnity(), 0, 0); - ans.m_vectors[j] += (temp *= QHatModp[i][j]); + auto tmp = xQHatInvModqi; + tmp.SwitchModulus(ans.m_vectors[j].GetModulus(), ans.m_vectors[j].GetRootOfUnity(), 0, 0); + ans.m_vectors[j] += (tmp *= QHatModp[i][j]); } } -#endif return ans; } @@ -961,18 +940,18 @@ void DCRTPolyImpl::ApproxModUp(const std::shared_ptr& paramsQ, this->SetFormat(Format::COEFFICIENT); } - auto partP = ApproxSwitchCRTBasis(paramsQ, paramsP, QHatInvModq, QHatInvModqPrecon, QHatModp, modpBarrettMu); + auto partP = this->ApproxSwitchCRTBasis(paramsQ, paramsP, QHatInvModq, QHatInvModqPrecon, QHatModp, modpBarrettMu); if (polyInNTT.size() > 0) m_vectors = std::move(polyInNTT); - size_t sizeQP = paramsQP->GetParams().size(); + uint32_t sizeQP = paramsQP->GetParams().size(); m_vectors.reserve(sizeQP); m_vectors.insert(m_vectors.end(), std::make_move_iterator(partP.m_vectors.begin()), std::make_move_iterator(partP.m_vectors.end())); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeQP)) - for (size_t i = 0; i < sizeQP; ++i) + for (uint32_t i = 0; i < sizeQP; ++i) m_vectors[i].SetFormat(Format::EVALUATION); m_format = Format::EVALUATION; m_params = paramsQP; @@ -987,11 +966,11 @@ DCRTPolyImpl DCRTPolyImpl::ApproxModDown( const std::vector& tInvModp, const std::vector& tInvModpPrecon, const NativeInteger& t, const std::vector& tModqPrecon) const { DCRTPolyImpl partP(paramsP, m_format, true); - size_t sizeP = paramsP->GetParams().size(); - size_t sizeQ = m_vectors.size() - sizeP; + uint32_t sizeP = paramsP->GetParams().size(); + uint32_t sizeQ = m_vectors.size() - sizeP; #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeP)) - for (size_t j = 0; j < sizeP; ++j) { + for (uint32_t j = 0; j < sizeP; ++j) { partP.m_vectors[j] = m_vectors[sizeQ + j]; partP.m_vectors[j].SetFormat(Format::COEFFICIENT); // Multiply everything by -t^(-1) mod P (BGVrns only) @@ -1010,7 +989,7 @@ DCRTPolyImpl DCRTPolyImpl::ApproxModDown( ans.DropLastElements(diffQ); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeQ)) - for (size_t i = 0; i < sizeQ; ++i) { + for (uint32_t i = 0; i < sizeQ; ++i) { // Multiply everything by t mod Q (BGVrns only) if (t > 0) partPSwitchedToQ.m_vectors[i] *= t; @@ -1028,8 +1007,8 @@ DCRTPolyImpl DCRTPolyImpl::SwitchCRTBasis(const std::shared_pt const std::vector>& alphaQModp, const std::vector& modpBarrettMu, const std::vector& qInv) const { - size_t sizeQ = m_vectors.size(); - size_t sizeP = paramsP->GetParams().size(); + uint32_t sizeQ = m_vectors.size(); + uint32_t sizeP = paramsP->GetParams().size(); /* // TODO: do we really want/need all of these checks? if (sizeQ == 0) @@ -1070,7 +1049,7 @@ DCRTPolyImpl DCRTPolyImpl::SwitchCRTBasis(const std::shared_pt #pragma omp parallel for firstprivate(xQHatInvModq) num_threads(OpenFHEParallelControls.GetThreadLimit(8)) for (uint32_t ri = 0; ri < ringDim; ++ri) { double nu{0.5}; - for (size_t i = 0; i < sizeQ; ++i) { + for (uint32_t i = 0; i < sizeQ; ++i) { const auto& qi = m_vectors[i].GetModulus(); // computes [x_i (Q/q_i)^{-1}]_{q_i} xQHatInvModq[i] = m_vectors[i][ri].ModMulFastConst(QHatInvModq[i], qi, QHatInvModqPrecon[i]); @@ -1080,18 +1059,18 @@ DCRTPolyImpl DCRTPolyImpl::SwitchCRTBasis(const std::shared_pt // alpha corresponds to the number of overflows, 0 <= static_cast(nu) <= sizeQ const auto& alphaQModpri = alphaQModp[static_cast(nu)]; - for (size_t j = 0; j < sizeP; ++j) { + for (uint32_t j = 0; j < sizeP; ++j) { const auto& pj = ans.m_vectors[j].GetModulus(); const auto& QHatModpj = QHatModp[j]; #if defined(HAVE_INT128) && NATIVEINT == 64 DoubleNativeInt curValue = 0; - for (size_t i = 0; i < sizeQ; ++i) + for (uint32_t i = 0; i < sizeQ; ++i) curValue += Mul128(xQHatInvModq[i].ConvertToInt(), QHatModpj[i].ConvertToInt()); const auto& curNativeValue = NativeInteger(BarrettUint128ModUint64(curValue, pj.ConvertToInt(), modpBarrettMu[j])); ans.m_vectors[j][ri] = curNativeValue.ModSubFast(alphaQModpri[j], pj); #else - for (size_t i = 0; i < sizeQ; ++i) + for (uint32_t i = 0; i < sizeQ; ++i) ans.m_vectors[j][ri].ModAddFastEq(xQHatInvModq[i].ModMul(QHatModpj[i], pj, mu[j]), pj); ans.m_vectors[j][ri].ModSubFastEq(alphaQModpri[j], pj); #endif @@ -1113,18 +1092,19 @@ void DCRTPolyImpl::ExpandCRTBasis( this->SetFormat(Format::COEFFICIENT); } - auto partP = SwitchCRTBasis(paramsP, QHatInvModq, QHatInvModqPrecon, QHatModp, alphaQModp, modpBarrettMu, qInv); + auto partP = + this->SwitchCRTBasis(paramsP, QHatInvModq, QHatInvModqPrecon, QHatModp, alphaQModp, modpBarrettMu, qInv); if ((resultFormat == Format::EVALUATION) && (polyInNTT.size() > 0)) m_vectors = std::move(polyInNTT); - size_t sizeQP = paramsQP->GetParams().size(); + uint32_t sizeQP = paramsQP->GetParams().size(); m_vectors.reserve(sizeQP); m_vectors.insert(m_vectors.end(), std::make_move_iterator(partP.m_vectors.begin()), std::make_move_iterator(partP.m_vectors.end())); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeQP)) - for (size_t i = 0; i < sizeQP; ++i) + for (uint32_t i = 0; i < sizeQP; ++i) m_vectors[i].SetFormat(resultFormat); m_format = resultFormat; m_params = paramsQP; @@ -1143,71 +1123,35 @@ void DCRTPolyImpl::ExpandCRTBasisReverseOrder( this->SetFormat(Format::COEFFICIENT); } - auto partP = SwitchCRTBasis(paramsP, QHatInvModq, QHatInvModqPrecon, QHatModp, alphaQModp, modpBarrettMu, qInv); + auto partP = + this->SwitchCRTBasis(paramsP, QHatInvModq, QHatInvModqPrecon, QHatModp, alphaQModp, modpBarrettMu, qInv); if ((resultFormat == Format::EVALUATION) && (polyInNTT.size() > 0)) m_vectors = std::move(polyInNTT); - size_t sizeQP = paramsQP->GetParams().size(); + uint32_t sizeQP = paramsQP->GetParams().size(); partP.m_vectors.reserve(sizeQP); partP.m_vectors.insert(partP.m_vectors.end(), std::make_move_iterator(m_vectors.begin()), std::make_move_iterator(m_vectors.end())); m_vectors = std::move(partP.m_vectors); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeQP)) - for (size_t i = 0; i < sizeQP; ++i) + for (uint32_t i = 0; i < sizeQP; ++i) m_vectors[i].SetFormat(resultFormat); m_format = resultFormat; m_params = paramsQP; } -// TODO: revisit after issue #237 is resolved template void DCRTPolyImpl::FastExpandCRTBasisPloverQ(const Precomputations& precomputed) { -#if defined(HAVE_INT128) && NATIVEINT == 64 auto partPl = - ApproxSwitchCRTBasis(m_params, precomputed.paramsPl, precomputed.mPlQHatInvModq, - precomputed.mPlQHatInvModqPrecon, precomputed.qInvModp, precomputed.modpBarrettMu); -#else - DCRTPolyImpl partPl(precomputed.paramsPl, m_format, true); - size_t sizeQ = m_vectors.size(); - size_t sizePl = partPl.m_vectors.size(); - #if 0 - for (size_t i = 0; i < sizeQ; ++i) { - auto xQHatInvModqi = m_vectors[i] * precomputed.mPlQHatInvModq[i]; - for (size_t j = 0; j < sizePl; ++j) { - auto temp = xQHatInvModqi; - temp.SwitchModulus(partPl.m_vectors[j].GetModulus(), partPl.m_vectors[j].GetRootOfUnity(), 0, 0); - partPl.m_vectors[j] += (temp *= precomputed.qInvModp[i][j]); - } - } - #else - std::vector mu; - mu.reserve(sizePl); - for (const auto& p : precomputed.paramsPl->GetParams()) - mu.push_back(p->GetModulus().ComputeMu()); - - uint32_t ringDim = m_params->GetRingDimension(); - #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(8)) - for (uint32_t ri = 0; ri < ringDim; ++ri) { - for (size_t i = 0; i < sizeQ; ++i) { - const auto& qInvModpi = precomputed.qInvModp[i]; - const auto& qi = m_vectors[i].GetModulus(); - const auto& xi = m_vectors[i][ri]; - auto xQHatInvModqi = - xi.ModMulFastConst(precomputed.mPlQHatInvModq[i], qi, precomputed.mPlQHatInvModqPrecon[i]); - for (size_t j = 0; j < sizePl; ++j) { - const auto& pj = partPl.m_vectors[j].GetModulus(); - partPl.m_vectors[j][ri].ModAddFastEq(xQHatInvModqi.ModMul(qInvModpi[j], pj, mu[j]), pj); - } - } - } - #endif -#endif + this->ApproxSwitchCRTBasis(m_params, precomputed.paramsPl, precomputed.mPlQHatInvModq, + precomputed.mPlQHatInvModqPrecon, precomputed.qInvModp, precomputed.modpBarrettMu); auto partQl = partPl.SwitchCRTBasis(precomputed.paramsQl, precomputed.PlHatInvModp, precomputed.PlHatInvModpPrecon, precomputed.PlHatModq, precomputed.alphaPlModq, precomputed.modqBarrettMu, precomputed.pInv); - m_vectors = std::move(partQl.m_vectors); + + m_vectors = std::move(partQl.m_vectors); m_vectors.reserve(partQl.m_vectors.size() + partPl.m_vectors.size()); m_vectors.insert(m_vectors.end(), std::make_move_iterator(partPl.m_vectors.begin()), std::make_move_iterator(partPl.m_vectors.end())); @@ -1217,19 +1161,20 @@ void DCRTPolyImpl::FastExpandCRTBasisPloverQ(const Precomputations& pre template void DCRTPolyImpl::ExpandCRTBasisQlHat(const std::shared_ptr& paramsQ, const std::vector& QlHatModq, - const std::vector& QlHatModqPrecon, const usint sizeQ) { - size_t sizeQl(m_vectors.size()); + const std::vector& QlHatModqPrecon, + const uint32_t sizeQ) { + uint32_t sizeQl(m_vectors.size()); uint32_t ringDim(m_params->GetRingDimension()); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeQl)) - for (size_t i = 0; i < sizeQl; ++i) { + for (uint32_t i = 0; i < sizeQl; ++i) { const NativeInteger& qi = m_vectors[i].GetModulus(); const NativeInteger& QlHatModqi = QlHatModq[i]; const NativeInteger& QlHatModqiPrecon = QlHatModqPrecon[i]; - for (usint ri = 0; ri < ringDim; ri++) + for (uint32_t ri = 0; ri < ringDim; ++ri) m_vectors[i][ri].ModMulFastConstEq(QlHatModqi, qi, QlHatModqiPrecon); } m_vectors.resize(sizeQ); - for (size_t i = sizeQl; i < sizeQ; ++i) { + for (uint32_t i = sizeQl; i < sizeQ; ++i) { typename DCRTPolyImpl::PolyType newvec(paramsQ->GetParams()[i], m_format, true); m_vectors[i] = std::move(newvec); } @@ -1243,14 +1188,14 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( const std::vector& tQHatInvModqBDivqModt, const std::vector& tQHatInvModqBDivqModtPrecon, const std::vector& tQHatInvModqDivqFrac, const std::vector& tQHatInvModqDivqBFrac) const { - usint ringDim = m_params->GetRingDimension(); - usint sizeQ = m_vectors.size(); + uint32_t ringDim = m_params->GetRingDimension(); + uint32_t sizeQ = m_vectors.size(); // MSB of q_i - usint qMSB = m_vectors[0].GetModulus().GetMSB(); + uint32_t qMSB = m_vectors[0].GetModulus().GetMSB(); // MSB of t - usint tMSB = t.GetMSB(); + uint32_t tMSB = t.GetMSB(); // MSB of sizeQ - usint sizeQMSB = GetMSB64(sizeQ); + uint32_t sizeQMSB = GetMSB64(sizeQ); DCRTPolyImpl::PolyType::Vector coefficients(ringDim, t.ConvertToInt()); // For power of two t we can do modulo reduction easily @@ -1269,10 +1214,10 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( // additions without modulo reduction, and do modulo reduction // only once #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.5; NativeInteger intSum = 0, tmp; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmp = m_vectors[i][ri]; floatSum += tmp.ConvertToDouble() * tQHatInvModqDivqFrac[i]; @@ -1297,10 +1242,10 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( // sizeQ * 2^30 * 2^{-53}. We always have sizeQ < 2^11, which means the // error is bounded by 1/4, and the rounding will be correct. #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.5; NativeInteger intSum = 0, tmp; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmp = m_vectors[i][ri]; floatSum += tmp.ConvertToDouble() * tQHatInvModqDivqFrac[i]; @@ -1315,18 +1260,18 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( } } else { - usint qMSBHf = qMSB >> 1; + uint32_t qMSBHf = qMSB >> 1; if ((qMSBHf + tMSB + sizeQMSB) < 62) { // No intermediate modulo reductions are needed in this case // we fit in 62 bits, so we can do multiplications and // additions without modulo reduction, and do modulo reduction // only once #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.5; NativeInteger intSum = 0; NativeInteger tmpHi, tmpLo; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmpLo = m_vectors[i][ri]; tmpHi = tmpLo.RShift(qMSBHf); tmpLo.SubEqFast(tmpHi.LShift(qMSBHf)); @@ -1347,11 +1292,11 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( } else { #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.5; NativeInteger intSum = 0; NativeInteger tmpHi, tmpLo; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmpLo = m_vectors[i][ri]; tmpHi = tmpLo.RShift(qMSBHf); tmpLo.SubEqFast(tmpHi.LShift(qMSBHf)); @@ -1388,10 +1333,10 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( // additions without modulo reduction, and do modulo reduction // only once using floating point techniques #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.0; NativeInteger intSum = 0, tmp; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmp = m_vectors[i][ri]; floatSum += tmp.ConvertToDouble() * tQHatInvModqDivqFrac[i]; @@ -1420,10 +1365,10 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( // sizeQ * 2^30 * 2^{-53}. We always have sizeQ < 2^11, which means the // error is bounded by 1/4, and the rounding will be correct. #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum{0.0}; NativeInteger intSum{0}; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { const auto& tmp = m_vectors[i][ri]; floatSum += tmp.ConvertToDouble() * tQHatInvModqDivqFrac[i]; intSum.AddEqFast( @@ -1440,18 +1385,18 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( } } else { - usint qMSBHf = qMSB >> 1; + uint32_t qMSBHf = qMSB >> 1; if ((qMSBHf + tMSB + sizeQMSB) < 52) { // No intermediate modulo reductions are needed in this case // we fit in 52 bits, so we can do multiplications and // additions without modulo reduction, and do modulo reduction // only once using floating point techniques #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.0; NativeInteger intSum = 0; NativeInteger tmpHi, tmpLo; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmpLo = m_vectors[i][ri]; tmpHi = tmpLo.RShift(qMSBHf); tmpLo.SubEqFast(tmpHi.LShift(qMSBHf)); @@ -1476,11 +1421,11 @@ typename DCRTPolyImpl::PolyType DCRTPolyImpl::ScaleAndRound( } else { #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(4)) - for (usint ri = 0; ri < ringDim; ri++) { + for (uint32_t ri = 0; ri < ringDim; ri++) { double floatSum = 0.0; NativeInteger intSum = 0; NativeInteger tmpHi, tmpLo; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { tmpLo = m_vectors[i][ri]; tmpHi = tmpLo.RShift(qMSBHf); tmpLo.SubEqFast(tmpHi.LShift(qMSBHf)); @@ -1520,9 +1465,9 @@ DCRTPolyImpl DCRTPolyImpl::ApproxScaleAndRound( const std::shared_ptr& paramsP, const std::vector>& tPSHatInvModsDivsModp, const std::vector& modpBarretMu) const { DCRTPolyImpl ans(paramsP, m_format, true); - size_t sizeQP = m_vectors.size(); - size_t sizeP = ans.m_vectors.size(); - size_t sizeQ = sizeQP - sizeP; + uint32_t sizeQP = m_vectors.size(); + uint32_t sizeP = ans.m_vectors.size(); + uint32_t sizeQ = sizeQP - sizeP; [[maybe_unused]] std::vector mu; mu.reserve(sizeP); @@ -1532,12 +1477,12 @@ DCRTPolyImpl DCRTPolyImpl::ApproxScaleAndRound( uint32_t ringDim = m_params->GetRingDimension(); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(8)) for (uint32_t ri = 0; ri < ringDim; ++ri) { - for (size_t j = 0; j < sizeP; ++j) { + for (uint32_t j = 0; j < sizeP; ++j) { const auto& pj = ans.m_vectors[j].GetModulus(); const auto& tPSHatInvModsDivsModpj = tPSHatInvModsDivsModp[j]; #if defined(HAVE_INT128) && NATIVEINT == 64 DoubleNativeInt curValue = 0; - for (size_t i = 0; i < sizeQ; ++i) { + for (uint32_t i = 0; i < sizeQ; ++i) { const NativeInteger& xi = m_vectors[i][ri]; curValue += Mul128(xi.ConvertToInt(), tPSHatInvModsDivsModpj[i].ConvertToInt()); } @@ -1546,7 +1491,7 @@ DCRTPolyImpl DCRTPolyImpl::ApproxScaleAndRound( ans.m_vectors[j][ri] = BarrettUint128ModUint64(curValue, pj.ConvertToInt(), modpBarretMu[j]); #else - for (size_t i = 0; i < sizeQ; ++i) { + for (uint32_t i = 0; i < sizeQ; ++i) { const NativeInteger& xi = m_vectors[i][ri]; ans.m_vectors[j][ri].ModAddFastEq(xi.ModMul(tPSHatInvModsDivsModpj[i], pj, mu[j]), pj); } @@ -2014,7 +1959,7 @@ template std::ostream& operator<<(std::ostream& os, const DCRTPolyImpl& p) { // TODO(gryan): Standardize this printing so it is like other poly's os << "---START PRINT DOUBLE CRT-- WITH SIZE" << p.m_vectors.size() << std::endl; - for (usint i = 0; i < p.m_vectors.size(); i++) { + for (uint32_t i = 0; i < p.m_vectors.size(); i++) { os << "VECTOR " << i << std::endl; os << p.m_vectors[i]; } diff --git a/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp b/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp index 9a4403c77..96f02cd98 100644 --- a/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp +++ b/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp @@ -355,15 +355,14 @@ TEST_F(UTBFVRNS_CRT, BFVrns_FastExpandCRTBasisPloverQ) { NativePoly ans1(x1p, Format::COEFFICIENT); NativePoly ans2(x2p, Format::COEFFICIENT); NativePoly ans3(x3p, Format::COEFFICIENT); - ans0 = {805568738929329616, 1078766251747424582, 785656076316475932, 599125608237504784, - 541576441836927290, 152721755350883626, 574857357780891061, 1081393409810468825}; - ans1 = {434562805454153184, 312761043978375123, 509951653046700586, 879239171041671808, - 385039618723450975, 638710747265582661, 246115869294473638, 352338293114574371}; - ans2 = {955839852875274614, 186398073668078476, 710455872402389881, 1065981546244475424, - 1049296073052489283, 578396240339812092, 26954876970280156, 1019223053257416912}; - ans3 = {874592295621923164, 585167928946466637, 612704504638527027, 551633899923050545, - 758002500979691774, 694035684451390662, 625796987487151016, 96319544173820807}; - + ans0 = {805568738929329615, 1078766251747424581, 785656076316475931, 599125608237504783, + 541576441836927289, 152721755350883625, 574857357780891059, 1081393409810468824}; + ans1 = {434562805454153183, 312761043978375122, 509951653046700585, 879239171041671807, + 385039618723450974, 638710747265582660, 246115869294473636, 352338293114574370}; + ans2 = {955839852875274613, 186398073668078475, 710455872402389880, 1065981546244475423, + 1049296073052489282, 578396240339812091, 26954876970280154, 1019223053257416911}; + ans3 = {874592295621923163, 585167928946466636, 612704504638527026, 551633899923050544, + 758002500979691773, 694035684451390661, 625796987487151014, 96319544173820806}; EXPECT_EQ(a.GetElementAtIndex(0), ans0); EXPECT_EQ(a.GetElementAtIndex(1), ans1); EXPECT_EQ(a.GetElementAtIndex(2), ans2); From 171163e5efec37d6306b0e00397fe33d5389d9b7 Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Tue, 4 Feb 2025 13:57:20 -0500 Subject: [PATCH 3/7] add WITH_REDUCED_NOISE flag as OpenFHE CMake options; reformat CMake files --- CMakeLists.User.txt | 38 ++-- CMakeLists.txt | 358 ++++++++++++++++------------------ OpenFHEConfig.cmake.in | 41 ++-- OpenFHEConfigVersion.cmake.in | 10 +- configure/config_core.in | 3 +- src/binfhe/CMakeLists.txt | 133 ++++++------- src/core/CMakeLists.txt | 161 +++++++-------- src/pke/CMakeLists.txt | 165 ++++++++-------- 8 files changed, 438 insertions(+), 471 deletions(-) diff --git a/CMakeLists.User.txt b/CMakeLists.User.txt index c54134f7b..04dda0133 100644 --- a/CMakeLists.User.txt +++ b/CMakeLists.User.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.5.1) +cmake_minimum_required(VERSION 3.5.1) ### To use gcc/g++ on a Macintosh, you must set the Compilers ### here, not inside the project @@ -18,10 +18,10 @@ cmake_minimum_required (VERSION 3.5.1) project(demo CXX) set(CMAKE_CXX_STANDARD 17) -option( BUILD_STATIC "Set to ON to include static versions of the library" OFF) +option(BUILD_STATIC "Set to ON to include static versions of the library" OFF) find_package(OpenFHE CONFIG REQUIRED) -if (OpenFHE_FOUND) +if(OpenFHE_FOUND) message(STATUS "FOUND PACKAGE OpenFHE") message(STATUS "OpenFHE Version: ${BASE_OPENFHE_VERSION}") message(STATUS "OpenFHE installed as shared libraries: ${OpenFHE_SHARED}") @@ -30,30 +30,30 @@ if (OpenFHE_FOUND) message(STATUS "OpenFHE Native Backend size: ${OpenFHE_NATIVE_SIZE}") else() message(FATAL_ERROR "PACKAGE OpenFHE NOT FOUND") -endif () +endif() -set( CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS} ) +set(CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS}) -include_directories( ${OPENMP_INCLUDES} ) -include_directories( ${OpenFHE_INCLUDE} ) -include_directories( ${OpenFHE_INCLUDE}/third-party/include ) -include_directories( ${OpenFHE_INCLUDE}/core ) -include_directories( ${OpenFHE_INCLUDE}/pke ) -include_directories( ${OpenFHE_INCLUDE}/binfhe ) +include_directories(${OPENMP_INCLUDES}) +include_directories(${OpenFHE_INCLUDE}) +include_directories(${OpenFHE_INCLUDE}/third-party/include) +include_directories(${OpenFHE_INCLUDE}/core) +include_directories(${OpenFHE_INCLUDE}/pke) +include_directories(${OpenFHE_INCLUDE}/binfhe) ### add directories for other OpenFHE modules as needed for your project -link_directories( ${OpenFHE_LIBDIR} ) -link_directories( ${OPENMP_LIBRARIES} ) +link_directories(${OpenFHE_LIBDIR}) +link_directories(${OPENMP_LIBRARIES}) if(BUILD_STATIC) - set( CMAKE_EXE_LINKER_FLAGS "${OpenFHE_EXE_LINKER_FLAGS} -static") - link_libraries( ${OpenFHE_STATIC_LIBRARIES} ) + set(CMAKE_EXE_LINKER_FLAGS "${OpenFHE_EXE_LINKER_FLAGS} -static") + link_libraries(${OpenFHE_STATIC_LIBRARIES}) else() - set( CMAKE_EXE_LINKER_FLAGS ${OpenFHE_EXE_LINKER_FLAGS} ) - link_libraries( ${OpenFHE_SHARED_LIBRARIES} ) + set(CMAKE_EXE_LINKER_FLAGS ${OpenFHE_EXE_LINKER_FLAGS}) + link_libraries(${OpenFHE_SHARED_LIBRARIES}) endif() ### ADD YOUR EXECUTABLE(s) HERE -### add_executable( EXECUTABLE-NAME SOURCES ) +### add_executable(EXECUTABLE-NAME SOURCES) ### ### EXAMPLE: -### add_executable( test demo-simple-example.cpp ) +### add_executable(test demo-simple-example.cpp) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e5a4ab2..58402ff0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ ## An option has the value of ON or OFF ## See below for the list of options -cmake_minimum_required (VERSION 3.5.1) +cmake_minimum_required(VERSION 3.5.1) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) @@ -40,85 +40,87 @@ if(CMAKE_BUILD_TYPE) set(RELEASE_TYPES Debug Release RelWithDebInfo MinSizeRel) list(FIND RELEASE_TYPES ${CMAKE_BUILD_TYPE} INDEX_FOUND) if(${INDEX_FOUND} EQUAL -1) - message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of Debug, Release, RelWithDebInfo, or MinSizeRel" ) + message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of Debug, Release, RelWithDebInfo, or MinSizeRel") endif() else() # if no build type is chosen, default to Release mode set(CMAKE_BUILD_TYPE Release CACHE STRING - "Choose the type of build, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel." FORCE ) + "Choose the type of build, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel." FORCE) endif() -message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode" ) +message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode") -if ( EMSCRIPTEN ) +if (EMSCRIPTEN) set(BUILD_SHARED OFF) - message( "Shared library is not supported by Emscripten") - option( BUILD_STATIC "Set to ON to build static versions of the library" ON ) - option( BUILD_UNITTESTS "Set to ON to build unit tests for the library" OFF ) - option( BUILD_EXAMPLES "Set to ON to build examples for the library" OFF ) - option( BUILD_BENCHMARKS "Set to ON to build benchmarks for the library" OFF ) + message("Shared library is not supported by Emscripten") + option(BUILD_STATIC "Set to ON to build static versions of the library" ON ) + option(BUILD_UNITTESTS "Set to ON to build unit tests for the library" OFF ) + option(BUILD_EXAMPLES "Set to ON to build examples for the library" OFF ) + option(BUILD_BENCHMARKS "Set to ON to build benchmarks for the library" OFF ) set(WITH_OPENMP OFF) - message( "OpenMP is not supported by Emscripten" ) + message("OpenMP is not supported by Emscripten") else() - option( BUILD_SHARED "Set to ON to build shared versions of the library" ON ) - option( BUILD_STATIC "Set to ON to build static versions of the library" OFF ) - option( BUILD_UNITTESTS "Set to ON to build unit tests for the library" ON ) - option( BUILD_EXAMPLES "Set to ON to build examples for the library" ON ) - option( BUILD_BENCHMARKS "Set to ON to build benchmarks for the library" ON ) - option( WITH_OPENMP "Use OpenMP to enable " ON ) -endif() - -option( BUILD_EXTRAS "Set to ON to build extras for the library" OFF ) -option( GIT_SUBMOD_AUTO "Submodules auto-update" ON ) -option( WITH_BE2 "Include MATHBACKEND 2 in build by setting WITH_BE2 to ON" OFF ) -option( WITH_BE4 "Include MATHBACKEND 4 in build by setting WITH_BE4 to ON" OFF ) -option( WITH_NTL "Include MATHBACKEND 6 and NTL in build by setting WITH_NTL to ON" OFF ) -option( WITH_TCM "Activate tcmalloc by setting WITH_TCM to ON" OFF ) -option( WITH_NATIVEOPT "Use machine-specific optimizations" OFF ) -option( WITH_COVTEST "Turn on to enable coverage testing" OFF ) -option( WITH_NOISE_DEBUG "Use only when running lattice estimator; not for production" OFF ) -option( USE_MACPORTS "Use MacPorts installed packages" OFF ) + option(BUILD_SHARED "Set to ON to build shared versions of the library" ON ) + option(BUILD_STATIC "Set to ON to build static versions of the library" OFF ) + option(BUILD_UNITTESTS "Set to ON to build unit tests for the library" ON ) + option(BUILD_EXAMPLES "Set to ON to build examples for the library" ON ) + option(BUILD_BENCHMARKS "Set to ON to build benchmarks for the library" ON ) + option(WITH_OPENMP "Use OpenMP to enable " ON ) +endif() + +option(BUILD_EXTRAS "Set to ON to build extras for the library" OFF ) +option(GIT_SUBMOD_AUTO "Submodules auto-update" ON ) +option(WITH_BE2 "Include MATHBACKEND 2 in build by setting WITH_BE2 to ON" OFF ) +option(WITH_BE4 "Include MATHBACKEND 4 in build by setting WITH_BE4 to ON" OFF ) +option(WITH_NTL "Include MATHBACKEND 6 and NTL in build by setting WITH_NTL to ON" OFF ) +option(WITH_TCM "Activate tcmalloc by setting WITH_TCM to ON" OFF ) +option(WITH_NATIVEOPT "Use machine-specific optimizations" OFF ) +option(WITH_COVTEST "Turn on to enable coverage testing" OFF ) +option(WITH_NOISE_DEBUG "Use only when running lattice estimator; not for production" OFF ) +option(WITH_REDUCED_NOISE "Enable reduced noise at cost of increased compute" OFF ) +option(USE_MACPORTS "Use MacPorts installed packages" OFF ) # Set required number of bits for native integer in build by setting NATIVE_SIZE to 64 or 128 -if( NOT NATIVE_SIZE ) - set( NATIVE_SIZE 64 ) +if(NOT NATIVE_SIZE) + set(NATIVE_SIZE 64) endif() -if( NOT CKKS_M_FACTOR ) - set( CKKS_M_FACTOR 1 ) +if(NOT CKKS_M_FACTOR) + set(CKKS_M_FACTOR 1) endif() ### Print options -message( STATUS "BUILD_UNITTESTS: ${BUILD_UNITTESTS}") -message( STATUS "BUILD_EXAMPLES: ${BUILD_EXAMPLES}") -message( STATUS "BUILD_BENCHMARKS: ${BUILD_BENCHMARKS}") -message( STATUS "BUILD_EXTRAS: ${BUILD_EXTRAS}") -message( STATUS "BUILD_STATIC: ${BUILD_STATIC}") -message( STATUS "BUILD_SHARED: ${BUILD_SHARED}") -message( STATUS "GIT_SUBMOD_AUTO: ${GIT_SUBMOD_AUTO}") -message( STATUS "WITH_BE2: ${WITH_BE2}") -message( STATUS "WITH_BE4: ${WITH_BE4}") -message( STATUS "WITH_NTL: ${WITH_NTL}") -message( STATUS "WITH_TCM: ${WITH_TCM}") -message( STATUS "WITH_OPENMP: ${WITH_OPENMP}") -message( STATUS "NATIVE_SIZE: ${NATIVE_SIZE}") -message( STATUS "CKKS_M_FACTOR: ${CKKS_M_FACTOR}") -message( STATUS "WITH_NATIVEOPT: ${WITH_NATIVEOPT}") -message( STATUS "WITH_COVTEST: ${WITH_COVTEST}") -message( STATUS "WITH_NOISE_DEBUG: ${WITH_NOISE_DEBUG}") -message( STATUS "USE_MACPORTS: ${USE_MACPORTS}") +message(STATUS "BUILD_UNITTESTS: ${BUILD_UNITTESTS}") +message(STATUS "BUILD_EXAMPLES: ${BUILD_EXAMPLES}") +message(STATUS "BUILD_BENCHMARKS: ${BUILD_BENCHMARKS}") +message(STATUS "BUILD_EXTRAS: ${BUILD_EXTRAS}") +message(STATUS "BUILD_STATIC: ${BUILD_STATIC}") +message(STATUS "BUILD_SHARED: ${BUILD_SHARED}") +message(STATUS "GIT_SUBMOD_AUTO: ${GIT_SUBMOD_AUTO}") +message(STATUS "WITH_BE2: ${WITH_BE2}") +message(STATUS "WITH_BE4: ${WITH_BE4}") +message(STATUS "WITH_NTL: ${WITH_NTL}") +message(STATUS "WITH_TCM: ${WITH_TCM}") +message(STATUS "WITH_OPENMP: ${WITH_OPENMP}") +message(STATUS "NATIVE_SIZE: ${NATIVE_SIZE}") +message(STATUS "CKKS_M_FACTOR: ${CKKS_M_FACTOR}") +message(STATUS "WITH_NATIVEOPT: ${WITH_NATIVEOPT}") +message(STATUS "WITH_COVTEST: ${WITH_COVTEST}") +message(STATUS "WITH_NOISE_DEBUG: ${WITH_NOISE_DEBUG}") +message(STATUS "WITH_REDUCED_NOISE: ${WITH_REDUCED_NOISE}") +message(STATUS "USE_MACPORTS: ${USE_MACPORTS}") #-------------------------------------------------------------------- # Compiler logic #-------------------------------------------------------------------- if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # require at least gcc 9.0 - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) message(WARNING "GCC version should be at least 9.0.") endif() -elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # require at least clang 10 - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) message(WARNING "Clang version should be at least 10.0.") endif() else() @@ -126,7 +128,7 @@ else() endif() # use, i.e. don't skip the full RPATH for the build tree -set(CMAKE_SKIP_BUILD_RPATH FALSE) +set(CMAKE_SKIP_BUILD_RPATH FALSE) # when building, don't use the install RPATH already # (but later on when installing) @@ -151,27 +153,26 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set (IGNORE_WARNINGS "-Wno-parentheses") # we can use GNU built-in functions provided by GCC for debugging. ex: __builtin_LINE (), __builtin_FUNCTION (), __builtin_FILE () add_definitions(-DBUILTIN_INFO_AVAILABLE) - message (STATUS "BUILTIN_INFO_AVAILABLE is defined") + message(STATUS "BUILTIN_INFO_AVAILABLE is defined") endif() -if( WITH_NATIVEOPT ) - set (NATIVE_OPT "-march=native") +if(WITH_NATIVEOPT) + set(NATIVE_OPT "-march=native") else() - set (NATIVE_OPT "") + set(NATIVE_OPT "") endif() set(C_COMPILE_FLAGS "-Wall -Werror -O3 ${NATIVE_OPT} -DOPENFHE_VERSION=${OPENFHE_VERSION}") set(CXX_COMPILE_FLAGS "-Wall -Werror -O3 ${NATIVE_OPT} -DOPENFHE_VERSION=${OPENFHE_VERSION} ${IGNORE_WARNINGS}") -if ( EMSCRIPTEN ) +if(EMSCRIPTEN) set(EMSCRIPTEN_IGNORE_WARNINGS "-Wno-unused-but-set-variable -Wno-unknown-warning-option") set(C_COMPILE_FLAGS "${C_COMPILE_FLAGS} ${EMSCRIPTEN_IGNORE_WARNINGS}") set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} ${EMSCRIPTEN_IGNORE_WARNINGS}") add_compile_options(-fexceptions) add_link_options( -sINITIAL_MEMORY=2047MB -sMAXIMUM_MEMORY=4GB -sALLOW_MEMORY_GROWTH=1 - -sMALLOC=emmalloc -sNO_DISABLE_EXCEPTION_CATCHING - ) + -sMALLOC=emmalloc -sNO_DISABLE_EXCEPTION_CATCHING) endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_COMPILE_FLAGS}") @@ -181,8 +182,8 @@ if(WITH_COVTEST) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") link_libraries(gcov) - set( BUILDDIR ${CMAKE_CURRENT_SOURCE_DIR}/build/) - set( COVDIR ${BUILDDIR}coverage/) + set(BUILDDIR ${CMAKE_CURRENT_SOURCE_DIR}/build/) + set(COVDIR ${BUILDDIR}coverage/) endif() if(UNIX AND NOT APPLE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -204,8 +205,6 @@ set(OpenFHE_PACKAGE_LIBS ${OpenFHE_STATIC_LIBS} ${OpenFHE_SHARED_LIBS}) #-------------------------------------------------------------------- # Installation logic #-------------------------------------------------------------------- - - ### set up for install set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") set(INSTALL_INCLUDE_DIR include/openfhe CACHE PATH "Installation directory for headers") @@ -224,7 +223,7 @@ foreach(p LIB INCLUDE CMAKE) endforeach() message("***** INSTALL IS AT ${CMAKE_INSTALL_PREFIX}; to change, run cmake with -DCMAKE_INSTALL_PREFIX=/your/path") -set (CMAKE_INSTALL_MESSAGE LAZY) +set(CMAKE_INSTALL_MESSAGE LAZY) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -234,32 +233,29 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) #-------------------------------------------------------------------- ## clobber cleans and deletes the third-party stuff add_custom_target( - COMMAND make clean - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -) + COMMAND make clean + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target("uninstall" COMMENT "Uninstall OpenFHE files") add_custom_command( - TARGET "uninstall" - POST_BUILD - COMMENT "Uninstall files within install_manifest.txt" - COMMAND ../scripts/uninstall_openfhe.sh - USES_TERMINAL -) - + TARGET "uninstall" + POST_BUILD + COMMENT "Uninstall files within install_manifest.txt" + COMMAND ../scripts/uninstall_openfhe.sh + USES_TERMINAL) #-------------------------------------------------------------------- # Machine-specific checks #-------------------------------------------------------------------- # determine the architecture on a Linux/Unix/macOS/MinGW system if(CMAKE_HOST_UNIX OR MINGW) - EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE ) + EXECUTE_PROCESS(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE) else() set(ARCHITECTURE "unknown") endif() if(ARCHITECTURE) - if (${ARCHITECTURE} MATCHES "i386") + if(${ARCHITECTURE} MATCHES "i386") message(SEND_ERROR "The " ${ARCHITECTURE} " architecture is not supported") else() message(STATUS "Architecture is " ${ARCHITECTURE}) @@ -271,34 +267,34 @@ include(CheckTypeSize) check_type_size("__int128" INT128) check_type_size("uint64_t" INT64) -if (NOT(BUILD_SHARED OR BUILD_STATIC)) +if(NOT(BUILD_SHARED OR BUILD_STATIC)) message(SEND_ERROR "Either BUILD_SHARED or BUILD_STATIC neeed to be turned on.") endif() -if( "${NATIVE_SIZE}" EQUAL 128 ) - if ( EMSCRIPTEN ) +if("${NATIVE_SIZE}" EQUAL 128) + if(EMSCRIPTEN) message(SEND_ERROR "NATIVE_SIZE == 128 is not supported for EMSCRIPTEN") endif() - if( ${HAVE_INT128} ) - set( NATIVEINT 128 ) - message (STATUS "NATIVEINT is set to " ${NATIVEINT}) + if(${HAVE_INT128}) + set(NATIVEINT 128) + message(STATUS "NATIVEINT is set to " ${NATIVEINT}) else() message(SEND_ERROR "Cannot support NATIVE_SIZE == 128") endif() -elseif( "${NATIVE_SIZE}" EQUAL 64 ) - if ( EMSCRIPTEN ) - set( HAVE_INT128 FALSE) +elseif("${NATIVE_SIZE}" EQUAL 64) + if(EMSCRIPTEN) + set(HAVE_INT128 FALSE) endif() - if( ${HAVE_INT64} ) - set( NATIVEINT 64 ) - message (STATUS "NATIVEINT is set to " ${NATIVEINT}) + if(${HAVE_INT64}) + set(NATIVEINT 64) + message(STATUS "NATIVEINT is set to " ${NATIVEINT}) else() message(SEND_ERROR "Cannot support NATIVE_SIZE == 64") endif() -elseif( "${NATIVE_SIZE}" EQUAL 32 ) - if( ${HAVE_INT64} ) - set( NATIVEINT 32 ) - set( HAVE_INT128 FALSE) +elseif("${NATIVE_SIZE}" EQUAL 32) + if(${HAVE_INT64}) + set(NATIVEINT 32) + set(HAVE_INT128 FALSE) message (STATUS "NATIVEINT is set to " ${NATIVEINT}) else() message(SEND_ERROR "Cannot support NATIVE_SIZE == 32") @@ -312,36 +308,36 @@ endif() #-------------------------------------------------------------------- # Backend logic #-------------------------------------------------------------------- -if( NOT MATHBACKEND) - set( MATHBACKEND 4 ) +if(NOT MATHBACKEND) + set(MATHBACKEND 4) endif() -message (STATUS "MATHBACKEND is set to " ${MATHBACKEND}) +message(STATUS "MATHBACKEND is set to " ${MATHBACKEND}) -if( "${NATIVEINT}" EQUAL 128 ) - if( "${MATHBACKEND}" EQUAL 6 ) - set (WITH_NTL OFF) - set (MATHBACKEND 4) - message (STATUS "MATHBACKEND 6 is not compatible with 128-bit native backend. Setting MATHBACKEND to 4.") - elseif( WITH_NTL ) - set (WITH_NTL OFF) - message (STATUS "MATHBACKEND 6 is not compatible with 128-bit native backend. Setting WITH_NTL to OFF.") +if("${NATIVEINT}" EQUAL 128) + if("${MATHBACKEND}" EQUAL 6) + set(WITH_NTL OFF) + set(MATHBACKEND 4) + message(STATUS "MATHBACKEND 6 is not compatible with 128-bit native backend. Setting MATHBACKEND to 4.") + elseif(WITH_NTL) + set(WITH_NTL OFF) + message(STATUS "MATHBACKEND 6 is not compatible with 128-bit native backend. Setting WITH_NTL to OFF.") endif() endif() -if( "${MATHBACKEND}" EQUAL 2 ) - if( NOT WITH_BE2 ) - set (WITH_BE2 ON) +if("${MATHBACKEND}" EQUAL 2) + if(NOT WITH_BE2) + set(WITH_BE2 ON) message(STATUS "MATHBACKEND set to 2. Setting WITH_BE2 to ON") endif() -elseif( "${MATHBACKEND}" EQUAL 4 ) - if( NOT WITH_BE4 ) - set (WITH_BE4 ON) +elseif("${MATHBACKEND}" EQUAL 4) + if(NOT WITH_BE4) + set(WITH_BE4 ON) message(STATUS "MATHBACKEND set to 4. Setting WITH_BE4 to ON") endif() -elseif( "${MATHBACKEND}" EQUAL 6 ) - if( NOT WITH_NTL ) - set (WITH_NTL ON) +elseif("${MATHBACKEND}" EQUAL 6) + if(NOT WITH_NTL) + set(WITH_NTL ON) message(STATUS "MATHBACKEND set to 6. Setting WITH_NTL to ON") endif() else() @@ -378,7 +374,7 @@ if(WITH_TCM OR WITH_NTL) endif() string(LENGTH "${AUTOCONF_VER}" AUTOCONF_VER_LEN) - if( ${AUTOCONF_VER_LEN} EQUAL 0 ) + if(${AUTOCONF_VER_LEN} EQUAL 0) message(SEND_ERROR "Autoconf is not installed.") endif() endif() @@ -386,15 +382,15 @@ endif() #-------------------------------------------------------------------- # OpenMP logic #-------------------------------------------------------------------- -if (WITH_OPENMP) +if(WITH_OPENMP) # Used to optionally compile openmp code add_definitions(-DPARALLEL) # Set OpenMP configuration manually for macOS - if (APPLE) - if (USE_MACPORTS) + if(APPLE) + if(USE_MACPORTS) # Macports-based installation - message( STATUS "Using Macports setup") + message(STATUS "Using Macports setup") set(OPENMP_LIBRARIES "/opt/local/lib/libomp") set(OPENMP_INCLUDES "/opt/local/include/libomp") if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "AppleClang") @@ -407,15 +403,15 @@ if (WITH_OPENMP) set(OpenMP_CXX_LIB_NAMES "omp") set(OpenMP_omp_LIBRARY ${OpenMP_CXX_LIB_NAMES}) endif() - else (USE_MACPORTS) + else(USE_MACPORTS) # Homebrew-based installation # Check for Apple M1 Processor - if (${ARCHITECTURE} MATCHES "arm64") - message( STATUS "Apple M1 detected") + if(${ARCHITECTURE} MATCHES "arm64") + message(STATUS "Apple M1 detected") set(OPENMP_LIBRARIES "/opt/homebrew/opt/libomp/lib") set(OPENMP_INCLUDES "/opt/homebrew/opt/libomp/include") else() # Apple Intel Processor - message( STATUS "Apple Intel detected") + message(STATUS "Apple Intel detected") set(OPENMP_LIBRARIES "/usr/local/opt/libomp/lib") set(OPENMP_INCLUDES "/usr/local/opt/libomp/include") endif() @@ -430,33 +426,33 @@ if (WITH_OPENMP) set(OpenMP_CXX_LIB_NAMES "libomp") set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES}) endif() - endif (USE_MACPORTS) + endif(USE_MACPORTS) include_directories("${OPENMP_INCLUDES}") link_directories("${OPENMP_LIBRARIES}") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - message( STATUS "OPENMP_LIBRARIES: " ${OPENMP_LIBRARIES}) - message( STATUS "OPENMP_INCLUDES: " ${OPENMP_INCLUDES}) - message( STATUS "OpenMP_CXX_FLAGS: " ${OpenMP_CXX_FLAGS}) - message( STATUS "OpenMP_CXX_LIB_NAMES: " ${OpenMP_CXX_LIB_NAMES}) + message(STATUS "OPENMP_LIBRARIES: " ${OPENMP_LIBRARIES}) + message(STATUS "OPENMP_INCLUDES: " ${OPENMP_INCLUDES}) + message(STATUS "OpenMP_CXX_FLAGS: " ${OpenMP_CXX_FLAGS}) + message(STATUS "OpenMP_CXX_LIB_NAMES: " ${OpenMP_CXX_LIB_NAMES}) endif() - find_package (OpenMP) + find_package(OpenMP) # OpenMP_CXX_FOUND was added in cmake 3.9.x so we are also checking the OpenMP_FOUND flag - if (OpenMP_CXX_FOUND OR OpenMP_FOUND) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") + if(OpenMP_CXX_FOUND OR OpenMP_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") else() message(SEND_ERROR "** ERROR ** OpenMP is not installed. If using macOS/clang, please run 'cmake ..' again.") endif() - if (OpenMP_C_FOUND OR OpenMP_FOUND) + if(OpenMP_C_FOUND OR OpenMP_FOUND) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") endif() else() # WITH_OPENMP == OFF - find_package (Threads REQUIRED) + find_package(Threads REQUIRED) # Disable unknown #pragma omp warning set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") @@ -477,7 +473,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) #-------------------------------------------------------------------- if(GIT_SUBMOD_AUTO AND EXISTS "${PROJECT_SOURCE_DIR}/.git") # Update submodules as needed - find_package (Git REQUIRED) + find_package(Git REQUIRED) message(STATUS "Submodule update") if(NOT GIT_SUBMODULE_SYNCED) # "git submodule sync --recursive" should run only once, when CMakeCache.txt doesn't exist' @@ -509,44 +505,43 @@ endif() #-------------------------------------------------------------------- # Coverage logic #-------------------------------------------------------------------- -if ( WITH_COVTEST ) +if(WITH_COVTEST) find_program(LCOV_BIN lcov) - if (LCOV_BIN MATCHES "lcov$") + if(LCOV_BIN MATCHES "lcov$") #Creates the command make cov - add_custom_target( cov + add_custom_target(cov DEPENDS core_tests pke_tests binfhe_tests COMMAND cd ${BUILDDIR} && mkdir -p coverage COMMAND cd ${BUILDDIR}/src/core/CMakeFiles/core_tests.dir/unittest/ && gcov *.gcno && lcov --capture --directory . --output-file ${COVDIR}/core.info COMMAND cd ${BUILDDIR}/src/pke/CMakeFiles/pke_tests.dir/unittest/ && gcov *.gcno && lcov --capture --directory . --output-file ${COVDIR}/pke.info COMMAND cd ${BUILDDIR}/src/binfhe/CMakeFiles/binfhe_tests.dir/unittest/ && gcov *.gcno && lcov --capture --directory . --output-file ${COVDIR}/binfhe.info - COMMAND cd ${COVDIR} && mkdir -p assets && genhtml -t "Coverage Test" -o ${COVDIR}/assets/ *.info - ) + COMMAND cd ${COVDIR} && mkdir -p assets && genhtml -t "Coverage Test" -o ${COVDIR}/assets/ *.info) message(STATUS "lcov found in ${LCOV_BIN}") - else () + else() message(STATUS "lcov needs to be installed to generate a coverage report") - endif () + endif() endif() #-------------------------------------------------------------------- # Third-party logic #-------------------------------------------------------------------- -include (ExternalProject) +include(ExternalProject) # third party directories -set( THIRDPARTYDIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party ) -include_directories( ${THIRDPARTYDIR}/include ) +set(THIRDPARTYDIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party) +include_directories(${THIRDPARTYDIR}/include) ### Handle third-party CEREAL -include_directories( ${THIRDPARTYDIR}/cereal/include ) +include_directories(${THIRDPARTYDIR}/cereal/include) install(DIRECTORY ${THIRDPARTYDIR}/cereal/include/ DESTINATION include/openfhe) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/third-party/google-test/googletest ) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/third-party/google-test/googletest/include ) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src/core/include ) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src/binfhe/include ) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third-party/google-test/googletest) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third-party/google-test/googletest/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/core/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/binfhe/include) -include_directories( ${CMAKE_CURRENT_BINARY_DIR}/src/core ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/core) ### Handle third-party gperftools for optional tcmalloc @@ -556,23 +551,21 @@ add_custom_target( COMMAND ./configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/third-party --enable-minimal COMMAND make COMMAND make install - WORKING_DIRECTORY ${THIRDPARTYDIR}/gperftools -) + WORKING_DIRECTORY ${THIRDPARTYDIR}/gperftools) add_custom_target( tcm_clean COMMAND rm -rf include/gperftools include/google lib/libtcmalloc_minimal* lib/pkgconfig/libtcmalloc* lib/pkgconfig/libprofiler.pc share/doc/gperftools - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third-party -) + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third-party) if(BUILD_STATIC) -add_library(tcmalloc_static STATIC IMPORTED GLOBAL) -set_target_properties(tcmalloc_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/third-party/lib/libtcmalloc_minimal${CMAKE_STATIC_LIBRARY_SUFFIX}) + add_library(tcmalloc_static STATIC IMPORTED GLOBAL) + set_target_properties(tcmalloc_static PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/third-party/lib/libtcmalloc_minimal${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() if(BUILD_SHARED) -add_library(tcmalloc SHARED IMPORTED GLOBAL) -set_target_properties(tcmalloc PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/third-party/lib/libtcmalloc_minimal${CMAKE_SHARED_LIBRARY_SUFFIX}) + add_library(tcmalloc SHARED IMPORTED GLOBAL) + set_target_properties(tcmalloc PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/third-party/lib/libtcmalloc_minimal${CMAKE_SHARED_LIBRARY_SUFFIX}) endif() if(WITH_TCM) @@ -588,19 +581,16 @@ if(WITH_NTL) list(APPEND general_paths "/usr" "/usr/local" "/opt" "/opt/local") list(APPEND header_suffixes "include" "include/NTL" "include/${CMAKE_LIBRARY_ARCHITECTURE}") list(APPEND lib_suffixes "lib" "lib/${CMAKE_LIBRARY_ARCHITECTURE}") - if (NOT(NTL_INCLUDE_DIR AND NTL_LIBRARIES)) + if(NOT(NTL_INCLUDE_DIR AND NTL_LIBRARIES)) find_path(NTL_INCLUDE_DIR NAMES RR.h PATHS ${general_paths} - PATH_SUFFIXES ${header_suffixes} - ) + PATH_SUFFIXES ${header_suffixes}) find_library(NTL_LIBRARIES NAMES ntl libntl ONLY_CMAKE_FIND_ROOT_PATH PATHS ${general_paths} - PATH_SUFFIXES ${lib_suffixes} - ) - + PATH_SUFFIXES ${lib_suffixes}) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(NTL DEFAULT_MSG NTL_INCLUDE_DIR NTL_LIBRARIES) if(NTL_FOUND) @@ -615,14 +605,12 @@ if(WITH_NTL) find_path(GMP_INCLUDE_DIR NAMES gmp.h PATHS ${general_paths} - PATH_SUFFIXES ${header_suffixes} - ) + PATH_SUFFIXES ${header_suffixes}) find_library(GMP_LIBRARIES NAMES gmp libgmp ONLY_CMAKE_FIND_ROOT_PATH PATHS ${general_paths} - PATH_SUFFIXES ${lib_suffixes} - ) + PATH_SUFFIXES ${lib_suffixes}) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_INCLUDE_DIR GMP_LIBRARIES) @@ -651,7 +639,7 @@ set(BINDEMODATAPATH ${CMAKE_CURRENT_BINARY_DIR}/demoData) # copies demoData folder from the root of the repo to build/demoData if the folder does not exist add_custom_target(third-party ALL - COMMAND [ ! -d ${BINDEMODATAPATH} ] && cp -R ${DEMODATAPATH} ${BINDEMODATAPATH} && echo "-- Copied demoData files" || echo "-- demoData folder already exists" ) + COMMAND [ ! -d ${BINDEMODATAPATH} ] && cp -R ${DEMODATAPATH} ${BINDEMODATAPATH} && echo "-- Copied demoData files" || echo "-- demoData folder already exists") # when running "make clean", additionally deletes the demoData folder and CMake cache file set(ADDITIONAL_CLEAN_FILES "") @@ -659,7 +647,7 @@ LIST(APPEND ADDITIONAL_CLEAN_FILES ${BINDEMODATAPATH}) LIST(APPEND ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt) ## for tests -if( BUILD_UNITTESTS ) +if(BUILD_UNITTESTS) set(UNITTESTMAIN ${PROJECT_SOURCE_DIR}/test/Main_TestAll.cpp) endif() @@ -669,12 +657,12 @@ add_subdirectory(src/pke) add_subdirectory(src/binfhe) ### build the google test handlers -###if( BUILD_UNITTESTS ) +###if(BUILD_UNITTESTS) ### add_subdirectory(third-party/google-test EXCLUDE_FROM_ALL) ###endif() ### build the google benchmark handlers (just the parts we need) -if ( BUILD_BENCHMARKS ) +if(BUILD_BENCHMARKS) set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library." FORCE) set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" FORCE) set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Enable building the unit tests which depend on gtest" FORCE) @@ -683,25 +671,25 @@ if ( BUILD_BENCHMARKS ) endif() ## clobber cleans AND deletes the third-party stuff -add_custom_target( clobber COMMAND make clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) +add_custom_target(clobber COMMAND make clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -if( BUILD_UNITTESTS ) - add_custom_target( testall +if(BUILD_UNITTESTS) + add_custom_target(testall DEPENDS core_tests pke_tests binfhe_tests COMMAND echo core: && unittest/core_tests -t || true COMMAND echo pke: && unittest/pke_tests -t || true - COMMAND echo binfhe: && unittest/binfhe_tests -t ) + COMMAND echo binfhe: && unittest/binfhe_tests -t) endif() -if (BUILD_EXAMPLES) - add_custom_target( allexamples DEPENDS allcoreexamples allpkeexamples allbinfheexamples ) +if(BUILD_EXAMPLES) + add_custom_target(allexamples DEPENDS allcoreexamples allpkeexamples allbinfheexamples) endif() -if (BUILD_EXTRAS) - add_custom_target( allextras DEPENDS allcoreextras allpkeextras ) +if(BUILD_EXTRAS) + add_custom_target(allextras DEPENDS allcoreextras allpkeextras) endif() -add_custom_target( allmodules DEPENDS ${OpenFHE_PACKAGE_LIBS} ) +add_custom_target(allmodules DEPENDS ${OpenFHE_PACKAGE_LIBS}) # Add the additional "make clean" files GET_DIRECTORY_PROPERTY(clean_files ADDITIONAL_MAKE_CLEAN_FILES) diff --git a/OpenFHEConfig.cmake.in b/OpenFHEConfig.cmake.in index 35914ecef..85b05abeb 100644 --- a/OpenFHEConfig.cmake.in +++ b/OpenFHEConfig.cmake.in @@ -2,12 +2,11 @@ # It defines the following variables # OpenFHE_INCLUDE_DIRS - include directories for OpenFHE # OpenFHE_LIBRARIES - libraries to link against - get_filename_component(OpenFHE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) # Our library dependencies (contains definitions for IMPORTED targets) if(NOT OpenFHE_BINARY_DIR) - include("${OpenFHE_CMAKE_DIR}/OpenFHETargets.cmake") + include("${OpenFHE_CMAKE_DIR}/OpenFHETargets.cmake") endif() # These are IMPORTED targets created by OpenFHETargets.cmake @@ -24,7 +23,7 @@ set(OPENMP_LIBRARIES "@OPENMP_LIBRARIES@") set(OpenFHE_CXX_FLAGS "@CMAKE_CXX_FLAGS@") set(OpenFHE_C_FLAGS "@CMAKE_C_FLAGS@") -set (OpenFHE_EXE_LINKER_FLAGS "@CMAKE_EXE_LINKER_FLAGS@") +set(OpenFHE_EXE_LINKER_FLAGS "@CMAKE_EXE_LINKER_FLAGS@") # CXX info set(OpenFHE_CXX_STANDARD "@CMAKE_CXX_STANDARD@") @@ -35,10 +34,13 @@ set(OpenFHE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@") set(OpenFHE_STATIC "@BUILD_STATIC@") set(OpenFHE_SHARED "@BUILD_SHARED@") set(OpenFHE_TCM "@WITH_TCM@") +set(OpenFHE_NTL "@WITH_NTL@") set(OpenFHE_OPENMP "@WITH_OPENMP@") set(OpenFHE_NATIVE_SIZE "@NATIVE_SIZE@") set(OpenFHE_CKKS_M_FACTOR "@CKKS_M_FACTOR@") set(OpenFHE_NATIVEOPT "@WITH_NATIVEOPT@") +set(OpenFHE_NOISEDEBUG "@WITH_NOISE_DEBUG@") +set(OpenFHE_REDUCEDNOISE "@WITH_REDUCED_NOISE@") # Math Backend set(OpenFHE_BACKEND "@MATHBACKEND@") @@ -49,23 +51,22 @@ set(OpenFHE_ARCHITECTURE "@ARCHITECTURE@") set(OpenFHE_BACKEND_FLAGS_BASE "@OpenFHE_BACKEND_FLAGS@") # Compile Definitions - -if( "@BUILD_SHARED@" ) - set(OpenFHE_BINFHE_COMPILE_DEFINITIONS "@_pal_binfhe_compile_defs@") - set(OpenFHE_CORE_COMPILE_DEFINITIONS "@_pal_core_compile_defs@") - set(OpenFHE_PKE_COMPILE_DEFINITIONS "@_pal_pke_compile_defs@") - set(OpenFHE_COMPILE_DEFINITIONS - ${OpenFHE_BINFHE_COMPILE_DEFINITIONS} - ${OpenFHE_CORE_COMPILE_DEFINITIONS} - ${OpenFHE_PKE_COMPILE_DEFINITIONS}) +if("@BUILD_SHARED@") + set(OpenFHE_BINFHE_COMPILE_DEFINITIONS "@_pal_binfhe_compile_defs@") + set(OpenFHE_CORE_COMPILE_DEFINITIONS "@_pal_core_compile_defs@") + set(OpenFHE_PKE_COMPILE_DEFINITIONS "@_pal_pke_compile_defs@") + set(OpenFHE_COMPILE_DEFINITIONS + ${OpenFHE_BINFHE_COMPILE_DEFINITIONS} + ${OpenFHE_CORE_COMPILE_DEFINITIONS} + ${OpenFHE_PKE_COMPILE_DEFINITIONS}) endif() -if( "@BUILD_STATIC@" ) - set(OpenFHE_BINFHE_COMPILE_DEFINITIONS_STATIC "@_pal_binfhe_compile_defs_static@") - set(OpenFHE_CORE_COMPILE_DEFINITIONS_STATIC "@_pal_core_compile_defs_static@") - set(OpenFHE_PKE_COMPILE_DEFINITIONS_STATIC "@_pal_pke_compile_defs_static@") - set(OpenFHE_COMPILE_DEFINITIONS_STATIC - ${OpenFHE_BINFHE_COMPILE_DEFINITIONS_STATIC} - ${OpenFHE_CORE_COMPILE_DEFINITIONS_STATIC} - ${OpenFHE_PKE_COMPILE_DEFINITIONS_STATIC}) +if("@BUILD_STATIC@") + set(OpenFHE_BINFHE_COMPILE_DEFINITIONS_STATIC "@_pal_binfhe_compile_defs_static@") + set(OpenFHE_CORE_COMPILE_DEFINITIONS_STATIC "@_pal_core_compile_defs_static@") + set(OpenFHE_PKE_COMPILE_DEFINITIONS_STATIC "@_pal_pke_compile_defs_static@") + set(OpenFHE_COMPILE_DEFINITIONS_STATIC + ${OpenFHE_BINFHE_COMPILE_DEFINITIONS_STATIC} + ${OpenFHE_CORE_COMPILE_DEFINITIONS_STATIC} + ${OpenFHE_PKE_COMPILE_DEFINITIONS_STATIC}) endif() diff --git a/OpenFHEConfigVersion.cmake.in b/OpenFHEConfigVersion.cmake.in index d63381074..9e59d9da8 100644 --- a/OpenFHEConfigVersion.cmake.in +++ b/OpenFHEConfigVersion.cmake.in @@ -2,10 +2,10 @@ set(PACKAGE_VERSION "@OPENFHE_VERSION@") # Check whether the requested PACKAGE_FIND_VERSION is compatible if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_COMPATIBLE FALSE) + set(PACKAGE_VERSION_COMPATIBLE FALSE) else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() endif() diff --git a/configure/config_core.in b/configure/config_core.in index d45193ed4..d2251dce4 100644 --- a/configure/config_core.in +++ b/configure/config_core.in @@ -7,6 +7,7 @@ #cmakedefine WITH_BE2 #cmakedefine WITH_BE4 #cmakedefine WITH_NOISE_DEBUG +#cmakedefine WITH_REDUCED_NOISE #cmakedefine WITH_NTL #cmakedefine WITH_TCM @@ -16,4 +17,4 @@ #cmakedefine MATHBACKEND @MATHBACKEND@ #cmakedefine NATIVEINT @NATIVEINT@ -#endif // __CMAKE_GENERATED_CONFIG_CORE_H__ +#endif // __CMAKE_GENERATED_CONFIG_CORE_H__ diff --git a/src/binfhe/CMakeLists.txt b/src/binfhe/CMakeLists.txt index 568fc24ad..9470449eb 100644 --- a/src/binfhe/CMakeLists.txt +++ b/src/binfhe/CMakeLists.txt @@ -3,7 +3,7 @@ # # all files named *.cpp are compiled to form the library -file (GLOB BINFHE_SRC_FILES CONFIGURE_DEPENDS lib/*.cpp) +file(GLOB BINFHE_SRC_FILES CONFIGURE_DEPENDS lib/*.cpp) include_directories(${CORE_INCLUDE_DIRS}) list(APPEND BINFHE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include") @@ -18,93 +18,88 @@ set(BINFHE_VERSION ${BINFHE_VERSION_MAJOR}.${BINFHE_VERSION_MINOR}.${BINFHE_VERS add_library(binfheobj OBJECT ${BINFHE_SRC_FILES}) set_property(TARGET binfheobj PROPERTY POSITION_INDEPENDENT_CODE 1) -if ( BUILD_SHARED ) - add_dependencies(binfheobj OPENFHEcore) - add_library (OPENFHEbinfhe SHARED $) - set_property(TARGET OPENFHEbinfhe PROPERTY VERSION ${BINFHE_VERSION}) - set_property(TARGET OPENFHEbinfhe PROPERTY SOVERSION ${BINFHE_VERSION_MAJOR}) - set_property(TARGET OPENFHEbinfhe PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - install(TARGETS OPENFHEbinfhe - EXPORT OpenFHETargets - DESTINATION lib) +if(BUILD_SHARED) + add_dependencies(binfheobj OPENFHEcore) + add_library(OPENFHEbinfhe SHARED $) + set_property(TARGET OPENFHEbinfhe PROPERTY VERSION ${BINFHE_VERSION}) + set_property(TARGET OPENFHEbinfhe PROPERTY SOVERSION ${BINFHE_VERSION_MAJOR}) + set_property(TARGET OPENFHEbinfhe PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + install(TARGETS OPENFHEbinfhe EXPORT OpenFHETargets DESTINATION lib) endif() -if( BUILD_STATIC ) +if(BUILD_STATIC) add_dependencies(binfheobj OPENFHEcore_static) - add_library (OPENFHEbinfhe_static STATIC $) - set_property(TARGET OPENFHEbinfhe_static PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - install(TARGETS OPENFHEbinfhe_static - EXPORT OpenFHETargets - DESTINATION lib) + add_library(OPENFHEbinfhe_static STATIC $) + set_property(TARGET OPENFHEbinfhe_static PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + install(TARGETS OPENFHEbinfhe_static EXPORT OpenFHETargets DESTINATION lib) endif() -install(DIRECTORY include/ - DESTINATION include/openfhe/binfhe) +install(DIRECTORY include/ DESTINATION include/openfhe/binfhe) -add_custom_target( allbinfhe ) +add_custom_target(allbinfhe) -if( BUILD_SHARED ) -set (BINFHELIBS PUBLIC OPENFHEbinfhe PUBLIC OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) - target_link_libraries (OPENFHEbinfhe PUBLIC OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) - add_dependencies( allbinfhe OPENFHEbinfhe ) +if(BUILD_SHARED) +set(BINFHELIBS PUBLIC OPENFHEbinfhe PUBLIC OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) + target_link_libraries(OPENFHEbinfhe PUBLIC OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) + add_dependencies(allbinfhe OPENFHEbinfhe) endif() -if( BUILD_STATIC ) -set (BINFHELIBS ${BINFHELIBS} PUBLIC OPENFHEbinfhe_static PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS}) - target_link_libraries (OPENFHEbinfhe_static PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) - add_dependencies( allbinfhe OPENFHEbinfhe_static ) +if(BUILD_STATIC) +set(BINFHELIBS ${BINFHELIBS} PUBLIC OPENFHEbinfhe_static PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS}) + target_link_libraries(OPENFHEbinfhe_static PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) + add_dependencies(allbinfhe OPENFHEbinfhe_static) endif() -if( BUILD_UNITTESTS ) - file (GLOB BINFHE_TEST_SRC_FILES CONFIGURE_DEPENDS unittest/*.cpp) - add_executable (binfhe_tests ${BINFHE_TEST_SRC_FILES} ${UNITTESTMAIN}) - set_property(TARGET binfhe_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) - target_link_libraries ( binfhe_tests ${BINFHELIBS} ${ADDITIONAL_LIBS}) - if (NOT ${WITH_OPENMP}) - target_link_libraries ( binfhe_tests PRIVATE Threads::Threads) - endif() +if(BUILD_UNITTESTS) + file(GLOB BINFHE_TEST_SRC_FILES CONFIGURE_DEPENDS unittest/*.cpp) + add_executable(binfhe_tests ${BINFHE_TEST_SRC_FILES} ${UNITTESTMAIN}) + set_property(TARGET binfhe_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) + target_link_libraries(binfhe_tests ${BINFHELIBS} ${ADDITIONAL_LIBS}) + if(NOT ${WITH_OPENMP}) + target_link_libraries(binfhe_tests PRIVATE Threads::Threads) + endif() - add_dependencies( allbinfhe binfhe_tests ) + add_dependencies(allbinfhe binfhe_tests) - add_custom_command( OUTPUT runbinfhetests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_BINARY_DIR}/unittest/binfhe_tests ) - add_custom_target( testbinfhe DEPENDS binfhe_tests runbinfhetests ) + add_custom_command(OUTPUT runbinfhetests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_BINARY_DIR}/unittest/binfhe_tests) + add_custom_target(testbinfhe DEPENDS binfhe_tests runbinfhetests) endif() -set (BINFHEAPPS "") -if( BUILD_EXAMPLES) - file (GLOB BINFHE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp) - foreach (app ${BINFHE_EXAMPLES_SRC_FILES}) - get_filename_component ( exe ${app} NAME_WE ) - add_executable ( ${exe} ${app} ) - set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/binfhe) - set( BINFHEAPPS ${BINFHEAPPS} ${exe} ) - target_link_libraries ( ${exe} ${BINFHELIBS} ${ADDITIONAL_LIBS}) - endforeach() - - file (GLOB BINFHE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/pke/*.cpp) - foreach (app ${BINFHE_EXAMPLES_SRC_FILES}) - get_filename_component ( exe ${app} NAME_WE ) - add_executable ( ${exe} ${app} ) - set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/binfhe/pke) - set( BINFHEAPPS ${BINFHEAPPS} ${exe} ) - target_link_libraries ( ${exe} ${BINFHELIBS} ${ADDITIONAL_LIBS}) - endforeach() - - add_custom_target( allbinfheexamples ) - add_dependencies( allbinfheexamples ${BINFHEAPPS} ) - add_dependencies( allbinfhe allbinfheexamples) +set(BINFHEAPPS "") +if(BUILD_EXAMPLES) + file(GLOB BINFHE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp) + foreach(app ${BINFHE_EXAMPLES_SRC_FILES}) + get_filename_component(exe ${app} NAME_WE) + add_executable(${exe} ${app}) + set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/binfhe) + set(BINFHEAPPS ${BINFHEAPPS} ${exe}) + target_link_libraries(${exe} ${BINFHELIBS} ${ADDITIONAL_LIBS}) + endforeach() + + file(GLOB BINFHE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/pke/*.cpp) + foreach(app ${BINFHE_EXAMPLES_SRC_FILES}) + get_filename_component(exe ${app} NAME_WE) + add_executable(${exe} ${app}) + set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/binfhe/pke) + set(BINFHEAPPS ${BINFHEAPPS} ${exe}) + target_link_libraries(${exe} ${BINFHELIBS} ${ADDITIONAL_LIBS}) + endforeach() + + add_custom_target(allbinfheexamples) + add_dependencies(allbinfheexamples ${BINFHEAPPS}) + add_dependencies(allbinfhe allbinfheexamples) endif() -add_custom_command( OUTPUT binfheinfocmd COMMAND echo Builds OPENFHEbinfhe and these apps: ${BINFHEAPPS} ) -add_custom_target( binfheinfo DEPENDS binfheinfocmd ) +add_custom_command(OUTPUT binfheinfocmd COMMAND echo Builds OPENFHEbinfhe and these apps: ${BINFHEAPPS}) +add_custom_target(binfheinfo DEPENDS binfheinfocmd) # Collect compile definitions and pass them upward -if ( BUILD_SHARED ) - get_target_property(_compile_defs OPENFHEbinfhe COMPILE_DEFINITIONS) - set(_pal_binfhe_compile_defs ${_compile_defs} PARENT_SCOPE) +if(BUILD_SHARED) + get_target_property(_compile_defs OPENFHEbinfhe COMPILE_DEFINITIONS) + set(_pal_binfhe_compile_defs ${_compile_defs} PARENT_SCOPE) endif() -if( BUILD_STATIC ) - get_target_property(_compile_defs_static OPENFHEbinfhe_static COMPILE_DEFINITIONS) - set(_pal_binfhe_compile_defs_static ${_compile_defs_static} PARENT_SCOPE) +if(BUILD_STATIC) + get_target_property(_compile_defs_static OPENFHEbinfhe_static COMPILE_DEFINITIONS) + set(_pal_binfhe_compile_defs_static ${_compile_defs_static} PARENT_SCOPE) endif() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e2c897ba6..47bbcbfd1 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -3,14 +3,13 @@ # # all files named *.c or */cpp are compiled to form the library -file (GLOB_RECURSE CORE_SRC_FILES CONFIGURE_DEPENDS lib/*.c lib/*.cpp lib/utils/*.cpp) +file(GLOB_RECURSE CORE_SRC_FILES CONFIGURE_DEPENDS lib/*.c lib/*.cpp lib/utils/*.cpp) list(APPEND CORE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include") list(APPEND CORE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib") include_directories(${CORE_INCLUDE_DIRS}) set(CORE_INCLUDE_DIRS "${CORE_INCLUDE_DIRS}" CACHE INTERNAL "") - set(CORE_VERSION_MAJOR ${OPENFHE_VERSION_MAJOR}) set(CORE_VERSION_MINOR ${OPENFHE_VERSION_MINOR}) set(CORE_VERSION_PATCH ${OPENFHE_VERSION_PATCH}) @@ -21,108 +20,98 @@ add_dependencies(coreobj third-party) set_property(TARGET coreobj PROPERTY POSITION_INDEPENDENT_CODE 1) -if ( BUILD_SHARED ) - add_library (OPENFHEcore SHARED $) - set_property(TARGET OPENFHEcore PROPERTY VERSION ${CORE_VERSION}) - set_property(TARGET OPENFHEcore PROPERTY SOVERSION ${CORE_VERSION_MAJOR}) - set_property(TARGET OPENFHEcore PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - install(TARGETS OPENFHEcore - EXPORT OpenFHETargets - DESTINATION lib) +if(BUILD_SHARED) + add_library(OPENFHEcore SHARED $) + set_property(TARGET OPENFHEcore PROPERTY VERSION ${CORE_VERSION}) + set_property(TARGET OPENFHEcore PROPERTY SOVERSION ${CORE_VERSION_MAJOR}) + set_property(TARGET OPENFHEcore PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + install(TARGETS OPENFHEcore EXPORT OpenFHETargets DESTINATION lib) endif() - -if( BUILD_STATIC ) - add_library (OPENFHEcore_static STATIC $) - set_property(TARGET OPENFHEcore_static PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - install(TARGETS OPENFHEcore_static - EXPORT OpenFHETargets - DESTINATION lib) +if(BUILD_STATIC) + add_library(OPENFHEcore_static STATIC $) + set_property(TARGET OPENFHEcore_static PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + install(TARGETS OPENFHEcore_static EXPORT OpenFHETargets DESTINATION lib) endif() -install(DIRECTORY include/ - DESTINATION include/openfhe/core) +install(DIRECTORY include/ DESTINATION include/openfhe/core) -add_custom_target( allcore ) +add_custom_target(allcore) -if( BUILD_SHARED ) - set (CORELIBS PUBLIC OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) - target_link_libraries (OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) - add_dependencies( allcore OPENFHEcore) +if(BUILD_SHARED) + set(CORELIBS PUBLIC OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) + target_link_libraries(OPENFHEcore ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) + add_dependencies(allcore OPENFHEcore) endif() -if( BUILD_STATIC ) - set (CORELIBS ${CORELIBS} PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS}) - target_link_libraries (OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) - add_dependencies( allcore OPENFHEcore_static) +if(BUILD_STATIC) + set(CORELIBS ${CORELIBS} PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS}) + target_link_libraries(OPENFHEcore_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) + add_dependencies(allcore OPENFHEcore_static) endif() -if( BUILD_UNITTESTS ) - if( "${NATIVE_SIZE}" EQUAL 32 ) - message("**** core_tests are not linked for NATIVE_SIZE=32") - else() - file (GLOB CORE_TEST_SRC_FILES CONFIGURE_DEPENDS unittest/*.cpp) - endif() - set (CORE_TEST_SRC_FILES ${CORE_TEST_SRC_FILES}) - add_executable( core_tests ${CORE_TEST_SRC_FILES} ${UNITTESTMAIN} ) - set_property(TARGET core_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) - target_link_libraries ( core_tests ${CORELIBS} ${ADDITIONAL_LIBS}) - if (NOT ${WITH_OPENMP}) - target_link_libraries ( core_tests PRIVATE Threads::Threads) - endif() - - add_dependencies( allcore core_tests ) - - add_custom_command( OUTPUT runcoretests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_BINARY_DIR}/unittest/core_tests ) - add_custom_target( testcore DEPENDS core_tests runcoretests ) +if(BUILD_UNITTESTS) + if("${NATIVE_SIZE}" EQUAL 32) + message("**** core_tests are not linked for NATIVE_SIZE=32") + else() + file(GLOB CORE_TEST_SRC_FILES CONFIGURE_DEPENDS unittest/*.cpp) + endif() + set(CORE_TEST_SRC_FILES ${CORE_TEST_SRC_FILES}) + add_executable(core_tests ${CORE_TEST_SRC_FILES} ${UNITTESTMAIN}) + set_property(TARGET core_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) + target_link_libraries(core_tests ${CORELIBS} ${ADDITIONAL_LIBS}) + if(NOT ${WITH_OPENMP}) + target_link_libraries(core_tests PRIVATE Threads::Threads) + endif() + add_dependencies(allcore core_tests) + add_custom_command(OUTPUT runcoretests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_BINARY_DIR}/unittest/core_tests) + add_custom_target(testcore DEPENDS core_tests runcoretests) endif() -set( COREAPPS "" ) -if ( BUILD_EXAMPLES ) - file (GLOB CORE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp) - foreach (app ${CORE_EXAMPLES_SRC_FILES}) - get_filename_component ( exe ${app} NAME_WE ) - if (${exe} STREQUAL "parallel" AND NOT ${WITH_OPENMP}) - message("Skipping ${exe} because WITH_OPENMP=OFF") - continue() - endif() - add_executable ( ${exe} ${app} ) - set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/core) - set( COREAPPS ${COREAPPS} ${exe} ) - target_link_libraries ( ${exe} ${CORELIBS} ${ADDITIONAL_LIBS}) - endforeach() - - add_custom_target( allcoreexamples ) - add_dependencies( allcoreexamples ${COREAPPS} ) - add_dependencies( allcore allcoreexamples ) +set(COREAPPS "") +if(BUILD_EXAMPLES) + file(GLOB CORE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp) + foreach(app ${CORE_EXAMPLES_SRC_FILES}) + get_filename_component(exe ${app} NAME_WE) + if(${exe} STREQUAL "parallel" AND NOT ${WITH_OPENMP}) + message("Skipping ${exe} because WITH_OPENMP=OFF") + continue() + endif() + add_executable(${exe} ${app}) + set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/core) + set(COREAPPS ${COREAPPS} ${exe}) + target_link_libraries(${exe} ${CORELIBS} ${ADDITIONAL_LIBS}) + endforeach() + add_custom_target(allcoreexamples) + add_dependencies(allcoreexamples ${COREAPPS}) + add_dependencies(allcore allcoreexamples) endif() -set( COREEXTRAS "" ) -if (BUILD_EXTRAS) - file (GLOB CORE_EXTRAS_SRC_FILES CONFIGURE_DEPENDS extras/*.cpp) - foreach (app ${CORE_EXTRAS_SRC_FILES}) - get_filename_component ( exe ${app} NAME_WE ) - add_executable ( ${exe} ${app} ) - set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/extras/core) - set( COREEXTRAS ${COREEXTRAS} ${exe} ) - target_link_libraries ( ${exe} ${CORELIBS} ${ADDITIONAL_LIBS}) - endforeach() - - add_custom_target( allcoreextras ) - add_dependencies( allcoreextras ${COREEXTRAS} ) - add_dependencies( allcore allcoreextras ) +set(COREEXTRAS "") +if(BUILD_EXTRAS) + file(GLOB CORE_EXTRAS_SRC_FILES CONFIGURE_DEPENDS extras/*.cpp) + foreach(app ${CORE_EXTRAS_SRC_FILES}) + get_filename_component(exe ${app} NAME_WE) + add_executable(${exe} ${app}) + set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/extras/core) + set(COREEXTRAS ${COREEXTRAS} ${exe}) + target_link_libraries(${exe} ${CORELIBS} ${ADDITIONAL_LIBS}) + endforeach() + add_custom_target(allcoreextras) + add_dependencies(allcoreextras ${COREEXTRAS}) + add_dependencies(allcore allcoreextras) endif() -add_custom_command( OUTPUT coreinfocmd COMMAND echo Builds OPENFHEcore and these apps: ${COREAPPS} ) -add_custom_target( coreinfo DEPENDS coreinfocmd ) +add_custom_command(OUTPUT coreinfocmd COMMAND echo Builds OPENFHEcore and these apps: ${COREAPPS}) +add_custom_target(coreinfo DEPENDS coreinfocmd) # Collect compile definitions and pass them upward -if ( BUILD_SHARED ) - get_target_property(_compile_defs OPENFHEcore COMPILE_DEFINITIONS) - set(_pal_core_compile_defs ${_compile_defs} PARENT_SCOPE) +if(BUILD_SHARED) + get_target_property(_compile_defs OPENFHEcore COMPILE_DEFINITIONS) + set(_pal_core_compile_defs ${_compile_defs} PARENT_SCOPE) endif() -if( BUILD_STATIC ) - get_target_property(_compile_defs_static OPENFHEcore_static COMPILE_DEFINITIONS) - set(_pal_core_compile_defs_static ${_compile_defs_static} PARENT_SCOPE) +if(BUILD_STATIC) + get_target_property(_compile_defs_static OPENFHEcore_static COMPILE_DEFINITIONS) + set(_pal_core_compile_defs_static ${_compile_defs_static} PARENT_SCOPE) endif() diff --git a/src/pke/CMakeLists.txt b/src/pke/CMakeLists.txt index bf8eb34c4..ced6ddf95 100644 --- a/src/pke/CMakeLists.txt +++ b/src/pke/CMakeLists.txt @@ -3,7 +3,7 @@ # # all files named *.cpp are compiled to form the library -file (GLOB_RECURSE PKE_SRC_FILES CONFIGURE_DEPENDS lib/*.cpp) +file(GLOB_RECURSE PKE_SRC_FILES CONFIGURE_DEPENDS lib/*.cpp) include_directories(${CORE_INCLUDE_DIRS}) list(APPEND PKE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include") @@ -15,114 +15,107 @@ set(PKE_VERSION_MINOR ${OPENFHE_VERSION_MINOR}) set(PKE_VERSION_PATCH ${OPENFHE_VERSION_PATCH}) set(PKE_VERSION ${PKE_VERSION_MAJOR}.${PKE_VERSION_MINOR}.${PKE_VERSION_PATCH}) -add_library (pkeobj OBJECT ${PKE_SRC_FILES}) +add_library(pkeobj OBJECT ${PKE_SRC_FILES}) set_property(TARGET pkeobj PROPERTY POSITION_INDEPENDENT_CODE 1) -if( BUILD_SHARED ) - add_dependencies(pkeobj OPENFHEcore OPENFHEbinfhe) - add_library (OPENFHEpke SHARED $) - set_property(TARGET OPENFHEpke PROPERTY VERSION ${PKE_VERSION}) - set_property(TARGET OPENFHEpke PROPERTY SOVERSION ${PKE_VERSION_MAJOR}) - set_property(TARGET OPENFHEpke PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - install(TARGETS OPENFHEpke - EXPORT OpenFHETargets - DESTINATION lib) +if(BUILD_SHARED) + add_dependencies(pkeobj OPENFHEcore OPENFHEbinfhe) + add_library(OPENFHEpke SHARED $) + set_property(TARGET OPENFHEpke PROPERTY VERSION ${PKE_VERSION}) + set_property(TARGET OPENFHEpke PROPERTY SOVERSION ${PKE_VERSION_MAJOR}) + set_property(TARGET OPENFHEpke PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + install(TARGETS OPENFHEpke EXPORT OpenFHETargets DESTINATION lib) endif() -if( BUILD_STATIC ) - add_dependencies(pkeobj OPENFHEcore_static OPENFHEbinfhe_static) - add_library (OPENFHEpke_static STATIC $) - set_property(TARGET OPENFHEpke_static PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - install(TARGETS OPENFHEpke_static - EXPORT OpenFHETargets - DESTINATION lib) +if(BUILD_STATIC) + add_dependencies(pkeobj OPENFHEcore_static OPENFHEbinfhe_static) + add_library(OPENFHEpke_static STATIC $) + set_property(TARGET OPENFHEpke_static PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + install(TARGETS OPENFHEpke_static EXPORT OpenFHETargets DESTINATION lib) endif() install(DIRECTORY include/ DESTINATION include/openfhe/pke) install(DIRECTORY unittest/utils/ DESTINATION include/openfhe/pke/unittest/utils FILES_MATCHING PATTERN "*.h") -add_custom_target( allpke ) +add_custom_target(allpke) -if( BUILD_SHARED ) - set (PKELIBS PUBLIC OPENFHEpke PUBLIC OPENFHEcore PUBLIC OPENFHEbinfhe ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) - target_link_libraries (OPENFHEpke PUBLIC OPENFHEcore PUBLIC OPENFHEbinfhe ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) - add_dependencies( allpke OPENFHEpke) +if(BUILD_SHARED) + set(PKELIBS PUBLIC OPENFHEpke PUBLIC OPENFHEcore PUBLIC OPENFHEbinfhe ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) + target_link_libraries(OPENFHEpke PUBLIC OPENFHEcore PUBLIC OPENFHEbinfhe ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) + add_dependencies(allpke OPENFHEpke) endif() -if( BUILD_STATIC ) - set (PKELIBS ${PKELIBS} PUBLIC OPENFHEpke_static PUBLIC OPENFHEcore_static PUBLIC OPENFHEbinfhe_static ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) - target_link_libraries (OPENFHEpke_static PUBLIC OPENFHEcore_static PUBLIC OPENFHEbinfhe_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) - add_dependencies( allpke OPENFHEpke_static) +if(BUILD_STATIC) + set(PKELIBS ${PKELIBS} PUBLIC OPENFHEpke_static PUBLIC OPENFHEcore_static PUBLIC OPENFHEbinfhe_static ${THIRDPARTYLIBS} ${OpenMP_CXX_FLAGS}) + target_link_libraries(OPENFHEpke_static PUBLIC OPENFHEcore_static PUBLIC OPENFHEbinfhe_static ${THIRDPARTYSTATICLIBS} ${OpenMP_CXX_FLAGS} ${ADDITIONAL_LIBS}) + add_dependencies(allpke OPENFHEpke_static) endif() -if( BUILD_UNITTESTS ) - if( "${NATIVE_SIZE}" EQUAL 32 ) - message("**** pke_tests are not linked for NATIVE_SIZE=32") - else() - file (GLOB_RECURSE PKE_TEST_SRC_FILES CONFIGURE_DEPENDS unittest/*.cpp) - endif() - add_executable (pke_tests ${PKE_TEST_SRC_FILES} ${UNITTESTMAIN}) - set_property(TARGET pke_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) - target_include_directories(pke_tests PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils") - target_link_libraries ( pke_tests ${PKELIBS} ${ADDITIONAL_LIBS}) - if (NOT ${WITH_OPENMP} ) - target_link_libraries ( pke_tests PRIVATE Threads::Threads) - endif() - add_dependencies( allpke pke_tests ) - - add_custom_command( OUTPUT runpketests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_BINARY_DIR}/unittest/pke_tests ) - add_custom_target( testpke DEPENDS pke_tests runpketests ) +if(BUILD_UNITTESTS) + if("${NATIVE_SIZE}" EQUAL 32) + message("**** pke_tests are not linked for NATIVE_SIZE=32") + else() + file(GLOB_RECURSE PKE_TEST_SRC_FILES CONFIGURE_DEPENDS unittest/*.cpp) + endif() + add_executable(pke_tests ${PKE_TEST_SRC_FILES} ${UNITTESTMAIN}) + set_property(TARGET pke_tests PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/unittest) + target_include_directories(pke_tests PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils") + target_link_libraries(pke_tests ${PKELIBS} ${ADDITIONAL_LIBS}) + if(NOT ${WITH_OPENMP}) + target_link_libraries(pke_tests PRIVATE Threads::Threads) + endif() + add_dependencies(allpke pke_tests) + add_custom_command(OUTPUT runpketests WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_BINARY_DIR}/unittest/pke_tests) + add_custom_target(testpke DEPENDS pke_tests runpketests) endif() set(PKEAPPS "") -if ( BUILD_EXAMPLES) - file (GLOB PKE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp) - foreach (app ${PKE_EXAMPLES_SRC_FILES}) - get_filename_component ( exe ${app} NAME_WE ) - if(${exe} STREQUAL "scheme-switching-serial") - # add schemeswitching-data-serializer.cpp to link line and - # include the unittest/utils directory where schemeswitching-data-serializer.h is - add_executable ( ${exe} ${app} "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils/schemeswitching-data-serializer.cpp") - target_include_directories( ${exe} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils") - else() - add_executable ( ${exe} ${app} ) - endif() - set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/pke) - set( PKEAPPS ${PKEAPPS} ${exe} ) - target_link_libraries ( ${exe} ${PKELIBS} ${ADDITIONAL_LIBS}) - endforeach() - - add_custom_target( allpkeexamples ) - add_dependencies( allpkeexamples ${PKEAPPS} ) - add_dependencies( allpke allpkeexamples ) +if(BUILD_EXAMPLES) + file(GLOB PKE_EXAMPLES_SRC_FILES CONFIGURE_DEPENDS examples/*.cpp) + foreach(app ${PKE_EXAMPLES_SRC_FILES}) + get_filename_component(exe ${app} NAME_WE) + if(${exe} STREQUAL "scheme-switching-serial") + # add schemeswitching-data-serializer.cpp to link line and + # include the unittest/utils directory where schemeswitching-data-serializer.h is + add_executable(${exe} ${app} "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils/schemeswitching-data-serializer.cpp") + target_include_directories(${exe} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/unittest/utils") + else() + add_executable(${exe} ${app}) + endif() + set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples/pke) + set(PKEAPPS ${PKEAPPS} ${exe}) + target_link_libraries(${exe} ${PKELIBS} ${ADDITIONAL_LIBS}) + endforeach() + add_custom_target(allpkeexamples) + add_dependencies(allpkeexamples ${PKEAPPS}) + add_dependencies(allpke allpkeexamples) endif() -set( PKEEXTRAS "" ) -if (BUILD_EXTRAS) - file (GLOB PKE_EXTRAS_SRC_FILES CONFIGURE_DEPENDS extras/*.cpp) - foreach (app ${PKE_EXTRAS_SRC_FILES}) - get_filename_component ( exe ${app} NAME_WE ) - add_executable (${exe} ${app} ) - set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/extras/pke) - set( PKEEXTRAS ${PKEEXTRAS} ${exe} ) - target_link_libraries ( ${exe} ${PKELIBS} ${ADDITIONAL_LIBS}) - endforeach() - - add_custom_target( allpkeextras ) - add_dependencies( allpkeextras ${PKEEXTRAS} ) - add_dependencies( allpke allpkeextras ) +set(PKEEXTRAS "") +if(BUILD_EXTRAS) + file(GLOB PKE_EXTRAS_SRC_FILES CONFIGURE_DEPENDS extras/*.cpp) + foreach(app ${PKE_EXTRAS_SRC_FILES}) + get_filename_component(exe ${app} NAME_WE) + add_executable(${exe} ${app}) + set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/extras/pke) + set(PKEEXTRAS ${PKEEXTRAS} ${exe}) + target_link_libraries(${exe} ${PKELIBS} ${ADDITIONAL_LIBS}) + endforeach() + add_custom_target(allpkeextras) + add_dependencies(allpkeextras ${PKEEXTRAS}) + add_dependencies(allpke allpkeextras) endif() -add_custom_command( OUTPUT pkeinfocmd COMMAND echo Builds OPENFHEpke and these apps: ${PKEAPPS} ) -add_custom_target( pkeinfo DEPENDS pkeinfocmd ) +add_custom_command(OUTPUT pkeinfocmd COMMAND echo Builds OPENFHEpke and these apps: ${PKEAPPS}) +add_custom_target(pkeinfo DEPENDS pkeinfocmd) # Collect compile definitions and pass them upward -if ( BUILD_SHARED ) - get_target_property(_compile_defs OPENFHEpke COMPILE_DEFINITIONS) - set(_pal_pke_compile_defs ${_compile_defs} PARENT_SCOPE) +if(BUILD_SHARED) + get_target_property(_compile_defs OPENFHEpke COMPILE_DEFINITIONS) + set(_pal_pke_compile_defs ${_compile_defs} PARENT_SCOPE) endif() -if( BUILD_STATIC ) - get_target_property(_compile_defs_static OPENFHEpke_static COMPILE_DEFINITIONS) - set(_pal_pke_compile_defs_static ${_compile_defs_static} PARENT_SCOPE) +if(BUILD_STATIC) + get_target_property(_compile_defs_static OPENFHEpke_static COMPILE_DEFINITIONS) + set(_pal_pke_compile_defs_static ${_compile_defs_static} PARENT_SCOPE) endif() From fb0c1cf0b265b0a32e0d5fe1078efaff35f63fd5 Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Wed, 5 Feb 2025 13:49:03 -0500 Subject: [PATCH 4/7] add LazySwitchModulus() functionality --- src/core/include/lattice/hal/dcrtpoly-interface.h | 1 - src/core/include/lattice/hal/default/poly-impl.h | 10 ++++++++++ src/core/include/lattice/hal/default/poly.h | 2 ++ src/core/include/lattice/hal/poly-interface.h | 4 +++- src/core/include/math/hal/bigintdyn/mubintvecdyn.h | 1 + src/core/include/math/hal/bigintfxd/mubintvecfxd.h | 1 + src/core/include/math/hal/bigintntl/mubintvecntl.h | 1 + src/core/include/math/hal/intnat/mubintvecnat.h | 1 + src/core/lib/math/hal/bigintdyn/mubintvecdyn.cpp | 7 +++++++ src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp | 7 +++++++ src/core/lib/math/hal/bigintntl/mubintvecntl.cpp | 7 +++++++ src/core/lib/math/hal/intnat/mubintvecnat.cpp | 7 +++++++ 12 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/core/include/lattice/hal/dcrtpoly-interface.h b/src/core/include/lattice/hal/dcrtpoly-interface.h index ba3343b59..36f945855 100644 --- a/src/core/include/lattice/hal/dcrtpoly-interface.h +++ b/src/core/include/lattice/hal/dcrtpoly-interface.h @@ -707,7 +707,6 @@ class DCRTPolyInterface : public ILElement { * @return is the result of the multiplication. */ DerivedType& operator*=(const DerivedType& rhs) override = 0; - // return this->GetDerived().operator*=(rhs); // multiplicative inverse operation /** diff --git a/src/core/include/lattice/hal/default/poly-impl.h b/src/core/include/lattice/hal/default/poly-impl.h index 04e0d1e97..4da9ef540 100644 --- a/src/core/include/lattice/hal/default/poly-impl.h +++ b/src/core/include/lattice/hal/default/poly-impl.h @@ -406,6 +406,16 @@ void PolyImpl::SwitchModulus(const Integer& modulus, const Integer& roo } } +template +void PolyImpl::LazySwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, + const Integer& rootOfUnityArb) { + if (m_values != nullptr) { + m_values->LazySwitchModulus(modulus); + auto c{m_params->GetCyclotomicOrder()}; + m_params = std::make_shared(c, modulus, rootOfUnity, modulusArb, rootOfUnityArb); + } +} + template void PolyImpl::SwitchFormat() { const auto& co{m_params->GetCyclotomicOrder()}; diff --git a/src/core/include/lattice/hal/default/poly.h b/src/core/include/lattice/hal/default/poly.h index 411d2aae8..712550c15 100644 --- a/src/core/include/lattice/hal/default/poly.h +++ b/src/core/include/lattice/hal/default/poly.h @@ -317,6 +317,8 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl void SwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, const Integer& rootOfUnityArb) override; + void LazySwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, + const Integer& rootOfUnityArb) override; void SwitchFormat() override; void MakeSparse(uint32_t wFactor) override; bool InverseExists() const override; diff --git a/src/core/include/lattice/hal/poly-interface.h b/src/core/include/lattice/hal/poly-interface.h index 7d9089ac7..43b0e5234 100644 --- a/src/core/include/lattice/hal/poly-interface.h +++ b/src/core/include/lattice/hal/poly-interface.h @@ -481,7 +481,9 @@ class PolyInterface : public ILElement { * rootOfUnity for the modulus */ void SwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, - const Integer& rootOfUnityArb) override = 0; + const Integer& rootOfUnityArb) override = 0; + virtual void LazySwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, + const Integer& rootOfUnityArb) = 0; /** * @brief Convert from Coefficient to CRT or vice versa; calls FFT and inverse FFT diff --git a/src/core/include/math/hal/bigintdyn/mubintvecdyn.h b/src/core/include/math/hal/bigintdyn/mubintvecdyn.h index b5dd07b5d..e3c228d88 100644 --- a/src/core/include/math/hal/bigintdyn/mubintvecdyn.h +++ b/src/core/include/math/hal/bigintdyn/mubintvecdyn.h @@ -315,6 +315,7 @@ class mubintvec final : public lbcrypto::BigVectorInterface, } void SwitchModulus(const myT& newModulus); + void LazySwitchModulus(const myT& newModulus); // public modulus accessors inline bool isModulusSet(void) const { diff --git a/src/core/include/math/hal/intnat/mubintvecnat.h b/src/core/include/math/hal/intnat/mubintvecnat.h index f4e400eda..7adb35dca 100644 --- a/src/core/include/math/hal/intnat/mubintvecnat.h +++ b/src/core/include/math/hal/intnat/mubintvecnat.h @@ -323,6 +323,7 @@ class NativeVectorT final : public lbcrypto::BigVectorInterface::SwitchModulus(const ubint_el_t& modulus) { this->SetModulus(modulus); } +template +void mubintvec::LazySwitchModulus(const ubint_el_t& modulus) { + for (auto& v : m_data) + v.ModEq(modulus); + this->SetModulus(modulus); +} + template mubintvec mubintvec::Mod(const ubint_el_t& modulus) const { auto ans(*this); diff --git a/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp b/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp index bf752aa37..2bdebd775 100644 --- a/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp +++ b/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp @@ -226,6 +226,13 @@ void BigVectorFixedT::SwitchModulus(const IntegerType& newModulus) this->SetModulus(newModulus); } +template +void BigVectorFixedT::LazySwitchModulus(const IntegerType& modulus) { + for (uint32_t i = 0; i < m_length; ++i) + this->m_data[i].ModEq(modulus); + this->SetModulus(modulus); +} + // MODULAR ARITHMETIC OPERATIONS template diff --git a/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp b/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp index 623ecfc62..33aaaf0d5 100644 --- a/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp +++ b/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp @@ -382,6 +382,13 @@ void myVecP::SwitchModulus(const myT& newModulus) { this->SetModulus(newModulus); } +template +void myVecP::LazySwitchModulus(const myT& modulus) { + for (uint32_t i = 0; i < this->GetLength(); ++i) + this->operator[](i).ModEq(modulus); + this->SetModulus(modulus); +} + // MODULAR ARITHMETIC FUNCTIONS template diff --git a/src/core/lib/math/hal/intnat/mubintvecnat.cpp b/src/core/lib/math/hal/intnat/mubintvecnat.cpp index 68a505d6e..3c4782d14 100644 --- a/src/core/lib/math/hal/intnat/mubintvecnat.cpp +++ b/src/core/lib/math/hal/intnat/mubintvecnat.cpp @@ -121,6 +121,13 @@ void NativeVectorT::SwitchModulus(const IntegerType& modulus) { this->SetModulus(modulus); } +template +void NativeVectorT::LazySwitchModulus(const IntegerType& modulus) { + for (auto& v : m_data) + v.ModEq(modulus); + this->SetModulus(modulus); +} + template NativeVectorT NativeVectorT::Mod(const IntegerType& modulus) const { auto ans(*this); From 1b46d37695e836f9223a75a6c58249c28a02cd9d Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Wed, 5 Feb 2025 19:20:29 -0500 Subject: [PATCH 5/7] add MultAccEqNoCheck() functionality --- src/core/include/lattice/hal/default/poly.h | 6 ++++++ src/core/include/lattice/hal/poly-interface.h | 2 ++ src/core/include/math/hal/bigintdyn/mubintvecdyn.h | 4 ++++ src/core/include/math/hal/bigintfxd/mubintvecfxd.h | 4 ++++ src/core/include/math/hal/bigintntl/mubintvecntl.h | 4 ++++ src/core/include/math/hal/intnat/mubintvecnat.h | 2 ++ src/core/include/math/hal/vector.h | 3 +++ src/core/lib/math/hal/intnat/mubintvecnat.cpp | 13 +++++++++++++ 8 files changed, 38 insertions(+) diff --git a/src/core/include/lattice/hal/default/poly.h b/src/core/include/lattice/hal/default/poly.h index 712550c15..547cd992f 100644 --- a/src/core/include/lattice/hal/default/poly.h +++ b/src/core/include/lattice/hal/default/poly.h @@ -319,6 +319,12 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl const Integer& rootOfUnityArb) override; void LazySwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, const Integer& rootOfUnityArb) override; + + PolyImpl& MultAccEqNoCheck(const PolyImpl& V, const Integer& I) override { + m_values->MultAccEqNoCheck(*V.m_values, I); + return *this; + } + void SwitchFormat() override; void MakeSparse(uint32_t wFactor) override; bool InverseExists() const override; diff --git a/src/core/include/lattice/hal/poly-interface.h b/src/core/include/lattice/hal/poly-interface.h index 43b0e5234..332eaa5a5 100644 --- a/src/core/include/lattice/hal/poly-interface.h +++ b/src/core/include/lattice/hal/poly-interface.h @@ -485,6 +485,8 @@ class PolyInterface : public ILElement { virtual void LazySwitchModulus(const Integer& modulus, const Integer& rootOfUnity, const Integer& modulusArb, const Integer& rootOfUnityArb) = 0; + virtual DerivedType& MultAccEqNoCheck(const DerivedType& V, const Integer& I) = 0; + /** * @brief Convert from Coefficient to CRT or vice versa; calls FFT and inverse FFT * diff --git a/src/core/include/math/hal/bigintdyn/mubintvecdyn.h b/src/core/include/math/hal/bigintdyn/mubintvecdyn.h index e3c228d88..554f2bbcc 100644 --- a/src/core/include/math/hal/bigintdyn/mubintvecdyn.h +++ b/src/core/include/math/hal/bigintdyn/mubintvecdyn.h @@ -317,6 +317,10 @@ class mubintvec final : public lbcrypto::BigVectorInterface, void SwitchModulus(const myT& newModulus); void LazySwitchModulus(const myT& newModulus); + myT& MultAccEqNoCheck(const myT& v, const uint64_t& i) { + OPENFHE_THROW("MultAccEqNoCheck() not implemented for mubintvecntl"); + } + // public modulus accessors inline bool isModulusSet(void) const { return (this->m_modulus_state == INITIALIZED); diff --git a/src/core/include/math/hal/intnat/mubintvecnat.h b/src/core/include/math/hal/intnat/mubintvecnat.h index 7adb35dca..173023302 100644 --- a/src/core/include/math/hal/intnat/mubintvecnat.h +++ b/src/core/include/math/hal/intnat/mubintvecnat.h @@ -325,6 +325,8 @@ class NativeVectorT final : public lbcrypto::BigVectorInterface::LazySwitchModulus(const IntegerType& modulus) { this->SetModulus(modulus); } +template +NativeVectorT& NativeVectorT::MultAccEqNoCheck(const NativeVectorT& V, const IntegerType& I) { + auto iv{I}; + auto mv{m_modulus}; + if (iv.m_value >= mv.m_value) + iv.ModEq(mv); + auto iinv{iv.PrepModMulConst(mv)}; + const uint32_t ringdm = m_data.size(); + for (uint32_t i = 0; i < ringdm; ++i) + m_data[i].ModAddFastEq(V.m_data[i].ModMulFastConst(iv, mv, iinv), mv); + return *this; +} + template NativeVectorT NativeVectorT::Mod(const IntegerType& modulus) const { auto ans(*this); From 62f9b6a93da9a7e5e856f4a84bedf16d943b2e41 Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Wed, 5 Feb 2025 19:29:59 -0500 Subject: [PATCH 6/7] further updates to ApproxSwitchCRTBasis() --- configure/config_core.in | 2 ++ .../lattice/hal/default/dcrtpoly-impl.h | 29 ++++++++++++++++++- .../utbfvrns/UnitTestBFVrnsCRTOperations.cpp | 13 +++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/configure/config_core.in b/configure/config_core.in index d2251dce4..21121c0e4 100644 --- a/configure/config_core.in +++ b/configure/config_core.in @@ -10,6 +10,8 @@ #cmakedefine WITH_REDUCED_NOISE #cmakedefine WITH_NTL #cmakedefine WITH_TCM +#cmakedefine WITH_OPENMP +#cmakedefine WITH_NATIVEOPT #cmakedefine CKKS_M_FACTOR @CKKS_M_FACTOR@ #cmakedefine HAVE_INT128 @HAVE_INT128@ diff --git a/src/core/include/lattice/hal/default/dcrtpoly-impl.h b/src/core/include/lattice/hal/default/dcrtpoly-impl.h index e47b4eb95..a3a0fed12 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly-impl.h +++ b/src/core/include/lattice/hal/default/dcrtpoly-impl.h @@ -914,15 +914,42 @@ DCRTPolyImpl DCRTPolyImpl::ApproxSwitchCRTBasis( DCRTPolyImpl ans(paramsP, m_format, true); uint32_t sizeQ = (m_vectors.size() > paramsQ->GetParams().size()) ? paramsQ->GetParams().size() : m_vectors.size(); uint32_t sizeP = ans.m_vectors.size(); +#if defined(HAVE_INT128) && (NATIVEINT == 64) && !defined(WITH_REDUCED_NOISE) && \ + (defined(WITH_OPENMP) || (defined(__clang__) && !defined(WITH_NATIVEOPT))) + uint32_t ringDim = m_params->GetRingDimension(); + std::vector sum(sizeP); + #pragma omp parallel for firstprivate(sum) num_threads(OpenFHEParallelControls.GetThreadLimit(8)) + for (uint32_t ri = 0; ri < ringDim; ++ri) { + std::fill(sum.begin(), sum.end(), 0); + for (uint32_t i = 0; i < sizeQ; ++i) { + const auto& QHatModpi = QHatModp[i]; + const auto& qi = m_vectors[i].GetModulus(); + const auto xQHatInvModqi = m_vectors[i][ri] + .ModMulFastConst(QHatInvModq[i], qi, QHatInvModqPrecon[i]) + .template ConvertToInt(); + for (uint32_t j = 0; j < sizeP; ++j) + sum[j] += Mul128(xQHatInvModqi, QHatModpi[j].ConvertToInt()); + } + for (uint32_t j = 0; j < sizeP; ++j) { + auto&& pj = ans.m_vectors[j].GetModulus().template ConvertToInt(); + ans.m_vectors[j][ri] = BarrettUint128ModUint64(sum[j], pj, modpBarrettMu[j]); + } + } +#else for (uint32_t i = 0; i < sizeQ; ++i) { auto xQHatInvModqi = m_vectors[i] * QHatInvModq[i]; -#pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeP)) + #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeP)) for (uint32_t j = 0; j < sizeP; ++j) { + #if defined(WITH_REDUCED_NOISE) auto tmp = xQHatInvModqi; tmp.SwitchModulus(ans.m_vectors[j].GetModulus(), ans.m_vectors[j].GetRootOfUnity(), 0, 0); ans.m_vectors[j] += (tmp *= QHatModp[i][j]); + #else + ans.m_vectors[j].MultAccEqNoCheck(xQHatInvModqi, QHatModp[i][j]); + #endif } } +#endif return ans; } diff --git a/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp b/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp index 96f02cd98..efb538a2d 100644 --- a/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp +++ b/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp @@ -355,6 +355,8 @@ TEST_F(UTBFVRNS_CRT, BFVrns_FastExpandCRTBasisPloverQ) { NativePoly ans1(x1p, Format::COEFFICIENT); NativePoly ans2(x2p, Format::COEFFICIENT); NativePoly ans3(x3p, Format::COEFFICIENT); + +#if defined(WITH_REDUCED_NOISE) ans0 = {805568738929329615, 1078766251747424581, 785656076316475931, 599125608237504783, 541576441836927289, 152721755350883625, 574857357780891059, 1081393409810468824}; ans1 = {434562805454153183, 312761043978375122, 509951653046700585, 879239171041671807, @@ -363,6 +365,17 @@ TEST_F(UTBFVRNS_CRT, BFVrns_FastExpandCRTBasisPloverQ) { 1049296073052489282, 578396240339812091, 26954876970280154, 1019223053257416911}; ans3 = {874592295621923163, 585167928946466636, 612704504638527026, 551633899923050544, 758002500979691773, 694035684451390661, 625796987487151014, 96319544173820806}; +#else + ans0 = {805568738929329616, 1078766251747424582, 785656076316475932, 599125608237504784, + 541576441836927290, 152721755350883626, 574857357780891061, 1081393409810468825}; + ans1 = {434562805454153184, 312761043978375123, 509951653046700586, 879239171041671808, + 385039618723450975, 638710747265582661, 246115869294473638, 352338293114574371}; + ans2 = {955839852875274614, 186398073668078476, 710455872402389881, 1065981546244475424, + 1049296073052489283, 578396240339812092, 26954876970280156, 1019223053257416912}; + ans3 = {874592295621923164, 585167928946466637, 612704504638527027, 551633899923050545, + 758002500979691774, 694035684451390662, 625796987487151016, 96319544173820807}; +#endif + EXPECT_EQ(a.GetElementAtIndex(0), ans0); EXPECT_EQ(a.GetElementAtIndex(1), ans1); EXPECT_EQ(a.GetElementAtIndex(2), ans2); From 61b3c3f8162079f64570f466e46c02ea373edf28 Mon Sep 17 00:00:00 2001 From: Carlo Pascoe Date: Thu, 6 Feb 2025 15:00:52 -0500 Subject: [PATCH 7/7] fix for BE6 --- src/core/include/math/hal/bigintntl/mubintvecntl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/math/hal/bigintntl/mubintvecntl.h b/src/core/include/math/hal/bigintntl/mubintvecntl.h index bfff420db..e067ce214 100644 --- a/src/core/include/math/hal/bigintntl/mubintvecntl.h +++ b/src/core/include/math/hal/bigintntl/mubintvecntl.h @@ -180,7 +180,7 @@ class myVecP : public NTL::Vec, void SwitchModulus(const myT& newModulus); void LazySwitchModulus(const myT& newModulus); - myT& MultAccEqNoCheck(const myT& v, const uint64_t& i) { + myT& MultAccEqNoCheck(const myVecP& v, const myT& i) { OPENFHE_THROW("MultAccEqNoCheck() not implemented for mubintvecntl"); }