Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Select a parameter set in CinguParam" ? #40

Open
FredericGava opened this issue Jun 25, 2021 · 4 comments
Open

"Select a parameter set in CinguParam" ? #40

FredericGava opened this issue Jun 25, 2021 · 4 comments

Comments

@FredericGava
Copy link

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(),
make_shared());

vector 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()->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
Copy link
Author

To complete. Now, with the following code :

void bubbleSort(vector 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(),
make_shared());

vector 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

@ssmiler
Copy link
Collaborator

ssmiler commented Jun 29, 2021

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
Copy link
Collaborator

ssmiler commented Jun 29, 2021

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.

@FredericGava
Copy link
Author

Thanks. By replacing "void bubbleSort(vector arr, int size)" by "void bubbleSort(vector &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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants