mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-10 04:35:03 -05:00
docs: use consistent style for comment blocks
prefix comment blocks with ///
This commit is contained in:
@@ -17,13 +17,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// C wrapper of the mlir::concretelang::LambdaArgument
|
||||
/// C wrapper of the mlir::concretelang::LambdaArgument
|
||||
struct lambdaArgument {
|
||||
std::shared_ptr<mlir::concretelang::LambdaArgument> ptr;
|
||||
};
|
||||
typedef struct lambdaArgument lambdaArgument;
|
||||
|
||||
// Hold a list of lambdaArgument to represent execution arguments
|
||||
/// Hold a list of lambdaArgument to represent execution arguments
|
||||
struct executionArguments {
|
||||
lambdaArgument *data;
|
||||
size_t size;
|
||||
@@ -136,13 +136,13 @@ evaluationKeysUnserialize(const std::string &buffer);
|
||||
MLIR_CAPI_EXPORTED std::string evaluationKeysSerialize(
|
||||
concretelang::clientlib::EvaluationKeys &evaluationKeys);
|
||||
|
||||
// Parse then print a textual representation of an MLIR module
|
||||
/// Parse then print a textual representation of an MLIR module
|
||||
MLIR_CAPI_EXPORTED std::string roundTrip(const char *module);
|
||||
|
||||
// Terminate parallelization
|
||||
/// Terminate parallelization
|
||||
MLIR_CAPI_EXPORTED void terminateParallelization();
|
||||
|
||||
// Create a lambdaArgument from a tensor of different data types
|
||||
/// Create a lambdaArgument from a tensor of different data types
|
||||
MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU8(
|
||||
std::vector<uint8_t> data, std::vector<int64_t> dimensions);
|
||||
MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU16(
|
||||
@@ -151,22 +151,22 @@ MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU32(
|
||||
std::vector<uint32_t> data, std::vector<int64_t> dimensions);
|
||||
MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU64(
|
||||
std::vector<uint64_t> data, std::vector<int64_t> dimensions);
|
||||
// Create a lambdaArgument from a scalar
|
||||
/// Create a lambdaArgument from a scalar
|
||||
MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromScalar(uint64_t scalar);
|
||||
// Check if a lambdaArgument holds a tensor
|
||||
/// Check if a lambdaArgument holds a tensor
|
||||
MLIR_CAPI_EXPORTED bool lambdaArgumentIsTensor(lambdaArgument &lambda_arg);
|
||||
// Get tensor data from lambdaArgument
|
||||
/// Get tensor data from lambdaArgument
|
||||
MLIR_CAPI_EXPORTED std::vector<uint64_t>
|
||||
lambdaArgumentGetTensorData(lambdaArgument &lambda_arg);
|
||||
// Get tensor dimensions from lambdaArgument
|
||||
/// Get tensor dimensions from lambdaArgument
|
||||
MLIR_CAPI_EXPORTED std::vector<int64_t>
|
||||
lambdaArgumentGetTensorDimensions(lambdaArgument &lambda_arg);
|
||||
// Check if a lambdaArgument holds a scalar
|
||||
/// Check if a lambdaArgument holds a scalar
|
||||
MLIR_CAPI_EXPORTED bool lambdaArgumentIsScalar(lambdaArgument &lambda_arg);
|
||||
// Get scalar value from lambdaArgument
|
||||
/// Get scalar value from lambdaArgument
|
||||
MLIR_CAPI_EXPORTED uint64_t lambdaArgumentGetScalar(lambdaArgument &lambda_arg);
|
||||
|
||||
// Compile the textual representation of MLIR modules to a library.
|
||||
/// Compile the textual representation of MLIR modules to a library.
|
||||
MLIR_CAPI_EXPORTED std::string library(std::string libraryPath,
|
||||
std::vector<std::string> modules);
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ using tensor1_out = std::vector<scalar_out>;
|
||||
using tensor2_out = std::vector<std::vector<scalar_out>>;
|
||||
using tensor3_out = std::vector<std::vector<std::vector<scalar_out>>>;
|
||||
|
||||
/// Low-level class to create the client side view of a FHE function.
|
||||
class ClientLambda {
|
||||
/// Low-level class to create the client side view of a FHE function.
|
||||
public:
|
||||
virtual ~ClientLambda() = default;
|
||||
|
||||
|
||||
@@ -104,11 +104,11 @@ static inline bool operator==(const EncryptionGate &lhs,
|
||||
}
|
||||
|
||||
struct CircuitGateShape {
|
||||
// Width of the scalar value
|
||||
/// Width of the scalar value
|
||||
size_t width;
|
||||
// Dimensions of the tensor, empty if scalar
|
||||
/// Dimensions of the tensor, empty if scalar
|
||||
std::vector<int64_t> dimensions;
|
||||
// Size of the buffer containing the tensor
|
||||
/// Size of the buffer containing the tensor
|
||||
size_t size;
|
||||
};
|
||||
static inline bool operator==(const CircuitGateShape &lhs,
|
||||
|
||||
@@ -23,11 +23,11 @@ using concretelang::error::StringError;
|
||||
|
||||
class PublicArguments;
|
||||
|
||||
/// Temporary object used to hold and encrypt parameters before calling a
|
||||
/// ClientLambda. Use preferably TypeClientLambda and serializeCall(Args...).
|
||||
/// Otherwise convert it to a PublicArguments and use
|
||||
/// serializeCall(PublicArguments, KeySet).
|
||||
class EncryptedArguments {
|
||||
/// Temporary object used to hold and encrypt parameters before calling a
|
||||
/// ClientLambda. Use preferably TypeClientLambda and serializeCall(Args...).
|
||||
/// Otherwise convert it to a PublicArguments and use
|
||||
/// serializeCall(PublicArguments, KeySet).
|
||||
public:
|
||||
EncryptedArguments() : currentPos(0) {}
|
||||
|
||||
@@ -64,18 +64,18 @@ public:
|
||||
RuntimeContext runtimeContext);
|
||||
|
||||
/// Check that all arguments as been pushed.
|
||||
/// TODO: Remove public method here
|
||||
// TODO: Remove public method here
|
||||
outcome::checked<void, StringError> checkAllArgs(KeySet &keySet);
|
||||
|
||||
public:
|
||||
// Add a uint64_t scalar argument.
|
||||
/// Add a uint64_t scalar argument.
|
||||
outcome::checked<void, StringError> pushArg(uint64_t arg, KeySet &keySet);
|
||||
|
||||
/// Add a vector-tensor argument.
|
||||
outcome::checked<void, StringError> pushArg(std::vector<uint8_t> arg,
|
||||
KeySet &keySet);
|
||||
|
||||
// Add a 1D tensor argument with data and size of the dimension.
|
||||
/// Add a 1D tensor argument with data and size of the dimension.
|
||||
template <typename T>
|
||||
outcome::checked<void, StringError> pushArg(const T *data, int64_t dim1,
|
||||
KeySet &keySet) {
|
||||
@@ -114,14 +114,14 @@ public:
|
||||
|
||||
// Generalize by computing shape by template recursion
|
||||
|
||||
// Set a argument at the given pos as a 1D tensor of T.
|
||||
/// Set a argument at the given pos as a 1D tensor of T.
|
||||
template <typename T>
|
||||
outcome::checked<void, StringError> pushArg(T *data, int64_t dim1,
|
||||
KeySet &keySet) {
|
||||
return pushArg<T>(data, llvm::ArrayRef<int64_t>(&dim1, 1), keySet);
|
||||
}
|
||||
|
||||
// Set a argument at the given pos as a tensor of T.
|
||||
/// Set a argument at the given pos as a tensor of T.
|
||||
template <typename T>
|
||||
outcome::checked<void, StringError>
|
||||
pushArg(T *data, llvm::ArrayRef<int64_t> shape, KeySet &keySet) {
|
||||
@@ -133,8 +133,8 @@ public:
|
||||
llvm::ArrayRef<int64_t> shape,
|
||||
KeySet &keySet);
|
||||
|
||||
// Recursive case for scalars: extract first scalar argument from
|
||||
// parameter pack and forward rest
|
||||
/// Recursive case for scalars: extract first scalar argument from
|
||||
/// parameter pack and forward rest
|
||||
template <typename Arg0, typename... OtherArgs>
|
||||
outcome::checked<void, StringError> pushArgs(KeySet &keySet, Arg0 arg0,
|
||||
OtherArgs... others) {
|
||||
@@ -142,8 +142,8 @@ public:
|
||||
return pushArgs(keySet, others...);
|
||||
}
|
||||
|
||||
// Recursive case for tensors: extract pointer and size from
|
||||
// parameter pack and forward rest
|
||||
/// Recursive case for tensors: extract pointer and size from
|
||||
/// parameter pack and forward rest
|
||||
template <typename Arg0, typename... OtherArgs>
|
||||
outcome::checked<void, StringError>
|
||||
pushArgs(KeySet &keySet, Arg0 *arg0, size_t size, OtherArgs... others) {
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
return pushArgs(keySet, others...);
|
||||
}
|
||||
|
||||
// Terminal case of pushArgs
|
||||
/// Terminal case of pushArgs
|
||||
outcome::checked<void, StringError> pushArgs(KeySet &keySet) {
|
||||
return checkAllArgs(keySet);
|
||||
}
|
||||
@@ -160,11 +160,11 @@ private:
|
||||
outcome::checked<void, StringError> checkPushTooManyArgs(KeySet &keySet);
|
||||
|
||||
private:
|
||||
// Position of the next pushed argument
|
||||
/// Position of the next pushed argument
|
||||
size_t currentPos;
|
||||
std::vector<void *> preparedArgs;
|
||||
|
||||
// Store buffers of ciphertexts
|
||||
/// Store buffers of ciphertexts
|
||||
std::vector<TensorData> ciphertextBuffers;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,43 +32,43 @@ public:
|
||||
~KeySet();
|
||||
KeySet(KeySet &other) = delete;
|
||||
|
||||
// allocate a KeySet according the ClientParameters.
|
||||
/// allocate a KeySet according the ClientParameters.
|
||||
static outcome::checked<std::unique_ptr<KeySet>, StringError>
|
||||
generate(ClientParameters ¶ms, uint64_t seed_msb, uint64_t seed_lsb);
|
||||
|
||||
// isInputEncrypted return true if the input at the given pos is encrypted.
|
||||
/// isInputEncrypted return true if the input at the given pos is encrypted.
|
||||
bool isInputEncrypted(size_t pos);
|
||||
|
||||
// getInputLweSecretKeyParam returns the parameters of the lwe secret key for
|
||||
// the input at the given `pos`.
|
||||
// The input must be encrupted
|
||||
/// getInputLweSecretKeyParam returns the parameters of the lwe secret key for
|
||||
/// the input at the given `pos`.
|
||||
/// The input must be encrupted
|
||||
LweSecretKeyParam getInputLweSecretKeyParam(size_t pos) {
|
||||
auto gate = inputGate(pos);
|
||||
auto inputSk = this->secretKeys.find(gate.encryption->secretKeyID);
|
||||
return inputSk->second.first;
|
||||
}
|
||||
|
||||
// getOutputLweSecretKeyParam returns the parameters of the lwe secret key for
|
||||
// the given output.
|
||||
/// getOutputLweSecretKeyParam returns the parameters of the lwe secret key
|
||||
/// for the given output.
|
||||
LweSecretKeyParam getOutputLweSecretKeyParam(size_t pos) {
|
||||
auto gate = outputGate(pos);
|
||||
auto outputSk = this->secretKeys.find(gate.encryption->secretKeyID);
|
||||
return outputSk->second.first;
|
||||
}
|
||||
|
||||
// allocate a lwe ciphertext buffer for the argument at argPos, set the size
|
||||
// of the allocated buffer.
|
||||
/// allocate a lwe ciphertext buffer for the argument at argPos, set the size
|
||||
/// of the allocated buffer.
|
||||
outcome::checked<void, StringError>
|
||||
allocate_lwe(size_t argPos, uint64_t **ciphertext, uint64_t &size);
|
||||
|
||||
// encrypt the input to the ciphertext for the argument at argPos.
|
||||
/// encrypt the input to the ciphertext for the argument at argPos.
|
||||
outcome::checked<void, StringError>
|
||||
encrypt_lwe(size_t argPos, uint64_t *ciphertext, uint64_t input);
|
||||
|
||||
// isOuputEncrypted return true if the output at the given pos is encrypted.
|
||||
/// isOuputEncrypted return true if the output at the given pos is encrypted.
|
||||
bool isOutputEncrypted(size_t pos);
|
||||
|
||||
// decrypt the ciphertext to the output for the argument at argPos.
|
||||
/// decrypt the ciphertext to the output for the argument at argPos.
|
||||
outcome::checked<void, StringError>
|
||||
decrypt_lwe(size_t argPos, uint64_t *ciphertext, uint64_t &output);
|
||||
|
||||
|
||||
@@ -32,9 +32,10 @@ namespace clientlib {
|
||||
using concretelang::error::StringError;
|
||||
|
||||
class EncryptedArguments;
|
||||
|
||||
/// PublicArguments will be sended to the server. It includes encrypted
|
||||
/// arguments and public keys.
|
||||
class PublicArguments {
|
||||
/// PublicArguments will be sended to the server. It includes encrypted
|
||||
/// arguments and public keys.
|
||||
public:
|
||||
PublicArguments(const ClientParameters &clientParameters,
|
||||
std::vector<void *> &&preparedArgs,
|
||||
@@ -56,13 +57,13 @@ private:
|
||||
|
||||
ClientParameters clientParameters;
|
||||
std::vector<void *> preparedArgs;
|
||||
// Store buffers of ciphertexts
|
||||
/// Store buffers of ciphertexts
|
||||
std::vector<TensorData> ciphertextBuffers;
|
||||
};
|
||||
|
||||
/// PublicResult is a result of a ServerLambda call which contains encrypted
|
||||
/// results.
|
||||
struct PublicResult {
|
||||
/// PublicResult is a result of a ServerLambda call which contains encrypted
|
||||
/// results.
|
||||
|
||||
PublicResult(const ClientParameters &clientParameters,
|
||||
std::vector<TensorData> buffers = {})
|
||||
|
||||
@@ -52,10 +52,10 @@ PlaintextType convertPlaintextTypeFromPType(mlir::MLIRContext *context,
|
||||
return PlaintextType::get(context, type.getP() + 1);
|
||||
}
|
||||
|
||||
// convertPlaintextTypeFromType create a plaintext type according the
|
||||
// precision of the given type argument. The type should be a GLWECipherText
|
||||
// (if operand is not yet lowered) or a LWECipherTextType (if operand is
|
||||
// already lowered).
|
||||
/// convertPlaintextTypeFromType create a plaintext type according the
|
||||
/// precision of the given type argument. The type should be a GLWECipherText
|
||||
/// (if operand is not yet lowered) or a LWECipherTextType (if operand is
|
||||
/// already lowered).
|
||||
PlaintextType convertPlaintextTypeFromType(mlir::MLIRContext *context,
|
||||
mlir::Type &type) {
|
||||
auto glwe = type.dyn_cast_or_null<GLWECipherTextType>();
|
||||
@@ -76,10 +76,10 @@ CleartextType convertCleartextTypeFromPType(mlir::MLIRContext *context,
|
||||
return CleartextType::get(context, type.getP() + 1);
|
||||
}
|
||||
|
||||
// convertCleartextTypeFromType create a cleartext type according the
|
||||
// precision of the given type argument. The type should be a GLWECipherText
|
||||
// (if operand is not yet lowered) or a LWECipherTextType (if operand is
|
||||
// already lowered).
|
||||
/// convertCleartextTypeFromType create a cleartext type according the
|
||||
/// precision of the given type argument. The type should be a GLWECipherText
|
||||
/// (if operand is not yet lowered) or a LWECipherTextType (if operand is
|
||||
/// already lowered).
|
||||
CleartextType convertCleartextTypeFromType(mlir::MLIRContext *context,
|
||||
mlir::Type &type) {
|
||||
auto glwe = type.dyn_cast_or_null<GLWECipherTextType>();
|
||||
|
||||
@@ -24,11 +24,10 @@ bool verifyEncryptedIntegerAndIntegerInputsConsistency(Operation &op,
|
||||
EncryptedIntegerType &a,
|
||||
IntegerType &b);
|
||||
|
||||
/** Shared error message for all ApplyLookupTable variant Op (several Dialect)
|
||||
* E.g. FHE.apply_lookup_table(input, lut)
|
||||
* Message when the lut tensor has an invalid size,
|
||||
* i.e. it cannot accomodate the input elements bitwidth
|
||||
*/
|
||||
/// Shared error message for all ApplyLookupTable variant Op (several Dialect)
|
||||
/// E.g. FHE.apply_lookup_table(input, lut)
|
||||
/// Message when the lut tensor has an invalid size,
|
||||
/// i.e. it cannot accomodate the input elements bitwidth
|
||||
template <class Op>
|
||||
void emitErrorBadLutSize(Op &op, std::string lutName, std::string inputName,
|
||||
int expectedSize, int bitWidth) {
|
||||
|
||||
@@ -19,7 +19,7 @@ extern void *dl_handle;
|
||||
struct WorkFunctionRegistry;
|
||||
extern WorkFunctionRegistry *node_level_work_function_registry;
|
||||
|
||||
// Recover the name of the work function
|
||||
/// Recover the name of the work function
|
||||
static inline const char *_dfr_get_function_name_from_address(void *fn) {
|
||||
Dl_info info;
|
||||
|
||||
@@ -38,8 +38,8 @@ static inline wfnptr _dfr_get_function_pointer_from_name(const char *fn_name) {
|
||||
return (wfnptr)ptr;
|
||||
}
|
||||
|
||||
// Determine where new task should run. For now just round-robin
|
||||
// distribution - TODO: optimise.
|
||||
/// Determine where new task should run. For now just round-robin
|
||||
/// distribution - TODO: optimise.
|
||||
static inline size_t _dfr_find_next_execution_locality() {
|
||||
static size_t num_nodes = hpx::get_num_localities().get();
|
||||
static std::atomic<std::size_t> next_locality{0};
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef struct RuntimeContext {
|
||||
|
||||
RuntimeContext() {}
|
||||
|
||||
// Ensure that the engines map is not copied
|
||||
/// Ensure that the engines map is not copied
|
||||
RuntimeContext(const RuntimeContext &ctx)
|
||||
: evaluationKeys(ctx.evaluationKeys) {}
|
||||
RuntimeContext(const RuntimeContext &&other)
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt
|
||||
// for license information.
|
||||
|
||||
/**
|
||||
Define the API exposed to the compiler for code generation.
|
||||
*/
|
||||
/// Define the API exposed to the compiler for code generation.
|
||||
|
||||
#ifndef CONCRETELANG_DFR_RUNTIME_API_H
|
||||
#define CONCRETELANG_DFR_RUNTIME_API_H
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
protected:
|
||||
ClientParameters clientParameters;
|
||||
void *(*func)(void *...);
|
||||
// Retain module and open shared lib alive
|
||||
/// Retain module and open shared lib alive
|
||||
std::shared_ptr<DynamicModule> module;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
namespace mlir {
|
||||
namespace concretelang {
|
||||
|
||||
// Compilation context that acts as the root owner of LLVM and MLIR
|
||||
// data structures directly and indirectly referenced by artefacts
|
||||
// produced by the `CompilerEngine`.
|
||||
/// Compilation context that acts as the root owner of LLVM and MLIR
|
||||
/// data structures directly and indirectly referenced by artefacts
|
||||
/// produced by the `CompilerEngine`.
|
||||
class CompilationContext {
|
||||
public:
|
||||
CompilationContext();
|
||||
@@ -68,8 +68,8 @@ struct CompilationOptions {
|
||||
|
||||
class CompilerEngine {
|
||||
public:
|
||||
// Result of an invocation of the `CompilerEngine` with optional
|
||||
// fields for the results produced by different stages.
|
||||
/// Result of an invocation of the `CompilerEngine` with optional
|
||||
/// fields for the results produced by different stages.
|
||||
class CompilationResult {
|
||||
public:
|
||||
CompilationResult(std::shared_ptr<CompilationContext> compilationContext =
|
||||
@@ -89,37 +89,35 @@ public:
|
||||
std::string outputDirPath;
|
||||
std::vector<std::string> objectsPath;
|
||||
std::vector<mlir::concretelang::ClientParameters> clientParametersList;
|
||||
/** Path to the runtime library. Will be linked to the output library if set
|
||||
*/
|
||||
/// Path to the runtime library. Will be linked to the output library if set
|
||||
std::string runtimeLibraryPath;
|
||||
bool cleanUp;
|
||||
|
||||
public:
|
||||
/** Create a library instance on which you can add compilation results.
|
||||
* Then you can emit a library file with the given path.
|
||||
* cleanUp at false keeps intermediate .obj files for later use. */
|
||||
/// Create a library instance on which you can add compilation results.
|
||||
/// Then you can emit a library file with the given path.
|
||||
/// cleanUp at false keeps intermediate .obj files for later use.
|
||||
Library(std::string outputDirPath, std::string runtimeLibraryPath = "",
|
||||
bool cleanUp = true)
|
||||
: outputDirPath(outputDirPath), runtimeLibraryPath(runtimeLibraryPath),
|
||||
cleanUp(cleanUp) {}
|
||||
/** Add a compilation result to the library */
|
||||
/// Add a compilation result to the library
|
||||
llvm::Expected<std::string> addCompilation(CompilationResult &compilation);
|
||||
/** Emit the library artifacts with the previously added compilation result
|
||||
*/
|
||||
/// Emit the library artifacts with the previously added compilation result
|
||||
llvm::Error emitArtifacts(bool sharedLib, bool staticLib,
|
||||
bool clientParameters, bool cppHeader);
|
||||
/** After a shared library has been emitted, its path is here */
|
||||
/// After a shared library has been emitted, its path is here
|
||||
std::string sharedLibraryPath;
|
||||
/** After a static library has been emitted, its path is here */
|
||||
/// After a static library has been emitted, its path is here
|
||||
std::string staticLibraryPath;
|
||||
|
||||
/** Returns the path of the shared library */
|
||||
/// Returns the path of the shared library
|
||||
static std::string getSharedLibraryPath(std::string outputDirPath);
|
||||
|
||||
/** Returns the path of the static library */
|
||||
/// Returns the path of the static library
|
||||
static std::string getStaticLibraryPath(std::string outputDirPath);
|
||||
|
||||
/** Returns the path of the static library */
|
||||
/// Returns the path of the static library
|
||||
static std::string getClientParametersPath(std::string outputDirPath);
|
||||
|
||||
// For advanced use
|
||||
@@ -132,56 +130,56 @@ public:
|
||||
~Library();
|
||||
|
||||
private:
|
||||
/** Emit a shared library with the previously added compilation result */
|
||||
/// Emit a shared library with the previously added compilation result
|
||||
llvm::Expected<std::string> emitStatic();
|
||||
/** Emit a shared library with the previously added compilation result */
|
||||
/// Emit a shared library with the previously added compilation result
|
||||
llvm::Expected<std::string> emitShared();
|
||||
/** Emit a json ClientParameters corresponding to library content */
|
||||
/// Emit a json ClientParameters corresponding to library content
|
||||
llvm::Expected<std::string> emitClientParametersJSON();
|
||||
/// Emit a client header file for this corresponding to library content
|
||||
llvm::Expected<std::string> emitCppHeader();
|
||||
};
|
||||
|
||||
// Specification of the exit stage of the compilation pipeline
|
||||
/// Specification of the exit stage of the compilation pipeline
|
||||
enum class Target {
|
||||
// Only read sources and produce corresponding MLIR module
|
||||
/// Only read sources and produce corresponding MLIR module
|
||||
ROUND_TRIP,
|
||||
|
||||
// Read sources and exit before any lowering
|
||||
/// Read sources and exit before any lowering
|
||||
FHE,
|
||||
|
||||
// Read sources and lower all FHE operations to TFHE
|
||||
// operations
|
||||
/// Read sources and lower all FHE operations to TFHE
|
||||
/// operations
|
||||
TFHE,
|
||||
|
||||
// Read sources and lower all FHE and TFHE operations to Concrete
|
||||
// operations
|
||||
/// Read sources and lower all FHE and TFHE operations to Concrete
|
||||
/// operations
|
||||
CONCRETE,
|
||||
|
||||
// Read sources and lower all FHE, TFHE and Concrete operations to BConcrete
|
||||
// operations
|
||||
/// Read sources and lower all FHE, TFHE and Concrete operations to
|
||||
/// BConcrete operations
|
||||
BCONCRETE,
|
||||
|
||||
// Read sources and lower all FHE, TFHE and Concrete
|
||||
// operations to canonical MLIR dialects. Cryptographic operations
|
||||
// are lowered to invocations of the concrete library.
|
||||
/// Read sources and lower all FHE, TFHE and Concrete
|
||||
/// operations to canonical MLIR dialects. Cryptographic operations
|
||||
/// are lowered to invocations of the concrete library.
|
||||
STD,
|
||||
|
||||
// Read sources and lower all FHE, TFHE and Concrete
|
||||
// operations to operations from the LLVM dialect. Cryptographic
|
||||
// operations are lowered to invocations of the concrete library.
|
||||
/// Read sources and lower all FHE, TFHE and Concrete
|
||||
/// operations to operations from the LLVM dialect. Cryptographic
|
||||
/// operations are lowered to invocations of the concrete library.
|
||||
LLVM,
|
||||
|
||||
// Same as `LLVM`, but lowers to actual LLVM IR instead of the
|
||||
// LLVM dialect
|
||||
/// Same as `LLVM`, but lowers to actual LLVM IR instead of the
|
||||
/// LLVM dialect
|
||||
LLVM_IR,
|
||||
|
||||
// Same as `LLVM_IR`, but invokes the LLVM optimization pipeline
|
||||
// to produce optimized LLVM IR
|
||||
/// Same as `LLVM_IR`, but invokes the LLVM optimization pipeline
|
||||
/// to produce optimized LLVM IR
|
||||
OPTIMIZED_LLVM_IR,
|
||||
|
||||
// Same as `OPTIMIZED_LLVM_IR`, but compiles and add an object file to a
|
||||
// futur library
|
||||
/// Same as `OPTIMIZED_LLVM_IR`, but compiles and add an object file to a
|
||||
/// futur library
|
||||
LIBRARY
|
||||
};
|
||||
|
||||
|
||||
@@ -11,21 +11,21 @@
|
||||
namespace mlir {
|
||||
namespace concretelang {
|
||||
|
||||
// Internal error class that allows for composing `llvm::Error`s
|
||||
// similar to `llvm::createStringError()`, but using stream-like
|
||||
// composition with `operator<<`.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// llvm::Error foo(int i, size_t s, ...) {
|
||||
// ...
|
||||
// if(...) {
|
||||
// return StreamStringError()
|
||||
// << "Some error message with an integer: "
|
||||
// << i << " and a size_t: " << s;
|
||||
// }
|
||||
// ...
|
||||
// }
|
||||
/// Internal error class that allows for composing `llvm::Error`s
|
||||
/// similar to `llvm::createStringError()`, but using stream-like
|
||||
/// composition with `operator<<`.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// llvm::Error foo(int i, size_t s, ...) {
|
||||
/// ...
|
||||
/// if(...) {
|
||||
/// return StreamStringError()
|
||||
/// << "Some error message with an integer: "
|
||||
/// << i << " and a size_t: " << s;
|
||||
/// }
|
||||
/// ...
|
||||
/// }
|
||||
class StreamStringError {
|
||||
public:
|
||||
StreamStringError(const llvm::StringRef &s) : buffer(s.str()), os(buffer){};
|
||||
|
||||
@@ -55,9 +55,9 @@ private:
|
||||
mlir::LLVM::LLVMFunctionType type;
|
||||
std::string name;
|
||||
std::unique_ptr<mlir::ExecutionEngine> engine;
|
||||
// Tell if the DF parallelization was on or during compilation. This will be
|
||||
// useful to abort execution if the runtime doesn't support dataflow
|
||||
// execution, instead of having undefined symbol issues
|
||||
/// Tell if the DF parallelization was on or during compilation. This will be
|
||||
/// useful to abort execution if the runtime doesn't support dataflow
|
||||
/// execution, instead of having undefined symbol issues
|
||||
bool useDataflow = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
namespace mlir {
|
||||
namespace concretelang {
|
||||
|
||||
// Abstract base class for lambda arguments
|
||||
/// Abstract base class for lambda arguments
|
||||
class LambdaArgument
|
||||
: public llvm::RTTIExtends<LambdaArgument, llvm::RTTIRoot> {
|
||||
public:
|
||||
@@ -25,13 +25,13 @@ public:
|
||||
|
||||
template <typename T> bool isa() const { return llvm::isa<T>(*this); }
|
||||
|
||||
// Cast functions on constant instances
|
||||
/// Cast functions on constant instances
|
||||
template <typename T> const T &cast() const { return llvm::cast<T>(*this); }
|
||||
template <typename T> const T *dyn_cast() const {
|
||||
return llvm::dyn_cast<T>(this);
|
||||
}
|
||||
|
||||
// Cast functions for mutable instances
|
||||
/// Cast functions for mutable instances
|
||||
template <typename T> T &cast() { return llvm::cast<T>(*this); }
|
||||
template <typename T> T *dyn_cast() { return llvm::dyn_cast<T>(this); }
|
||||
|
||||
@@ -41,10 +41,10 @@ protected:
|
||||
LambdaArgument(){};
|
||||
};
|
||||
|
||||
// Class for integer arguments. `BackingIntType` is used as the data
|
||||
// type to hold the argument's value. The precision is the actual
|
||||
// precision of the value, which might be different from the precision
|
||||
// of the backing integer type.
|
||||
/// Class for integer arguments. `BackingIntType` is used as the data
|
||||
/// type to hold the argument's value. The precision is the actual
|
||||
/// precision of the value, which might be different from the precision
|
||||
/// of the backing integer type.
|
||||
template <typename BackingIntType = uint64_t>
|
||||
class IntLambdaArgument
|
||||
: public llvm::RTTIExtends<IntLambdaArgument<BackingIntType>,
|
||||
@@ -75,10 +75,10 @@ protected:
|
||||
template <typename BackingIntType>
|
||||
char IntLambdaArgument<BackingIntType>::ID = 0;
|
||||
|
||||
// Class for encrypted integer arguments. `BackingIntType` is used as
|
||||
// the data type to hold the argument's plaintext value. The precision
|
||||
// is the actual precision of the value, which might be different from
|
||||
// the precision of the backing integer type.
|
||||
/// Class for encrypted integer arguments. `BackingIntType` is used as
|
||||
/// the data type to hold the argument's plaintext value. The precision
|
||||
/// is the actual precision of the value, which might be different from
|
||||
/// the precision of the backing integer type.
|
||||
template <typename BackingIntType = uint64_t>
|
||||
class EIntLambdaArgument
|
||||
: public llvm::RTTIExtends<EIntLambdaArgument<BackingIntType>,
|
||||
@@ -91,8 +91,8 @@ template <typename BackingIntType>
|
||||
char EIntLambdaArgument<BackingIntType>::ID = 0;
|
||||
|
||||
namespace {
|
||||
// Calculates `accu *= factor` or returns an error if the result
|
||||
// would overflow
|
||||
/// Calculates `accu *= factor` or returns an error if the result
|
||||
/// would overflow
|
||||
template <typename AccuT, typename ValT>
|
||||
llvm::Error safeUnsignedMul(AccuT &accu, ValT factor) {
|
||||
static_assert(std::numeric_limits<AccuT>::is_integer &&
|
||||
@@ -113,10 +113,10 @@ llvm::Error safeUnsignedMul(AccuT &accu, ValT factor) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Class for Tensor arguments. This can either be plaintext tensors
|
||||
// (for `ScalarArgumentT = IntLambaArgument<T>`) or tensors
|
||||
// representing encrypted integers (for `ScalarArgumentT =
|
||||
// EIntLambaArgument<T>`).
|
||||
/// Class for Tensor arguments. This can either be plaintext tensors
|
||||
/// (for `ScalarArgumentT = IntLambaArgument<T>`) or tensors
|
||||
/// representing encrypted integers (for `ScalarArgumentT =
|
||||
/// EIntLambaArgument<T>`).
|
||||
template <typename ScalarArgumentT>
|
||||
class TensorLambdaArgument
|
||||
: public llvm::RTTIExtends<TensorLambdaArgument<ScalarArgumentT>,
|
||||
@@ -124,10 +124,10 @@ class TensorLambdaArgument
|
||||
public:
|
||||
typedef ScalarArgumentT scalar_type;
|
||||
|
||||
// Construct tensor argument from the one-dimensional array `value`,
|
||||
// but interpreting the array's values as a linearized
|
||||
// multi-dimensional tensor with the sizes of the dimensions
|
||||
// specified in `dimensions`.
|
||||
/// Construct tensor argument from the one-dimensional array `value`,
|
||||
/// but interpreting the array's values as a linearized
|
||||
/// multi-dimensional tensor with the sizes of the dimensions
|
||||
/// specified in `dimensions`.
|
||||
TensorLambdaArgument(
|
||||
llvm::ArrayRef<typename ScalarArgumentT::value_type> value,
|
||||
llvm::ArrayRef<int64_t> dimensions)
|
||||
@@ -135,8 +135,8 @@ public:
|
||||
std::copy(value.begin(), value.end(), std::back_inserter(this->value));
|
||||
}
|
||||
|
||||
// Construct a one-dimensional tensor argument from the
|
||||
// array `value`.
|
||||
/// Construct a one-dimensional tensor argument from the
|
||||
/// array `value`.
|
||||
TensorLambdaArgument(
|
||||
llvm::ArrayRef<typename ScalarArgumentT::value_type> value)
|
||||
: TensorLambdaArgument(value, {(int64_t)value.size()}) {}
|
||||
@@ -152,9 +152,9 @@ public:
|
||||
|
||||
const std::vector<int64_t> &getDimensions() const { return this->dimensions; }
|
||||
|
||||
// Returns the total number of elements in the tensor. If the number
|
||||
// of elements cannot be represented as a `size_t`, the method
|
||||
// returns an error.
|
||||
/// Returns the total number of elements in the tensor. If the number
|
||||
/// of elements cannot be represented as a `size_t`, the method
|
||||
/// returns an error.
|
||||
llvm::Expected<size_t> getNumElements() const {
|
||||
size_t accu = 1;
|
||||
|
||||
@@ -165,14 +165,14 @@ public:
|
||||
return accu;
|
||||
}
|
||||
|
||||
// Returns a bare pointer to the linearized values of the tensor
|
||||
// (constant version).
|
||||
/// Returns a bare pointer to the linearized values of the tensor
|
||||
/// (constant version).
|
||||
const typename ScalarArgumentT::value_type *getValue() const {
|
||||
return this->value.data();
|
||||
}
|
||||
|
||||
// Returns a bare pointer to the linearized values of the tensor (mutable
|
||||
// version).
|
||||
/// Returns a bare pointer to the linearized values of the tensor (mutable
|
||||
/// version).
|
||||
typename ScalarArgumentT::value_type *getValue() {
|
||||
return this->value.data();
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace {
|
||||
// `typedResult` must be declared at namespace scope due to return
|
||||
// type template specialization
|
||||
|
||||
// Helper function for implementing type-dependent preparation of the result.
|
||||
/// Helper function for implementing type-dependent preparation of the result.
|
||||
template <typename ResT>
|
||||
llvm::Expected<ResT> typedResult(clientlib::KeySet &keySet,
|
||||
clientlib::PublicResult &result);
|
||||
|
||||
// Specialization of `typedResult()` for scalar results, forwarding
|
||||
// scalar value to caller
|
||||
/// Specialization of `typedResult()` for scalar results, forwarding
|
||||
/// scalar value to caller
|
||||
template <>
|
||||
inline llvm::Expected<uint64_t> typedResult(clientlib::KeySet &keySet,
|
||||
clientlib::PublicResult &result) {
|
||||
@@ -60,14 +60,13 @@ typedVectorResult(clientlib::KeySet &keySet, clientlib::PublicResult &result) {
|
||||
return std::move(clearResult.value());
|
||||
}
|
||||
|
||||
// Specializations of `typedResult()` for vector results, initializing
|
||||
// an `std::vector` of the right size with the results and forwarding
|
||||
// it to the caller with move semantics.
|
||||
//
|
||||
// Cannot factor out into a template template <typename T> inline
|
||||
// llvm::Expected<std::vector<uint8_t>>
|
||||
// typedResult(clientlib::KeySet &keySet, clientlib::PublicResult &result); due
|
||||
// to ambiguity with scalar template
|
||||
/// Specializations of `typedResult()` for vector results, initializing
|
||||
/// an `std::vector` of the right size with the results and forwarding
|
||||
/// it to the caller with move semantics.
|
||||
/// Cannot factor out into a template template <typename T> inline
|
||||
/// llvm::Expected<std::vector<uint8_t>>
|
||||
/// typedResult(clientlib::KeySet &keySet, clientlib::PublicResult &result); due
|
||||
/// to ambiguity with scalar template
|
||||
template <>
|
||||
inline llvm::Expected<std::vector<uint8_t>>
|
||||
typedResult(clientlib::KeySet &keySet, clientlib::PublicResult &result) {
|
||||
@@ -105,8 +104,8 @@ buildTensorLambdaResult(clientlib::KeySet &keySet,
|
||||
*tensorOrError, tensorDim);
|
||||
}
|
||||
|
||||
// pecialization of `typedResult()` for a single result wrapped into
|
||||
// a `LambdaArgument`.
|
||||
/// pecialization of `typedResult()` for a single result wrapped into
|
||||
/// a `LambdaArgument`.
|
||||
template <>
|
||||
inline llvm::Expected<std::unique_ptr<LambdaArgument>>
|
||||
typedResult(clientlib::KeySet &keySet, clientlib::PublicResult &result) {
|
||||
@@ -138,18 +137,18 @@ typedResult(clientlib::KeySet &keySet, clientlib::PublicResult &result) {
|
||||
|
||||
} // namespace
|
||||
|
||||
// Adaptor class that push arguments specified as instances of
|
||||
// `LambdaArgument` to `clientlib::EncryptedArguments`.
|
||||
/// Adaptor class that push arguments specified as instances of
|
||||
/// `LambdaArgument` to `clientlib::EncryptedArguments`.
|
||||
class LambdaArgumentAdaptor {
|
||||
public:
|
||||
// Checks if the argument `arg` is an plaintext / encrypted integer
|
||||
// argument or a plaintext / encrypted tensor argument with a
|
||||
// backing integer type `IntT` and push the argument to `encryptedArgs`.
|
||||
//
|
||||
// Returns `true` if `arg` has one of the types above and its value
|
||||
// was successfully added to `encryptedArgs`, `false` if none of the types
|
||||
// matches or an error if a type matched, but adding the argument to
|
||||
// `encryptedArgs` failed.
|
||||
/// Checks if the argument `arg` is an plaintext / encrypted integer
|
||||
/// argument or a plaintext / encrypted tensor argument with a
|
||||
/// backing integer type `IntT` and push the argument to `encryptedArgs`.
|
||||
///
|
||||
/// Returns `true` if `arg` has one of the types above and its value
|
||||
/// was successfully added to `encryptedArgs`, `false` if none of the types
|
||||
/// matches or an error if a type matched, but adding the argument to
|
||||
/// `encryptedArgs` failed.
|
||||
template <typename IntT>
|
||||
static inline llvm::Expected<bool>
|
||||
tryAddArg(clientlib::EncryptedArguments &encryptedArgs,
|
||||
@@ -174,7 +173,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Recursive case for `tryAddArg<IntT>(...)`
|
||||
/// Recursive case for `tryAddArg<IntT>(...)`
|
||||
template <typename IntT, typename NextIntT, typename... IntTs>
|
||||
static inline llvm::Expected<bool>
|
||||
tryAddArg(clientlib::EncryptedArguments &encryptedArgs,
|
||||
@@ -191,9 +190,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Attempts to push a single argument `arg` to `encryptedArgs`. Returns an
|
||||
// error if either the argument type is unsupported or if the argument types
|
||||
// is supported, but adding it to `encryptedArgs` failed.
|
||||
/// Attempts to push a single argument `arg` to `encryptedArgs`. Returns an
|
||||
/// error if either the argument type is unsupported or if the argument types
|
||||
/// is supported, but adding it to `encryptedArgs` failed.
|
||||
static inline llvm::Error
|
||||
addArgument(clientlib::EncryptedArguments &encryptedArgs,
|
||||
const LambdaArgument &arg, clientlib::KeySet &keySet) {
|
||||
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
private:
|
||||
std::string outputPath;
|
||||
std::string runtimeLibraryPath;
|
||||
// Flags to select generated artifacts
|
||||
/// Flags to select generated artifacts
|
||||
bool generateSharedLib;
|
||||
bool generateStaticLib;
|
||||
bool generateClientParameters;
|
||||
|
||||
@@ -11,20 +11,20 @@
|
||||
namespace mlir {
|
||||
namespace concretelang {
|
||||
|
||||
// Returning references to instances of different classes `S` and `T`
|
||||
// is prohibited, even if `T` inherits from `S`. The wrapper class
|
||||
// `StreamWrap` can be initialized with a pointer to an instance of
|
||||
// `S` or any of its subclasses and acts as a proxy transparently
|
||||
// forwarding all calls to `S::operator<<`. The class thus hides the
|
||||
// dereferencing of the pointer and a reference to it can be used as a
|
||||
// replacement for a reference to `S`.
|
||||
/// Returning references to instances of different classes `S` and `T`
|
||||
/// is prohibited, even if `T` inherits from `S`. The wrapper class
|
||||
/// `StreamWrap` can be initialized with a pointer to an instance of
|
||||
/// `S` or any of its subclasses and acts as a proxy transparently
|
||||
/// forwarding all calls to `S::operator<<`. The class thus hides the
|
||||
/// dereferencing of the pointer and a reference to it can be used as a
|
||||
/// replacement for a reference to `S`.
|
||||
template <class S> class StreamWrap {
|
||||
public:
|
||||
StreamWrap() = delete;
|
||||
StreamWrap(S *s) : s(s) {}
|
||||
|
||||
// Forward all invocations of
|
||||
// `StreamWrap<S>::operator<<` to S::operator<<`.
|
||||
/// Forward all invocations of
|
||||
/// `StreamWrap<S>::operator<<` to S::operator<<`.
|
||||
template <class T> StreamWrap<S> &operator<<(const T &v) {
|
||||
*this->s << v;
|
||||
return *this;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#ifndef CONCRETELANG_SUPPORT_MATH_H_
|
||||
#define CONCRETELANG_SUPPORT_MATH_H_
|
||||
|
||||
// Calculates (T)ceil(log2f(v))
|
||||
// TODO: Replace with some fancy bit twiddling hack
|
||||
/// Calculates (T)ceil(log2f(v))
|
||||
template <typename T> static T ceilLog2(const T v) {
|
||||
// TODO: Replace with some fancy bit twiddling hack
|
||||
T tmp = v;
|
||||
T log2 = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user