Lib-benchmark fails to run when setting NATIVE_INT as 32 globally

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

  1. set AUXMODSIZE as 28,
  2. NATIVE_SIZE in CMakeLists.txt as 32.
  3. 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?