Files
concrete/tools/concrete-protocol/CMakeLists.txt
Alexandre Péré e8ef48ffd8 feat(compiler): introduce concrete-protocol
This commit:
 + Adds support for a protocol which enables inter-op between concrete,
   tfhe-rs and potentially other contributors to the fhe ecosystem.
 + Gets rid of hand-made serialization in the compiler, and
   client/server libs.
 + Refactors client/server libs to allow more pre/post processing of
   circuit inputs/outputs.

The protocol is supported by a definition in the shape of a capnp file,
which defines different types of objects among which:
 + ProgramInfo object, which is a precise description of a set of fhe
   circuit coming from the same compilation (understand function type
   information), and the associated key set.
 + *Key objects, which represent secret/public keys used to
   encrypt/execute fhe circuits.
 + Value object, which represent values that can be transferred between
   client and server to support calls to fhe circuits.

The hand-rolled serialization that was previously used is completely
dropped in favor of capnp in the whole codebase.

The client/server libs, are refactored to introduce a modular design for
pre-post processing. Reading the ProgramInfo file associated with a
compilation, the client and server libs assemble a pipeline of
transformers (functions) for pre and post processing of values coming in
and out of a circuit. This design properly decouples various aspects of
the processing, and allows these capabilities to be safely extended.

In practice this commit includes the following:
 + Defines the specification in a concreteprotocol package
 + Integrate the compilation of this package as a compiler dependency
   via cmake
 + Modify the compiler to use the Encodings objects defined in the
   protocol
 + Modify the compiler to emit ProgramInfo files as compilation
   artifact, and gets rid of the bloated ClientParameters.
 + Introduces a new Common library containing the functionalities shared
   between the compiler and the client/server libs.
 + Introduces a functional pre-post processing pipeline to this common
   library
 + Modify the client/server libs to support loading ProgramInfo objects,
   and calling circuits using Value messages.
 + Drops support of JIT.
 + Drops support of C-api.
 + Drops support of Rust bindings.

Co-authored-by: Nikita Frolov <nf@mkmks.org>
2023-11-09 17:09:04 +01:00

68 lines
3.0 KiB
CMake

cmake_minimum_required(VERSION 3.17)
project(concrete-protocol CXX)
include(ExternalProject)
set(CAPNP_VERSION 1.0.1)
set(CAPNP_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/capnp_bin_dir)
set(CAPNP_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/capnp_src_dir)
set(CAPNP_LIB_DIR ${CAPNP_BIN_DIR}/c++/src)
set(CAPNP_INCLUDE_DIR ${CAPNP_SRC_DIR}/c++/src)
file(MAKE_DIRECTORY "${CAPNP_BIN_DIR}")
set(CAPNP_CMD ${CAPNP_BIN_DIR}/c++/src/capnp/capnp)
set(CAPNP_LIBRARY libcapnp.a)
set(CAPNP_JSON_LIBRARY libcapnp-json.a)
set(KJ_LIBRARY libkj.a)
ExternalProject_Add(
capnp_repo
GIT_REPOSITORY https://github.com/capnproto/capnproto.git
GIT_TAG release-${CAPNP_VERSION}
GIT_SUBMODULES_RECURSE ON
GIT_PROGRESS TRUE
BUILD_ALWAYS 1
INSTALL_COMMAND cp ${CAPNP_LIB_DIR}/capnp/${CAPNP_LIBRARY} ${CAPNP_LIB_DIR}/capnp/${CAPNP_JSON_LIBRARY} ${CAPNP_LIB_DIR}/kj/${KJ_LIBRARY} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
BINARY_DIR ${CAPNP_BIN_DIR}
SOURCE_DIR ${CAPNP_SRC_DIR}
CMAKE_ARGS -Dcapnp_BUILD_TESTS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CAPNP_LIBRARY} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CAPNP_JSON_LIBRARY} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${KJ_LIBRARY} ${CAPNP_CMD}
)
add_library(kj STATIC IMPORTED GLOBAL)
set_property(TARGET kj PROPERTY IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${KJ_LIBRARY})
add_dependencies(kj capnp_repo)
add_library(capnp STATIC IMPORTED GLOBAL)
set_property(TARGET capnp PROPERTY IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CAPNP_LIBRARY})
add_dependencies(capnp capnp_repo)
add_library(capnp-json STATIC IMPORTED GLOBAL)
set_property(TARGET capnp-json PROPERTY IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CAPNP_JSON_LIBRARY})
add_dependencies(capnp-json capnp_repo)
add_executable(capnpc IMPORTED)
set_property(TARGET capnpc PROPERTY IMPORTED_LOCATION ${CAPNP_CMD})
add_dependencies(capnpc capnp_repo)
get_filename_component(CONCRETE_PROTOCOL_CAPNP_FILE "src/concrete-protocol.capnp" ABSOLUTE)
get_filename_component(CONCRETE_PROTOCOL_FOLDER "${CONCRETE_PROTOCOL_CAPNP_FILE}" DIRECTORY)
set(GENERATED_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
file(MAKE_DIRECTORY "${GENERATED_DIRECTORY}")
get_filename_component(CAPNP_GENERATED_CPP "${GENERATED_DIRECTORY}/concrete-protocol.capnp.c++" ABSOLUTE)
get_filename_component(CAPNP_GENERATED_HDR "${GENERATED_DIRECTORY}/concrete-protocol.capnp.h" ABSOLUTE)
set_source_files_properties(${CAPNP_GENERATED_CPP} PROPERTIES GENERATED TRUE)
set_source_files_properties(${CAPNP_GENERATED_HDR} PROPERTIES GENERATED TRUE)
add_custom_command(
OUTPUT ${CAPNP_GENERATED_CPP} ${CAPNP_GENERATED_HDR}
COMMAND ${CAPNP_CMD} compile --src-prefix=${CONCRETE_PROTOCOL_FOLDER} --import-path=${CAPNP_INCLUDE_DIR} --output=${CAPNP_CMD}c-c++:${GENERATED_DIRECTORY} ${CONCRETE_PROTOCOL_CAPNP_FILE} DEPENDS capnpc
)
include_directories(${CAPNP_INCLUDE_DIR})
add_library(concrete-protocol STATIC
${CAPNP_GENERATED_CPP}
${CAPNP_GENERATED_HDR})
target_link_libraries(concrete-protocol PUBLIC capnp capnp-json kj)