diff --git a/compiler/include/concretelang-c/Support/CompilerEngine.h b/compiler/include/concretelang-c/Support/CompilerEngine.h index 98b4380ba..11ff45092 100644 --- a/compiler/include/concretelang-c/Support/CompilerEngine.h +++ b/compiler/include/concretelang-c/Support/CompilerEngine.h @@ -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 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 data, std::vector dimensions); MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU16( @@ -151,22 +151,22 @@ MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU32( std::vector data, std::vector dimensions); MLIR_CAPI_EXPORTED lambdaArgument lambdaArgumentFromTensorU64( std::vector data, std::vector 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 lambdaArgumentGetTensorData(lambdaArgument &lambda_arg); -// Get tensor dimensions from lambdaArgument +/// Get tensor dimensions from lambdaArgument MLIR_CAPI_EXPORTED std::vector 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 modules); diff --git a/compiler/include/concretelang/ClientLib/ClientLambda.h b/compiler/include/concretelang/ClientLib/ClientLambda.h index 8db8b249a..abca94f9f 100644 --- a/compiler/include/concretelang/ClientLib/ClientLambda.h +++ b/compiler/include/concretelang/ClientLib/ClientLambda.h @@ -29,8 +29,8 @@ using tensor1_out = std::vector; using tensor2_out = std::vector>; using tensor3_out = std::vector>>; +/// 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; diff --git a/compiler/include/concretelang/ClientLib/ClientParameters.h b/compiler/include/concretelang/ClientLib/ClientParameters.h index 4e186de0e..8e8f98940 100644 --- a/compiler/include/concretelang/ClientLib/ClientParameters.h +++ b/compiler/include/concretelang/ClientLib/ClientParameters.h @@ -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 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, diff --git a/compiler/include/concretelang/ClientLib/EncryptedArguments.h b/compiler/include/concretelang/ClientLib/EncryptedArguments.h index c610c6b89..71eb68e66 100644 --- a/compiler/include/concretelang/ClientLib/EncryptedArguments.h +++ b/compiler/include/concretelang/ClientLib/EncryptedArguments.h @@ -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 checkAllArgs(KeySet &keySet); public: - // Add a uint64_t scalar argument. + /// Add a uint64_t scalar argument. outcome::checked pushArg(uint64_t arg, KeySet &keySet); /// Add a vector-tensor argument. outcome::checked pushArg(std::vector 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 outcome::checked 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 outcome::checked pushArg(T *data, int64_t dim1, KeySet &keySet) { return pushArg(data, llvm::ArrayRef(&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 outcome::checked pushArg(T *data, llvm::ArrayRef shape, KeySet &keySet) { @@ -133,8 +133,8 @@ public: llvm::ArrayRef 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 outcome::checked 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 outcome::checked 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 pushArgs(KeySet &keySet) { return checkAllArgs(keySet); } @@ -160,11 +160,11 @@ private: outcome::checked checkPushTooManyArgs(KeySet &keySet); private: - // Position of the next pushed argument + /// Position of the next pushed argument size_t currentPos; std::vector preparedArgs; - // Store buffers of ciphertexts + /// Store buffers of ciphertexts std::vector ciphertextBuffers; }; diff --git a/compiler/include/concretelang/ClientLib/KeySet.h b/compiler/include/concretelang/ClientLib/KeySet.h index 9a789b12e..207606375 100644 --- a/compiler/include/concretelang/ClientLib/KeySet.h +++ b/compiler/include/concretelang/ClientLib/KeySet.h @@ -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, 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 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 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 decrypt_lwe(size_t argPos, uint64_t *ciphertext, uint64_t &output); diff --git a/compiler/include/concretelang/ClientLib/PublicArguments.h b/compiler/include/concretelang/ClientLib/PublicArguments.h index f11c0d09b..9baa12a44 100644 --- a/compiler/include/concretelang/ClientLib/PublicArguments.h +++ b/compiler/include/concretelang/ClientLib/PublicArguments.h @@ -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 &&preparedArgs, @@ -56,13 +57,13 @@ private: ClientParameters clientParameters; std::vector preparedArgs; - // Store buffers of ciphertexts + /// Store buffers of ciphertexts std::vector 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 buffers = {}) diff --git a/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h b/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h index 186fcfbe2..f8a750266 100644 --- a/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h +++ b/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h @@ -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(); @@ -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(); diff --git a/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h b/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h index d926cf42d..ac91f13cc 100644 --- a/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h @@ -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 void emitErrorBadLutSize(Op &op, std::string lutName, std::string inputName, int expectedSize, int bitWidth) { diff --git a/compiler/include/concretelang/Runtime/DFRuntime.hpp b/compiler/include/concretelang/Runtime/DFRuntime.hpp index 82d5dfbb3..8fa8d9267 100644 --- a/compiler/include/concretelang/Runtime/DFRuntime.hpp +++ b/compiler/include/concretelang/Runtime/DFRuntime.hpp @@ -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 next_locality{0}; diff --git a/compiler/include/concretelang/Runtime/context.h b/compiler/include/concretelang/Runtime/context.h index 6a22a8ffc..1bb0e1121 100644 --- a/compiler/include/concretelang/Runtime/context.h +++ b/compiler/include/concretelang/Runtime/context.h @@ -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) diff --git a/compiler/include/concretelang/Runtime/runtime_api.h b/compiler/include/concretelang/Runtime/runtime_api.h index 63179aee6..b3f05f6e0 100644 --- a/compiler/include/concretelang/Runtime/runtime_api.h +++ b/compiler/include/concretelang/Runtime/runtime_api.h @@ -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 diff --git a/compiler/include/concretelang/ServerLib/ServerLambda.h b/compiler/include/concretelang/ServerLib/ServerLambda.h index 337f281ac..3cffc17a5 100644 --- a/compiler/include/concretelang/ServerLib/ServerLambda.h +++ b/compiler/include/concretelang/ServerLib/ServerLambda.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 module; }; diff --git a/compiler/include/concretelang/Support/CompilerEngine.h b/compiler/include/concretelang/Support/CompilerEngine.h index 2c19e1120..7164641b6 100644 --- a/compiler/include/concretelang/Support/CompilerEngine.h +++ b/compiler/include/concretelang/Support/CompilerEngine.h @@ -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 = @@ -89,37 +89,35 @@ public: std::string outputDirPath; std::vector objectsPath; std::vector 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 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 emitStatic(); - /** Emit a shared library with the previously added compilation result */ + /// Emit a shared library with the previously added compilation result llvm::Expected emitShared(); - /** Emit a json ClientParameters corresponding to library content */ + /// Emit a json ClientParameters corresponding to library content llvm::Expected emitClientParametersJSON(); /// Emit a client header file for this corresponding to library content llvm::Expected 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 }; diff --git a/compiler/include/concretelang/Support/Error.h b/compiler/include/concretelang/Support/Error.h index 4d5349153..1c341b5a3 100644 --- a/compiler/include/concretelang/Support/Error.h +++ b/compiler/include/concretelang/Support/Error.h @@ -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){}; diff --git a/compiler/include/concretelang/Support/Jit.h b/compiler/include/concretelang/Support/Jit.h index 487548a6b..7c882b5f1 100644 --- a/compiler/include/concretelang/Support/Jit.h +++ b/compiler/include/concretelang/Support/Jit.h @@ -55,9 +55,9 @@ private: mlir::LLVM::LLVMFunctionType type; std::string name; std::unique_ptr 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; }; diff --git a/compiler/include/concretelang/Support/LambdaArgument.h b/compiler/include/concretelang/Support/LambdaArgument.h index afb01b6e3..67358b339 100644 --- a/compiler/include/concretelang/Support/LambdaArgument.h +++ b/compiler/include/concretelang/Support/LambdaArgument.h @@ -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 { public: @@ -25,13 +25,13 @@ public: template bool isa() const { return llvm::isa(*this); } - // Cast functions on constant instances + /// Cast functions on constant instances template const T &cast() const { return llvm::cast(*this); } template const T *dyn_cast() const { return llvm::dyn_cast(this); } - // Cast functions for mutable instances + /// Cast functions for mutable instances template T &cast() { return llvm::cast(*this); } template T *dyn_cast() { return llvm::dyn_cast(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 class IntLambdaArgument : public llvm::RTTIExtends, @@ -75,10 +75,10 @@ protected: template char IntLambdaArgument::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 class EIntLambdaArgument : public llvm::RTTIExtends, @@ -91,8 +91,8 @@ template char EIntLambdaArgument::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 llvm::Error safeUnsignedMul(AccuT &accu, ValT factor) { static_assert(std::numeric_limits::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`) or tensors -// representing encrypted integers (for `ScalarArgumentT = -// EIntLambaArgument`). +/// Class for Tensor arguments. This can either be plaintext tensors +/// (for `ScalarArgumentT = IntLambaArgument`) or tensors +/// representing encrypted integers (for `ScalarArgumentT = +/// EIntLambaArgument`). template class TensorLambdaArgument : public llvm::RTTIExtends, @@ -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 value, llvm::ArrayRef 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 value) : TensorLambdaArgument(value, {(int64_t)value.size()}) {} @@ -152,9 +152,9 @@ public: const std::vector &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 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(); } diff --git a/compiler/include/concretelang/Support/LambdaSupport.h b/compiler/include/concretelang/Support/LambdaSupport.h index d25cac08b..e1c5646f5 100644 --- a/compiler/include/concretelang/Support/LambdaSupport.h +++ b/compiler/include/concretelang/Support/LambdaSupport.h @@ -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 llvm::Expected 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 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 inline -// llvm::Expected> -// 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 inline +/// llvm::Expected> +/// typedResult(clientlib::KeySet &keySet, clientlib::PublicResult &result); due +/// to ambiguity with scalar template template <> inline llvm::Expected> 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> 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 static inline llvm::Expected tryAddArg(clientlib::EncryptedArguments &encryptedArgs, @@ -174,7 +173,7 @@ public: return false; } - // Recursive case for `tryAddArg(...)` + /// Recursive case for `tryAddArg(...)` template static inline llvm::Expected 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) { diff --git a/compiler/include/concretelang/Support/LibrarySupport.h b/compiler/include/concretelang/Support/LibrarySupport.h index 5818070e8..c973b4c8d 100644 --- a/compiler/include/concretelang/Support/LibrarySupport.h +++ b/compiler/include/concretelang/Support/LibrarySupport.h @@ -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; diff --git a/compiler/include/concretelang/Support/logging.h b/compiler/include/concretelang/Support/logging.h index cc6335a23..95c56820d 100644 --- a/compiler/include/concretelang/Support/logging.h +++ b/compiler/include/concretelang/Support/logging.h @@ -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 StreamWrap { public: StreamWrap() = delete; StreamWrap(S *s) : s(s) {} - // Forward all invocations of - // `StreamWrap::operator<<` to S::operator<<`. + /// Forward all invocations of + /// `StreamWrap::operator<<` to S::operator<<`. template StreamWrap &operator<<(const T &v) { *this->s << v; return *this; diff --git a/compiler/include/concretelang/Support/math.h b/compiler/include/concretelang/Support/math.h index 2c06901ff..46afe6813 100644 --- a/compiler/include/concretelang/Support/math.h +++ b/compiler/include/concretelang/Support/math.h @@ -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 static T ceilLog2(const T v) { + // TODO: Replace with some fancy bit twiddling hack T tmp = v; T log2 = 0; diff --git a/compiler/lib/Conversion/ConcreteToBConcrete/ConcreteToBConcrete.cpp b/compiler/lib/Conversion/ConcreteToBConcrete/ConcreteToBConcrete.cpp index d3cd12d1a..abe7ddf3c 100644 --- a/compiler/lib/Conversion/ConcreteToBConcrete/ConcreteToBConcrete.cpp +++ b/compiler/lib/Conversion/ConcreteToBConcrete/ConcreteToBConcrete.cpp @@ -155,26 +155,26 @@ struct ConcreteIntToCleartextOpPattern }; }; -// This rewrite pattern transforms any instance of `Concrete.zero_tensor` -// operators. -// -// Example: -// -// ```mlir -// %0 = "Concrete.zero_tensor" () : -// tensor<...x!Concrete.lwe_ciphertext> -// ``` -// -// becomes: -// -// ```mlir -// %0 = tensor.generate { -// ^bb0(... : index): -// %c0 = arith.constant 0 : i64 -// tensor.yield %z -// }: tensor<...xlweDim+1xi64> -// i64> -// ``` +/// This rewrite pattern transforms any instance of `Concrete.zero_tensor` +/// operators. +/// +/// Example: +/// +/// ```mlir +/// %0 = "Concrete.zero_tensor" () : +/// tensor<...x!Concrete.lwe_ciphertext> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %0 = tensor.generate { +/// ^bb0(... : index): +/// %c0 = arith.constant 0 : i64 +/// tensor.yield %z +/// }: tensor<...xlweDim+1xi64> +/// i64> +/// ``` template struct ZeroOpPattern : public mlir::OpRewritePattern { ZeroOpPattern(::mlir::MLIRContext *context, mlir::PatternBenefit benefit = 1) @@ -204,19 +204,19 @@ struct ZeroOpPattern : public mlir::OpRewritePattern { }; }; -// This template rewrite pattern transforms any instance of -// `ConcreteOp` to an instance of `BConcreteOp`. -// -// Example: -// -// %0 = "ConcreteOp"(%arg0, ...) : -// (!Concrete.lwe_ciphertext, ...) -> -// (!Concrete.lwe_ciphertext) -// -// becomes: -// -// %0 = "BConcreteOp"(%arg0, ...) : (tensor>, ..., ) -> -// (tensor>) +/// This template rewrite pattern transforms any instance of +/// `ConcreteOp` to an instance of `BConcreteOp`. +/// +/// Example: +/// +/// %0 = "ConcreteOp"(%arg0, ...) : +/// (!Concrete.lwe_ciphertext, ...) -> +/// (!Concrete.lwe_ciphertext) +/// +/// becomes: +/// +/// %0 = "BConcreteOp"(%arg0, ...) : (tensor>, ..., ) -> +/// (tensor>) template struct LowToBConcrete : public mlir::OpRewritePattern { LowToBConcrete(::mlir::MLIRContext *context, mlir::PatternBenefit benefit = 1) @@ -248,27 +248,27 @@ struct LowToBConcrete : public mlir::OpRewritePattern { }; }; -// This rewrite pattern transforms any instance of -// `Concrete.glwe_from_table` operators. -// -// Example: -// -// ```mlir -// %0 = "Concrete.glwe_from_table"(%tlu) -// : (tensor<$Dxi64>) -> -// !Concrete.glwe_ciphertext<$polynomialSize,$glweDimension,$p> -// ``` -// -// with $D = 2^$p -// -// becomes: -// -// ```mlir -// %0 = linalg.init_tensor [polynomialSize*(glweDimension+1)] -// : tensor -// "BConcrete.fill_glwe_from_table" : (%0, polynomialSize, glweDimension, %tlu) -// : tensor, i64, i64, tensor<$Dxi64> -// ``` +/// This rewrite pattern transforms any instance of +/// `Concrete.glwe_from_table` operators. +/// +/// Example: +/// +/// ```mlir +/// %0 = "Concrete.glwe_from_table"(%tlu) +/// : (tensor<$Dxi64>) -> +/// !Concrete.glwe_ciphertext<$polynomialSize,$glweDimension,$p> +/// ``` +/// +/// with $D = 2^$p +/// +/// becomes: +/// +/// ```mlir +/// %0 = linalg.init_tensor [polynomialSize*(glweDimension+1)] +/// : tensor +/// "BConcrete.fill_glwe_from_table" : (%0, polynomialSize, glweDimension, %tlu) +/// : tensor, i64, i64, tensor<$Dxi64> +/// ``` struct GlweFromTablePattern : public mlir::OpRewritePattern< mlir::concretelang::Concrete::GlweFromTable> { GlweFromTablePattern(::mlir::MLIRContext *context, @@ -305,26 +305,26 @@ struct GlweFromTablePattern : public mlir::OpRewritePattern< }; }; -// This rewrite pattern transforms any instance of -// `tensor.extract_slice` operators that operates on tensor of lwe ciphertext. -// -// Example: -// -// ```mlir -// %0 = tensor.extract_slice %arg0 -// [offsets...] [sizes...] [strides...] -// : tensor<...x!Concrete.lwe_ciphertext> to -// tensor<...x!Concrete.lwe_ciphertext> -// ``` -// -// becomes: -// -// ```mlir -// %0 = tensor.extract_slice %arg0 -// [offsets..., 0] [sizes..., lweDimension+1] [strides..., 1] -// : tensor<...xlweDimension+1,i64> to -// tensor<...xlweDimension+1,i64> -// ``` +/// This rewrite pattern transforms any instance of +/// `tensor.extract_slice` operators that operates on tensor of lwe ciphertext. +/// +/// Example: +/// +/// ```mlir +/// %0 = tensor.extract_slice %arg0 +/// [offsets...] [sizes...] [strides...] +/// : tensor<...x!Concrete.lwe_ciphertext> to +/// tensor<...x!Concrete.lwe_ciphertext> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %0 = tensor.extract_slice %arg0 +/// [offsets..., 0] [sizes..., lweDimension+1] [strides..., 1] +/// : tensor<...xlweDimension+1,i64> to +/// tensor<...xlweDimension+1,i64> +/// ``` struct ExtractSliceOpPattern : public mlir::OpRewritePattern { ExtractSliceOpPattern(::mlir::MLIRContext *context, @@ -380,27 +380,26 @@ struct ExtractSliceOpPattern }; }; -// This rewrite pattern transforms any instance of -// `tensor.extract` operators that operates on tensor of lwe ciphertext. -// -// Example: -// -// ```mlir -// %0 = tensor.extract %t[offsets...] -// : tensor<...x!Concrete.lwe_ciphertext> -// ``` -// -// becomes: -// -// ```mlir -// %1 = tensor.extract_slice %arg0 -// [offsets...] [1..., lweDimension+1] [1...] -// : tensor<...xlweDimension+1,i64> to -// tensor<1...xlweDimension+1,i64> -// %0 = linalg.tensor_collapse_shape %0 [[...]] : -// tensor<1x1xlweDimension+1xi64> into tensor -// ``` -// +/// This rewrite pattern transforms any instance of +/// `tensor.extract` operators that operates on tensor of lwe ciphertext. +/// +/// Example: +/// +/// ```mlir +/// %0 = tensor.extract %t[offsets...] +/// : tensor<...x!Concrete.lwe_ciphertext> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %1 = tensor.extract_slice %arg0 +/// [offsets...] [1..., lweDimension+1] [1...] +/// : tensor<...xlweDimension+1,i64> to +/// tensor<1...xlweDimension+1,i64> +/// %0 = linalg.tensor_collapse_shape %0 [[...]] : +/// tensor<1x1xlweDimension+1xi64> into tensor +/// ``` // TODO: since they are a bug on lowering extract_slice with rank reduction we // add a linalg.tensor_collapse_shape after the extract_slice without rank // reduction. See @@ -487,26 +486,26 @@ struct ExtractOpPattern }; }; -// This rewrite pattern transforms any instance of -// `tensor.insert_slice` operators that operates on tensor of lwe ciphertext. -// -// Example: -// -// ```mlir -// %0 = tensor.insert_slice %arg1 -// into %arg0[offsets...] [sizes...] [strides...] -// : tensor<...x!Concrete.lwe_ciphertext> into -// tensor<...x!Concrete.lwe_ciphertext> -// ``` -// -// becomes: -// -// ```mlir -// %0 = tensor.insert_slice %arg1 -// into %arg0[offsets..., 0] [sizes..., lweDimension+1] [strides..., 1] -// : tensor<...xlweDimension+1xi64> into -// tensor<...xlweDimension+1xi64> -// ``` +/// This rewrite pattern transforms any instance of +/// `tensor.insert_slice` operators that operates on tensor of lwe ciphertext. +/// +/// Example: +/// +/// ```mlir +/// %0 = tensor.insert_slice %arg1 +/// into %arg0[offsets...] [sizes...] [strides...] +/// : tensor<...x!Concrete.lwe_ciphertext> into +/// tensor<...x!Concrete.lwe_ciphertext> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %0 = tensor.insert_slice %arg1 +/// into %arg0[offsets..., 0] [sizes..., lweDimension+1] [strides..., 1] +/// : tensor<...xlweDimension+1xi64> into +/// tensor<...xlweDimension+1xi64> +/// ``` struct InsertSliceOpPattern : public mlir::OpRewritePattern { InsertSliceOpPattern(::mlir::MLIRContext *context, @@ -559,28 +558,28 @@ struct InsertSliceOpPattern }; }; -// This rewrite pattern transforms any instance of `tensor.insert` -// operators that operates on an lwe ciphertexts to a -// `tensor.insert_slice` op operating on the bufferized representation -// of the ciphertext. -// -// Example: -// -// ```mlir -// %0 = tensor.insert %arg1 -// into %arg0[offsets...] -// : !Concrete.lwe_ciphertext into -// tensor<...x!Concrete.lwe_ciphertext> -// ``` -// -// becomes: -// -// ```mlir -// %0 = tensor.insert_slice %arg1 -// into %arg0[offsets..., 0] [sizes..., lweDimension+1] [strides..., 1] -// : tensor into -// tensor<...xlweDimension+1xi64> -// ``` +/// This rewrite pattern transforms any instance of `tensor.insert` +/// operators that operates on an lwe ciphertexts to a +/// `tensor.insert_slice` op operating on the bufferized representation +/// of the ciphertext. +/// +/// Example: +/// +/// ```mlir +/// %0 = tensor.insert %arg1 +/// into %arg0[offsets...] +/// : !Concrete.lwe_ciphertext into +/// tensor<...x!Concrete.lwe_ciphertext> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %0 = tensor.insert_slice %arg1 +/// into %arg0[offsets..., 0] [sizes..., lweDimension+1] [strides..., 1] +/// : tensor into +/// tensor<...xlweDimension+1xi64> +/// ``` struct InsertOpPattern : public mlir::OpRewritePattern { InsertOpPattern(::mlir::MLIRContext *context, mlir::PatternBenefit benefit = 1) @@ -628,31 +627,31 @@ struct InsertOpPattern : public mlir::OpRewritePattern { }; }; -// This rewrite pattern transforms any instance of -// `tensor.from_elements` operators that operates on tensor of lwe ciphertext. -// -// Example: -// -// ```mlir -// %0 = tensor.from_elements %e0, ..., %e(n-1) -// : tensor> -// ``` -// -// becomes: -// -// ```mlir -// %m = memref.alloc() : memref -// %s0 = memref.subview %m[0, 0][1, lweDim+1][1, 1] : memref -// %m0 = memref.buffer_cast %e0 : memref -// memref.copy %m0, s0 : memref to memref -// ... -// %s(n-1) = memref.subview %m[(n-1), 0][1, lweDim+1][1, 1] -// : memref -// %m(n-1) = memref.buffer_cast %e(n-1) : memref -// memref.copy %e(n-1), s(n-1) -// : memref to memref -// %0 = memref.tensor_load %m : memref -// ``` +/// This rewrite pattern transforms any instance of +/// `tensor.from_elements` operators that operates on tensor of lwe ciphertext. +/// +/// Example: +/// +/// ```mlir +/// %0 = tensor.from_elements %e0, ..., %e(n-1) +/// : tensor> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %m = memref.alloc() : memref +/// %s0 = memref.subview %m[0, 0][1, lweDim+1][1, 1] : memref +/// %m0 = memref.buffer_cast %e0 : memref +/// memref.copy %m0, s0 : memref to memref +/// ... +/// %s(n-1) = memref.subview %m[(n-1), 0][1, lweDim+1][1, 1] +/// : memref +/// %m(n-1) = memref.buffer_cast %e(n-1) : memref +/// memref.copy %e(n-1), s(n-1) +/// : memref to memref +/// %0 = memref.tensor_load %m : memref +/// ``` struct FromElementsOpPattern : public mlir::OpRewritePattern { FromElementsOpPattern(::mlir::MLIRContext *context, @@ -715,26 +714,26 @@ struct FromElementsOpPattern }; }; -// This template rewrite pattern transforms any instance of -// `ShapeOp` operators that operates on tensor of lwe ciphertext by adding the -// lwe size as a size of the tensor result and by adding a trivial reassociation -// at the end of the reassociations map. -// -// Example: -// -// ```mlir -// %0 = "ShapeOp" %arg0 [reassocations...] -// : tensor<...x!Concrete.lwe_ciphertext> into -// tensor<...x!Concrete.lwe_ciphertext> -// ``` -// -// becomes: -// -// ```mlir -// %0 = "ShapeOp" %arg0 [reassociations..., [inRank or outRank]] -// : tensor<...xlweDimesion+1xi64> into -// tensor<...xlweDimesion+1xi64> -// ``` +/// This template rewrite pattern transforms any instance of +/// `ShapeOp` operators that operates on tensor of lwe ciphertext by adding the +/// lwe size as a size of the tensor result and by adding a trivial +/// reassociation at the end of the reassociations map. +/// +/// Example: +/// +/// ```mlir +/// %0 = "ShapeOp" %arg0 [reassocations...] +/// : tensor<...x!Concrete.lwe_ciphertext> into +/// tensor<...x!Concrete.lwe_ciphertext> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %0 = "ShapeOp" %arg0 [reassociations..., [inRank or outRank]] +/// : tensor<...xlweDimesion+1xi64> into +/// tensor<...xlweDimesion+1xi64> +/// ``` template struct TensorShapeOpPattern : public mlir::OpRewritePattern { TensorShapeOpPattern(::mlir::MLIRContext *context, @@ -775,8 +774,8 @@ struct TensorShapeOpPattern : public mlir::OpRewritePattern { }; }; -// Add the instantiated TensorShapeOpPattern rewrite pattern with the `ShapeOp` -// to the patterns set and populate the conversion target. +/// Add the instantiated TensorShapeOpPattern rewrite pattern with the `ShapeOp` +/// to the patterns set and populate the conversion target. template void insertTensorShapeOpPattern(mlir::MLIRContext &context, mlir::RewritePatternSet &patterns, @@ -789,26 +788,26 @@ void insertTensorShapeOpPattern(mlir::MLIRContext &context, }); } -// Rewrites `linalg.init_tensor` ops for which the converted type in -// BConcrete is different from the original type. -// -// Example: -// -// ``` -// linalg.init_tensor [4] : tensor<4x!Concrete.lwe_ciphertext<4096,6>> -// ``` -// -// which has become after type conversion: -// -// ``` -// linalg.init_tensor [4] : tensor<4x4097xi64> -// ``` -// -// is finally fixed: -// -// ``` -// linalg.init_tensor [4, 4097] : tensor<4x4097xi64> -// ``` +/// Rewrites `linalg.init_tensor` ops for which the converted type in +/// BConcrete is different from the original type. +/// +/// Example: +/// +/// ``` +/// linalg.init_tensor [4] : tensor<4x!Concrete.lwe_ciphertext<4096,6>> +/// ``` +/// +/// which has become after type conversion: +/// +/// ``` +/// linalg.init_tensor [4] : tensor<4x4097xi64> +/// ``` +/// +/// is finally fixed: +/// +/// ``` +/// linalg.init_tensor [4, 4097] : tensor<4x4097xi64> +/// ``` struct InitTensorOpPattern : public mlir::OpRewritePattern { InitTensorOpPattern(::mlir::MLIRContext *context, diff --git a/compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp b/compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp index f7e4530d7..2539a46f7 100644 --- a/compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp +++ b/compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp @@ -40,41 +40,41 @@ struct DotToLinalgGeneric : ::mlir::OpRewritePattern<::mlir::concretelang::FHELinalg::Dot>( context, mlir::concretelang::DEFAULT_PATTERN_BENEFIT) {} - // This rewrite pattern transforms any instance of - // `FHELinalg.dot_eint_int` to an instance of `linalg.generic` with an - // appropriate region using `FHE.mul_eint_int` and - // `FHE.add_eint` operations, an appropriate specification for the - // iteration dimensions and appropriate operations managing the - // accumulator of `linalg.generic`. - // - // Example: - // - // %o = "FHELinalg.dot_eint_int"(%arg0, %arg1) : - // (tensor<4x!FHE.eint<0>>, - // tensor<4xi32>) -> (!FHE.eint<0>) - // - // becomes: - // - // %0 = "FHE.zero_tensor"() : () -> tensor<1x!FHE.eint<0>> - // %1 = linalg.generic { - // indexing_maps = [#map0, #map0, #map1], - // iterator_types = ["reduction"] - // } - // ins(%arg0, %arg1 : tensor<2x!FHE.eint<0>>, tensor<2xi32>) - // outs(%0 : tensor<1x!FHE.eint<0>>) { - // ^bb0(%arg2: !FHE.eint<0>, %arg3: i32, %arg4: !FHE.eint<0>): - // %4 = "FHE.mul_eint_int"(%arg2, %arg3) : - // (!FHE.eint<0>, i32) -> !FHE.eint<0> - // - // %5 = "FHE.add_eint"(%4, %arg4) : - // (!FHE.eint<0>, !FHE.eint<0>) -> !FHE.eint<0> - // - // linalg.yield %5 : !FHE.eint<0> - // } -> tensor<1x!FHE.eint<0>> - // - // %c0 = constant 0 : index - // %o = tensor.extract %1[%c0] : tensor<1x!FHE.eint<0>> - // + /// This rewrite pattern transforms any instance of + /// `FHELinalg.dot_eint_int` to an instance of `linalg.generic` with an + /// appropriate region using `FHE.mul_eint_int` and + /// `FHE.add_eint` operations, an appropriate specification for the + /// iteration dimensions and appropriate operations managing the + /// accumulator of `linalg.generic`. + /// + /// Example: + /// + /// %o = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + /// (tensor<4x!FHE.eint<0>>, + /// tensor<4xi32>) -> (!FHE.eint<0>) + /// + /// becomes: + /// + /// %0 = "FHE.zero_tensor"() : () -> tensor<1x!FHE.eint<0>> + /// %1 = linalg.generic { + /// indexing_maps = [#map0, #map0, #map1], + /// iterator_types = ["reduction"] + /// } + /// ins(%arg0, %arg1 : tensor<2x!FHE.eint<0>>, tensor<2xi32>) + /// outs(%0 : tensor<1x!FHE.eint<0>>) { + /// ^bb0(%arg2: !FHE.eint<0>, %arg3: i32, %arg4: !FHE.eint<0>): + /// %4 = "FHE.mul_eint_int"(%arg2, %arg3) : + /// (!FHE.eint<0>, i32) -> !FHE.eint<0> + /// + /// %5 = "FHE.add_eint"(%4, %arg4) : + /// (!FHE.eint<0>, !FHE.eint<0>) -> !FHE.eint<0> + /// + /// linalg.yield %5 : !FHE.eint<0> + /// } -> tensor<1x!FHE.eint<0>> + /// + /// %c0 = constant 0 : index + /// %o = tensor.extract %1[%c0] : tensor<1x!FHE.eint<0>> + /// ::mlir::LogicalResult matchAndRewrite(::mlir::concretelang::FHELinalg::Dot dotOp, ::mlir::PatternRewriter &rewriter) const override { @@ -149,16 +149,16 @@ getBroadcastedAffineMap(const mlir::RankedTensorType &resultType, rewriter.getContext()); } -// This create an affine map following the broadcasting rules, but also takes -// out one specific element of the LUT from the LUT dimension, which should be -// the last. -// -// Example: -// -// resultType: 4x2x5, operandType: 4x2x8, lut_index: 3 -// return: affine_map<(d0, d1, d2) -> (d0, d1, 3) -// last dimension of the operand is the lut size, and we take the map takes out -// the element at index 3 +/// This create an affine map following the broadcasting rules, but also takes +/// out one specific element of the LUT from the LUT dimension, which should be +/// the last. +/// +/// Example: +/// +/// resultType: 4x2x5, operandType: 4x2x8, lut_index: 3 +/// return: affine_map<(d0, d1, d2) -> (d0, d1, 3) +/// last dimension of the operand is the lut size, and we take the map takes out +/// the element at index 3 mlir::AffineMap getBroadcastedAffineMapMultiLUT(const mlir::RankedTensorType &resultType, const mlir::RankedTensorType &operandType, @@ -183,44 +183,44 @@ getBroadcastedAffineMapMultiLUT(const mlir::RankedTensorType &resultType, rewriter.getContext()); } -// This template rewrite pattern transforms any instance of -// operators `FHELinalgOp` that implements the broadasting rules to an -// instance of `linalg.generic` with an appropriate region using `FHEOp` -// operation, an appropriate specification for the iteration dimensions and -// appropriate operations managing the accumulator of `linalg.generic`. -// -// Example: -// -// %res = FHELinalg.op(%lhs, %rhs): -// (tensor>, tensor) -// -> tensor> -// -// becomes: -// -// #maps_0 = [ -// affine_map<(a$R", ..., a$A, ..., a1) -> -// (dim(lhs, $A) == 1 ? 0 : a$A,..., dim(lhs, 1) == 1 ? 0 : a1)>, -// affine_map<(a$R", ..., a1) -> -// (dim(rhs, $B') == 1 ? 0 : a$B', ..., dim(rhs, 1) == 1 ? 0 : a1)>, -// affine_map<(a$R", ..., a1) -> (a$R", ..., a1) -// ] -// #attributes_0 { -// indexing_maps = #maps_0, -// iterator_types = ["parallel", ..., "parallel"], // $R" parallel -// } -// %init = linalg.init_tensor [DR",...,D1"] -// : tensor> -// %res = linalg.generic { -// ins(%lhs, %rhs: tensor>,tensor) -// outs(%init : tensor>) -// { -// ^bb0(%arg0: !FHE.eint

, %arg1: T): -// %0 = FHE.op(%arg0, %arg1): !FHE.eint

, T -> -// !FHE.eint

-// linalg.yield %0 : !FHE.eint

-// } -// } -// +/// This template rewrite pattern transforms any instance of +/// operators `FHELinalgOp` that implements the broadasting rules to an +/// instance of `linalg.generic` with an appropriate region using `FHEOp` +/// operation, an appropriate specification for the iteration dimensions and +/// appropriate operations managing the accumulator of `linalg.generic`. +/// +/// Example: +/// +/// %res = FHELinalg.op(%lhs, %rhs): +/// (tensor>, tensor) +/// -> tensor> +/// +/// becomes: +/// +/// #maps_0 = [ +/// affine_map<(a$R", ..., a$A, ..., a1) -> +/// (dim(lhs, $A) == 1 ? 0 : a$A,..., dim(lhs, 1) == 1 ? 0 : a1)>, +/// affine_map<(a$R", ..., a1) -> +/// (dim(rhs, $B') == 1 ? 0 : a$B', ..., dim(rhs, 1) == 1 ? 0 : a1)>, +/// affine_map<(a$R", ..., a1) -> (a$R", ..., a1) +/// ] +/// #attributes_0 { +/// indexing_maps = #maps_0, +/// iterator_types = ["parallel", ..., "parallel"], // $R" parallel +/// } +/// %init = linalg.init_tensor [DR",...,D1"] +/// : tensor> +/// %res = linalg.generic { +/// ins(%lhs, %rhs: tensor>,tensor) +/// outs(%init : tensor>) +/// { +/// ^bb0(%arg0: !FHE.eint

, %arg1: T): +/// %0 = FHE.op(%arg0, %arg1): !FHE.eint

, T -> +/// !FHE.eint

+/// linalg.yield %0 : !FHE.eint

+/// } +/// } +/// template struct FHELinalgOpToLinalgGeneric : public mlir::OpRewritePattern { FHELinalgOpToLinalgGeneric(::mlir::MLIRContext *context, @@ -290,51 +290,51 @@ llvm::SmallVector parallelIteratorType(int n) { return llvm::SmallVector(n, "parallel"); } -// This class rewrite pattern transforms any instance of -// operators `FHELinalg.ApplyMappedLookupTableEintOp` that implements the -// broadasting rules to an instance of `linalg.generic` with an appropriate -// region using `FHE.ApplyLookupTableEintOp` operation, an appropriate -// specification for the iteration dimensions and appropriate operations -// managing the accumulator of `linalg.generic`. -// -// The current implementation does not rely on 'tensor.extract_slice' -// because of a bug in lowering this operation. -// -// Example: -// %res = "FHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) -// : (tensor<2x3x!FHE.eint<2>>, tensor<5x4xi64>, tensor<2x3xindex>) -// -> tensor<2x3x!FHE.eint<2>> -// -// becomes: -// -// #map = affine_map<(d0, d1) -> (d0, d1)> -// %init = linalg.init_tensor [2, 3] : tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> -// %output = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types -// = ["parallel", "parallel"]} ins(%arg0, %arg2 : -// tensor<2x3x!TFHE.glwe<{_,_,_}{2}>>, tensor<2x3xindex>) outs(%0 : -// tensor<2x3x!TFHE.glwe<{_,_,_}{2}>>) { -// ^bb0(%arg3: !TFHE.glwe<{_,_,_}{2}>, %lut_idx: index, %arg5: -// !TFHE.glwe<{_,_,_}{2}>): // no predecessors -// // SHOULD BE -// %lut = tensor.extract_slice %arg1[%[[LUTIDX]], 0] [1,4] [1, 1] -// : tensor<5x4xi64> to tensor<4xi64> -// // BUT IS -// %i0 = arith.constant 0 : index -// ... -// %i3 = arith.constant 3 : index -// %e0 = tensor.extract %arg5[%lut_idx, %i0] : tensor<5x4xi64> -// ... -// %e3 = tensor.extract %arg5[%lut_idx, %i3] : tensor<5x4xi64> -// %lut = tensor.from_elements %e0, ..., %e3 : tensor<4xi64> -// %res = "TFHE.apply_lookup_table"(%arg3, %[[LUT]]) -// {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension -// = -1 : i32, -// levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -// -1 : i32, polynomialSize = -1 : i32} -// : (!TFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> -// !TFHE.glwe<{_,_,_}{2}> linalg.yield %res : -// !TFHE.glwe<{_,_,_}{2}> -// } -> tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> +/// This class rewrite pattern transforms any instance of +/// operators `FHELinalg.ApplyMappedLookupTableEintOp` that implements the +/// broadasting rules to an instance of `linalg.generic` with an appropriate +/// region using `FHE.ApplyLookupTableEintOp` operation, an appropriate +/// specification for the iteration dimensions and appropriate operations +/// managing the accumulator of `linalg.generic`. +/// +/// The current implementation does not rely on 'tensor.extract_slice' +/// because of a bug in lowering this operation. +/// +/// Example: +/// %res = "FHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) +/// : (tensor<2x3x!FHE.eint<2>>, tensor<5x4xi64>, tensor<2x3xindex>) +/// -> tensor<2x3x!FHE.eint<2>> +/// +/// becomes: +/// +/// #map = affine_map<(d0, d1) -> (d0, d1)> +/// %init = linalg.init_tensor [2, 3] : tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> +/// %output = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types +/// = ["parallel", "parallel"]} ins(%arg0, %arg2 : +/// tensor<2x3x!TFHE.glwe<{_,_,_}{2}>>, tensor<2x3xindex>) outs(%0 : +/// tensor<2x3x!TFHE.glwe<{_,_,_}{2}>>) { +/// ^bb0(%arg3: !TFHE.glwe<{_,_,_}{2}>, %lut_idx: index, %arg5: +/// !TFHE.glwe<{_,_,_}{2}>): // no predecessors +/// // SHOULD BE +/// %lut = tensor.extract_slice %arg1[%[[LUTIDX]], 0] [1,4] [1, 1] +/// : tensor<5x4xi64> to tensor<4xi64> +/// // BUT IS +/// %i0 = arith.constant 0 : index +/// ... +/// %i3 = arith.constant 3 : index +/// %e0 = tensor.extract %arg5[%lut_idx, %i0] : tensor<5x4xi64> +/// ... +/// %e3 = tensor.extract %arg5[%lut_idx, %i3] : tensor<5x4xi64> +/// %lut = tensor.from_elements %e0, ..., %e3 : tensor<4xi64> +/// %res = "TFHE.apply_lookup_table"(%arg3, %[[LUT]]) +/// {baseLogBS = -1 : i32, baseLogKS = -1 : i32, +/// glweDimension = -1 : i32, +/// levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = +/// -1 : i32, polynomialSize = -1 : i32} +/// : (!TFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> +/// !TFHE.glwe<{_,_,_}{2}> linalg.yield %res : +/// !TFHE.glwe<{_,_,_}{2}> +/// } -> tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> namespace FHELinalg = mlir::concretelang::FHELinalg; @@ -450,50 +450,50 @@ struct FHELinalgApplyMappedLookupTableToLinalgGeneric }; }; -// This class rewrite pattern transforms any instance of -// operators `FHELinalg.ApplyMultiLookupTableEintOp` that implements the -// broadasting rules to an instance of `linalg.generic` with an appropriate -// region using `FHE.ApplyLookupTableEintOp` operation, an appropriate -// specification for the iteration dimensions and appropriate operaztions -// managing the accumulator of `linalg.generic`. -// -// Example: -// -// %res = "FHELinalg.apply_multi_lookup_table"(%t, %luts): -// (tensor<4x3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> -// -// becomes: -// -// #maps_0 = [ -// affine_map<(d0, d1) -> (d0, d1)> -// affine_map<(d0, d1) -> (d1, 0)> -// affine_map<(d0, d1) -> (d1, 1)> -// affine_map<(d0, d1) -> (d1, 2)> -// affine_map<(d0, d1) -> (d1, 3)> -// ] -// #attributes_0 { -// indexing_maps = #maps_0, -// iterator_types = ["parallel", "parallel"], -// } -// %init = linalg.init_tensor [4, 3] -// : tensor<4x3x!FHE.eint<2>> -// %res = linalg.generic { -// ins(%t, %luts, %luts, %luts, %luts: tensor<4x3x!FHE.eint

>, -// tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) -// outs(%init : tensor<4x3x!FHE.eint<2>>) -// { -// ^bb0(%arg0: !FHE.eint<2>, %arg1: i64, %arg2: i64, %arg3: i64, -// %arg4: i64, %arg5: !FHE.eint<2>): -// %lut = tensor.from_elements %arg1, %arg2, %arg3, %arg4 : -// tensor<4xi64> %0 = "TFHE.apply_lookup_table"(%arg0, %lut) -// {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : -// i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : -// i32, polynomialSize = -1 : i32} : (!TFHE.glwe<{_,_,_}{2}>, -// tensor<4xi64>) -> !TFHE.glwe<{_,_,_}{2}> -// linalg.yield %0 : !FHE.eint<2> -// } -// } -// +/// This class rewrite pattern transforms any instance of +/// operators `FHELinalg.ApplyMultiLookupTableEintOp` that implements the +/// broadasting rules to an instance of `linalg.generic` with an appropriate +/// region using `FHE.ApplyLookupTableEintOp` operation, an appropriate +/// specification for the iteration dimensions and appropriate operaztions +/// managing the accumulator of `linalg.generic`. +/// +/// Example: +/// +/// %res = "FHELinalg.apply_multi_lookup_table"(%t, %luts): +/// (tensor<4x3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> +/// +/// becomes: +/// +/// #maps_0 = [ +/// affine_map<(d0, d1) -> (d0, d1)> +/// affine_map<(d0, d1) -> (d1, 0)> +/// affine_map<(d0, d1) -> (d1, 1)> +/// affine_map<(d0, d1) -> (d1, 2)> +/// affine_map<(d0, d1) -> (d1, 3)> +/// ] +/// #attributes_0 { +/// indexing_maps = #maps_0, +/// iterator_types = ["parallel", "parallel"], +/// } +/// %init = linalg.init_tensor [4, 3] +/// : tensor<4x3x!FHE.eint<2>> +/// %res = linalg.generic { +/// ins(%t, %luts, %luts, %luts, %luts: tensor<4x3x!FHE.eint

>, +/// tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) +/// outs(%init : tensor<4x3x!FHE.eint<2>>) +/// { +/// ^bb0(%arg0: !FHE.eint<2>, %arg1: i64, %arg2: i64, %arg3: i64, +/// %arg4: i64, %arg5: !FHE.eint<2>): +/// %lut = tensor.from_elements %arg1, %arg2, %arg3, %arg4 : +/// tensor<4xi64> %0 = "TFHE.apply_lookup_table"(%arg0, %lut) +/// {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 +/// : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 +/// : i32, polynomialSize = -1 : i32} : (!TFHE.glwe<{_,_,_}{2}>, +/// tensor<4xi64>) -> !TFHE.glwe<{_,_,_}{2}> +/// linalg.yield %0 : !FHE.eint<2> +/// } +/// } +/// struct FHELinalgApplyMultiLookupTableToLinalgGeneric : public mlir::OpRewritePattern< mlir::concretelang::FHELinalg::ApplyMultiLookupTableEintOp> { @@ -578,42 +578,42 @@ struct FHELinalgApplyMultiLookupTableToLinalgGeneric }; }; -// This template rewrite pattern transforms any instance of -// operators `FHELinalg.apply_lookup_table` that implements the broadasting -// rules to an instance of `linalg.generic` with an appropriate region using -// `FHE.apply_lookup_table` operation, an appropriate specification for the -// iteration dimensions and appropriate operations managing the accumulator of -// `linalg.generic`. -// -// Example: -// -// FHELinalg.apply_lookup_table(%t, %lut): -// tensor>, tensor -// -> tensor> -// -// becomes: -// -// #maps_0 = [ -// affine_map<(aN, ..., a1) -> (aN, ..., a1)>, -// affine_map<(aN, ..., a1) -> (aN, ..., a1)> -// ] -// #attributes_0 { -// indexing_maps = #maps_0, -// iterator_types = ["parallel",..],//N parallel -// } -// %init = linalg.init_tensor [DN,...,D1] -// : tensor> -// %res = linalg.generic { -// ins(%t: tensor>) -// outs(%init : tensor>) -// { -// ^bb0(%arg0: !FHE.eint

): -// %0 = FHE.apply_lookup_table(%arg0, %lut): !FHE.eint

, -// tensor<4xi64> -> !FHE.eint -// linalg.yield %0 : !FHE.eint -// } -// } -// +/// This template rewrite pattern transforms any instance of +/// operators `FHELinalg.apply_lookup_table` that implements the broadasting +/// rules to an instance of `linalg.generic` with an appropriate region using +/// `FHE.apply_lookup_table` operation, an appropriate specification for the +/// iteration dimensions and appropriate operations managing the accumulator of +/// `linalg.generic`. +/// +/// Example: +/// +/// FHELinalg.apply_lookup_table(%t, %lut): +/// tensor>, tensor +/// -> tensor> +/// +/// becomes: +/// +/// #maps_0 = [ +/// affine_map<(aN, ..., a1) -> (aN, ..., a1)>, +/// affine_map<(aN, ..., a1) -> (aN, ..., a1)> +/// ] +/// #attributes_0 { +/// indexing_maps = #maps_0, +/// iterator_types = ["parallel",..],//N parallel +/// } +/// %init = linalg.init_tensor [DN,...,D1] +/// : tensor> +/// %res = linalg.generic { +/// ins(%t: tensor>) +/// outs(%init : tensor>) +/// { +/// ^bb0(%arg0: !FHE.eint

): +/// %0 = FHE.apply_lookup_table(%arg0, %lut): !FHE.eint

, +/// tensor<4xi64> -> !FHE.eint +/// linalg.yield %0 : !FHE.eint +/// } +/// } +/// struct FHELinalgApplyLookupTableToLinalgGeneric : public mlir::OpRewritePattern< mlir::concretelang::FHELinalg::ApplyLookupTableEintOp> { @@ -681,39 +681,39 @@ struct FHELinalgApplyLookupTableToLinalgGeneric }; }; -// This template rewrite pattern transforms any instance of -// operators `FHELinalg.neg_eint` to an instance of `linalg.generic` with an -// appropriate region using `FHE.neg_eint` operation, an appropriate -// specification for the iteration dimensions and appropriate operations -// managing the accumulator of `linalg.generic`. -// -// Example: -// -// FHELinalg.neg_eint(%tensor): -// tensor> -> tensor> -// -// becomes: -// -// #maps_0 = [ -// affine_map<(aN, ..., a1) -> (aN, ..., a1)>, -// affine_map<(aN, ..., a1) -> (aN, ..., a1)> -// ] -// #attributes_0 { -// indexing_maps = #maps_0, -// iterator_types = ["parallel",..],//N parallel -// } -// %init = linalg.init_tensor [DN,...,D1] -// : tensor> -// %res = linalg.generic { -// ins(%tensor: tensor>) -// outs(%init : tensor>) -// { -// ^bb0(%arg0: !FHE.eint

): -// %0 = FHE.neg_eint(%arg0): !FHE.eint

-> !FHE.eint -// linalg.yield %0 : !FHE.eint -// } -// } -// +/// This template rewrite pattern transforms any instance of +/// operators `FHELinalg.neg_eint` to an instance of `linalg.generic` with an +/// appropriate region using `FHE.neg_eint` operation, an appropriate +/// specification for the iteration dimensions and appropriate operations +/// managing the accumulator of `linalg.generic`. +/// +/// Example: +/// +/// FHELinalg.neg_eint(%tensor): +/// tensor> -> tensor> +/// +/// becomes: +/// +/// #maps_0 = [ +/// affine_map<(aN, ..., a1) -> (aN, ..., a1)>, +/// affine_map<(aN, ..., a1) -> (aN, ..., a1)> +/// ] +/// #attributes_0 { +/// indexing_maps = #maps_0, +/// iterator_types = ["parallel",..],//N parallel +/// } +/// %init = linalg.init_tensor [DN,...,D1] +/// : tensor> +/// %res = linalg.generic { +/// ins(%tensor: tensor>) +/// outs(%init : tensor>) +/// { +/// ^bb0(%arg0: !FHE.eint

): +/// %0 = FHE.neg_eint(%arg0): !FHE.eint

-> !FHE.eint +/// linalg.yield %0 : !FHE.eint +/// } +/// } +/// struct FHELinalgNegEintToLinalgGeneric : public mlir::OpRewritePattern { FHELinalgNegEintToLinalgGeneric( @@ -778,44 +778,43 @@ struct FHELinalgNegEintToLinalgGeneric }; }; -// This template rewrite pattern transforms any instance of -// operators `FHELinalgMatmulOp` to an instance of `linalg.generic` -// with an appropriate region using a builder that create the multiplication -// operators and `FHE.add_eint` operation, an appropriate specification for -// the iteration dimensions and appropriate operations managing the accumulator -// of `linalg.generic`. -// -// Example: -// -// "FHELinalg.matmul_eint_int(%a, %b) : -// (tensor>, tensor) -> -// tensor>" - -// -// becomes: -// -// #maps_0 = [ -// (m, n, p) -> (m, p), -// (m, n, p) -> (p, n), -// (m, n, p) -> (m, n) -// ] -// #attributes_0 = { -// indexing_maps = #maps_0, -// iterator_types = ["parallel", "parallel", "reduction"] -// } -// %init = FHE.zero_tensor : tensor> -// linalg.generic #attributes_0 -// ins(%A, %B : tensor>, -// tensor) -// outs(%C : tensor>) -// { -// ^bb0(%a: !FHE.eint

, %b: ip', %c: !FHE.eint

) : -// %d = createMulOp(%a, %b): !FHE.eint

-// %e = "FHE.add_eint"(%c, %d): -// (!FHE.eint

, !FHE.eint

) -> !FHE.eint

-// linalg.yield %e : !FHE.eint

-// } -// +/// This template rewrite pattern transforms any instance of +/// operators `FHELinalgMatmulOp` to an instance of `linalg.generic` +/// with an appropriate region using a builder that create the multiplication +/// operators and `FHE.add_eint` operation, an appropriate specification for +/// the iteration dimensions and appropriate operations managing the accumulator +/// of `linalg.generic`. +/// +/// Example: +/// +/// "FHELinalg.matmul_eint_int(%a, %b) : +/// (tensor>, tensor) -> +/// tensor>" +/// +/// becomes: +/// +/// #maps_0 = [ +/// (m, n, p) -> (m, p), +/// (m, n, p) -> (p, n), +/// (m, n, p) -> (m, n) +/// ] +/// #attributes_0 = { +/// indexing_maps = #maps_0, +/// iterator_types = ["parallel", "parallel", "reduction"] +/// } +/// %init = FHE.zero_tensor : tensor> +/// linalg.generic #attributes_0 +/// ins(%A, %B : tensor>, +/// tensor) +/// outs(%C : tensor>) +/// { +/// ^bb0(%a: !FHE.eint

, %b: ip', %c: !FHE.eint

) : +/// %d = createMulOp(%a, %b): !FHE.eint

+/// %e = "FHE.add_eint"(%c, %d): +/// (!FHE.eint

, !FHE.eint

) -> !FHE.eint

+/// linalg.yield %e : !FHE.eint

+/// } +/// template struct FHELinalgMatmulToLinalgGeneric : public mlir::OpRewritePattern { @@ -1089,37 +1088,37 @@ private: createMulOp; }; -// This rewrite pattern transforms any instance of operators -// `FHELinalg.sum` to an instance of `linalg.generic`. -// -// Example: -// -// %result = "FHELinalg.sum"(%input) : -// tensor>() -> !FHE.eint

-// -// becomes: -// -// #map0 = affine_map<(i0, i1, ..., iN) -> (i0, i1, ..., iN)> -// #map1 = affine_map<(i0, i1, ..., iN) -> (0)> -// -// %accumulator = "FHE.zero_tensor"() : () -> tensor<1x!FHE.eint<7>> -// %accumulation = linalg.generic -// { -// indexing_maps = [#map0, #map1], -// iterator_types = ["reduction", "reduction", ..., "reduction"] -// } -// ins(%input : tensor>) -// outs(%accumulator : tensor<1x!FHE.eint<7>>) -// { -// ^bb0(%a: !FHE.eint<7>, %b: !FHE.eint<7>): -// %c = "FHE.add_eint"(%a, %b) : -// (!FHE.eint<7>, !FHE.eint<7>) -> !FHE.eint<7> -// linalg.yield %c : !FHE.eint<7> -// } -> tensor<1x!FHE.eint<7>> -// -// %index = arith.constant 0 : index -// %result = tensor.extract %index : tensor<1x!FHE.eint<7>> -// +/// This rewrite pattern transforms any instance of operators +/// `FHELinalg.sum` to an instance of `linalg.generic`. +/// +/// Example: +/// +/// %result = "FHELinalg.sum"(%input) : +/// tensor>() -> !FHE.eint

+/// +/// becomes: +/// +/// #map0 = affine_map<(i0, i1, ..., iN) -> (i0, i1, ..., iN)> +/// #map1 = affine_map<(i0, i1, ..., iN) -> (0)> +/// +/// %accumulator = "FHE.zero_tensor"() : () -> tensor<1x!FHE.eint<7>> +/// %accumulation = linalg.generic +/// { +/// indexing_maps = [#map0, #map1], +/// iterator_types = ["reduction", "reduction", ..., "reduction"] +/// } +/// ins(%input : tensor>) +/// outs(%accumulator : tensor<1x!FHE.eint<7>>) +/// { +/// ^bb0(%a: !FHE.eint<7>, %b: !FHE.eint<7>): +/// %c = "FHE.add_eint"(%a, %b) : +/// (!FHE.eint<7>, !FHE.eint<7>) -> !FHE.eint<7> +/// linalg.yield %c : !FHE.eint<7> +/// } -> tensor<1x!FHE.eint<7>> +/// +/// %index = arith.constant 0 : index +/// %result = tensor.extract %index : tensor<1x!FHE.eint<7>> +/// struct SumToLinalgGeneric : public ::mlir::OpRewritePattern { SumToLinalgGeneric(::mlir::MLIRContext *context) @@ -1245,32 +1244,32 @@ struct SumToLinalgGeneric }; }; -// This rewrite pattern transforms any instance of operators -// `FHELinalg.transpose` to an instance of `linalg.generic`. -// -// Example: -// -// %result = "FHELinalg.transpose"(%input: tensor>) -// -> tensor -// -// becomes: -// -// #map0 = affine_map<(i0, i1, ..., iN) -> (iN, ..., i1, i0)> -// #map1 = affine_map<(i0, i1, ..., iN) -> (i0, i1, ..., iN)> -// -// %accumulator = "FHE.zero_tensor"() : () -> -// tensor> %result = linalg.generic -// { -// indexing_maps = [#map0, #map1], -// iterator_types = ["parallel", "parallel", ..., "parallel"] -// } -// ins(%input : tensor>) -// outs(%accumulator : tensor>) -// { -// ^bb0(%a: !FHE.eint<7>, %b: !FHE.eint<7>): -// linalg.yield %a : !FHE.eint<7> -// } -> tensor> -// +/// This rewrite pattern transforms any instance of operators +/// `FHELinalg.transpose` to an instance of `linalg.generic`. +/// +/// Example: +/// +/// %result = "FHELinalg.transpose"(%input: tensor>) +/// -> tensor +/// +/// becomes: +/// +/// #map0 = affine_map<(i0, i1, ..., iN) -> (iN, ..., i1, i0)> +/// #map1 = affine_map<(i0, i1, ..., iN) -> (i0, i1, ..., iN)> +/// +/// %accumulator = "FHE.zero_tensor"() : () -> +/// tensor> %result = linalg.generic +/// { +/// indexing_maps = [#map0, #map1], +/// iterator_types = ["parallel", "parallel", ..., "parallel"] +/// } +/// ins(%input : tensor>) +/// outs(%accumulator : tensor>) +/// { +/// ^bb0(%a: !FHE.eint<7>, %b: !FHE.eint<7>): +/// linalg.yield %a : !FHE.eint<7> +/// } -> tensor> +/// struct TransposeToLinalgGeneric : public ::mlir::OpRewritePattern< mlir::concretelang::FHELinalg::TransposeOp> { @@ -1325,25 +1324,25 @@ struct TransposeToLinalgGeneric }; }; -// This rewrite pattern transforms any instance of operators -// `FHELinalg.concat` to instances of `tensor.insert_slice` -// -// Example: -// -// %result = "FHELinalg.concat"(%x, %y) { axis = 1 } : -// (tensor<2x3x!FHE.eint<4>>, tensor<2x4x!FHE.eint<4>>) -// -> tensor<2x7x!FHE.eint<4>> -// -// becomes: -// -// %empty = "FHE.zero_tensor"() : () -> tensor<2x7x!FHE.eint<4>> -// -// %x_copied = tensor.insert_slice %x into %empty[0, 0] [2, 3] [1, 1] -// : tensor<2x3x!FHE.eint<4>> into tensor<2x7x!FHE.eint<4>> -// -// %y_copied = tensor.insert_slice %y into %x_copied[0, 3] [2, 4] [1, 1] -// : tensor<2x4x!FHE.eint<4>> into tensor<2x7x!FHE.eint<4>> -// +/// This rewrite pattern transforms any instance of operators +/// `FHELinalg.concat` to instances of `tensor.insert_slice` +/// +/// Example: +/// +/// %result = "FHELinalg.concat"(%x, %y) { axis = 1 } : +/// (tensor<2x3x!FHE.eint<4>>, tensor<2x4x!FHE.eint<4>>) +/// -> tensor<2x7x!FHE.eint<4>> +/// +/// becomes: +/// +/// %empty = "FHE.zero_tensor"() : () -> tensor<2x7x!FHE.eint<4>> +/// +/// %x_copied = tensor.insert_slice %x into %empty[0, 0] [2, 3] [1, 1] +/// : tensor<2x3x!FHE.eint<4>> into tensor<2x7x!FHE.eint<4>> +/// +/// %y_copied = tensor.insert_slice %y into %x_copied[0, 3] [2, 4] [1, 1] +/// : tensor<2x4x!FHE.eint<4>> into tensor<2x7x!FHE.eint<4>> +/// struct ConcatRewritePattern : public mlir::OpRewritePattern { ConcatRewritePattern(mlir::MLIRContext *context) @@ -1449,8 +1448,8 @@ getAsOpFoldResult(mlir::OpBuilder &b, mlir::Location loc, })); } -// Helper function to get the padding tensor given the padding int values, and -// the value to pad with +/// Helper function to get the padding tensor given the padding int values, and +/// the value to pad with static mlir::Value getPaddedTensor(mlir::Operation *op, mlir::OpBuilder &b, mlir::Value &input, mlir::SmallVectorImpl &lowPaddingInts, @@ -1472,10 +1471,10 @@ getPaddedTensor(mlir::Operation *op, mlir::OpBuilder &b, mlir::Value &input, return paddedInput; } -// This rewrite pattern transforms any instance of operators -// `FHELinalg.conv2d` to an instance of `linalg.fhelinalg_conv_2d_nchw_fchw`. -// The transformation consists of padding the input tensor, and initializing the -// output tensor with bias values if any. +/// This rewrite pattern transforms any instance of operators +/// `FHELinalg.conv2d` to an instance of `linalg.fhelinalg_conv_2d_nchw_fchw`. +/// The transformation consists of padding the input tensor, and initializing +/// the output tensor with bias values if any. struct FHELinalgConv2dToLinalgConv2d : public ::mlir::OpRewritePattern { FHELinalgConv2dToLinalgConv2d(::mlir::MLIRContext *context) diff --git a/compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp b/compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp index f6cc093e9..a77aee321 100644 --- a/compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp +++ b/compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp @@ -60,30 +60,30 @@ public: } }; -// This rewrite pattern transforms any instance of `FHE.apply_lookup_table` -// operators. -// -// Example: -// -// ```mlir -// %0 = "FHE.apply_lookup_table"(%ct, %lut): (!FHE.eint<2>, tensor<4xi64>) -// ->(!FHE.eint<2>) -// ``` -// -// becomes: -// -// ```mlir -// %glwe_lut = "TFHE.glwe_from_table"(%lut) -// : (tensor<4xi64>) -> !TFHE.glwe<{_,_,_}{2}> -// %glwe_ks = "TFHE.keyswitch_glwe"(%ct) -// {baseLog = -1 : i32, level = -1 : i32} -// : (!TFHE.glwe<{_,_,_}{2}>) -> !TFHE.glwe<{_,_,_}{2}> -// %0 = "TFHE.bootstrap_glwe"(%glwe_ks, %glwe_lut) -// {baseLog = -1 : i32, glweDimension = -1 : i32, level = -1 : i32, -// polynomialSize = -1 : i32} -// : (!TFHE.glwe<{_,_,_}{2}>, !TFHE.glwe<{_,_,_}{2}>) -> -// !TFHE.glwe<{_,_,_}{2}> -// ``` +/// This rewrite pattern transforms any instance of `FHE.apply_lookup_table` +/// operators. +/// +/// Example: +/// +/// ```mlir +/// %0 = "FHE.apply_lookup_table"(%ct, %lut): (!FHE.eint<2>, tensor<4xi64>) +/// ->(!FHE.eint<2>) +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %glwe_lut = "TFHE.glwe_from_table"(%lut) +/// : (tensor<4xi64>) -> !TFHE.glwe<{_,_,_}{2}> +/// %glwe_ks = "TFHE.keyswitch_glwe"(%ct) +/// {baseLog = -1 : i32, level = -1 : i32} +/// : (!TFHE.glwe<{_,_,_}{2}>) -> !TFHE.glwe<{_,_,_}{2}> +/// %0 = "TFHE.bootstrap_glwe"(%glwe_ks, %glwe_lut) +/// {baseLog = -1 : i32, glweDimension = -1 : i32, level = -1 : i32, +/// polynomialSize = -1 : i32} +/// : (!TFHE.glwe<{_,_,_}{2}>, !TFHE.glwe<{_,_,_}{2}>) -> +/// !TFHE.glwe<{_,_,_}{2}> +/// ``` struct ApplyLookupTableEintOpPattern : public mlir::OpRewritePattern { ApplyLookupTableEintOpPattern(mlir::MLIRContext *context, @@ -115,8 +115,8 @@ struct ApplyLookupTableEintOpPattern }; }; -// This rewrite pattern transforms any instance of `FHE.sub_eint_int` -// operators to a negation and an addition. +/// This rewrite pattern transforms any instance of `FHE.sub_eint_int` +/// operators to a negation and an addition. struct SubEintIntOpPattern : public mlir::OpRewritePattern { SubEintIntOpPattern(mlir::MLIRContext *context, mlir::PatternBenefit benefit = 1) @@ -156,8 +156,8 @@ struct SubEintIntOpPattern : public mlir::OpRewritePattern { }; }; -// This rewrite pattern transforms any instance of `FHE.sub_eint` -// operators to a negation and an addition. +/// This rewrite pattern transforms any instance of `FHE.sub_eint` +/// operators to a negation and an addition. struct SubEintOpPattern : public mlir::OpRewritePattern { SubEintOpPattern(mlir::MLIRContext *context, mlir::PatternBenefit benefit = 1) : ::mlir::OpRewritePattern(context, benefit) {} diff --git a/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp b/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp index 3de07402d..dba2019ce 100644 --- a/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp +++ b/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp @@ -43,26 +43,26 @@ struct MLIRLowerableDialectsToLLVMPass }; } // namespace -// This rewrite pattern transforms any instance of `memref.copy` -// operators on 1D memref. -// This is introduced to avoid the MLIR lowering of `memref.copy` of ranked -// memref that basically allocate unranked memref structure on the stack before -// calling @memrefCopy. -// -// Example: -// -// ```mlir -// memref.copy %src, %dst : memref to memref -// ``` -// -// becomes: -// -// ```mlir -// %_src = memref.cast %src = memref to memref -// %_dst = memref.cast %dst = memref to memref -// call @memref_copy_one_rank(%_src, %_dst) : (tensor, tensor) -> -// () -// ``` +/// This rewrite pattern transforms any instance of `memref.copy` +/// operators on 1D memref. +/// This is introduced to avoid the MLIR lowering of `memref.copy` of ranked +/// memref that basically allocate unranked memref structure on the stack before +/// calling @memrefCopy. +/// +/// Example: +/// +/// ```mlir +/// memref.copy %src, %dst : memref to memref +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %_src = memref.cast %src = memref to memref +/// %_dst = memref.cast %dst = memref to memref +/// call @memref_copy_one_rank(%_src, %_dst) : (tensor, tensor) -> +/// () +/// ``` struct Memref1DCopyOpPattern : public mlir::OpRewritePattern { Memref1DCopyOpPattern(mlir::MLIRContext *context, diff --git a/compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp b/compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp index 00fada188..9813ed7fb 100644 --- a/compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp +++ b/compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp @@ -147,25 +147,25 @@ private: mlir::concretelang::V0FHEContext &fheContext; }; -// This rewrite pattern transforms any instance of `TFHE.glwe_from_table` by -// parametrize GLWE return type and pad the table if the precision has been -// changed. -// -// Example: -// -// ```mlir -// %lut = arith.constant dense<[0, 1, 2, 3]> : tensor<4xi64> -// %0 = "TFHE.glwe_from_table" (%lut) : (tensor<4xi64>) -> -// !TFHE.glwe<{_,_,_}{2}> -// ``` -// -// becomes: -// -// ```mlir -// %lut = arith.constant dense<[0, 1, 2, 3, 0, 1, 2, 3]> : tensor<8xi64> -// %0 = "TFHE.glwe_from_table" (%lut) : (tensor<8xi64>) -> -// !TFHE.glwe<{_,_,_}{3}> -// ``` +/// This rewrite pattern transforms any instance of `TFHE.glwe_from_table` by +/// parametrize GLWE return type and pad the table if the precision has been +/// changed. +/// +/// Example: +/// +/// ```mlir +/// %lut = arith.constant dense<[0, 1, 2, 3]> : tensor<4xi64> +/// %0 = "TFHE.glwe_from_table" (%lut) : (tensor<4xi64>) -> +/// !TFHE.glwe<{_,_,_}{2}> +/// ``` +/// +/// becomes: +/// +/// ```mlir +/// %lut = arith.constant dense<[0, 1, 2, 3, 0, 1, 2, 3]> : tensor<8xi64> +/// %0 = "TFHE.glwe_from_table" (%lut) : (tensor<8xi64>) -> +/// !TFHE.glwe<{_,_,_}{3}> +/// ``` struct GLWEFromTablePattern : public mlir::OpRewritePattern { GLWEFromTablePattern(mlir::MLIRContext *context, diff --git a/compiler/lib/Dialect/BConcrete/Transforms/AddRuntimeContext.cpp b/compiler/lib/Dialect/BConcrete/Transforms/AddRuntimeContext.cpp index fd40c0d3f..a96d01078 100644 --- a/compiler/lib/Dialect/BConcrete/Transforms/AddRuntimeContext.cpp +++ b/compiler/lib/Dialect/BConcrete/Transforms/AddRuntimeContext.cpp @@ -57,8 +57,8 @@ struct AddRuntimeContextToFuncOpPattern return mlir::success(); } - // Legal function are one that are private or has a Concrete.context as last - // arguments. + /// Legal function are one that are private or has a Concrete.context as last + /// arguments. static bool isLegal(mlir::func::FuncOp funcOp) { if (!funcOp.isPublic()) { return true; diff --git a/compiler/lib/Dialect/BConcrete/Transforms/BufferizableOpInterfaceImpl.cpp b/compiler/lib/Dialect/BConcrete/Transforms/BufferizableOpInterfaceImpl.cpp index 2c3bb4b6f..b5f4dc2d8 100644 --- a/compiler/lib/Dialect/BConcrete/Transforms/BufferizableOpInterfaceImpl.cpp +++ b/compiler/lib/Dialect/BConcrete/Transforms/BufferizableOpInterfaceImpl.cpp @@ -44,7 +44,7 @@ mlir::Type getDynamic1DMemrefWithUnknownOffset(mlir::RewriterBase &rewriter) { mlir::getAffineSymbolExpr(0, ctx))); } -// Returns `memref.cast %0 : memref to memref` if %0 a 1D memref +/// Returns `memref.cast %0 : memref to memref` if %0 a 1D memref mlir::Value getCasted1DMemRef(mlir::RewriterBase &rewriter, mlir::Location loc, mlir::Value value) { mlir::Type valueType = value.getType(); @@ -115,7 +115,7 @@ mlir::LogicalResult insertForwardDeclarationOfTheCAPI( return insertForwardDeclaration(op, rewriter, funcName, funcType); } -// Returns the value of the context argument from the enclosing func +/// Returns the value of the context argument from the enclosing func mlir::Value getContextArgument(mlir::Operation *op) { mlir::Block *block = op->getBlock(); while (block != nullptr) { @@ -233,25 +233,25 @@ struct BufferizableGlweFromTableOpInterface return BufferRelation::None; } - // Bufferize GlweFromTable - // ``` - // "BConcrete.fill_glwe_table"(%glwe, %lut) {glweDimension=1, - // polynomialSize=2048, outPrecision=3} : - // (tensor<4096xi64>, tensor<32xi64>) -> () - // ``` - // - // to - // - // ``` - // %glweDim = arith.constant 1 : i32 - // %polySize = arith.constant 2048 : i32 - // %outPrecision = arith.constant 3 : i32 - // %glwe_ = memref.cast %glwe : memref<4096xi64> to memref - // %lut_ = memref.cast %lut : memref<32xi64> to memref - // call @expand_lut_in_trivial_glwe_ct(%glwe, %polySize, %glweDim, - // %outPrecision, %lut_) : - // (tensor, i32, i32, tensor) -> () - // ``` + /// Bufferize GlweFromTable + /// ``` + /// "BConcrete.fill_glwe_table"(%glwe, %lut) {glweDimension=1, + /// polynomialSize=2048, outPrecision=3} : + /// (tensor<4096xi64>, tensor<32xi64>) -> () + /// ``` + /// + /// to + /// + /// ``` + /// %glweDim = arith.constant 1 : i32 + /// %polySize = arith.constant 2048 : i32 + /// %outPrecision = arith.constant 3 : i32 + /// %glwe_ = memref.cast %glwe : memref<4096xi64> to memref + /// %lut_ = memref.cast %lut : memref<32xi64> to memref + /// call @expand_lut_in_trivial_glwe_ct(%glwe, %polySize, %glweDim, + /// %outPrecision, %lut_) : + /// (tensor, i32, i32, tensor) -> () + /// ``` LogicalResult bufferize(Operation *op, RewriterBase &rewriter, BufferizationState &state) const { diff --git a/compiler/lib/Dialect/Concrete/Transforms/Optimization.cpp b/compiler/lib/Dialect/Concrete/Transforms/Optimization.cpp index 02c77497d..50c153e09 100644 --- a/compiler/lib/Dialect/Concrete/Transforms/Optimization.cpp +++ b/compiler/lib/Dialect/Concrete/Transforms/Optimization.cpp @@ -16,7 +16,7 @@ namespace concretelang { namespace { -// Get the integer value that the cleartext was created from if it exists. +/// Get the integer value that the cleartext was created from if it exists. llvm::Optional getIntegerFromCleartextIfExists(mlir::Value cleartext) { assert( @@ -32,7 +32,7 @@ getIntegerFromCleartextIfExists(mlir::Value cleartext) { return {}; } -// Get the constant integer that the cleartext was created from if it exists. +/// Get the constant integer that the cleartext was created from if it exists. llvm::Optional getConstantIntFromCleartextIfExists(mlir::Value cleartext) { auto cleartextInt = getIntegerFromCleartextIfExists(cleartext); @@ -49,9 +49,9 @@ getConstantIntFromCleartextIfExists(mlir::Value cleartext) { return {}; } -// Rewrite a `Concrete.mul_cleartext_lwe_ciphertext` operation as a -// `Concrete.zero` operation if it's being multiplied with a constant 0, or as a -// `Concrete.negate_lwe_ciphertext` if multiplied with a constant -1. +/// Rewrite a `Concrete.mul_cleartext_lwe_ciphertext` operation as a +/// `Concrete.zero` operation if it's being multiplied with a constant 0, or as +/// a `Concrete.negate_lwe_ciphertext` if multiplied with a constant -1. class MulCleartextLweCiphertextOpPattern : public mlir::OpRewritePattern< mlir::concretelang::Concrete::MulCleartextLweCiphertextOp> { @@ -85,8 +85,8 @@ public: } }; -// Optimization pass that should choose more efficient ways of performing crypto -// operations. +/// Optimization pass that should choose more efficient ways of performing +/// crypto operations. class ConcreteOptimizationPass : public ConcreteOptimizationBase { public: diff --git a/compiler/lib/Dialect/FHE/Analysis/MANP.cpp b/compiler/lib/Dialect/FHE/Analysis/MANP.cpp index 801c03af9..79fd4eb6a 100644 --- a/compiler/lib/Dialect/FHE/Analysis/MANP.cpp +++ b/compiler/lib/Dialect/FHE/Analysis/MANP.cpp @@ -32,8 +32,8 @@ namespace mlir { namespace concretelang { namespace { -// Returns `true` if the given value is a scalar or tensor argument of -// a function, for which a MANP of 1 can be assumed. +/// Returns `true` if the given value is a scalar or tensor argument of +/// a function, for which a MANP of 1 can be assumed. static bool isEncryptedFunctionParameter(mlir::Value value) { if (!value.isa()) return false; @@ -54,9 +54,9 @@ static bool isEncryptedFunctionParameter(mlir::Value value) { .isa())); } -// Returns the bit width of `value` if `value` is an encrypted integer -// or the bit width of the elements if `value` is a tensor of -// encrypted integers. +/// Returns the bit width of `value` if `value` is an encrypted integer +/// or the bit width of the elements if `value` is a tensor of +/// encrypted integers. static unsigned int getEintPrecision(mlir::Value value) { if (auto ty = value.getType() .dyn_cast_or_null< @@ -77,11 +77,11 @@ static unsigned int getEintPrecision(mlir::Value value) { return 0; } -// The `MANPLatticeValue` represents the squared Minimal Arithmetic -// Noise Padding for an operation using the squared 2-norm of an -// equivalent dot operation. This can either be an actual value if the -// values for its predecessors have been calculated beforehand or an -// unknown value otherwise. +/// The `MANPLatticeValue` represents the squared Minimal Arithmetic +/// Noise Padding for an operation using the squared 2-norm of an +/// equivalent dot operation. This can either be an actual value if the +/// values for its predecessors have been calculated beforehand or an +/// unknown value otherwise. struct MANPLatticeValue { MANPLatticeValue(llvm::Optional manp = {}) : manp(manp) {} @@ -109,10 +109,10 @@ struct MANPLatticeValue { return this->manp == rhs.manp; } - // Required by `mlir::LatticeElement::join()`, but should never be - // invoked, as `MANPAnalysis::visitOperation()` takes care of - // combining the squared Minimal Arithmetic Noise Padding of - // operands into the Minimal Arithmetic Noise Padding of the result. + /// Required by `mlir::LatticeElement::join()`, but should never be + /// invoked, as `MANPAnalysis::visitOperation()` takes care of + /// combining the squared Minimal Arithmetic Noise Padding of + /// operands into the Minimal Arithmetic Noise Padding of the result. static MANPLatticeValue join(const MANPLatticeValue &lhs, const MANPLatticeValue &rhs) { assert(false && "Minimal Arithmetic Noise Padding values can only be " @@ -126,9 +126,9 @@ protected: llvm::Optional manp; }; -// Checks if `lhs` is less than `rhs`, where both values are assumed -// to be positive. The bit width of the smaller `APInt` is extended -// before comparison via `APInt::ult`. +/// Checks if `lhs` is less than `rhs`, where both values are assumed +/// to be positive. The bit width of the smaller `APInt` is extended +/// before comparison via `APInt::ult`. static bool APIntWidthExtendULT(const llvm::APInt &lhs, const llvm::APInt &rhs) { if (lhs.getBitWidth() < rhs.getBitWidth()) @@ -139,9 +139,9 @@ static bool APIntWidthExtendULT(const llvm::APInt &lhs, return lhs.ult(rhs); } -// Adds two `APInt` values, where both values are assumed to be -// positive. The bit width of the operands is extended in order to -// guarantee that the sum fits into the resulting `APInt`. +/// Adds two `APInt` values, where both values are assumed to be +/// positive. The bit width of the operands is extended in order to +/// guarantee that the sum fits into the resulting `APInt`. static llvm::APInt APIntWidthExtendUAdd(const llvm::APInt &lhs, const llvm::APInt &rhs) { unsigned maxBits = std::max(lhs.getBitWidth(), rhs.getBitWidth()); @@ -154,9 +154,9 @@ static llvm::APInt APIntWidthExtendUAdd(const llvm::APInt &lhs, return lhs.zext(targetWidth) + rhs.zext(targetWidth); } -// Multiplies two `APInt` values, where both values are assumed to be -// positive. The bit width of the operands is extended in order to -// guarantee that the product fits into the resulting `APInt`. +/// Multiplies two `APInt` values, where both values are assumed to be +/// positive. The bit width of the operands is extended in order to +/// guarantee that the product fits into the resulting `APInt`. static llvm::APInt APIntWidthExtendUMul(const llvm::APInt &lhs, const llvm::APInt &rhs) { // Make sure the required number of bits can be represented by the @@ -170,9 +170,9 @@ static llvm::APInt APIntWidthExtendUMul(const llvm::APInt &lhs, return lhs.zext(targetWidth) * rhs.zext(targetWidth); } -// Returns the maximum value beetwen `lhs` and `rhs`, where both values are -// assumed to be positive. The bit width of the smaller `APInt` is extended -// before comparison via `APInt::ult`. +/// Returns the maximum value beetwen `lhs` and `rhs`, where both values are +/// assumed to be positive. The bit width of the smaller `APInt` is extended +/// before comparison via `APInt::ult`. static llvm::APInt APIntUMax(const llvm::APInt &lhs, const llvm::APInt &rhs) { if (APIntWidthExtendULT(lhs, rhs)) { return rhs; @@ -180,9 +180,9 @@ static llvm::APInt APIntUMax(const llvm::APInt &lhs, const llvm::APInt &rhs) { return lhs; } -// Calculates the square of `i`. The bit width `i` is extended in -// order to guarantee that the product fits into the resulting -// `APInt`. +/// Calculates the square of `i`. The bit width `i` is extended in +/// order to guarantee that the product fits into the resulting +/// `APInt`. static llvm::APInt APIntWidthExtendUnsignedSq(const llvm::APInt &i) { // Make sure the required number of bits can be represented by the // `unsigned` argument of `zext`. @@ -194,7 +194,7 @@ static llvm::APInt APIntWidthExtendUnsignedSq(const llvm::APInt &i) { return ie * ie; } -// Calculates the square of the absolute value of `i`. +/// Calculates the square of the absolute value of `i`. static llvm::APInt APIntWidthExtendSqForConstant(const llvm::APInt &i) { // Make sure the required number of bits can be represented by the // `unsigned` argument of `zext`. @@ -204,9 +204,9 @@ static llvm::APInt APIntWidthExtendSqForConstant(const llvm::APInt &i) { i.abs().getZExtValue() * i.abs().getZExtValue()); } -// Calculates the square root of `i` and rounds it to the next highest -// integer value (i.e., the square of the result is guaranteed to be -// greater or equal to `i`). +/// Calculates the square root of `i` and rounds it to the next highest +/// integer value (i.e., the square of the result is guaranteed to be +/// greater or equal to `i`). static llvm::APInt APIntCeilSqrt(const llvm::APInt &i) { llvm::APInt res = i.sqrt(); llvm::APInt resSq = APIntWidthExtendUnsignedSq(res); @@ -217,17 +217,17 @@ static llvm::APInt APIntCeilSqrt(const llvm::APInt &i) { return res; } -// Returns a string representation of `i` assuming that `i` is an -// unsigned value. +/// Returns a string representation of `i` assuming that `i` is an +/// unsigned value. static std::string APIntToStringValUnsigned(const llvm::APInt &i) { llvm::SmallString<32> s; i.toStringUnsigned(s); return std::string(s.c_str()); } -// Calculates the square of the 2-norm of a tensor initialized with a -// dense matrix of constant, signless integers. Aborts if the value -// type or initialization of of `cstOp` is incorrect. +/// Calculates the square of the 2-norm of a tensor initialized with a +/// dense matrix of constant, signless integers. Aborts if the value +/// type or initialization of of `cstOp` is incorrect. static llvm::APInt denseCstTensorNorm2Sq(mlir::arith::ConstantOp cstOp, llvm::APInt eNorm) { mlir::DenseIntElementsAttr denseVals = @@ -252,10 +252,10 @@ static llvm::APInt denseCstTensorNorm2Sq(mlir::arith::ConstantOp cstOp, return accu; } -// Calculates the square of the 2-norm of a 1D tensor of signless -// integers by conservatively assuming that the dynamic values are the -// maximum for the integer width. Aborts if the tensor type `tTy` is -// incorrect. +/// Calculates the square of the 2-norm of a 1D tensor of signless +/// integers by conservatively assuming that the dynamic values are the +/// maximum for the integer width. Aborts if the tensor type `tTy` is +/// incorrect. static llvm::APInt denseDynTensorNorm2Sq(mlir::TensorType tTy, llvm::APInt eNorm) { assert(tTy && tTy.getElementType().isSignlessInteger() && @@ -283,7 +283,7 @@ static llvm::APInt denseDynTensorNorm2Sq(mlir::TensorType tTy, return APIntWidthExtendUMul(maxMulSqNorm, nEltsAP); } -// Returns the squared 2-norm of the maximum value of the dense values. +/// Returns the squared 2-norm of the maximum value of the dense values. static llvm::APInt maxIntNorm2Sq(mlir::DenseIntElementsAttr denseVals) { auto denseValsAP = denseVals.getValues(); @@ -298,9 +298,9 @@ static llvm::APInt maxIntNorm2Sq(mlir::DenseIntElementsAttr denseVals) { return APIntWidthExtendSqForConstant(maxCst); } -// Returns the squared 2-norm for a dynamic integer by conservatively -// assuming that the integer's value is the maximum for the integer -// width. +/// Returns the squared 2-norm for a dynamic integer by conservatively +/// assuming that the integer's value is the maximum for the integer +/// width. static llvm::APInt conservativeIntNorm2Sq(mlir::Type t) { assert(t.isSignlessInteger() && "Type must be a signless integer type"); assert(std::numeric_limits::max() - t.getIntOrFloatBitWidth() > 1); @@ -309,8 +309,8 @@ static llvm::APInt conservativeIntNorm2Sq(mlir::Type t) { return APIntWidthExtendUnsignedSq(maxVal); } -// Calculates the squared Minimal Arithmetic Noise Padding of an -// `FHELinalg.dot_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of an +/// `FHELinalg.dot_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHELinalg::Dot op, llvm::ArrayRef *> operandMANPs) { @@ -343,8 +343,8 @@ static llvm::APInt getSqMANP( } } -// Calculates the squared Minimal Arithmetic Noise Padding of an -// `FHE.add_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of an +/// `FHE.add_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::AddEintIntOp op, llvm::ArrayRef *> operandMANPs) { @@ -378,8 +378,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(sqNorm, eNorm); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.add_eint` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.add_eint` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::AddEintOp op, llvm::ArrayRef *> operandMANPs) { @@ -395,8 +395,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(a, b); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.sub_int_eint` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.sub_int_eint` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::SubIntEintOp op, llvm::ArrayRef *> operandMANPs) { @@ -429,8 +429,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(sqNorm, eNorm); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.sub_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.sub_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::SubEintIntOp op, llvm::ArrayRef *> operandMANPs) { @@ -463,8 +463,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(sqNorm, eNorm); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.sub_eint` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.sub_eint` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::SubEintOp op, llvm::ArrayRef *> operandMANPs) { @@ -480,8 +480,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(a, b); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.neg_eint` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.neg_eint` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::NegEintOp op, llvm::ArrayRef *> operandMANPs) { @@ -496,8 +496,8 @@ static llvm::APInt getSqMANP( return eNorm; } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.mul_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.mul_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHE::MulEintIntOp op, llvm::ArrayRef *> operandMANPs) { @@ -531,8 +531,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUMul(sqNorm, eNorm); } -// Calculates the squared Minimal Arithmetic Noise Padding of an -// `FHELinalg.add_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of an +/// `FHELinalg.add_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHELinalg::AddEintIntOp op, llvm::ArrayRef *> operandMANPs) { @@ -587,8 +587,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(a, b); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHELinalg.sub_int_eint` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHELinalg.sub_int_eint` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHELinalg::SubIntEintOp op, llvm::ArrayRef *> operandMANPs) { @@ -678,8 +678,8 @@ static llvm::APInt getSqMANP( return APIntWidthExtendUAdd(a, b); } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHELinalg.neg_eint` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHELinalg.neg_eint` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHELinalg::NegEintOp op, llvm::ArrayRef *> operandMANPs) { @@ -694,8 +694,8 @@ static llvm::APInt getSqMANP( return eNorm; } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.mul_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.mul_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHELinalg::MulEintIntOp op, llvm::ArrayRef *> operandMANPs) { @@ -804,8 +804,8 @@ static llvm::APInt calculateSqManpForMatMulWithDenseValues( return maximumNorm; } -// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `FHE.mul_eint_int` operation. +/// Calculates the squared Minimal Arithmetic Noise Padding of a dot operation +/// that is equivalent to an `FHE.mul_eint_int` operation. static llvm::APInt getSqMANP( mlir::concretelang::FHELinalg::MatMulEintIntOp op, llvm::ArrayRef *> operandMANPs) { @@ -1508,7 +1508,7 @@ private: } // namespace namespace { -// For documentation see MANP.td +/// For documentation see MANP.td struct MANPPass : public MANPBase { void runOnOperation() override { mlir::func::FuncOp func = getOperation(); @@ -1524,16 +1524,16 @@ protected: }; } // end anonymous namespace -// Create an instance of the Minimal Arithmetic Noise Padding analysis -// pass. If `debug` is true, for each operation, the pass emits a -// remark containing the squared Minimal Arithmetic Noise Padding of -// the equivalent dot operation. +/// Create an instance of the Minimal Arithmetic Noise Padding analysis +/// pass. If `debug` is true, for each operation, the pass emits a +/// remark containing the squared Minimal Arithmetic Noise Padding of +/// the equivalent dot operation. std::unique_ptr createMANPPass(bool debug) { return std::make_unique(debug); } namespace { -// For documentation see MANP.td +/// For documentation see MANP.td struct MaxMANPPass : public MaxMANPBase { void runOnOperation() override { mlir::func::FuncOp func = getOperation(); diff --git a/compiler/lib/Dialect/FHE/IR/FHEOps.cpp b/compiler/lib/Dialect/FHE/IR/FHEOps.cpp index 033961928..afd69ae04 100644 --- a/compiler/lib/Dialect/FHE/IR/FHEOps.cpp +++ b/compiler/lib/Dialect/FHE/IR/FHEOps.cpp @@ -163,7 +163,7 @@ bool verifyEncryptedIntegerInputsConsistency(::mlir::Operation &op, return mlir::success(); } -// Avoid addition with constant 0 +/// Avoid addition with constant 0 OpFoldResult AddEintIntOp::fold(ArrayRef operands) { assert(operands.size() == 2); auto toAdd = operands[1].dyn_cast_or_null(); @@ -176,7 +176,7 @@ OpFoldResult AddEintIntOp::fold(ArrayRef operands) { return nullptr; } -// Avoid subtraction with constant 0 +/// Avoid subtraction with constant 0 OpFoldResult SubEintIntOp::fold(ArrayRef operands) { assert(operands.size() == 2); auto toSub = operands[1].dyn_cast_or_null(); @@ -189,7 +189,7 @@ OpFoldResult SubEintIntOp::fold(ArrayRef operands) { return nullptr; } -// Avoid multiplication with constant 1 +/// Avoid multiplication with constant 1 OpFoldResult MulEintIntOp::fold(ArrayRef operands) { assert(operands.size() == 2); auto toMul = operands[1].dyn_cast_or_null(); diff --git a/compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp b/compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp index f4996cb90..9bcbcf615 100644 --- a/compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp +++ b/compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp @@ -1717,7 +1717,7 @@ mlir::LogicalResult TransposeOp::verify() { return mlir::success(); } -// Avoid addition with constant tensor of 0s +/// Avoid addition with constant tensor of 0s OpFoldResult AddEintIntOp::fold(ArrayRef operands) { assert(operands.size() == 2); auto toAdd = operands[1].dyn_cast_or_null(); @@ -1731,7 +1731,7 @@ OpFoldResult AddEintIntOp::fold(ArrayRef operands) { return getOperand(0); } -// Avoid subtraction with constant tensor of 0s +/// Avoid subtraction with constant tensor of 0s OpFoldResult SubEintIntOp::fold(ArrayRef operands) { assert(operands.size() == 2); auto toSub = operands[1].dyn_cast_or_null(); @@ -1745,7 +1745,7 @@ OpFoldResult SubEintIntOp::fold(ArrayRef operands) { return getOperand(0); } -// Avoid multiplication with constant tensor of 1s +/// Avoid multiplication with constant tensor of 1s OpFoldResult MulEintIntOp::fold(ArrayRef operands) { assert(operands.size() == 2); auto toMul = operands[1].dyn_cast_or_null(); diff --git a/compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp b/compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp index 84ea4125c..7041bbaf6 100644 --- a/compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp +++ b/compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp @@ -22,9 +22,9 @@ namespace concretelang { namespace { -// Creates a `tensor.extract_slice` operation that extracts a -// contiguous, 2-dimensional slice with a static size specified by -// `sizes` at the dynamic offset `offsets`. +/// Creates a `tensor.extract_slice` operation that extracts a +/// contiguous, 2-dimensional slice with a static size specified by +/// `sizes` at the dynamic offset `offsets`. mlir::tensor::ExtractSliceOp extractContiguous2DSlice(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value T, llvm::ArrayRef sizes, @@ -43,18 +43,18 @@ extractContiguous2DSlice(mlir::OpBuilder &builder, mlir::Location loc, builder.getI64IntegerAttr(1)}); } -// Creates a perfect loop nest of SCF for loops with the lower bounds -// `lbs`, the upper bounds `ubs` and the steps `steps` in the order -// from the outermost to the innermost loop. The values specified in -// `loopCarriedDeps` are loop-carried dependencies carried across all -// loops. -// -// The function `func` is called with a builder for the body of the -// innermost loop, the original location `loc`, a vector with all -// induction variables from the outermost to the innermost loop and the -// loop-carried dependencies. -// -// Returns the outermost loop. +/// Creates a perfect loop nest of SCF for loops with the lower bounds +/// `lbs`, the upper bounds `ubs` and the steps `steps` in the order +/// from the outermost to the innermost loop. The values specified in +/// `loopCarriedDeps` are loop-carried dependencies carried across all +/// loops. +/// +/// The function `func` is called with a builder for the body of the +/// innermost loop, the original location `loc`, a vector with all +/// induction variables from the outermost to the innermost loop and the +/// loop-carried dependencies. +/// +/// Returns the outermost loop. mlir::scf::ForOp buildLoopNestWithLoopCarriedDependency( mlir::OpBuilder builder, mlir::Location loc, llvm::ArrayRef lbs, llvm::ArrayRef ubs, @@ -104,28 +104,28 @@ mlir::scf::ForOp buildLoopNestWithLoopCarriedDependency( return fops[0]; } -// Marker to avoid infinite recursion of the rewriting pattern +/// Marker to avoid infinite recursion of the rewriting pattern static const mlir::StringLiteral kTransformMarker = "__internal_fhe_linalg_tiling_marker__"; -// Rewrite an `FHELinalg.matmul_eint_int` operation as an equivalent -// sequence of operations consisting of a perfect loop nest of SCF for -// loops with a `FHELinalg.matmul_eint_int` operation that performs -// a matrix multiplication on a single tile. -// -// The terminology is as follows: -// -// - A: The input matrix of encrypted integers of size `NxM` -// - B: The input matrix of plaintext integers of size `MxK` -// - C: The output matrix of encrypted integers of size `NxK` -// -// At each iteration of the innermost loop, the generated -// `FHELinalg.matmul_eint_int` operation performs a multiplication -// of a matrix tile of size `TxU` and a matrix of size `UxV`, -// producing a tile of size `UxV`. -// -// Partial tiles are currently not supported, i.e., `N` must be a -// multiple of `T`, `M` a multiple of `U` and `K` a multiple of `V`. +/// Rewrite an `FHELinalg.matmul_eint_int` operation as an equivalent +/// sequence of operations consisting of a perfect loop nest of SCF for +/// loops with a `FHELinalg.matmul_eint_int` operation that performs +/// a matrix multiplication on a single tile. +/// +/// The terminology is as follows: +/// +/// - A: The input matrix of encrypted integers of size `NxM` +/// - B: The input matrix of plaintext integers of size `MxK` +/// - C: The output matrix of encrypted integers of size `NxK` +/// +/// At each iteration of the innermost loop, the generated +/// `FHELinalg.matmul_eint_int` operation performs a multiplication +/// of a matrix tile of size `TxU` and a matrix of size `UxV`, +/// producing a tile of size `UxV`. +/// +/// Partial tiles are currently not supported, i.e., `N` must be a +/// multiple of `T`, `M` a multiple of `U` and `K` a multiple of `V`. class MatMulTilingPattern : public mlir::OpRewritePattern< mlir::concretelang::FHELinalg::MatMulEintIntOp> { @@ -312,8 +312,8 @@ public: } }; -// Perfoms the actual tiling of `FHELinalg.matmul_eint_int` -// operations that have been marked with a "tile-sizes" attribute. +/// Perfoms the actual tiling of `FHELinalg.matmul_eint_int` +/// operations that have been marked with a "tile-sizes" attribute. class FHELinalgTilingPass : public FHELinalgTilingBase { public: void runOnOperation() override { @@ -332,8 +332,8 @@ public: } }; -// Marks all `FHELinalg.matmul_eint_int` operations that with a -// "tile-sizes" attribute containing the specified tile sizes. +/// Marks all `FHELinalg.matmul_eint_int` operations that with a +/// "tile-sizes" attribute containing the specified tile sizes. class FHELinalgTilingMarkerPass : public FHELinalgTilingMarkerBase { public: diff --git a/compiler/lib/Dialect/RT/Analysis/BufferizeDataflowTaskOps.cpp b/compiler/lib/Dialect/RT/Analysis/BufferizeDataflowTaskOps.cpp index e0292fb27..47ec79760 100644 --- a/compiler/lib/Dialect/RT/Analysis/BufferizeDataflowTaskOps.cpp +++ b/compiler/lib/Dialect/RT/Analysis/BufferizeDataflowTaskOps.cpp @@ -90,7 +90,7 @@ void populateRTBufferizePatterns( } namespace { -// For documentation see Autopar.td +/// For documentation see Autopar.td struct BufferizeDataflowTaskOpsPass : public BufferizeDataflowTaskOpsBase { diff --git a/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp b/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp index b8a890b57..edd371b10 100644 --- a/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp +++ b/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp @@ -52,8 +52,8 @@ static bool isCandidateForTask(Operation *op) { FHELinalg::ConcatOp, FHELinalg::FhelinalgConv2DNchwFchwOp>(op); } -// Identify operations that are beneficial to sink into tasks. These -// operations must not have side-effects and not be `isCandidateForTask` +/// Identify operations that are beneficial to sink into tasks. These +/// operations must not have side-effects and not be `isCandidateForTask` static bool isSinkingBeneficiary(Operation *op) { return isa(op); @@ -126,7 +126,7 @@ LogicalResult sinkOperationsIntoDFTask(RT::DataflowTaskOp taskOp) { return success(); } -// For documentation see Autopar.td +/// For documentation see Autopar.td struct BuildDataflowTaskGraphPass : public BuildDataflowTaskGraphBase { @@ -194,7 +194,7 @@ std::unique_ptr createBuildDataflowTaskGraphPass(bool debug) { } namespace { -// Marker to avoid infinite recursion of the rewriting pattern +/// Marker to avoid infinite recursion of the rewriting pattern static const mlir::StringLiteral kTransformMarker = "_internal_RT_FixDataflowTaskOpInputsPattern_marker__"; @@ -232,7 +232,7 @@ public: } // namespace namespace { -// For documentation see Autopar.td +/// For documentation see Autopar.td struct FixupDataflowTaskOpsPass : public FixupDataflowTaskOpsBase { diff --git a/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp b/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp index 68762e069..8f2d17b7e 100644 --- a/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp +++ b/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp @@ -271,7 +271,7 @@ static void lowerDataflowTaskOp(RT::DataflowTaskOp DFTOp, DFTOp.erase(); } -// For documentation see Autopar.td +/// For documentation see Autopar.td struct LowerDataflowTasksPass : public LowerDataflowTasksBase { diff --git a/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp b/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp index bac5c0424..7fcb8962b 100644 --- a/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp +++ b/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp @@ -79,8 +79,8 @@ LLVM::LLVMFuncOp getOrInsertFuncOpDecl(mlir::Operation *op, return funcOp; } -// This function is only needed for debug purposes to inspect values -// in the generated code - it is therefore not generally in use. +/// This function is only needed for debug purposes to inspect values +/// in the generated code - it is therefore not generally in use. LLVM_ATTRIBUTE_UNUSED void insertPrintDebugCall(ConversionPatternRewriter &rewriter, mlir::Operation *op, Value val) { diff --git a/compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp b/compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp index 97dda595d..7afcf4b1c 100644 --- a/compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp +++ b/compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp @@ -51,9 +51,9 @@ mlir::LogicalResult _verifyGLWEIntegerOperator(mlir::OpState &op, return mlir::success(); } -// verifyGLWEIntegerOperator verify parameters of operators that has the -// following signature (!TFHE.glwe<{dim,poly,bits}{p}>, ip+1) -> -// (!TFHE.glwe<{dim,poly,bits}{p}>)) +/// verifyGLWEIntegerOperator verify parameters of operators that has the +/// following signature (!TFHE.glwe<{dim,poly,bits}{p}>, ip+1) -> +/// (!TFHE.glwe<{dim,poly,bits}{p}>)) template mlir::LogicalResult verifyGLWEIntegerOperator(Operator &op) { auto a = ((mlir::Type)(op.a().getType())).cast(); @@ -64,9 +64,9 @@ mlir::LogicalResult verifyGLWEIntegerOperator(Operator &op) { return _verifyGLWEIntegerOperator(op, a, b, result); } -// verifyIntegerGLWEOperator verify parameters of operators that has the -// following signature (ip+1, !TFHE.glwe<{dim,poly,bits}{p}>) -> -// (!TFHE.glwe<{dim,poly,bits}{p}>)) +/// verifyIntegerGLWEOperator verify parameters of operators that has the +/// following signature (ip+1, !TFHE.glwe<{dim,poly,bits}{p}>) -> +/// (!TFHE.glwe<{dim,poly,bits}{p}>)) template mlir::LogicalResult verifyIntegerGLWEOperator(Operator &op) { auto a = ((mlir::Type)(op.a().getType())).cast(); @@ -77,10 +77,10 @@ mlir::LogicalResult verifyIntegerGLWEOperator(Operator &op) { return _verifyGLWEIntegerOperator(op, b, a, result); } -// verifyBinaryGLWEOperator verify parameters of operators that has the -// following signature (!TFHE.glwe<{dim,poly,bits}{p}>, -// !TFHE.glwe<{dim,poly,bits}{p}>) -> -// (!TFHE.glwe<{dim,poly,bits}{p}>)) +/// verifyBinaryGLWEOperator verify parameters of operators that has the +/// following signature (!TFHE.glwe<{dim,poly,bits}{p}>, +/// !TFHE.glwe<{dim,poly,bits}{p}>) -> +/// (!TFHE.glwe<{dim,poly,bits}{p}>)) template mlir::LogicalResult verifyBinaryGLWEOperator(Operator &op) { auto a = ((mlir::Type)(op.a().getType())).cast(); @@ -111,9 +111,9 @@ mlir::LogicalResult verifyBinaryGLWEOperator(Operator &op) { return mlir::success(); } -// verifyUnaryGLWEOperator verify parameters of operators that has the following -// signature (!TFHE.glwe<{dim,poly,bits}{p}>) -> -// (!TFHE.glwe<{dim,poly,bits}{p}>)) +/// verifyUnaryGLWEOperator verify parameters of operators that has the +/// following signature (!TFHE.glwe<{dim,poly,bits}{p}>) -> +/// (!TFHE.glwe<{dim,poly,bits}{p}>)) template mlir::LogicalResult verifyUnaryGLWEOperator(Operator &op) { auto a = ((mlir::Type)(op.a().getType())).cast(); diff --git a/compiler/lib/Runtime/DFRuntime.cpp b/compiler/lib/Runtime/DFRuntime.cpp index 697979e64..dcbd62aac 100644 --- a/compiler/lib/Runtime/DFRuntime.cpp +++ b/compiler/lib/Runtime/DFRuntime.cpp @@ -3,14 +3,11 @@ // https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt // for license information. -/** - This file implements the dataflow runtime. It encapsulates all of - the underlying communication, parallelism, etc. and only exposes a - simplified interface for code generation in runtime_api.h - - This hides the details of implementation, including of the HPX - framework currently used, from the code generation side. - */ +/// This file implements the dataflow runtime. It encapsulates all of +/// the underlying communication, parallelism, etc. and only exposes a +/// simplified interface for code generation in runtime_api.h +/// This hides the details of implementation, including of the HPX +/// framework currently used, from the code generation side. #ifdef CONCRETELANG_PARALLEL_EXECUTION_ENABLED @@ -55,11 +52,11 @@ void _dfr_deallocate_future(void *in) { delete (static_cast *>(in)); } -// Runtime generic async_task. Each first NUM_PARAMS pairs of -// arguments in the variadic list corresponds to a void* pointer on a -// hpx::future and the size of data within the future. After -// that come NUM_OUTPUTS pairs of hpx::future* and size_t for -// the returns. +/// Runtime generic async_task. Each first NUM_PARAMS pairs of +/// arguments in the variadic list corresponds to a void* pointer on a +/// hpx::future and the size of data within the future. After +/// that come NUM_OUTPUTS pairs of hpx::future* and size_t for +/// the returns. void _dfr_create_async_task(wfnptr wfn, size_t num_params, size_t num_outputs, ...) { std::vector params; @@ -776,7 +773,7 @@ void _dfr_debug_print_task(const char *name, int inputs, int outputs) { // clang-format on } -// Generic utility function for printing debug info +/// Generic utility function for printing debug info void _dfr_print_debug(size_t val) { hpx::cout << "_dfr_print_debug : " << val << "\n" << std::flush; } diff --git a/compiler/lib/Runtime/context.cpp b/compiler/lib/Runtime/context.cpp index cf05154db..888793007 100644 --- a/compiler/lib/Runtime/context.cpp +++ b/compiler/lib/Runtime/context.cpp @@ -17,7 +17,7 @@ get_bootstrap_key_u64(mlir::concretelang::RuntimeContext *context) { return context->evaluationKeys.getBsk(); } -// Instantiate one engine per thread on demand +/// Instantiate one engine per thread on demand Engine *get_engine(mlir::concretelang::RuntimeContext *context) { pthread_t threadId = pthread_self(); std::lock_guard guard(context->engines_map_guard); diff --git a/compiler/lib/ServerLib/DynamicRankCall.cpp b/compiler/lib/ServerLib/DynamicRankCall.cpp index 8c4c609b2..74947ceac 100644 --- a/compiler/lib/ServerLib/DynamicRankCall.cpp +++ b/compiler/lib/ServerLib/DynamicRankCall.cpp @@ -15,13 +15,13 @@ namespace concretelang { namespace serverlib { -// Helper class template that yields an unsigned integer type given a -// size in bytes +/// Helper class template that yields an unsigned integer type given a +/// size in bytes template struct int_type_of_size {}; template <> struct int_type_of_size<4> { typedef uint32_t type; }; template <> struct int_type_of_size<8> { typedef uint64_t type; }; -// Converts one function pointer into another +/// Converts one function pointer into another // TODO: Not sure this is valid in all implementations / on all // architectures template FnDstT convert_fnptr(FnSrcT src) { diff --git a/compiler/lib/ServerLib/genDynamicRankCall.py b/compiler/lib/ServerLib/genDynamicRankCall.py index d800210c3..6ea898990 100644 --- a/compiler/lib/ServerLib/genDynamicRankCall.py +++ b/compiler/lib/ServerLib/genDynamicRankCall.py @@ -19,13 +19,13 @@ print( namespace concretelang { namespace serverlib { -// Helper class template that yields an unsigned integer type given a -// size in bytes +/// Helper class template that yields an unsigned integer type given a +/// size in bytes template struct int_type_of_size {}; template <> struct int_type_of_size<4> { typedef uint32_t type; }; template <> struct int_type_of_size<8> { typedef uint64_t type; }; -// Converts one function pointer into another +/// Converts one function pointer into another // TODO: Not sure this is valid in all implementations / on all // architectures template FnDstT convert_fnptr(FnSrcT src) { diff --git a/compiler/lib/Support/CompilerEngine.cpp b/compiler/lib/Support/CompilerEngine.cpp index c572c6800..489ac3223 100644 --- a/compiler/lib/Support/CompilerEngine.cpp +++ b/compiler/lib/Support/CompilerEngine.cpp @@ -39,8 +39,8 @@ namespace mlir { namespace concretelang { -// Creates a new compilation context that can be shared across -// compilation engines and results +/// Creates a new compilation context that can be shared across +/// compilation engines and results std::shared_ptr CompilationContext::createShared() { return std::make_shared(); } @@ -53,8 +53,8 @@ CompilationContext::~CompilationContext() { delete this->llvmContext; } -// Returns the MLIR context for a compilation context. Creates and -// initializes a new MLIR context if necessary. +/// Returns the MLIR context for a compilation context. Creates and +/// initializes a new MLIR context if necessary. mlir::MLIRContext *CompilationContext::getMLIRContext() { if (this->mlirContext == nullptr) { mlir::DialectRegistry registry; @@ -79,8 +79,8 @@ mlir::MLIRContext *CompilationContext::getMLIRContext() { return this->mlirContext; } -// Returns the LLVM context for a compilation context. Creates and -// initializes a new LLVM context if necessary. +/// Returns the LLVM context for a compilation context. Creates and +/// initializes a new LLVM context if necessary. llvm::LLVMContext *CompilationContext::getLLVMContext() { if (this->llvmContext == nullptr) this->llvmContext = new llvm::LLVMContext(); @@ -88,9 +88,9 @@ llvm::LLVMContext *CompilationContext::getLLVMContext() { return this->llvmContext; } -// Sets the FHE constraints for the compilation. Overrides any -// automatically detected configuration and prevents the autodetection -// pass from running. +/// Sets the FHE constraints for the compilation. Overrides any +/// automatically detected configuration and prevents the autodetection +/// pass from running. void CompilerEngine::setFHEConstraints( const mlir::concretelang::V0FHEConstraint &c) { this->overrideMaxEintPrecision = c.p; @@ -112,7 +112,7 @@ void CompilerEngine::setEnablePass( this->enablePass = enablePass; } -// Returns the overwritten V0FHEConstraint or try to compute them from FHE +/// Returns the overwritten V0FHEConstraint or try to compute them from FHE llvm::Expected> CompilerEngine::getV0FHEConstraint(CompilationResult &res) { mlir::MLIRContext &mlirContext = *this->compilationContext->getMLIRContext(); @@ -136,7 +136,7 @@ CompilerEngine::getV0FHEConstraint(CompilationResult &res) { return fheConstraintsOrErr.get(); } -// set the fheContext field if the v0Constraint can be computed +/// set the fheContext field if the v0Constraint can be computed llvm::Error CompilerEngine::determineFHEParameters(CompilationResult &res) { auto fheConstraintOrErr = getV0FHEConstraint(res); if (auto err = fheConstraintOrErr.takeError()) @@ -165,10 +165,10 @@ llvm::Error CompilerEngine::determineFHEParameters(CompilationResult &res) { } using OptionalLib = llvm::Optional>; -// Compile the sources managed by the source manager `sm` to the -// target dialect `target`. If successful, the result can be retrieved -// using `getModule()` and `getLLVMModule()`, respectively depending -// on the target dialect. +/// Compile the sources managed by the source manager `sm` to the +/// target dialect `target`. If successful, the result can be retrieved +/// using `getModule()` and `getLLVMModule()`, respectively depending +/// on the target dialect. llvm::Expected CompilerEngine::compile(llvm::SourceMgr &sm, Target target, OptionalLib lib) { std::unique_ptr smHandler; @@ -371,19 +371,19 @@ CompilerEngine::compile(llvm::SourceMgr &sm, Target target, OptionalLib lib) { return std::move(res); } -// Compile the source `s` to the target dialect `target`. If successful, the -// result can be retrieved using `getModule()` and `getLLVMModule()`, -// respectively depending on the target dialect. +/// Compile the source `s` to the target dialect `target`. If successful, the +/// result can be retrieved using `getModule()` and `getLLVMModule()`, +/// respectively depending on the target dialect. llvm::Expected CompilerEngine::compile(llvm::StringRef s, Target target, OptionalLib lib) { std::unique_ptr mb = llvm::MemoryBuffer::getMemBuffer(s); return this->compile(std::move(mb), target, lib); } -// Compile the contained in `buffer` to the target dialect -// `target`. If successful, the result can be retrieved using -// `getModule()` and `getLLVMModule()`, respectively depending on the -// target dialect. +/// Compile the contained in `buffer` to the target dialect +/// `target`. If successful, the result can be retrieved using +/// `getModule()` and `getLLVMModule()`, respectively depending on the +/// target dialect. llvm::Expected CompilerEngine::compile(std::unique_ptr buffer, Target target, OptionalLib lib) { @@ -442,7 +442,7 @@ CompilerEngine::compile(llvm::SourceMgr &sm, std::string outputDirPath, return *outputLib.get(); } -/** Returns the path of the shared library */ +/// Returns the path of the shared library std::string CompilerEngine::Library::getSharedLibraryPath(std::string outputDirPath) { llvm::SmallString<0> sharedLibraryPath(outputDirPath); @@ -450,7 +450,7 @@ CompilerEngine::Library::getSharedLibraryPath(std::string outputDirPath) { return sharedLibraryPath.str().str(); } -/** Returns the path of the static library */ +/// Returns the path of the static library std::string CompilerEngine::Library::getStaticLibraryPath(std::string outputDirPath) { llvm::SmallString<0> staticLibraryPath(outputDirPath); @@ -458,7 +458,7 @@ CompilerEngine::Library::getStaticLibraryPath(std::string outputDirPath) { return staticLibraryPath.str().str(); } -/** Returns the path of the static library */ +/// Returns the path of the static library std::string CompilerEngine::Library::getClientParametersPath(std::string outputDirPath) { llvm::SmallString<0> clientParametersPath(outputDirPath); diff --git a/compiler/lib/Support/V0ClientParameters.cpp b/compiler/lib/Support/V0ClientParameters.cpp index c044d4e9f..96c29e0eb 100644 --- a/compiler/lib/Support/V0ClientParameters.cpp +++ b/compiler/lib/Support/V0ClientParameters.cpp @@ -30,7 +30,7 @@ const auto securityLevel = SECURITY_LEVEL_128; const auto keyFormat = KEY_FORMAT_BINARY; const auto v0Curve = getV0Curves(securityLevel, keyFormat); -// For the v0 the secretKeyID and precision are the same for all gates. +/// For the v0 the secretKeyID and precision are the same for all gates. llvm::Expected gateFromMLIRType(LweSecretKeyID secretKeyID, Precision precision, Variance variance, diff --git a/compiler/lib/Support/logging.cpp b/compiler/lib/Support/logging.cpp index 13e31304d..0f27e25c6 100644 --- a/compiler/lib/Support/logging.cpp +++ b/compiler/lib/Support/logging.cpp @@ -11,17 +11,17 @@ static bool verbose = false; static StreamWrap errWrap(&llvm::errs()); static StreamWrap nullWrap(&llvm::nulls()); -// Returns a stream for logging errors +/// Returns a stream for logging errors StreamWrap &log_error(void) { return errWrap; } -// Returns a stream that either shows or discards messages depending -// on the setup through `setupLogging`. +/// Returns a stream that either shows or discards messages depending +/// on the setup through `setupLogging`. StreamWrap &log_verbose(void) { return (verbose) ? errWrap : nullWrap; } -// Sets up logging. If `verbose` is false, messages passed to -// `log_verbose` will be discarded. +/// Sets up logging. If `verbose` is false, messages passed to +/// `log_verbose` will be discarded. void setupLogging(bool verbose) { ::mlir::concretelang::verbose = verbose; } bool isVerbose() { return verbose; } } // namespace concretelang diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp index e8df051e4..5c8a3ebfa 100644 --- a/compiler/src/main.cpp +++ b/compiler/src/main.cpp @@ -271,32 +271,32 @@ cmdlineCompilationOptions() { return options; } -// Process a single source buffer -// -// The parameter `action` specifies how the buffer should be processed -// and thus defines the output. -// -// If the specified action involves JIT compilation, `funcName` -// designates the function to JIT compile. This function is invoked -// using the parameters given in `jitArgs`. -// -// The parameter `parametrizeTFHE` defines, whether the -// parametrization pass for TFHE is executed. If the `action` does -// not involve any MidlFHE manipulation, this parameter does not have -// any effect. -// -// The parameters `overrideMaxEintPrecision` and `overrideMaxMANP`, if -// set, override the values for the maximum required precision of -// encrypted integers and the maximum value for the Minimum Arithmetic -// Noise Padding otherwise determined automatically. -// -// If `verifyDiagnostics` is `true`, the procedure only checks if the -// diagnostic messages provided in the source buffer using -// `expected-error` are produced. If `verifyDiagnostics` is `false`, -// the procedure checks if the parsed module is valid and if all -// requested transformations succeeded. -// -// Compilation output is written to the stream specified by `os`. +/// Process a single source buffer +/// +/// The parameter `action` specifies how the buffer should be processed +/// and thus defines the output. +/// +/// If the specified action involves JIT compilation, `funcName` +/// designates the function to JIT compile. This function is invoked +/// using the parameters given in `jitArgs`. +/// +/// The parameter `parametrizeTFHE` defines, whether the +/// parametrization pass for TFHE is executed. If the `action` does +/// not involve any MidlFHE manipulation, this parameter does not have +/// any effect. +/// +/// The parameters `overrideMaxEintPrecision` and `overrideMaxMANP`, if +/// set, override the values for the maximum required precision of +/// encrypted integers and the maximum value for the Minimum Arithmetic +/// Noise Padding otherwise determined automatically. +/// +/// If `verifyDiagnostics` is `true`, the procedure only checks if the +/// diagnostic messages provided in the source buffer using +/// `expected-error` are produced. If `verifyDiagnostics` is `false`, +/// the procedure checks if the parsed module is valid and if all +/// requested transformations succeeded. +/// +/// Compilation output is written to the stream specified by `os`. mlir::LogicalResult processInputBuffer( std::unique_ptr buffer, std::string sourceFileName, mlir::concretelang::CompilationOptions &options, enum Action action,