Cingulata icon indicating copy to clipboard operation
Cingulata copied to clipboard

"Select a parameter set in CinguParam" ?

Open FredericGava opened this issue 3 years ago • 4 comments

Hi,

when compiling a program of sorting (from thfe) using docker run -it --rm -v $(pwd):/cingu cingulata:bfv

I get the following message :

[ 63%] Generating fhe_params.xml TEST_NAME=bfv-wifsSort MODE=static The parameters with lwe-estimator commit fb7deba are not in CinguParam. DESIRED_PARAMS=25_bkz_sieve_128_2 No parameter found with static mode. Automatically switch to interactive mode. MODE=interactive

  1. Select a parameter set in CinguParam (using LWE-Estimator commit=3019847)
  2. Quit Please enter your choice: 1 INTERACTIVE_CHOICE= COMMIT_ID=3019847 Invalid choice. You can generate suitable parameter sets using CinguParam module.

And then the execution using bvf mode is very very slow (2 minutes for sorting 4 integers with 10 cores!)

Thanks Frédéric Gava

The cxx file :

/* local includes */ //#include

//#include <bit_exec/decorator/attach.hxx> //#include <bit_exec/decorator/depth.hxx> //#include <bit_exec/decorator/stat.hxx> #include <bit_exec/tracker.hxx> #include <ci_context.hxx> #include <ci_fncs.hxx> #include <ci_int.hxx> #include <int_op_gen/mult_depth.hxx>

/* namespaces */ using namespace std; using namespace cingulata;

int main() {

CiContext::set_config(make_shared<BitTracker>(), make_shared<IntOpGenDepth>());

vector<CiInt> a(list_size, CiInt::u8); CiInt t{CiInt::u8}; CiBit swap;

for (int i = 0; i < list_size; ++i) a[i].read("a_" + to_string(i));

for (int i = 0; i < list_size-1; ++i) { for (int j = i+1; j < list_size; ++j) { swap = a[i] > a[j]; t = select(swap, a[i], a[j]); a[i] = select(swap, a[j], a[i]); a[j] = t; } }

for (int i = 0; i < list_size; ++i) a[i].write("r_" + to_string(i));

/* Export to file the "tracked" circuit */ CiContext::get_bit_exec_t<BitTracker>()->export_blif(blif_name, "wifsSort"); }

and the Cmake file

cmake_minimum_required(VERSION 3.0)

set(TEST_NAME bfv-wifsSort)

set(SRCS wifsSort.cxx) set(LIST_SIZE 4) set(BLIF_NAME ${TEST_NAME}.blif) set(BLOP_NAME ${TEST_NAME}-opt.blif)

add_compile_options(-Dlist_size=${LIST_SIZE} -Dblif_name="${BLIF_NAME}")

set(GEN_NAME ${TEST_NAME}-gen)

add_executable(${GEN_NAME} ${SRCS})

target_link_libraries(${GEN_NAME} common)

add_custom_command(OUTPUT ${BLIF_NAME} COMMAND ./${GEN_NAME} DEPENDS ${GEN_NAME})

add_custom_command(OUTPUT ${BLOP_NAME} COMMAND python3 ${OPTIM_DIR}/abc_optimize.py -i ${BLIF_NAME} -o ${BLOP_NAME} -v DEPENDS abc ${BLIF_NAME})

set(XML_PARAMS fhe_params.xml) set(MUL_DEPTH_SCRIPT ${OPTIM_DIR}/graph_info.py)

add_custom_command(OUTPUT ${XML_PARAMS} COMMAND bash ${SCRIPT_DIR}/selectParams.sh ${TEST_NAME} python3 ${MUL_DEPTH_SCRIPT} ${BLOP_NAME} --mult_depth_max ${MODEL} ${MIN_SECU} ${POLITIC} DEPENDS ${BLOP_NAME})

add_custom_target(${TEST_NAME} ALL DEPENDS ${XML_PARAMS} runtime)

set(APPS_DIR ${CMAKE_BINARY_DIR}/apps) set(CIRCUIT ${BLOP_NAME}) configure_file("run.sh.in" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/run.sh" @ONLY) file(COPY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/run.sh" DESTINATION . FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) file(COPY "README.md" DESTINATION .) file(COPY "data.txt" DESTINATION .)

FredericGava avatar Jun 25 '21 14:06 FredericGava

To complete. Now, with the following code :

void bubbleSort(vector<CiInt> a, int size) { CiInt t{CiInt::u8}; CiBit swap; for (int i = 0; i < size-1; ++i) { for (int j = i+1; j < size; ++j) { swap = a[i] > a[j]; t = select(swap, a[i], a[j]); a[i] = select(swap, a[j], a[i]); a[j] = t; } } }

int main() {

CiContext::set_config(make_shared<BitTracker>(), make_shared<IntOpGenDepth>());

vector<CiInt> a(list_size, CiInt::u8);

for (int i = 0; i < list_size; ++i) a[i].read("a_" + to_string(i));

bubbleSort(a,list_size);

....

I got :

[ 61%] Generating bfv-wifsSort.blif [ 62%] Generating bfv-wifsSort-opt.blif Input circuit x depth 0, x gates 216, + gates 426 Executing optimization command "" x depth 0, x gates 0, + gates 0 * Executing optimization command "resyn2" x depth 0, x gates 0, + gates 0 Executing optimization command "resyn2rs" x depth 0, x gates 0, + gates 0 Executing optimization command "recadd3;resyn2rs" !!! ABC optimization: something went wrong !!! [ 63%] Generating fhe_params.xml TEST_NAME=bfv-wifsSort MODE=static The parameters with lwe-estimator commit fb7deba are not in CinguParam. DESIRED_PARAMS=0_bkz_sieve_128_2 STATIC_CHOICE=0_bkz_sieve_128_2 (using LWE-Estimator commit=3019847) Parameter set automatically found in CinguParam: '0_bkz_sieve_128_2' -> '/cingu/build_bfv/tests/bfv/wifsSort/fhe_params.xml'

Did I miss something?

Thanks in advance, Frédéric Gava

FredericGava avatar Jun 27 '21 19:06 FredericGava

Executing optimization command "resyn2rs" x depth 0, x gates 0, + gates 0

In your second example, you are trying to sort a plaintext vector. That's why the multiplicative depth is 0

ssmiler avatar Jun 29 '21 09:06 ssmiler

In the first example the multiplicative depth is 25 and it's huge! BFV schemes are suited for small depth circuits where you can batch data in a SIMD way. You shall really use the TFHE scheme for sorting encrypted number.

ssmiler avatar Jun 29 '21 09:06 ssmiler

Thanks. By replacing "void bubbleSort(vector arr, int size)" by "void bubbleSort(vector<CiInt> &arr, int size)", It works. I was thinking that there is a kind of "flow analysis" inside Cingulata so that I can write generic methods and Cingulata will be able to find that the used vector is not a plaintext one.

But I still get this strange error message :

62%] Generating bfv-wifsSort-opt.blif Input circuit x depth 25, x gates 216, + gates 426 Executing optimization command "" x depth 25, x gates 162, + gates 186 * Executing optimization command "resyn2" x depth 40, x gates 588, + gates 9 Executing optimization command "resyn2rs" x depth 45, x gates 611, + gates 4 Executing optimization command "recadd3;resyn2rs" x depth 42, x gates 791, + gates 4 [ 63%] Generating fhe_params.xml TEST_NAME=bfv-wifsSort MODE=static The parameters with lwe-estimator commit fb7deba are not in CinguParam. DESIRED_PARAMS=25_bkz_sieve_128_2 No parameter found with static mode. Automatically switch to interactive mode. MODE=interactive

  1. Select a parameter set in CinguParam (using LWE-Estimator commit=3019847)
  2. Quit Please enter your choice: 1 INTERACTIVE_CHOICE= COMMIT_ID=3019847 Invalid choice. You can generate suitable parameter sets using CinguParam module. [ 63%] Built target bfv-wifsSort

Thanks in advance, Frédéric

ps: For TFHE, I will wait the thfe=>bliff output

FredericGava avatar Jun 29 '21 11:06 FredericGava