I have a use case to only use < 32-bit modulus, therefore I modify the CMakeLists.txt to change NATIVE_SIZE from 64 into 32, as listed below.
if( NOT NATIVE_SIZE )
set( NATIVE_SIZE 32 )
endif()
Accordingly, I set the parameters.SetScalingModSize(<>);
for BFVrns, CKKS and BGVrns context to parameters.SetScalingModSize(28)
. However I obtain the following errors. Might I seek suggestions on how to solve it? Besides this, might I seek suggestions on how to use CKKSrns context?
However, when I run the ./bin/benchmark/lib-benchmark after change
jianming@god2:~/work/CROSS_Prj/openfhe-development/build$ ./bin/benchmark/lib-benchmark >> benchmark_result_max_32modulus
2025-03-05T18:02:43-05:00
Running ./bin/benchmark/lib-benchmark
Run on (32 X 5083.4 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x16)
L1 Instruction 32 KiB (x16)
L2 Unified 512 KiB (x16)
L3 Unified 32768 KiB (x2)
Load Average: 0.34, 0.13, 0.09
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
terminate called after throwing an instance of 'lbcrypto::OpenFHEException'
what(): /home/jianming/work/CROSS_Prj/openfhe-development/src/core/include/lattice/hal/default/dcrtpoly-impl.h:l.1567:ScaleAndRound(): Use of ScaleAndRound with NATIVEINT == 32 may lead to overflow
Aborted (core dumped)
NATIVE_SIZE=32
was added for the binfhe
(FHEW/TFHE) schemes as it provides lower latency than the 64-bit mode. We do not typically use this mode for the pke
(SIMD) schemes. Could you clarify why you need 32-bit numbers for the pke
schemes?
Thanks so much for the detailed explanation. My reason is aiming to use Google TPU for supporting CKKS scheme configured from OpenFHE.
We found 60-bit modulus implementation won’t be as perfermant as 28-bit modulus. Therefore, we are seeking whether is it possible to directly generate 32-bit modulus from OpenFHE-CKKS scheme directly
Specifically for CKKS (the error message you got is for BFV; you should only run CKKS), I recommend also setting the first modulus to 28 bits and also setting AUXMODSIZE (search for it in the code) to 28. Note that the precision in this case will be quite small as the bottom 15-20 bits in CKKS ciphertexts contain noise.
1 Like
After I
- set AUXMODSIZE as 28,
- NATIVE_SIZE in CMakeLists.txt as 32.
- remove BFV and BGV evaluation from libbenchmark.
I got the following errors, any suggestions on how shall I proceed?
terminate called after throwing an instance of 'lbcrypto::OpenFHEException'
what(): /home/jianming/work/CROSS_Prj/openfhe-development/src/core/include/math/nbtheory-impl.h:l.354:LastPrime(): LastPrime: Requested bit length 60 exceeds maximum allowed length 28
Aborted (core dumped)
What about first modulus in CKKS?
Got it – is there a way that I could reduce the first modulus into within 32 bit?
Appreciated it, it works! Now extended moduli (sizeQ) are the only ones staying in 60-bit,
Is there a way to set them to only use 32-bit moduli as well?
Thanks a lot!
I tried the following combination of parameter setting and get the following error
- const size_t AUXMODSIZE = 28; in ckksrns-parametergeneration.cpp
- set( NATIVE_SIZE 32 ) Global_CMakeList.txt
- const int scaleModSize = 28; simple-real-numbers-serial.cpp
- add parameters.SetFirstModSize(scaleModSize); under this line to restrict the the first moduli to be within 27 bit
terminate called after throwing an instance of 'lbcrypto::OpenFHEException'
what(): /home/jianming/work/CROSS_Prj/openfhe-development/src/pke/lib/scheme/gen-cryptocontext-params-validation.cpp:l.50:validateParametersForCryptocontext(): scalingModSize should be less than 28
I am able to make it work by restricting the scaleModSize to 27 bit
New 3. const int scaleModSize = 27; simple-real-numbers-serial.cpp
Albeit this makes it working (greatly appreciate the help!) – might I seek confirmation whether did I do the correct things? I’m little concerned as I get 27-bit instead of desired 28-bits 
All steps are correct. NATIVE_SIZE=32 can be set in the command line instead of changing the CmakeList.txt file (you can run cmake -DNATIVE_SIZE=32 ..
).
27 is because in CKKS the moduli are chosen around 2^27 (some are below and others are above). It is done to minimize the deterministic rescaling error. This is why 59 is the maximum allowed scaleModSize in the 64-bit case, when moduli up to 60 bits are supported.
1 Like