mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-18 08:31:31 -05:00
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>
89 lines
2.9 KiB
C++
89 lines
2.9 KiB
C++
// Part of the Concrete Compiler Project, under the BSD3 License with Zama
|
|
// Exceptions. See
|
|
// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt
|
|
// for license information.
|
|
|
|
#include "concretelang/Runtime/context.h"
|
|
#include "concretelang/Common/Error.h"
|
|
#include "concretelang/Common/Keysets.h"
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
|
|
namespace mlir {
|
|
namespace concretelang {
|
|
|
|
FFT::FFT(size_t polynomial_size)
|
|
: fft(nullptr), polynomial_size(polynomial_size) {
|
|
fft = (struct Fft *)aligned_alloc(CONCRETE_FFT_ALIGN, CONCRETE_FFT_SIZE);
|
|
concrete_cpu_construct_concrete_fft(fft, polynomial_size);
|
|
}
|
|
|
|
FFT::FFT(FFT &&other) : fft(other.fft), polynomial_size(other.polynomial_size) {
|
|
other.fft = nullptr;
|
|
}
|
|
|
|
FFT::~FFT() {
|
|
if (fft != nullptr) {
|
|
concrete_cpu_destroy_concrete_fft(fft);
|
|
free(fft);
|
|
}
|
|
}
|
|
|
|
RuntimeContext::RuntimeContext(ServerKeyset serverKeyset)
|
|
: serverKeyset(serverKeyset) {
|
|
{
|
|
|
|
// Initialize for each bootstrap key the fourier one
|
|
for (size_t i = 0; i < serverKeyset.lweBootstrapKeys.size(); i++) {
|
|
|
|
auto bsk = serverKeyset.lweBootstrapKeys[i];
|
|
auto info = bsk.getInfo().asReader();
|
|
|
|
size_t decomposition_level_count = info.getParams().getLevelCount();
|
|
size_t decomposition_base_log = info.getParams().getBaseLog();
|
|
size_t glwe_dimension = info.getParams().getGlweDimension();
|
|
size_t polynomial_size = info.getParams().getPolynomialSize();
|
|
size_t input_lwe_dimension = info.getParams().getInputLweDimension();
|
|
|
|
// Create the FFT
|
|
FFT fft(polynomial_size);
|
|
|
|
// Allocate scratch for key conversion
|
|
size_t scratch_size;
|
|
size_t scratch_align;
|
|
concrete_cpu_bootstrap_key_convert_u64_to_fourier_scratch(
|
|
&scratch_size, &scratch_align, fft.fft);
|
|
auto scratch = (uint8_t *)aligned_alloc(scratch_align, scratch_size);
|
|
|
|
// Allocate the fourier_bootstrap_key
|
|
auto fourier_data = std::make_shared<std::vector<double>>();
|
|
fourier_data->resize(bsk.getSize());
|
|
auto bsk_data = bsk.getRawPtr();
|
|
|
|
// Convert bootstrap_key to the fourier domain
|
|
concrete_cpu_bootstrap_key_convert_u64_to_fourier(
|
|
bsk_data, fourier_data->data(), decomposition_level_count,
|
|
decomposition_base_log, glwe_dimension, polynomial_size,
|
|
input_lwe_dimension, fft.fft, scratch, scratch_size);
|
|
|
|
// Store the fourier_bootstrap_key in the context
|
|
fourier_bootstrap_keys.push_back(fourier_data);
|
|
ffts.push_back(std::move(fft));
|
|
free(scratch);
|
|
}
|
|
|
|
#ifdef CONCRETELANG_CUDA_SUPPORT
|
|
assert(cudaGetDeviceCount(&num_devices) == cudaSuccess);
|
|
bsk_gpu.resize(num_devices, nullptr);
|
|
ksk_gpu.resize(num_devices, nullptr);
|
|
for (int i = 0; i < num_devices; ++i) {
|
|
bsk_gpu_mutex.push_back(std::make_unique<std::mutex>());
|
|
ksk_gpu_mutex.push_back(std::make_unique<std::mutex>());
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
} // namespace concretelang
|
|
} // namespace mlir
|