diff --git a/compiler/Makefile b/compiler/Makefile index f076b8708..b775d5cdd 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -68,8 +68,8 @@ build-end-to-end-jit-clear-tensor: build-initialized build-end-to-end-jit-encrypted-tensor: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_jit_encrypted_tensor -build-end-to-end-jit-hlfhelinalg: build-initialized - cmake --build $(BUILD_DIR) --target end_to_end_jit_hlfhelinalg +build-end-to-end-jit-fhelinalg: build-initialized + cmake --build $(BUILD_DIR) --target end_to_end_jit_fhelinalg build-end-to-end-jit-lambda: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_jit_lambda @@ -80,7 +80,7 @@ build-end-to-end-jit-dfr: build-initialized build-end-to-end-jit-auto-parallelization: build-initialized cmake --build $(BUILD_DIR) --target end_to_end_jit_auto_parallelization -build-end-to-end-jit: build-end-to-end-jit-test build-end-to-end-jit-clear-tensor build-end-to-end-jit-encrypted-tensor build-end-to-end-jit-hlfhelinalg +build-end-to-end-jit: build-end-to-end-jit-test build-end-to-end-jit-clear-tensor build-end-to-end-jit-encrypted-tensor build-end-to-end-jit-fhelinalg test-end-to-end-jit-test: build-end-to-end-jit-test @@ -92,8 +92,8 @@ test-end-to-end-jit-clear-tensor: build-end-to-end-jit-clear-tensor test-end-to-end-jit-encrypted-tensor: build-end-to-end-jit-encrypted-tensor $(BUILD_DIR)/bin/end_to_end_jit_encrypted_tensor -test-end-to-end-jit-hlfhelinalg: build-end-to-end-jit-hlfhelinalg - $(BUILD_DIR)/bin/end_to_end_jit_hlfhelinalg +test-end-to-end-jit-fhelinalg: build-end-to-end-jit-fhelinalg + $(BUILD_DIR)/bin/end_to_end_jit_fhelinalg test-end-to-end-jit-lambda: build-initialized build-end-to-end-jit-lambda $(BUILD_DIR)/bin/end_to_end_jit_lambda @@ -104,7 +104,7 @@ test-end-to-end-jit-dfr: build-end-to-end-jit-dfr test-end-to-end-jit-auto-parallelization: build-end-to-end-jit-auto-parallelization $(BUILD_DIR)/bin/end_to_end_jit_auto_parallelization -test-end-to-end-jit: test-end-to-end-jit-test test-end-to-end-jit-clear-tensor test-end-to-end-jit-encrypted-tensor test-end-to-end-jit-hlfhelinalg +test-end-to-end-jit: test-end-to-end-jit-test test-end-to-end-jit-clear-tensor test-end-to-end-jit-encrypted-tensor test-end-to-end-jit-fhelinalg show-stress-tests-summary: @echo '------ Stress tests summary ------' @@ -163,7 +163,7 @@ update_python_version: test-end-to-end-jit-test \ test-end-to-end-jit-clear-tensor \ test-end-to-end-jit-encrypted-tensor \ - test-end-to-end-jit-hlfhelinalg \ + test-end-to-end-jit-fhelinalg \ test-python \ test \ add-deps \ diff --git a/compiler/include/concretelang-c/Dialect/HLFHE.h b/compiler/include/concretelang-c/Dialect/FHE.h similarity index 65% rename from compiler/include/concretelang-c/Dialect/HLFHE.h rename to compiler/include/concretelang-c/Dialect/FHE.h index 23d96cf09..ef0f3fcfa 100644 --- a/compiler/include/concretelang-c/Dialect/HLFHE.h +++ b/compiler/include/concretelang-c/Dialect/FHE.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_C_DIALECT_HLFHE_H -#define CONCRETELANG_C_DIALECT_HLFHE_H +#ifndef CONCRETELANG_C_DIALECT_FHE_H +#define CONCRETELANG_C_DIALECT_FHE_H #include "mlir-c/IR.h" #include "mlir-c/Registration.h" @@ -13,18 +13,18 @@ extern "C" { #endif -MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HLFHE, hlfhe); +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(FHE, fhe); /// Creates an encrypted integer type of `width` bits -MLIR_CAPI_EXPORTED MlirType hlfheEncryptedIntegerTypeGetChecked( +MLIR_CAPI_EXPORTED MlirType fheEncryptedIntegerTypeGetChecked( MlirContext context, unsigned width, mlir::function_ref emitError); /// If the type is an EncryptedInteger -MLIR_CAPI_EXPORTED bool hlfheTypeIsAnEncryptedIntegerType(MlirType); +MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedIntegerType(MlirType); #ifdef __cplusplus } #endif -#endif // CONCRETELANG_C_DIALECT_HLFHE_H +#endif // CONCRETELANG_C_DIALECT_FHE_H diff --git a/compiler/include/concretelang-c/Dialect/HLFHELinalg.h b/compiler/include/concretelang-c/Dialect/FHELinalg.h similarity index 65% rename from compiler/include/concretelang-c/Dialect/HLFHELinalg.h rename to compiler/include/concretelang-c/Dialect/FHELinalg.h index 69a85377a..83237be53 100644 --- a/compiler/include/concretelang-c/Dialect/HLFHELinalg.h +++ b/compiler/include/concretelang-c/Dialect/FHELinalg.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_C_DIALECT_HLFHELINALG_H -#define CONCRETELANG_C_DIALECT_HLFHELINALG_H +#ifndef CONCRETELANG_C_DIALECT_FHELINALG_H +#define CONCRETELANG_C_DIALECT_FHELINALG_H #include "mlir-c/IR.h" #include "mlir-c/Registration.h" @@ -13,10 +13,10 @@ extern "C" { #endif -MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HLFHELinalg, hlfhelinalg); +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(FHELinalg, fhelinalg); #ifdef __cplusplus } #endif -#endif // CONCRETELANG_C_DIALECT_HLFHELINALG_H +#endif // CONCRETELANG_C_DIALECT_FHELINALG_H diff --git a/compiler/include/concretelang/Conversion/CMakeLists.txt b/compiler/include/concretelang/Conversion/CMakeLists.txt index 29b37fe3d..11585b9d9 100644 --- a/compiler/include/concretelang/Conversion/CMakeLists.txt +++ b/compiler/include/concretelang/Conversion/CMakeLists.txt @@ -3,5 +3,5 @@ mlir_tablegen(Passes.h.inc -gen-pass-decls -name Conversion) add_public_tablegen_target(ConcretelangConversionPassIncGen) -add_subdirectory(HLFHEToMidLFHE) -add_subdirectory(MidLFHEToLowLFHE) \ No newline at end of file +add_subdirectory(FHEToTFHE) +add_subdirectory(TFHEToConcrete) \ No newline at end of file diff --git a/compiler/include/concretelang/Conversion/LowLFHEToConcreteCAPI/Pass.h b/compiler/include/concretelang/Conversion/ConcreteToConcreteCAPI/Pass.h similarity index 64% rename from compiler/include/concretelang/Conversion/LowLFHEToConcreteCAPI/Pass.h rename to compiler/include/concretelang/Conversion/ConcreteToConcreteCAPI/Pass.h index eb0290d6a..a99e6b0e9 100644 --- a/compiler/include/concretelang/Conversion/LowLFHEToConcreteCAPI/Pass.h +++ b/compiler/include/concretelang/Conversion/ConcreteToConcreteCAPI/Pass.h @@ -2,8 +2,8 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_LOWLFHETOCONCRETECAPI_PASS_H_ -#define CONCRETELANG_CONVERSION_LOWLFHETOCONCRETECAPI_PASS_H_ +#ifndef CONCRETELANG_CONVERSION_CONCRETETOCONCRETECAPI_PASS_H_ +#define CONCRETELANG_CONVERSION_CONCRETETOCONCRETECAPI_PASS_H_ #include "mlir/Pass/Pass.h" @@ -11,10 +11,10 @@ namespace mlir { namespace concretelang { -/// Create a pass to convert `LowLFHE` operators to function call to the +/// Create a pass to convert `Concrete` operators to function call to the /// `ConcreteCAPI` std::unique_ptr> -createConvertLowLFHEToConcreteCAPIPass(); +createConvertConcreteToConcreteCAPIPass(); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Conversion/LowLFHEUnparametrize/Pass.h b/compiler/include/concretelang/Conversion/ConcreteUnparametrize/Pass.h similarity index 68% rename from compiler/include/concretelang/Conversion/LowLFHEUnparametrize/Pass.h rename to compiler/include/concretelang/Conversion/ConcreteUnparametrize/Pass.h index aeba5e507..dd7bb4dbb 100644 --- a/compiler/include/concretelang/Conversion/LowLFHEUnparametrize/Pass.h +++ b/compiler/include/concretelang/Conversion/ConcreteUnparametrize/Pass.h @@ -2,15 +2,15 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_LOWLFHEUNPARAMETRIZE_PASS_H_ -#define CONCRETELANG_CONVERSION_LOWLFHEUNPARAMETRIZE_PASS_H_ +#ifndef CONCRETELANG_CONVERSION_CONCRETEUNPARAMETRIZE_PASS_H_ +#define CONCRETELANG_CONVERSION_CONCRETEUNPARAMETRIZE_PASS_H_ #include "mlir/Pass/Pass.h" namespace mlir { namespace concretelang { std::unique_ptr> -createConvertLowLFHEUnparametrizePass(); +createConvertConcreteUnparametrizePass(); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Conversion/HLFHETensorOpsToLinalg/Pass.h b/compiler/include/concretelang/Conversion/FHETensorOpsToLinalg/Pass.h similarity index 54% rename from compiler/include/concretelang/Conversion/HLFHETensorOpsToLinalg/Pass.h rename to compiler/include/concretelang/Conversion/FHETensorOpsToLinalg/Pass.h index 340715ff0..346e212b6 100644 --- a/compiler/include/concretelang/Conversion/HLFHETensorOpsToLinalg/Pass.h +++ b/compiler/include/concretelang/Conversion/FHETensorOpsToLinalg/Pass.h @@ -2,16 +2,16 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_HLFHETENSOROPSTOLINALG_PASS_H_ -#define CONCRETELANG_CONVERSION_HLFHETENSOROPSTOLINALG_PASS_H_ +#ifndef CONCRETELANG_CONVERSION_FHETENSOROPSTOLINALG_PASS_H_ +#define CONCRETELANG_CONVERSION_FHETENSOROPSTOLINALG_PASS_H_ #include "mlir/Pass/Pass.h" namespace mlir { namespace concretelang { -/// Create a pass to convert `HLFHE` tensor operators to linal.generic +/// Create a pass to convert `FHE` tensor operators to linal.generic /// operators. -std::unique_ptr createConvertHLFHETensorOpsToLinalg(); +std::unique_ptr createConvertFHETensorOpsToLinalg(); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Conversion/FHEToTFHE/CMakeLists.txt b/compiler/include/concretelang/Conversion/FHEToTFHE/CMakeLists.txt new file mode 100644 index 000000000..df6ef1a5f --- /dev/null +++ b/compiler/include/concretelang/Conversion/FHEToTFHE/CMakeLists.txt @@ -0,0 +1,5 @@ +set(LLVM_TARGET_DEFINITIONS Patterns.td) +mlir_tablegen(Patterns.h.inc -gen-rewriters -name FHE) +add_public_tablegen_target(FHEToTFHEPatternsIncGen) + +add_concretelang_doc(Patterns FHEToTFHEPatterns concretelang/ -gen-pass-doc) diff --git a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Pass.h b/compiler/include/concretelang/Conversion/FHEToTFHE/Pass.h similarity index 54% rename from compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Pass.h rename to compiler/include/concretelang/Conversion/FHEToTFHE/Pass.h index de16b4181..fc3959aa8 100644 --- a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Pass.h +++ b/compiler/include/concretelang/Conversion/FHEToTFHE/Pass.h @@ -2,15 +2,15 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_MIDLFHETOLOWLFHE_PASS_H_ -#define CONCRETELANG_CONVERSION_MIDLFHETOLOWLFHE_PASS_H_ +#ifndef CONCRETELANG_CONVERSION_FHETOTFHE_PASS_H_ +#define CONCRETELANG_CONVERSION_FHETOTFHE_PASS_H_ #include "mlir/Pass/Pass.h" namespace mlir { namespace concretelang { -/// Create a pass to convert `MidLFHE` dialect to `LowLFHE` dialect. -std::unique_ptr> createConvertMidLFHEToLowLFHEPass(); +/// Create a pass to convert `FHE` dialect to `TFHE` dialect. +std::unique_ptr> createConvertFHEToTFHEPass(); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Patterns.h b/compiler/include/concretelang/Conversion/FHEToTFHE/Patterns.h similarity index 72% rename from compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Patterns.h rename to compiler/include/concretelang/Conversion/FHEToTFHE/Patterns.h index e65efbd1f..e0edc184d 100644 --- a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Patterns.h +++ b/compiler/include/concretelang/Conversion/FHEToTFHE/Patterns.h @@ -1,50 +1,50 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_HLFHETOMIDLFHE_PATTERNS_H_ -#define CONCRETELANG_CONVERSION_HLFHETOMIDLFHE_PATTERNS_H_ +#ifndef CONCRETELANG_CONVERSION_FHETOTFHE_PATTERNS_H_ +#define CONCRETELANG_CONVERSION_FHETOTFHE_PATTERNS_H_ #include "mlir/Dialect/StandardOps/IR/Ops.h" #include "mlir/IR/Builders.h" #include "mlir/IR/PatternMatch.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.h" namespace mlir { namespace concretelang { -using HLFHE::EncryptedIntegerType; -using MidLFHE::GLWECipherTextType; +using FHE::EncryptedIntegerType; +using TFHE::GLWECipherTextType; -/// Converts HLFHE::EncryptedInteger into MidLFHE::GlweCiphetext +/// Converts FHE::EncryptedInteger into TFHE::GlweCiphetext GLWECipherTextType convertTypeEncryptedIntegerToGLWE(mlir::MLIRContext *context, EncryptedIntegerType &eint) { return GLWECipherTextType::get(context, -1, -1, -1, eint.getWidth()); } -mlir::Value createZeroGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, +mlir::Value createZeroGLWEOpFromFHE(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::OpResult result) { mlir::SmallVector args{}; mlir::SmallVector attrs; auto eint = - result.getType().cast(); + result.getType().cast(); mlir::SmallVector resTypes{ convertTypeEncryptedIntegerToGLWE(rewriter.getContext(), eint)}; - MidLFHE::ZeroGLWEOp op = - rewriter.create(loc, resTypes, args, attrs); + TFHE::ZeroGLWEOp op = + rewriter.create(loc, resTypes, args, attrs); return op.getODSResults(0).front(); } template -mlir::Value createGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, +mlir::Value createGLWEOpFromFHE(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Value arg0, mlir::Value arg1, mlir::OpResult result) { mlir::SmallVector args{arg0, arg1}; mlir::SmallVector attrs; auto eint = - result.getType().cast(); + result.getType().cast(); mlir::SmallVector resTypes{ convertTypeEncryptedIntegerToGLWE(rewriter.getContext(), eint)}; Operator op = rewriter.create(loc, resTypes, args, attrs); @@ -52,13 +52,13 @@ mlir::Value createGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, } template -mlir::Value createGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, +mlir::Value createGLWEOpFromFHE(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Value arg0, mlir::OpResult result) { mlir::SmallVector args{arg0}; mlir::SmallVector attrs; auto eint = - result.getType().cast(); + result.getType().cast(); mlir::SmallVector resTypes{ convertTypeEncryptedIntegerToGLWE(rewriter.getContext(), eint)}; Operator op = rewriter.create(loc, resTypes, args, attrs); @@ -66,7 +66,7 @@ mlir::Value createGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, } mlir::Value -createApplyLookupTableGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, +createApplyLookupTableGLWEOpFromFHE(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Value arg0, mlir::Value arg1, mlir::OpResult result) { mlir::SmallVector args{arg0, arg1}; @@ -86,10 +86,10 @@ createApplyLookupTableGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, unset), }; auto eint = - result.getType().cast(); + result.getType().cast(); mlir::SmallVector resTypes{ convertTypeEncryptedIntegerToGLWE(rewriter.getContext(), eint)}; - auto op = rewriter.create(loc, resTypes, + auto op = rewriter.create(loc, resTypes, args, attrs); return op.getODSResults(0).front(); } @@ -98,10 +98,10 @@ createApplyLookupTableGLWEOpFromHLFHE(mlir::PatternRewriter &rewriter, } // namespace mlir namespace { -#include "concretelang/Conversion/HLFHEToMidLFHE/Patterns.h.inc" +#include "concretelang/Conversion/FHEToTFHE/Patterns.h.inc" } -void populateWithGeneratedHLFHEToMidLFHE(mlir::RewritePatternSet &patterns) { +void populateWithGeneratedFHEToTFHE(mlir::RewritePatternSet &patterns) { populateWithGenerated(patterns); } diff --git a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Patterns.td b/compiler/include/concretelang/Conversion/FHEToTFHE/Patterns.td similarity index 61% rename from compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Patterns.td rename to compiler/include/concretelang/Conversion/FHEToTFHE/Patterns.td index 96e84a1c1..5583b03ef 100644 --- a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Patterns.td +++ b/compiler/include/concretelang/Conversion/FHEToTFHE/Patterns.td @@ -1,47 +1,47 @@ -#ifndef CONCRETELANG_CONVERSION_HLFHETOMIDLFHE_PATTERNS -#define CONCRETELANG_CONVERSION_HLFHETOMIDLFHE_PATTERNS +#ifndef CONCRETELANG_CONVERSION_FHETOTFHE_PATTERNS +#define CONCRETELANG_CONVERSION_FHETOTFHE_PATTERNS include "mlir/Pass/PassBase.td" -include "concretelang/Dialect/HLFHE/IR/HLFHEOps.td" -include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.td" +include "concretelang/Dialect/FHE/IR/FHEOps.td" +include "concretelang/Dialect/TFHE/IR/TFHEOps.td" -def createZeroGLWEOp : NativeCodeCall<"mlir::concretelang::createZeroGLWEOpFromHLFHE($_builder, $_loc, $0)">; +def createZeroGLWEOp : NativeCodeCall<"mlir::concretelang::createZeroGLWEOpFromFHE($_builder, $_loc, $0)">; def ZeroEintPattern : Pat< (ZeroEintOp:$result), (createZeroGLWEOp $result)>; -def createAddGLWEIntOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromHLFHE($_builder, $_loc, $0, $1, $2)">; +def createAddGLWEIntOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromFHE($_builder, $_loc, $0, $1, $2)">; def AddEintIntPattern : Pat< (AddEintIntOp:$result $arg0, $arg1), (createAddGLWEIntOp $arg0, $arg1, $result)>; -def createAddGLWEOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromHLFHE($_builder, $_loc, $0, $1, $2)">; +def createAddGLWEOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromFHE($_builder, $_loc, $0, $1, $2)">; def AddEintPattern : Pat< (AddEintOp:$result $arg0, $arg1), (createAddGLWEOp $arg0, $arg1, $result)>; -def createSubIntGLWEOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromHLFHE($_builder, $_loc, $0, $1, $2)">; +def createSubIntGLWEOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromFHE($_builder, $_loc, $0, $1, $2)">; def SubIntEintPattern : Pat< (SubIntEintOp:$result $arg0, $arg1), (createSubIntGLWEOp $arg0, $arg1, $result)>; -def createNegGLWEOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromHLFHE($_builder, $_loc, $0, $1)">; +def createNegGLWEOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromFHE($_builder, $_loc, $0, $1)">; def NegEintPattern : Pat< (NegEintOp:$result $arg0), (createNegGLWEOp $arg0, $result)>; -def createMulGLWEIntOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromHLFHE($_builder, $_loc, $0, $1, $2)">; +def createMulGLWEIntOp : NativeCodeCall<"mlir::concretelang::createGLWEOpFromFHE($_builder, $_loc, $0, $1, $2)">; def MulEintIntPattern : Pat< (MulEintIntOp:$result $arg0, $arg1), (createMulGLWEIntOp $arg0, $arg1, $result)>; -def createApplyLookupTableGLWEOp : NativeCodeCall<"mlir::concretelang::createApplyLookupTableGLWEOpFromHLFHE($_builder, $_loc, $0, $1, $2)">; +def createApplyLookupTableGLWEOp : NativeCodeCall<"mlir::concretelang::createApplyLookupTableGLWEOpFromFHE($_builder, $_loc, $0, $1, $2)">; def ApplyLookupTableEintPattern : Pat< (ApplyLookupTableEintOp:$result $arg0, $arg1), diff --git a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/CMakeLists.txt b/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/CMakeLists.txt deleted file mode 100644 index 65c817ed3..000000000 --- a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS Patterns.td) -mlir_tablegen(Patterns.h.inc -gen-rewriters -name HLFHE) -add_public_tablegen_target(HLFHEToMidLFHEPatternsIncGen) - -add_concretelang_doc(Patterns HLFHEToMidLFHEPatterns concretelang/ -gen-pass-doc) diff --git a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/CMakeLists.txt b/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/CMakeLists.txt deleted file mode 100644 index 1fb65dc4a..000000000 --- a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS Patterns.td) -mlir_tablegen(Patterns.h.inc -gen-rewriters -name MidLFHE) -add_public_tablegen_target(MidLFHEToLowLFHEPatternsIncGen) - -add_concretelang_doc(Patterns MidLFHEToLowLFHEPatterns concretelang/ -gen-pass-doc) diff --git a/compiler/include/concretelang/Conversion/Passes.h b/compiler/include/concretelang/Conversion/Passes.h index d08161681..ca77d61e7 100644 --- a/compiler/include/concretelang/Conversion/Passes.h +++ b/compiler/include/concretelang/Conversion/Passes.h @@ -9,16 +9,16 @@ #include "mlir/Dialect/SCF/SCF.h" #include "mlir/Dialect/StandardOps/IR/Ops.h" -#include "concretelang/Conversion/HLFHETensorOpsToLinalg/Pass.h" -#include "concretelang/Conversion/HLFHEToMidLFHE/Pass.h" -#include "concretelang/Conversion/LowLFHEToConcreteCAPI/Pass.h" -#include "concretelang/Conversion/LowLFHEUnparametrize/Pass.h" +#include "concretelang/Conversion/FHETensorOpsToLinalg/Pass.h" +#include "concretelang/Conversion/FHEToTFHE/Pass.h" +#include "concretelang/Conversion/ConcreteToConcreteCAPI/Pass.h" +#include "concretelang/Conversion/ConcreteUnparametrize/Pass.h" #include "concretelang/Conversion/MLIRLowerableDialectsToLLVM/Pass.h" -#include "concretelang/Conversion/MidLFHEGlobalParametrization/Pass.h" -#include "concretelang/Conversion/MidLFHEToLowLFHE/Pass.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h" +#include "concretelang/Conversion/TFHEGlobalParametrization/Pass.h" +#include "concretelang/Conversion/TFHEToConcrete/Pass.h" +#include "concretelang/Dialect/FHE/IR/FHEDialect.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteDialect.h" +#include "concretelang/Dialect/TFHE/IR/TFHEDialect.h" #define GEN_PASS_CLASSES #include "concretelang/Conversion/Passes.h.inc" diff --git a/compiler/include/concretelang/Conversion/Passes.td b/compiler/include/concretelang/Conversion/Passes.td index cd37bf943..260b6689c 100644 --- a/compiler/include/concretelang/Conversion/Passes.td +++ b/compiler/include/concretelang/Conversion/Passes.td @@ -3,45 +3,45 @@ include "mlir/Pass/PassBase.td" -def HLFHETensorOpsToLinalg : FunctionPass<"hlfhe-tensor-ops-to-linalg"> { - let summary = "Lowers tensor operations of HLFHE dialect to linalg.generic"; - let constructor = "mlir::concretelang::createConvertHLFHETensorOpsToLinalg()"; +def FHETensorOpsToLinalg : FunctionPass<"fhe-tensor-ops-to-linalg"> { + let summary = "Lowers tensor operations of FHE dialect to linalg.generic"; + let constructor = "mlir::concretelang::createConvertFHETensorOpsToLinalg()"; let dependentDialects = ["mlir::linalg::LinalgDialect"]; } -def HLFHEToMidLFHE : Pass<"hlfhe-to-midlfhe", "mlir::ModuleOp"> { - let summary = "Lowers operations from the HLFHE dialect to MidLFHE"; - let description = [{ Lowers operations from the HLFHE dialect to Std + Math }]; - let constructor = "mlir::concretelang::createConvertHLFHEToMidLFHEPass()"; +def FHEToTFHE : Pass<"fhe-to-tfhe", "mlir::ModuleOp"> { + let summary = "Lowers operations from the FHE dialect to TFHE"; + let description = [{ Lowers operations from the FHE dialect to Std + Math }]; + let constructor = "mlir::concretelang::createConvertFHEToTFHEPass()"; let options = []; let dependentDialects = ["mlir::linalg::LinalgDialect"]; } -def MidLFHEGlobalParametrization : Pass<"midlfhe-global-parametrization", "mlir::ModuleOp"> { - let summary = "Inject global fhe parameters to the MidLFHE dialect"; - let constructor = "mlir::concretelang::createConvertMidLFHEToLowLFHEPass()"; +def TFHEGlobalParametrization : Pass<"tfhe-global-parametrization", "mlir::ModuleOp"> { + let summary = "Inject global fhe parameters to the TFHE dialect"; + let constructor = "mlir::concretelang::createConvertTFHEToConcretePass()"; let options = []; - let dependentDialects = ["mlir::concretelang::MidLFHE::MidLFHEDialect"]; + let dependentDialects = ["mlir::concretelang::TFHE::TFHEDialect"]; } -def MidLFHEToLowLFHE : Pass<"midlfhe-to-lowlfhe", "mlir::ModuleOp"> { - let summary = "Lowers operations from the MidLFHE dialect to LowLFHE"; - let description = [{ Lowers operations from the MidLFHE dialect to LowLFHE }]; - let constructor = "mlir::concretelang::createConvertMidLFHEToLowLFHEPass()"; +def TFHEToConcrete : Pass<"tfhe-to-concrete", "mlir::ModuleOp"> { + let summary = "Lowers operations from the TFHE dialect to Concrete"; + let description = [{ Lowers operations from the TFHE dialect to Concrete }]; + let constructor = "mlir::concretelang::createConvertTFHEToConcretePass()"; let options = []; let dependentDialects = ["mlir::linalg::LinalgDialect"]; } -def LowLFHEToConcreteCAPI : Pass<"lowlfhe-to-concrete-c-api", "mlir::ModuleOp"> { - let summary = "Lower operations from the LowLFHE dialect to std with function call to the Concrete C API"; - let constructor = "mlir::concretelang::createConvertLowLFHEToConcreteCAPIPass()"; - let dependentDialects = ["mlir::concretelang::LowLFHE::LowLFHEDialect", "mlir::StandardOpsDialect", "mlir::memref::MemRefDialect"]; +def ConcreteToConcreteCAPI : Pass<"concrete-to-concrete-c-api", "mlir::ModuleOp"> { + let summary = "Lower operations from the Concrete dialect to std with function call to the Concrete C API"; + let constructor = "mlir::concretelang::createConvertConcreteToConcreteCAPIPass()"; + let dependentDialects = ["mlir::concretelang::Concrete::ConcreteDialect", "mlir::StandardOpsDialect", "mlir::memref::MemRefDialect"]; } -def LowLFHEUnparametrize : Pass<"lowlfhe-unparametrize", "mlir::ModuleOp"> { - let summary = "Unparametrize LowLFHE types and remove unrealized_conversion_cast"; - let constructor = "mlir::concretelang::createConvertLowLFHEToConcreteCAPIPass()"; - let dependentDialects = ["mlir::concretelang::LowLFHE::LowLFHEDialect", "mlir::StandardOpsDialect", "mlir::memref::MemRefDialect"]; +def ConcreteUnparametrize : Pass<"concrete-unparametrize", "mlir::ModuleOp"> { + let summary = "Unparametrize Concrete types and remove unrealized_conversion_cast"; + let constructor = "mlir::concretelang::createConvertConcreteToConcreteCAPIPass()"; + let dependentDialects = ["mlir::concretelang::Concrete::ConcreteDialect", "mlir::StandardOpsDialect", "mlir::memref::MemRefDialect"]; } def MLIRLowerableDialectsToLLVM : Pass<"mlir-lowerable-dialects-to-llvm", "mlir::ModuleOp"> { diff --git a/compiler/include/concretelang/Conversion/MidLFHEGlobalParametrization/Pass.h b/compiler/include/concretelang/Conversion/TFHEGlobalParametrization/Pass.h similarity index 63% rename from compiler/include/concretelang/Conversion/MidLFHEGlobalParametrization/Pass.h rename to compiler/include/concretelang/Conversion/TFHEGlobalParametrization/Pass.h index 54b00c839..c5b10c48f 100644 --- a/compiler/include/concretelang/Conversion/MidLFHEGlobalParametrization/Pass.h +++ b/compiler/include/concretelang/Conversion/TFHEGlobalParametrization/Pass.h @@ -2,8 +2,8 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_MIDLFHEGLOBALPARAMETRIZATION_PASS_H_ -#define CONCRETELANG_CONVERSION_MIDLFHEGLOBALPARAMETRIZATION_PASS_H_ +#ifndef CONCRETELANG_CONVERSION_TFHEGLOBALPARAMETRIZATION_PASS_H_ +#define CONCRETELANG_CONVERSION_TFHEGLOBALPARAMETRIZATION_PASS_H_ #include "mlir/Pass/Pass.h" @@ -11,9 +11,9 @@ namespace mlir { namespace concretelang { -/// Create a pass to inject fhe parameters to the MidLFHE types and operators. +/// Create a pass to inject fhe parameters to the TFHE types and operators. std::unique_ptr> -createConvertMidLFHEGlobalParametrizationPass( +createConvertTFHEGlobalParametrizationPass( mlir::concretelang::V0FHEContext &fheContext); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Conversion/TFHEToConcrete/CMakeLists.txt b/compiler/include/concretelang/Conversion/TFHEToConcrete/CMakeLists.txt new file mode 100644 index 000000000..2adf2531e --- /dev/null +++ b/compiler/include/concretelang/Conversion/TFHEToConcrete/CMakeLists.txt @@ -0,0 +1,5 @@ +set(LLVM_TARGET_DEFINITIONS Patterns.td) +mlir_tablegen(Patterns.h.inc -gen-rewriters -name TFHE) +add_public_tablegen_target(TFHEToConcretePatternsIncGen) + +add_concretelang_doc(Patterns TFHEToConcretePatterns concretelang/ -gen-pass-doc) diff --git a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Pass.h b/compiler/include/concretelang/Conversion/TFHEToConcrete/Pass.h similarity index 55% rename from compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Pass.h rename to compiler/include/concretelang/Conversion/TFHEToConcrete/Pass.h index 177ac3061..3c0197ad9 100644 --- a/compiler/include/concretelang/Conversion/HLFHEToMidLFHE/Pass.h +++ b/compiler/include/concretelang/Conversion/TFHEToConcrete/Pass.h @@ -2,15 +2,15 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_HLFHETOMIDLFHE_PASS_H_ -#define CONCRETELANG_CONVERSION_HLFHETOMIDLFHE_PASS_H_ +#ifndef CONCRETELANG_CONVERSION_TFHETOCONCRETE_PASS_H_ +#define CONCRETELANG_CONVERSION_TFHETOCONCRETE_PASS_H_ #include "mlir/Pass/Pass.h" namespace mlir { namespace concretelang { -/// Create a pass to convert `HLFHE` dialect to `MidLFHE` dialect. -std::unique_ptr> createConvertHLFHEToMidLFHEPass(); +/// Create a pass to convert `TFHE` dialect to `Concrete` dialect. +std::unique_ptr> createConvertTFHEToConcretePass(); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Patterns.h b/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h similarity index 82% rename from compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Patterns.h rename to compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h index 83dd3f0f9..ae504027b 100644 --- a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Patterns.h +++ b/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.h @@ -1,22 +1,22 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_CONVERSION_MIDLFHETOLOWLFHE_PATTERNS_H_ -#define CONCRETELANG_CONVERSION_MIDLFHETOLOWLFHE_PATTERNS_H_ +#ifndef CONCRETELANG_CONVERSION_TFHETOCONCRETE_PATTERNS_H_ +#define CONCRETELANG_CONVERSION_TFHETOCONCRETE_PATTERNS_H_ #include "mlir/Dialect/StandardOps/IR/Ops.h" #include "mlir/IR/Builders.h" #include "mlir/IR/PatternMatch.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.h" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.h" namespace mlir { namespace concretelang { -using LowLFHE::CleartextType; -using LowLFHE::LweCiphertextType; -using LowLFHE::PlaintextType; -using MidLFHE::GLWECipherTextType; +using Concrete::CleartextType; +using Concrete::LweCiphertextType; +using Concrete::PlaintextType; +using TFHE::GLWECipherTextType; LweCiphertextType convertTypeToLWE(mlir::MLIRContext *context, mlir::Type type) { @@ -81,7 +81,7 @@ CleartextType convertCleartextTypeFromType(mlir::MLIRContext *context, return nullptr; } -mlir::Value createZeroLWEOpFromMidLFHE(mlir::PatternRewriter &rewriter, +mlir::Value createZeroLWEOpFromTFHE(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::OpResult result) { mlir::SmallVector args{}; @@ -89,13 +89,13 @@ mlir::Value createZeroLWEOpFromMidLFHE(mlir::PatternRewriter &rewriter, auto glwe = result.getType().cast(); mlir::SmallVector resTypes{ convertTypeToLWE(rewriter.getContext(), glwe)}; - LowLFHE::ZeroLWEOp op = - rewriter.create(loc, resTypes, args, attrs); + Concrete::ZeroLWEOp op = + rewriter.create(loc, resTypes, args, attrs); return op.getODSResults(0).front(); } template -mlir::Value createLowLFHEOpFromMidLFHE(mlir::PatternRewriter &rewriter, +mlir::Value createConcreteOpFromTFHE(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Value arg0, mlir::Value arg1, mlir::OpResult result) { @@ -116,14 +116,14 @@ mlir::Value createAddPlainLweCiphertextWithGlwe( // encode int into plaintext mlir::Value encoded = rewriter - .create(loc, encoded_type, arg1) + .create(loc, encoded_type, arg1) .plaintext(); // convert result type LweCiphertextType lwe_type = convertTypeToLWE(rewriter.getContext(), result.getType()); // replace op using the encoded plaintext instead of int auto op = - rewriter.create( + rewriter.create( loc, lwe_type, arg0, encoded); return op.getODSResults(0).front(); } @@ -142,7 +142,7 @@ mlir::Value createSubIntLweCiphertext(mlir::PatternRewriter &rewriter, auto arg1_type = arg1.getType(); auto negated_arg1 = rewriter - .create( + .create( loc, convertTypeToLWE(rewriter.getContext(), arg1_type), arg1) .result(); return createAddPlainLweCiphertextWithGlwe(rewriter, loc, negated_arg1, arg0, @@ -154,7 +154,7 @@ mlir::Value createNegLweCiphertext(mlir::PatternRewriter &rewriter, mlir::OpResult result) { auto arg0_type = arg0.getType(); auto negated = - rewriter.create( + rewriter.create( loc, convertTypeToLWE(rewriter.getContext(), arg0_type), arg0); return negated.getODSResults(0).front(); } @@ -168,7 +168,7 @@ mlir::Value createMulClearLweCiphertext(mlir::PatternRewriter &rewriter, convertCleartextTypeFromType(rewriter.getContext(), inType); // encode int into plaintext mlir::Value encoded = rewriter - .create( + .create( loc, encoded_type, arg1) .cleartext(); // convert result type @@ -176,12 +176,12 @@ mlir::Value createMulClearLweCiphertext(mlir::PatternRewriter &rewriter, LweCiphertextType lwe_type = convertTypeToLWE(rewriter.getContext(), resType); // replace op using the encoded plaintext instead of int auto op = - rewriter.create( + rewriter.create( loc, lwe_type, arg0, encoded); return op.getODSResults(0).front(); } -// This is the rewritting of the HLFHE::ApplyLookupTable operation, it will be +// This is the rewritting of the FHE::ApplyLookupTable operation, it will be // rewritten as 3 new operations: // - Create the required GLWE ciphertext out of the plain lookup table // - Keyswitch the input ciphertext to match the input key of the bootstrapping @@ -189,7 +189,7 @@ mlir::Value createMulClearLweCiphertext(mlir::PatternRewriter &rewriter, // Example: // from: // ``` -// "%result = MidLFHE.apply_lookup_table"(% arg0, % tlu){ +// "%result = TFHE.apply_lookup_table"(% arg0, % tlu){ // glweDimension = 1 : i32, // polynomialSize = 2048 : i32, // levelKS = 3 : i32, @@ -197,29 +197,29 @@ mlir::Value createMulClearLweCiphertext(mlir::PatternRewriter &rewriter, // levelBS = 5 : i32, // baseLogBS = 4 : i32, // outputSizeKS = 600 : i32 -// } : (!MidLFHE.glwe<{2048, 1, 64} {4}>, tensor<16xi4>) -// ->(!MidLFHE.glwe<{2048, 1, 64} {4}>) +// } : (!TFHE.glwe<{2048, 1, 64} {4}>, tensor<16xi4>) +// ->(!TFHE.glwe<{2048, 1, 64} {4}>) // ``` // to: // ``` // % accumulator = -// "LowLFHE.glwe_from_table"( +// "Concrete.glwe_from_table"( // % [[TABLE]]){glweDimension = 1 : i32, p = 4 : i32, polynomialSize = // 2048 : i32} // : (tensor<16xi4>) -// ->!LowLFHE.glwe_ciphertext -// % keyswitched = "LowLFHE.keyswitch_lwe"(% arg0){ +// ->!Concrete.glwe_ciphertext +// % keyswitched = "Concrete.keyswitch_lwe"(% arg0){ // baseLog = 2 : i32, // level = 3 : i32 -// } : (!LowLFHE.lwe_ciphertext<2048, 4>) -// ->!LowLFHE.lwe_ciphertext<600, 4> -// % result = "LowLFHE.bootstrap_lwe"(% keyswitched, % accumulator){ +// } : (!Concrete.lwe_ciphertext<2048, 4>) +// ->!Concrete.lwe_ciphertext<600, 4> +// % result = "Concrete.bootstrap_lwe"(% keyswitched, % accumulator){ // baseLog = 4 : i32, // glweDimension = 1 : i32, // level = 5 : i32, // polynomialSize = 2048 : i32 -// } : (!LowLFHE.lwe_ciphertext<600, 4>, !LowLFHE.glwe_ciphertext) -// ->!LowLFHE.lwe_ciphertext<2048, 4> +// } : (!Concrete.lwe_ciphertext<600, 4>, !Concrete.glwe_ciphertext) +// ->!Concrete.lwe_ciphertext<2048, 4> // ``` mlir::Value createPBS(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::Value ct, mlir::Value table, @@ -236,8 +236,8 @@ mlir::Value createPBS(mlir::PatternRewriter &rewriter, mlir::Location loc, mlir::IntegerAttr precision = rewriter.getI32IntegerAttr(lwe_type.getP()); mlir::Value accumulator = rewriter - .create( - loc, LowLFHE::GlweCiphertextType::get(rewriter.getContext()), + .create( + loc, Concrete::GlweCiphertextType::get(rewriter.getContext()), table, polynomialSize, glweDimension, precision) .result(); @@ -255,7 +255,7 @@ mlir::Value createPBS(mlir::PatternRewriter &rewriter, mlir::Location loc, convertTypeToLWE(rewriter.getContext(), result.getType()); mlir::Value keyswitched = rewriter - .create(loc, ksOutType, + .create(loc, ksOutType, ksArgs, ksAttrs) .result(); @@ -275,7 +275,7 @@ mlir::Value createPBS(mlir::PatternRewriter &rewriter, mlir::Location loc, }; mlir::Value bootstrapped = rewriter - .create(loc, lwe_type, + .create(loc, lwe_type, bsArgs, bsAttrs) .result(); @@ -286,10 +286,10 @@ mlir::Value createPBS(mlir::PatternRewriter &rewriter, mlir::Location loc, } // namespace mlir namespace { -#include "concretelang/Conversion/MidLFHEToLowLFHE/Patterns.h.inc" +#include "concretelang/Conversion/TFHEToConcrete/Patterns.h.inc" } -void populateWithGeneratedMidLFHEToLowLFHE(mlir::RewritePatternSet &patterns) { +void populateWithGeneratedTFHEToConcrete(mlir::RewritePatternSet &patterns) { populateWithGenerated(patterns); } diff --git a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Patterns.td b/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.td similarity index 79% rename from compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Patterns.td rename to compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.td index 5fe65882b..405546534 100644 --- a/compiler/include/concretelang/Conversion/MidLFHEToLowLFHE/Patterns.td +++ b/compiler/include/concretelang/Conversion/TFHEToConcrete/Patterns.td @@ -1,18 +1,18 @@ -#ifndef CONCRETELANG_CONVERSION_MIDLFHETOLOWLFHE_PATTERNS -#define CONCRETELANG_CONVERSION_MIDLFHETOLOWLFHE_PATTERNS +#ifndef CONCRETELANG_CONVERSION_TFHETOCONCRETE_PATTERNS +#define CONCRETELANG_CONVERSION_TFHETOCONCRETE_PATTERNS include "mlir/Pass/PassBase.td" include "mlir/Dialect/StandardOps/IR/Ops.td" -include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.td" -include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.td" +include "concretelang/Dialect/Concrete/IR/ConcreteOps.td" +include "concretelang/Dialect/TFHE/IR/TFHEOps.td" -def createZeroLWEOp : NativeCodeCall<"mlir::concretelang::createZeroLWEOpFromMidLFHE($_builder, $_loc, $0)">; +def createZeroLWEOp : NativeCodeCall<"mlir::concretelang::createZeroLWEOpFromTFHE($_builder, $_loc, $0)">; def ZeroGLWEPattern : Pat< (ZeroGLWEOp:$result), (createZeroLWEOp $result)>; -def createAddLWEOp : NativeCodeCall<"mlir::concretelang::createLowLFHEOpFromMidLFHE($_builder, $_loc, $0, $1, $2)">; +def createAddLWEOp : NativeCodeCall<"mlir::concretelang::createConcreteOpFromTFHE($_builder, $_loc, $0, $1, $2)">; def AddGLWEPattern : Pat< (AddGLWEOp:$result $arg0, $arg1), diff --git a/compiler/include/concretelang/Dialect/CMakeLists.txt b/compiler/include/concretelang/Dialect/CMakeLists.txt index 0fa987877..7075a2e7f 100644 --- a/compiler/include/concretelang/Dialect/CMakeLists.txt +++ b/compiler/include/concretelang/Dialect/CMakeLists.txt @@ -1,5 +1,5 @@ -add_subdirectory(HLFHE) -add_subdirectory(HLFHELinalg) -add_subdirectory(MidLFHE) -add_subdirectory(LowLFHE) +add_subdirectory(FHE) +add_subdirectory(FHELinalg) +add_subdirectory(TFHE) +add_subdirectory(Concrete) add_subdirectory(RT) diff --git a/compiler/include/concretelang/Dialect/LowLFHE/CMakeLists.txt b/compiler/include/concretelang/Dialect/Concrete/CMakeLists.txt similarity index 100% rename from compiler/include/concretelang/Dialect/LowLFHE/CMakeLists.txt rename to compiler/include/concretelang/Dialect/Concrete/CMakeLists.txt diff --git a/compiler/include/concretelang/Dialect/Concrete/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/Concrete/IR/CMakeLists.txt new file mode 100644 index 000000000..9f6e7c3fe --- /dev/null +++ b/compiler/include/concretelang/Dialect/Concrete/IR/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_TARGET_DEFINITIONS ConcreteOps.td) +mlir_tablegen(ConcreteOps.h.inc -gen-op-decls) +mlir_tablegen(ConcreteOps.cpp.inc -gen-op-defs) +mlir_tablegen(ConcreteOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=Concrete) +mlir_tablegen(ConcreteOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=Concrete) +mlir_tablegen(ConcreteOpsDialect.h.inc -gen-dialect-decls -dialect=Concrete) +mlir_tablegen(ConcreteOpsDialect.cpp.inc -gen-dialect-defs -dialect=Concrete) +add_public_tablegen_target(MLIRConcreteOpsIncGen) +add_dependencies(mlir-headers MLIRConcreteOpsIncGen) + +add_concretelang_doc(ConcreteDialect ConcreteDialect concretelang/ -gen-dialect-doc) +add_concretelang_doc(ConcreteOps ConcreteOps concretelang/ -gen-op-doc) +add_concretelang_doc(ConcreteTypes ConcreteTypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteDialect.h similarity index 65% rename from compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h rename to compiler/include/concretelang/Dialect/Concrete/IR/ConcreteDialect.h index 0b68fb443..4b50b1293 100644 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h +++ b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteDialect.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_MIDLFHE_IR_MIDLFHEDIALECT_H -#define CONCRETELANG_DIALECT_MIDLFHE_IR_MIDLFHEDIALECT_H +#ifndef CONCRETELANG_DIALECT_Concrete_IR_ConcreteDIALECT_H +#define CONCRETELANG_DIALECT_Concrete_IR_ConcreteDIALECT_H #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" @@ -11,6 +11,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOpsDialect.h.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOpsDialect.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteDialect.td b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteDialect.td new file mode 100644 index 000000000..1da3649d6 --- /dev/null +++ b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteDialect.td @@ -0,0 +1,15 @@ +#ifndef CONCRETELANG_DIALECT_Concrete_IR_Concrete_DIALECT +#define CONCRETELANG_DIALECT_Concrete_IR_Concrete_DIALECT + +include "mlir/IR/OpBase.td" + +def Concrete_Dialect : Dialect { + let name = "Concrete"; + let summary = "Low Level Fully Homorphic Encryption dialect"; + let description = [{ + A dialect for representation of low level operation on fully homomorphic ciphertext. + }]; + let cppNamespace = "::mlir::concretelang::Concrete"; +} + +#endif diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteOps.h similarity index 64% rename from compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h rename to compiler/include/concretelang/Dialect/Concrete/IR/ConcreteOps.h index 8fa41cb14..8f249951c 100644 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h +++ b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteOps.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_MIDLFHE_IR_MIDLFHEOPS_H -#define CONCRETELANG_DIALECT_MIDLFHE_IR_MIDLFHEOPS_H +#ifndef CONCRETELANG_DIALECT_Concrete_Concrete_OPS_H +#define CONCRETELANG_DIALECT_Concrete_Concrete_OPS_H #include #include @@ -10,9 +10,9 @@ #include #include -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #define GET_OP_CLASSES -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEOps.td b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteOps.td similarity index 71% rename from compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEOps.td rename to compiler/include/concretelang/Dialect/Concrete/IR/ConcreteOps.td index 0ad889813..1e18e0b7d 100644 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEOps.td +++ b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteOps.td @@ -1,58 +1,58 @@ -#ifndef CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHE_OPS -#define CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHE_OPS +#ifndef CONCRETELANG_DIALECT_Concrete_IR_Concrete_OPS +#define CONCRETELANG_DIALECT_Concrete_IR_Concrete_OPS include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Interfaces/ControlFlowInterfaces.td" -include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.td" -include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.td" +include "concretelang/Dialect/Concrete/IR/ConcreteDialect.td" +include "concretelang/Dialect/Concrete/IR/ConcreteTypes.td" -class LowLFHE_Op traits = []> : - Op; +class Concrete_Op traits = []> : + Op; -def ZeroLWEOp : LowLFHE_Op<"zero"> { +def ZeroLWEOp : Concrete_Op<"zero"> { let summary = "Returns a trivial encyption of 0"; let arguments = (ins); let results = (outs LweCiphertextType:$out); } -def AddLweCiphertextsOp : LowLFHE_Op<"add_lwe_ciphertexts"> { +def AddLweCiphertextsOp : Concrete_Op<"add_lwe_ciphertexts"> { let summary = "Returns the sum of 2 lwe ciphertexts"; let arguments = (ins LweCiphertextType:$lhs, LweCiphertextType:$rhs); let results = (outs LweCiphertextType:$result); } -def AddPlaintextLweCiphertextOp : LowLFHE_Op<"add_plaintext_lwe_ciphertext"> { +def AddPlaintextLweCiphertextOp : Concrete_Op<"add_plaintext_lwe_ciphertext"> { let summary = "Returns the sum of a clear integer and a lwe ciphertext"; let arguments = (ins LweCiphertextType:$lhs, PlaintextType:$rhs); let results = (outs LweCiphertextType:$result); } -def MulCleartextLweCiphertextOp : LowLFHE_Op<"mul_cleartext_lwe_ciphertext"> { +def MulCleartextLweCiphertextOp : Concrete_Op<"mul_cleartext_lwe_ciphertext"> { let summary = "Returns the product of a clear integer and a lwe ciphertext"; let arguments = (ins LweCiphertextType:$lhs, CleartextType:$rhs); let results = (outs LweCiphertextType:$result); } -def NegateLweCiphertextOp : LowLFHE_Op<"negate_lwe_ciphertext"> { +def NegateLweCiphertextOp : Concrete_Op<"negate_lwe_ciphertext"> { let summary = "Negates a lwe ciphertext"; let arguments = (ins LweCiphertextType:$ciphertext); let results = (outs LweCiphertextType:$result); } -def GlweFromTable : LowLFHE_Op<"glwe_from_table"> { +def GlweFromTable : Concrete_Op<"glwe_from_table"> { let summary = "Creates a GLWE ciphertext which is the trivial encrytion of a the input table interpreted as a polynomial (to use later in a bootstrap)"; let arguments = (ins TensorOf<[AnyInteger]>:$table, I32Attr:$polynomialSize, I32Attr:$glweDimension, I32Attr:$p); let results = (outs GlweCiphertextType:$result); } -def BootstrapLweOp : LowLFHE_Op<"bootstrap_lwe"> { +def BootstrapLweOp : Concrete_Op<"bootstrap_lwe"> { let summary = "Bootstraps a LWE ciphertext with a GLWE trivial encryption of the lookup table"; @@ -68,7 +68,7 @@ def BootstrapLweOp : LowLFHE_Op<"bootstrap_lwe"> { let results = (outs LweCiphertextType:$result); } -def KeySwitchLweOp : LowLFHE_Op<"keyswitch_lwe"> { +def KeySwitchLweOp : Concrete_Op<"keyswitch_lwe"> { let summary = "Keyswitches a LWE ciphertext"; let arguments = (ins @@ -80,14 +80,14 @@ def KeySwitchLweOp : LowLFHE_Op<"keyswitch_lwe"> { let results = (outs LweCiphertextType:$result); } -def EncodeIntOp : LowLFHE_Op<"encode_int"> { +def EncodeIntOp : Concrete_Op<"encode_int"> { let summary = "Encodes an integer (for it to later be added to a LWE ciphertext)"; let arguments = (ins AnyInteger:$i); let results = (outs PlaintextType:$plaintext); } -def IntToCleartextOp : LowLFHE_Op<"int_to_cleartext"> { +def IntToCleartextOp : Concrete_Op<"int_to_cleartext"> { let summary = "Keyswitches a LWE ciphertext"; let arguments = (ins AnyInteger:$i); diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteTypes.h similarity index 66% rename from compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h rename to compiler/include/concretelang/Dialect/Concrete/IR/ConcreteTypes.h index 8ced2bc20..4fc31d1f7 100644 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h +++ b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteTypes.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHETYPES_H -#define CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHETYPES_H +#ifndef CONCRETELANG_DIALECT_Concrete_IR_ConcreteTYPES_H +#define CONCRETELANG_DIALECT_Concrete_IR_ConcreteTYPES_H #include "llvm/ADT/TypeSwitch.h" #include @@ -10,6 +10,6 @@ #include #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOpsTypes.h.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOpsTypes.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHETypes.td b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteTypes.td similarity index 85% rename from compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHETypes.td rename to compiler/include/concretelang/Dialect/Concrete/IR/ConcreteTypes.td index 652267c34..6b0db0083 100644 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHETypes.td +++ b/compiler/include/concretelang/Dialect/Concrete/IR/ConcreteTypes.td @@ -1,13 +1,13 @@ -#ifndef CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHE_TYPES -#define CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHE_TYPES +#ifndef CONCRETELANG_DIALECT_Concrete_IR_Concrete_TYPES +#define CONCRETELANG_DIALECT_Concrete_IR_Concrete_TYPES include "mlir/IR/BuiltinTypes.td" -include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.td" +include "concretelang/Dialect/Concrete/IR/ConcreteDialect.td" -class LowLFHE_Type traits = []> : TypeDef { } +class Concrete_Type traits = []> : TypeDef { } -def GlweCiphertextType : LowLFHE_Type<"GlweCiphertext"> { +def GlweCiphertextType : Concrete_Type<"GlweCiphertext"> { let mnemonic = "glwe_ciphertext"; let summary = "A GLWE ciphertext (encryption of a polynomial of fixed-precision integers)"; @@ -25,7 +25,7 @@ def GlweCiphertextType : LowLFHE_Type<"GlweCiphertext"> { }]; } -def LweCiphertextType : LowLFHE_Type<"LweCiphertext", [MemRefElementTypeInterface]> { +def LweCiphertextType : Concrete_Type<"LweCiphertext", [MemRefElementTypeInterface]> { let mnemonic = "lwe_ciphertext"; let summary = "A LWE ciphertext (encryption of a fixed-precision integer)"; @@ -70,7 +70,7 @@ def LweCiphertextType : LowLFHE_Type<"LweCiphertext", [MemRefElementTypeInterfac }]; } -def CleartextType : LowLFHE_Type<"Cleartext"> { +def CleartextType : Concrete_Type<"Cleartext"> { let mnemonic = "cleartext"; let summary = "A cleartext (a fixed-precision integer) ready to be multiplied to a LWE ciphertext"; @@ -104,7 +104,7 @@ def CleartextType : LowLFHE_Type<"Cleartext"> { }]; } -def PlaintextType : LowLFHE_Type<"Plaintext"> { +def PlaintextType : Concrete_Type<"Plaintext"> { let mnemonic = "plaintext"; let summary = "A Plaintext (a fixed-precision integer) ready to be added to a LWE ciphertext"; @@ -138,7 +138,7 @@ def PlaintextType : LowLFHE_Type<"Plaintext"> { }]; } -def PlaintextListType : LowLFHE_Type<"PlaintextList"> { +def PlaintextListType : Concrete_Type<"PlaintextList"> { let mnemonic = "plaintext_list"; let summary = "List of plaintexts"; @@ -156,7 +156,7 @@ def PlaintextListType : LowLFHE_Type<"PlaintextList"> { }]; } -def ForeignPlaintextListType : LowLFHE_Type<"ForeignPlaintextList"> { +def ForeignPlaintextListType : Concrete_Type<"ForeignPlaintextList"> { let mnemonic = "foreign_plaintext_list"; let summary = "A foreign (reference to a independently allocated memory space) plaintext list"; @@ -174,7 +174,7 @@ def ForeignPlaintextListType : LowLFHE_Type<"ForeignPlaintextList"> { }]; } -def LweKeySwitchKeyType : LowLFHE_Type<"LweKeySwitchKey"> { +def LweKeySwitchKeyType : Concrete_Type<"LweKeySwitchKey"> { let mnemonic = "lwe_key_switch_key"; let summary = "A LWE keyswitching key"; @@ -192,7 +192,7 @@ def LweKeySwitchKeyType : LowLFHE_Type<"LweKeySwitchKey"> { }]; } -def LweBootstrapKeyType : LowLFHE_Type<"LweBootstrapKey"> { +def LweBootstrapKeyType : Concrete_Type<"LweBootstrapKey"> { let mnemonic = "lwe_bootstrap_key"; let summary = "A LWE bootstrapping key"; @@ -210,7 +210,7 @@ def LweBootstrapKeyType : LowLFHE_Type<"LweBootstrapKey"> { }]; } -def Context : LowLFHE_Type<"Context"> { +def Context : Concrete_Type<"Context"> { let mnemonic = "context"; let summary = "A runtime context"; diff --git a/compiler/include/concretelang/Dialect/HLFHE/Analysis/CMakeLists.txt b/compiler/include/concretelang/Dialect/FHE/Analysis/CMakeLists.txt similarity index 100% rename from compiler/include/concretelang/Dialect/HLFHE/Analysis/CMakeLists.txt rename to compiler/include/concretelang/Dialect/FHE/Analysis/CMakeLists.txt diff --git a/compiler/include/concretelang/Dialect/HLFHE/Analysis/MANP.h b/compiler/include/concretelang/Dialect/FHE/Analysis/MANP.h similarity index 83% rename from compiler/include/concretelang/Dialect/HLFHE/Analysis/MANP.h rename to compiler/include/concretelang/Dialect/FHE/Analysis/MANP.h index 6670cbd5d..ded73c52b 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/Analysis/MANP.h +++ b/compiler/include/concretelang/Dialect/FHE/Analysis/MANP.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHE_ANALYSIS_MANP_H -#define CONCRETELANG_DIALECT_HLFHE_ANALYSIS_MANP_H +#ifndef CONCRETELANG_DIALECT_FHE_ANALYSIS_MANP_H +#define CONCRETELANG_DIALECT_FHE_ANALYSIS_MANP_H #include #include diff --git a/compiler/include/concretelang/Dialect/HLFHE/Analysis/MANP.td b/compiler/include/concretelang/Dialect/FHE/Analysis/MANP.td similarity index 59% rename from compiler/include/concretelang/Dialect/HLFHE/Analysis/MANP.td rename to compiler/include/concretelang/Dialect/FHE/Analysis/MANP.td index 20a5d66e8..719177552 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/Analysis/MANP.td +++ b/compiler/include/concretelang/Dialect/FHE/Analysis/MANP.td @@ -1,10 +1,10 @@ -#ifndef CONCRETELANG_DIALECT_HLFHE_ANALYSIS_MANP -#define CONCRETELANG_DIALECT_HLFHE_ANALYSIS_MANP +#ifndef CONCRETELANG_DIALECT_FHE_ANALYSIS_MANP +#define CONCRETELANG_DIALECT_FHE_ANALYSIS_MANP include "mlir/Pass/PassBase.td" def MANP : FunctionPass<"MANP"> { - let summary = "HLFHE Minimal Arithmetic Noise Padding Pass"; + let summary = "FHE Minimal Arithmetic Noise Padding Pass"; let description = [{ This pass calculates the Minimal Arithmetic Noise Padding (MANP) for each operation of a function and stores the result in an @@ -15,14 +15,14 @@ def MANP : FunctionPass<"MANP"> { The pass supports the following operations: - - HLFHELinalg.dot_eint_int - - HLFHE.zero - - HLFHE.add_eint_int - - HLFHE.add_eint - - HLFHE.sub_int_eint - - HLFHE.neg_eint - - HLFHE.mul_eint_int - - HLFHE.apply_lookup_table + - FHELinalg.dot_eint_int + - FHE.zero + - FHE.add_eint_int + - FHE.add_eint + - FHE.sub_int_eint + - FHE.neg_eint + - FHE.mul_eint_int + - FHE.apply_lookup_table If any other operation is encountered, the pass conservatively fails. The pass further makes the optimistic assumption that all @@ -42,24 +42,24 @@ def MANP : FunctionPass<"MANP"> { with the following replacement rules: - - Function argument a -> HLFHELinalg.dot_eint_int([a], [1]) - - HLFHE.apply_lookup_table -> HLFHELinalg.dot_eint_int([LUT result], [1]) - - HLFHE.zero() -> HLFHELinalg.dot_eint_int([encrypted 0], [1]) - - HLFHE.add_eint_int(e, c) -> HLFHELinalg.dot_eint_int([e, 1], [1, c]) - - HLFHE.add_eint(e0, e1) -> HLFHELinalg.dot_eint_int([e0, e1], [1, 1]) - - HLFHE.sub_int_eint(c, e) -> HLFHELinalg.dot_eint_int([e, c], [1, -1]) - - HLFHE.neg_eint(e) -> HLFHELinalg.dot_eint_int([e], [-1]) - - HLFHE.mul_eint_int(e, c) -> HLFHELinalg.dot_eint_int([e], [c]) + - Function argument a -> FHELinalg.dot_eint_int([a], [1]) + - FHE.apply_lookup_table -> FHELinalg.dot_eint_int([LUT result], [1]) + - FHE.zero() -> FHELinalg.dot_eint_int([encrypted 0], [1]) + - FHE.add_eint_int(e, c) -> FHELinalg.dot_eint_int([e, 1], [1, c]) + - FHE.add_eint(e0, e1) -> FHELinalg.dot_eint_int([e0, e1], [1, 1]) + - FHE.sub_int_eint(c, e) -> FHELinalg.dot_eint_int([e, c], [1, -1]) + - FHE.neg_eint(e) -> FHELinalg.dot_eint_int([e], [-1]) + - FHE.mul_eint_int(e, c) -> FHELinalg.dot_eint_int([e], [c]) Dependent dot operations, e.g., - a = HLFHELinalg.dot_eint_int([a0, a1, ...], [c0, c1, ...]) - b = HLFHELinalg.dot_eint_int([b0, b1, ...], [d0, d1, ...]) - x = HLFHELinalg.dot_eint_int([a, b, ...], [f0, f1, ...]) + a = FHELinalg.dot_eint_int([a0, a1, ...], [c0, c1, ...]) + b = FHELinalg.dot_eint_int([b0, b1, ...], [d0, d1, ...]) + x = FHELinalg.dot_eint_int([a, b, ...], [f0, f1, ...]) are merged as follows: - x = HLFHELinalg.dot_eint_int([a0, a1, ..., b0, b1, ...], + x = FHELinalg.dot_eint_int([a0, a1, ..., b0, b1, ...], [f0*c0, f0*c1, ..., f1*d0, f1*d1, ...]) However, the implementation does not explicitly create the @@ -80,15 +80,15 @@ def MANP : FunctionPass<"MANP"> { for the supported operations: - Function argument -> 1 - - HLFHE.apply_lookup_table -> 1 - - HLFHE.zero() -> 1 - - HLFHELinalg.dot_eint_int([e0, e1, ...], [c0, c1, ...]) -> + - FHE.apply_lookup_table -> 1 + - FHE.zero() -> 1 + - FHELinalg.dot_eint_int([e0, e1, ...], [c0, c1, ...]) -> c0*c0*sqN(e0) + c1*c1*sqN(e1) + ... - - HLFHE.add_eint_int(e, c) -> 1*1*sqN(e) + c*c*1*1 = sqN(e) + c*c - - HLFHE.add_eint(e0, e1) -> 1*1*sqN(e0) + 1*1*sqN(e2) = sqN(e1) + sqN(e2) - - HLFHE.sub_int_eint(c, e) -> 1*1*sqN(e) + c*c*(-1)*(-1) = sqN(e) + c*c - - HLFHE.neg_eint(e) -> (-1)*(-1)*sqN(e) = sqN(e) - - HLFHE.mul_eint_int(e, c) -> c*c*sqN(e) + - FHE.add_eint_int(e, c) -> 1*1*sqN(e) + c*c*1*1 = sqN(e) + c*c + - FHE.add_eint(e0, e1) -> 1*1*sqN(e0) + 1*1*sqN(e2) = sqN(e1) + sqN(e2) + - FHE.sub_int_eint(c, e) -> 1*1*sqN(e) + c*c*(-1)*(-1) = sqN(e) + c*c + - FHE.neg_eint(e) -> (-1)*(-1)*sqN(e) = sqN(e) + - FHE.mul_eint_int(e, c) -> c*c*sqN(e) The final, non-squared 2-norm of an operation is the square root of the squared value rounded to the next highest integer. @@ -96,7 +96,7 @@ def MANP : FunctionPass<"MANP"> { } def MaxMANP : FunctionPass<"MaxMANP"> { - let summary = "Extract maximum HLFHE Minimal Arithmetic Noise Padding and maximum encrypted integer width"; + let summary = "Extract maximum FHE Minimal Arithmetic Noise Padding and maximum encrypted integer width"; let description = [{ This pass calculates the squared Minimal Arithmetic Noise Padding (MANP) for each operation using the MANP pass and extracts the diff --git a/compiler/include/concretelang/Dialect/HLFHE/CMakeLists.txt b/compiler/include/concretelang/Dialect/FHE/CMakeLists.txt similarity index 100% rename from compiler/include/concretelang/Dialect/HLFHE/CMakeLists.txt rename to compiler/include/concretelang/Dialect/FHE/CMakeLists.txt diff --git a/compiler/include/concretelang/Dialect/FHE/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/FHE/IR/CMakeLists.txt new file mode 100644 index 000000000..a6b8e9a4f --- /dev/null +++ b/compiler/include/concretelang/Dialect/FHE/IR/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_TARGET_DEFINITIONS FHEOps.td) +mlir_tablegen(FHEOps.h.inc -gen-op-decls) +mlir_tablegen(FHEOps.cpp.inc -gen-op-defs) +mlir_tablegen(FHEOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=FHE) +mlir_tablegen(FHEOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=FHE) +mlir_tablegen(FHEOpsDialect.h.inc -gen-dialect-decls -dialect=FHE) +mlir_tablegen(FHEOpsDialect.cpp.inc -gen-dialect-defs -dialect=FHE) +add_public_tablegen_target(MLIRFHEOpsIncGen) +add_dependencies(mlir-headers MLIRFHEOpsIncGen) + +add_concretelang_doc(FHEDialect FHEDialect concretelang/ -gen-dialect-doc) +add_concretelang_doc(FHEOps FHEOps concretelang/ -gen-op-doc) +add_concretelang_doc(FHETypes FHETypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEDialect.h b/compiler/include/concretelang/Dialect/FHE/IR/FHEDialect.h similarity index 67% rename from compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEDialect.h rename to compiler/include/concretelang/Dialect/FHE/IR/FHEDialect.h index 6c8ccee95..002a4870c 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEDialect.h +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHEDialect.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHEDIALECT_H -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHEDIALECT_H +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHEDIALECT_H +#define CONCRETELANG_DIALECT_FHE_IR_FHEDIALECT_H #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" @@ -11,6 +11,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOpsDialect.h.inc" +#include "concretelang/Dialect/FHE/IR/FHEOpsDialect.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEDialect.td b/compiler/include/concretelang/Dialect/FHE/IR/FHEDialect.td similarity index 64% rename from compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEDialect.td rename to compiler/include/concretelang/Dialect/FHE/IR/FHEDialect.td index 76c83e5b9..934e06a74 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEDialect.td +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHEDialect.td @@ -1,4 +1,4 @@ -//===- HLFHEDialect.td - HLFHE dialect ----------------*- tablegen -*-===// +//===- FHEDialect.td - FHE dialect ----------------*- tablegen -*-===// // // This file is licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,18 +6,18 @@ // //===----------------------------------------------------------------------===// -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_DIALECT -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_DIALECT +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHE_DIALECT +#define CONCRETELANG_DIALECT_FHE_IR_FHE_DIALECT include "mlir/IR/OpBase.td" -def HLFHE_Dialect : Dialect { - let name = "HLFHE"; +def FHE_Dialect : Dialect { + let name = "FHE"; let summary = "High Level Fully Homorphic Encryption dialect"; let description = [{ A dialect for representation of high level operation on fully homomorphic ciphertext. }]; - let cppNamespace = "::mlir::concretelang::HLFHE"; + let cppNamespace = "::mlir::concretelang::FHE"; } #endif diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEOps.h b/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h similarity index 83% rename from compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEOps.h rename to compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h index 1c9993b00..1dcb8c9c6 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEOps.h +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.h @@ -1,19 +1,19 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHEOPS_H -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHEOPS_H +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHEOPS_H +#define CONCRETELANG_DIALECT_FHE_IR_FHEOPS_H #include #include #include #include -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" namespace mlir { namespace concretelang { -namespace HLFHE { +namespace FHE { bool verifyEncryptedIntegerInputAndResultConsistency( OpState &op, EncryptedIntegerType &input, EncryptedIntegerType &result); @@ -23,7 +23,7 @@ bool verifyEncryptedIntegerAndIntegerInputsConsistency(OpState &op, IntegerType &b); /** Shared error message for all ApplyLookupTable variant Op (several Dialect) - * E.g. HLFHE.apply_lookup_table(input, lut) + * 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 */ @@ -38,11 +38,11 @@ void emitErrorBadLutSize(Op &op, std::string lutName, std::string inputName, << " elements bitwidth (" << bitWidth << ")"; } -} // namespace HLFHE +} // namespace FHE } // namespace concretelang } // namespace mlir #define GET_OP_CLASSES -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h.inc" +#include "concretelang/Dialect/FHE/IR/FHEOps.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEOps.td b/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.td similarity index 69% rename from compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEOps.td rename to compiler/include/concretelang/Dialect/FHE/IR/FHEOps.td index c2d26c9d5..4549e600c 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHEOps.td +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHEOps.td @@ -1,4 +1,4 @@ -//===- HLFHEOps.td - High level FHE dialect ops ----------------*- tablegen -*-===// +//===- FHEOps.td - High level FHE dialect ops ----------------*- tablegen -*-===// // // This file is licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,27 +6,27 @@ // //===----------------------------------------------------------------------===// -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_OPS -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_OPS +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHE_OPS +#define CONCRETELANG_DIALECT_FHE_IR_FHE_OPS include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Interfaces/ControlFlowInterfaces.td" -include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.td" -include "concretelang/Dialect/HLFHE/IR/HLFHETypes.td" +include "concretelang/Dialect/FHE/IR/FHEDialect.td" +include "concretelang/Dialect/FHE/IR/FHETypes.td" -class HLFHE_Op traits = []> : - Op; +class FHE_Op traits = []> : + Op; // Generates an encrypted zero constant -def ZeroEintOp : HLFHE_Op<"zero", [NoSideEffect]> { +def ZeroEintOp : FHE_Op<"zero", [NoSideEffect]> { let summary = "Return an encryption of 0"; let arguments = (ins); let results = (outs EncryptedIntegerType:$out); } -def AddEintIntOp : HLFHE_Op<"add_eint_int"> { +def AddEintIntOp : FHE_Op<"add_eint_int"> { let summary = "Adds an encrypted integer and a clear integer"; @@ -40,11 +40,11 @@ def AddEintIntOp : HLFHE_Op<"add_eint_int"> { ]; let verifier = [{ - return ::mlir::concretelang::HLFHE::verifyAddEintIntOp(*this); + return ::mlir::concretelang::FHE::verifyAddEintIntOp(*this); }]; } -def AddEintOp : HLFHE_Op<"add_eint"> { +def AddEintOp : FHE_Op<"add_eint"> { let summary = "Adds two encrypted integers"; @@ -58,11 +58,11 @@ def AddEintOp : HLFHE_Op<"add_eint"> { ]; let verifier = [{ - return ::mlir::concretelang::HLFHE::verifyAddEintOp(*this); + return ::mlir::concretelang::FHE::verifyAddEintOp(*this); }]; } -def SubIntEintOp : HLFHE_Op<"sub_int_eint"> { +def SubIntEintOp : FHE_Op<"sub_int_eint"> { let summary = "Substract a clear integer and an encrypted integer"; @@ -76,11 +76,11 @@ def SubIntEintOp : HLFHE_Op<"sub_int_eint"> { ]; let verifier = [{ - return ::mlir::concretelang::HLFHE::verifySubIntEintOp(*this); + return ::mlir::concretelang::FHE::verifySubIntEintOp(*this); }]; } -def NegEintOp : HLFHE_Op<"neg_eint"> { +def NegEintOp : FHE_Op<"neg_eint"> { let summary = "Negates an encrypted integer"; @@ -94,11 +94,11 @@ def NegEintOp : HLFHE_Op<"neg_eint"> { ]; let verifier = [{ - return ::mlir::concretelang::HLFHE::verifyNegEintOp(*this); + return ::mlir::concretelang::FHE::verifyNegEintOp(*this); }]; } -def MulEintIntOp : HLFHE_Op<"mul_eint_int"> { +def MulEintIntOp : FHE_Op<"mul_eint_int"> { let summary = "Mulitplies an encrypted integer and a clear integer"; @@ -112,11 +112,11 @@ def MulEintIntOp : HLFHE_Op<"mul_eint_int"> { ]; let verifier = [{ - return ::mlir::concretelang::HLFHE::verifyMulEintIntOp(*this); + return ::mlir::concretelang::FHE::verifyMulEintIntOp(*this); }]; } -def ApplyLookupTableEintOp : HLFHE_Op<"apply_lookup_table"> { +def ApplyLookupTableEintOp : FHE_Op<"apply_lookup_table"> { let summary = "Applies a clear lookup table to an encrypted integer"; @@ -125,7 +125,7 @@ def ApplyLookupTableEintOp : HLFHE_Op<"apply_lookup_table"> { let results = (outs EncryptedIntegerType); let verifier = [{ - return ::mlir::concretelang::HLFHE::verifyApplyLookupTable(*this); + return ::mlir::concretelang::FHE::verifyApplyLookupTable(*this); }]; } diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHETypes.h b/compiler/include/concretelang/Dialect/FHE/IR/FHETypes.h similarity index 69% rename from compiler/include/concretelang/Dialect/HLFHE/IR/HLFHETypes.h rename to compiler/include/concretelang/Dialect/FHE/IR/FHETypes.h index 80d7fd1e0..72f414852 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHETypes.h +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHETypes.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHETYPES_H -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHETYPES_H +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHETYPES_H +#define CONCRETELANG_DIALECT_FHE_IR_FHETYPES_H #include "llvm/ADT/TypeSwitch.h" #include @@ -10,6 +10,6 @@ #include #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/HLFHE/IR/HLFHEOpsTypes.h.inc" +#include "concretelang/Dialect/FHE/IR/FHEOpsTypes.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHETypes.td b/compiler/include/concretelang/Dialect/FHE/IR/FHETypes.td similarity index 71% rename from compiler/include/concretelang/Dialect/HLFHE/IR/HLFHETypes.td rename to compiler/include/concretelang/Dialect/FHE/IR/FHETypes.td index 3716a0878..0a4a25ba0 100644 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/HLFHETypes.td +++ b/compiler/include/concretelang/Dialect/FHE/IR/FHETypes.td @@ -1,13 +1,13 @@ -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_TYPES -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_TYPES +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHE_TYPES +#define CONCRETELANG_DIALECT_FHE_IR_FHE_TYPES -include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.td" +include "concretelang/Dialect/FHE/IR/FHEDialect.td" include "mlir/IR/BuiltinTypes.td" -class HLFHE_Type traits = []> : - TypeDef { } +class FHE_Type traits = []> : + TypeDef { } -def EncryptedIntegerType : HLFHE_Type<"EncryptedInteger", +def EncryptedIntegerType : FHE_Type<"EncryptedInteger", [MemRefElementTypeInterface]> { let mnemonic = "eint"; diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/CMakeLists.txt b/compiler/include/concretelang/Dialect/FHELinalg/CMakeLists.txt similarity index 100% rename from compiler/include/concretelang/Dialect/HLFHELinalg/CMakeLists.txt rename to compiler/include/concretelang/Dialect/FHELinalg/CMakeLists.txt diff --git a/compiler/include/concretelang/Dialect/FHELinalg/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/FHELinalg/IR/CMakeLists.txt new file mode 100644 index 000000000..57f8cb5b4 --- /dev/null +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_TARGET_DEFINITIONS FHELinalgOps.td) +mlir_tablegen(FHELinalgOps.h.inc -gen-op-decls) +mlir_tablegen(FHELinalgOps.cpp.inc -gen-op-defs) +mlir_tablegen(FHELinalgOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=FHELinalg) +mlir_tablegen(FHELinalgOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=FHELinalg) +mlir_tablegen(FHELinalgOpsDialect.h.inc -gen-dialect-decls -dialect=FHELinalg) +mlir_tablegen(FHELinalgOpsDialect.cpp.inc -gen-dialect-defs -dialect=FHELinalg) +add_public_tablegen_target(MLIRFHELinalgOpsIncGen) +add_dependencies(mlir-headers MLIRFHELinalgOpsIncGen) + +add_concretelang_doc(FHELinalgDialect FHELinalgDialect concretelang/ -gen-dialect-doc) +add_concretelang_doc(FHELinalgOps FHELinalgOps concretelang/ -gen-op-doc) +add_concretelang_doc(FHELinalgTypes FHELinalgTypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.h b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h similarity index 58% rename from compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.h rename to compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h index 78752951b..a3d4ce1ce 100644 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.h +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h @@ -1,13 +1,13 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalgDIALECT_H -#define CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalgDIALECT_H +#ifndef CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalgDIALECT_H +#define CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalgDIALECT_H #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOpsDialect.h.inc" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOpsDialect.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.td b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.td new file mode 100644 index 000000000..0bcf37c52 --- /dev/null +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.td @@ -0,0 +1,15 @@ +#ifndef CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalg_DIALECT +#define CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalg_DIALECT + +include "mlir/IR/OpBase.td" + +def FHELinalg_Dialect : Dialect { + let name = "FHELinalg"; + let summary = "High Level Fully Homorphic Encryption Linalg dialect"; + let description = [{ + A dialect for representation of high level linalg operations on fully homomorphic ciphertexts. + }]; + let cppNamespace = "::mlir::concretelang::FHELinalg"; +} + +#endif diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h similarity index 81% rename from compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h rename to compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h index 70541bc7d..c10d091f2 100644 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h @@ -1,13 +1,13 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalgOPS_H -#define CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalgOPS_H +#ifndef CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalgOPS_H +#define CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalgOPS_H #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h" #include #include @@ -42,8 +42,8 @@ public: /// TensorBinaryEintInt verifies that the operation matches the following /// signature -/// `(tensor<...x!HLFHE.eint<$p>>, tensor<...xi$p'>) -> -/// tensor<...x!HLFHE.eint<$p>>` where `$p <= $p+1`. +/// `(tensor<...x!FHE.eint<$p>>, tensor<...xi$p'>) -> +/// tensor<...x!FHE.eint<$p>>` where `$p <= $p+1`. template class TensorBinaryEintInt : public mlir::OpTrait::TraitBase { @@ -55,8 +55,8 @@ public: /// TensorBinaryEintInt verifies that the operation matches the following /// signature -/// `(tensor<...xi$p'>, tensor<...x!HLFHE.eint<$p>>) -> -/// tensor<...x!HLFHE.eint<$p>>` where `$p <= $p+1`. +/// `(tensor<...xi$p'>, tensor<...x!FHE.eint<$p>>) -> +/// tensor<...x!FHE.eint<$p>>` where `$p <= $p+1`. template class TensorBinaryIntEint : public mlir::OpTrait::TraitBase { @@ -67,8 +67,8 @@ public: }; /// TensorBinary verify the operation match the following signature -/// `(tensor<...x!HLFHE.eint<$p>>, tensor<...x!HLFHE.eint<$p>>) -> -/// tensor<...x!HLFHE.eint<$p>>` +/// `(tensor<...x!FHE.eint<$p>>, tensor<...x!FHE.eint<$p>>) -> +/// tensor<...x!FHE.eint<$p>>` template class TensorBinaryEint : public mlir::OpTrait::TraitBase { @@ -79,7 +79,7 @@ public: }; /// TensorBinary verify the operation match the following signature -/// `(tensor<...x!HLFHE.eint<$p>>) -> tensor<...x!HLFHE.eint<$p>>` +/// `(tensor<...x!FHE.eint<$p>>) -> tensor<...x!FHE.eint<$p>>` template class TensorUnaryEint : public mlir::OpTrait::TraitBase { @@ -93,6 +93,6 @@ public: } // namespace mlir #define GET_OP_CLASSES -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h.inc" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.td b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td similarity index 73% rename from compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.td rename to compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td index 3163535ac..59fda6b96 100644 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.td +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td @@ -1,14 +1,14 @@ -#ifndef CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalg_OPS -#define CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalg_OPS +#ifndef CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalg_OPS +#define CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalg_OPS include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Interfaces/ControlFlowInterfaces.td" -include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.td" -include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.td" +include "concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.td" +include "concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.td" -class HLFHELinalg_Op traits = []> : - Op; +class FHELinalg_Op traits = []> : + Op; // TensorBroadcastingRules verify that the operands and result verify the broadcasting rules def TensorBroadcastingRules : NativeOpTrait<"TensorBroadcastingRules">; @@ -18,7 +18,7 @@ def TensorBinaryEint : NativeOpTrait<"TensorBinaryEint">; def TensorUnaryEint : NativeOpTrait<"TensorUnaryEint">; -def AddEintIntOp : HLFHELinalg_Op<"add_eint_int", [TensorBroadcastingRules, TensorBinaryEintInt]> { +def AddEintIntOp : FHELinalg_Op<"add_eint_int", [TensorBroadcastingRules, TensorBinaryEintInt]> { let summary = "Returns a tensor that contains the addition of a tensor of encrypted integers and a tensor of clear integers."; let description = [{ @@ -28,10 +28,10 @@ def AddEintIntOp : HLFHELinalg_Op<"add_eint_int", [TensorBroadcastingRules, Tens Examples: ```mlir // Returns the term to term addition of `%a0` with `%a1` - "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<4>>, tensor<4xi5>) -> tensor<4x!HLFHE.eint<4>> + "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<4>>, tensor<4xi5>) -> tensor<4x!FHE.eint<4>> // Returns the term to term addition of `%a0` with `%a1`, where dimensions equal to one are stretched. - "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x1x4x!HLFHE.eint<4>>, tensor<1x4x4xi5>) -> tensor<4x4x4x!HLFHE.eint<4>> + "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x1x4x!FHE.eint<4>>, tensor<1x4x4xi5>) -> tensor<4x4x4x!FHE.eint<4>> // Returns the addition of a 3x3 matrix of encrypted integers and a 3x1 matrix (a column) of integers. // @@ -40,7 +40,7 @@ def AddEintIntOp : HLFHELinalg_Op<"add_eint_int", [TensorBroadcastingRules, Tens // [7,8,9] [3] [10,11,12] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!FHE.eint<4>> // Returns the addition of a 3x3 matrix of encrypted integers and a 1x3 matrix (a line) of integers. // @@ -49,10 +49,10 @@ def AddEintIntOp : HLFHELinalg_Op<"add_eint_int", [TensorBroadcastingRules, Tens // [7,8,9] [8,10,12] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!FHE.eint<4>> // Same behavior than the previous one, but as the dimension #2 is missing of operand #2. - "HLFHELinalg.add_eint_int(%a0, %a1)" : (tensor<3x4x!HLFHE.eint<4>>, tensor<3xi5>) -> tensor<4x4x4x!HLFHE.eint<4>> + "FHELinalg.add_eint_int(%a0, %a1)" : (tensor<3x4x!FHE.eint<4>>, tensor<3xi5>) -> tensor<4x4x4x!FHE.eint<4>> ``` }]; @@ -71,7 +71,7 @@ def AddEintIntOp : HLFHELinalg_Op<"add_eint_int", [TensorBroadcastingRules, Tens ]; } -def AddEintOp : HLFHELinalg_Op<"add_eint", [TensorBroadcastingRules, TensorBinaryEint]> { +def AddEintOp : FHELinalg_Op<"add_eint", [TensorBroadcastingRules, TensorBinaryEint]> { let summary = "Returns a tensor that contains the addition of two tensor of encrypted integers."; let description = [{ @@ -81,10 +81,10 @@ def AddEintOp : HLFHELinalg_Op<"add_eint", [TensorBroadcastingRules, TensorBinar Examples: ```mlir // Returns the term to term addition of `%a0` with `%a1` - "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<4x!HLFHE.eint<4>>, tensor<4x!HLFHE.eint<4>>) -> tensor<4x!HLFHE.eint<4>> + "FHELinalg.add_eint"(%a0, %a1) : (tensor<4x!FHE.eint<4>>, tensor<4x!FHE.eint<4>>) -> tensor<4x!FHE.eint<4>> // Returns the term to term addition of `%a0` with `%a1`, where dimensions equal to one are stretched. - "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<4x1x4x!HLFHE.eint<4>>, tensor<1x4x4x!HLFHE.eint<4>>) -> tensor<4x4x4x!HLFHE.eint<4>> + "FHELinalg.add_eint"(%a0, %a1) : (tensor<4x1x4x!FHE.eint<4>>, tensor<1x4x4x!FHE.eint<4>>) -> tensor<4x4x4x!FHE.eint<4>> // Returns the addition of a 3x3 matrix of encrypted integers and a 3x1 matrix (a column) of encrypted integers. // @@ -93,7 +93,7 @@ def AddEintOp : HLFHELinalg_Op<"add_eint", [TensorBroadcastingRules, TensorBinar // [7,8,9] [3] [10,11,12] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x1x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x1x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> // Returns the addition of a 3x3 matrix of encrypted integers and a 1x3 matrix (a line) of encrypted integers. // @@ -102,10 +102,10 @@ def AddEintOp : HLFHELinalg_Op<"add_eint", [TensorBroadcastingRules, TensorBinar // [7,8,9] [8,10,12] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<1x3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<1x3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> // Same behavior than the previous one, but as the dimension #2 of operand #2 is missing. - "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> ``` }]; @@ -123,7 +123,7 @@ def AddEintOp : HLFHELinalg_Op<"add_eint", [TensorBroadcastingRules, TensorBinar ]; } -def SubIntEintOp : HLFHELinalg_Op<"sub_int_eint", [TensorBroadcastingRules, TensorBinaryIntEint]> { +def SubIntEintOp : FHELinalg_Op<"sub_int_eint", [TensorBroadcastingRules, TensorBinaryIntEint]> { let summary = "Returns a tensor that contains the substraction of a tensor of clear integers and a tensor of encrypted integers."; let description = [{ @@ -133,10 +133,10 @@ def SubIntEintOp : HLFHELinalg_Op<"sub_int_eint", [TensorBroadcastingRules, Tens Examples: ```mlir // Returns the term to term substraction of `%a0` with `%a1` - "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4xi5>, tensor<4x!HLFHE.eint<4>>) -> tensor<4x!HLFHE.eint<4>> + "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4xi5>, tensor<4x!FHE.eint<4>>) -> tensor<4x!FHE.eint<4>> // Returns the term to term substraction of `%a0` with `%a1`, where dimensions equal to one are stretched. - "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4x1x4xi5>, tensor<1x4x4x!HLFHE.eint<4>>) -> tensor<4x4x4x!HLFHE.eint<4>> + "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4x1x4xi5>, tensor<1x4x4x!FHE.eint<4>>) -> tensor<4x4x4x!FHE.eint<4>> // Returns the substraction of a 3x3 matrix of integers and a 3x1 matrix (a column) of encrypted integers. // @@ -145,7 +145,7 @@ def SubIntEintOp : HLFHELinalg_Op<"sub_int_eint", [TensorBroadcastingRules, Tens // [7,8,9] [3] [4,5,6] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<3x1x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<3x1x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> // Returns the substraction of a 3x3 matrix of integers and a 1x3 matrix (a line) of encrypted integers. // @@ -154,10 +154,10 @@ def SubIntEintOp : HLFHELinalg_Op<"sub_int_eint", [TensorBroadcastingRules, Tens // [7,8,9] [6,6,6] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<1x3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<1x3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> // Same behavior than the previous one, but as the dimension #2 is missing of operand #2. - "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> ``` }]; @@ -176,7 +176,7 @@ def SubIntEintOp : HLFHELinalg_Op<"sub_int_eint", [TensorBroadcastingRules, Tens ]; } -def NegEintOp : HLFHELinalg_Op<"neg_eint", [TensorUnaryEint]> { +def NegEintOp : FHELinalg_Op<"neg_eint", [TensorUnaryEint]> { let summary = "Returns a tensor that contains the negation of a tensor of encrypted integers."; let description = [{ @@ -185,7 +185,7 @@ def NegEintOp : HLFHELinalg_Op<"neg_eint", [TensorUnaryEint]> { Examples: ```mlir // Returns the term to term negation of `%a0` - "HLFHELinalg.neg_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.neg_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> // // ( [1,2,3] ) [31,30,29] // negate ( [4,5,6] ) = [28,27,26] @@ -208,7 +208,7 @@ def NegEintOp : HLFHELinalg_Op<"neg_eint", [TensorUnaryEint]> { ]; } -def MulEintIntOp : HLFHELinalg_Op<"mul_eint_int", [TensorBroadcastingRules, TensorBinaryEintInt]> { +def MulEintIntOp : FHELinalg_Op<"mul_eint_int", [TensorBroadcastingRules, TensorBinaryEintInt]> { let summary = "Returns a tensor that contains the multiplication of a tensor of encrypted integers and a tensor of clear integers."; let description = [{ @@ -218,10 +218,10 @@ def MulEintIntOp : HLFHELinalg_Op<"mul_eint_int", [TensorBroadcastingRules, Tens Examples: ```mlir // Returns the term to term multiplication of `%a0` with `%a1` - "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<4>>, tensor<4xi5>) -> tensor<4x!HLFHE.eint<4>> + "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<4>>, tensor<4xi5>) -> tensor<4x!FHE.eint<4>> // Returns the term to term multiplication of `%a0` with `%a1`, where dimensions equal to one are stretched. - "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x1x4x!HLFHE.eint<4>>, tensor<1x4x4xi5>) -> tensor<4x4x4x!HLFHE.eint<4>> + "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x1x4x!FHE.eint<4>>, tensor<1x4x4xi5>) -> tensor<4x4x4x!FHE.eint<4>> // Returns the multiplication of a 3x3 matrix of encrypted integers and a 3x1 matrix (a column) of integers. // @@ -230,7 +230,7 @@ def MulEintIntOp : HLFHELinalg_Op<"mul_eint_int", [TensorBroadcastingRules, Tens // [7,8,9] [3] [21,24,27] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!FHE.eint<4>> // Returns the multiplication of a 3x3 matrix of encrypted integers and a 1x3 matrix (a line) of integers. // @@ -239,10 +239,10 @@ def MulEintIntOp : HLFHELinalg_Op<"mul_eint_int", [TensorBroadcastingRules, Tens // [7,8,9] [8,10,12] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!FHE.eint<4>> // Same behavior than the previous one, but as the dimension #2 is missing of operand #2. - "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3xi5>) -> tensor<3x3x!HLFHE.eint<4>> + "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3xi5>) -> tensor<3x3x!FHE.eint<4>> ``` }]; @@ -255,7 +255,7 @@ def MulEintIntOp : HLFHELinalg_Op<"mul_eint_int", [TensorBroadcastingRules, Tens let results = (outs Type.predicate, HasStaticShapePred]>>); } -def ApplyLookupTableEintOp : HLFHELinalg_Op<"apply_lookup_table", []> { +def ApplyLookupTableEintOp : FHELinalg_Op<"apply_lookup_table", []> { let summary = "Returns a tensor that contains the result of the lookup on a table."; let description = [{ @@ -264,7 +264,7 @@ def ApplyLookupTableEintOp : HLFHELinalg_Op<"apply_lookup_table", []> { ```mlir // The result of this operation, is a tensor that contains the result of the lookup on a table. // i.e. %res[i, ..., k] = %lut[%t[i, ..., k]] - %res = HLFHELinalg.apply_lookup_table(%t, %lut): tensor>, tensor -> tensor> + %res = FHELinalg.apply_lookup_table(%t, %lut): tensor>, tensor -> tensor> ``` The `%lut` argument must be a tensor with one dimension, where its dimension is equals to `2^p` where `p` is the width of the encrypted integers. @@ -277,7 +277,7 @@ def ApplyLookupTableEintOp : HLFHELinalg_Op<"apply_lookup_table", []> { // [0,1,2] [1,3,5] // [3,0,1] lut [1,3,5,7] = [7,1,3] // [2,3,0] [5,7,1] - "HLFHELinalg.apply_lookup_table"(%t, %lut) : (tensor<3x3x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!HLFHE.eint<3>> + "FHELinalg.apply_lookup_table"(%t, %lut) : (tensor<3x3x!FHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!FHE.eint<3>> ``` }]; @@ -289,11 +289,11 @@ def ApplyLookupTableEintOp : HLFHELinalg_Op<"apply_lookup_table", []> { let results = (outs Type.predicate, HasStaticShapePred]>>); let verifier = [{ - return ::mlir::concretelang::HLFHELinalg::verifyApplyLookupTable(*this); + return ::mlir::concretelang::FHELinalg::verifyApplyLookupTable(*this); }]; } -def ApplyMultiLookupTableEintOp : HLFHELinalg_Op<"apply_multi_lookup_table", []> { +def ApplyMultiLookupTableEintOp : FHELinalg_Op<"apply_multi_lookup_table", []> { let summary = "Returns a tensor that contains the result of the lookup on a table, using a different lookup table for each element."; let description = [{ @@ -303,7 +303,7 @@ def ApplyMultiLookupTableEintOp : HLFHELinalg_Op<"apply_multi_lookup_table", []> ```mlir // The result of this operation, is a tensor that contains the result of the lookup on different tables. // i.e. %res[i, ..., k] = [ %luts[i][%t[i]], ..., %luts[k][%t[k]] ] - %res = HLFHELinalg.apply_multi_lookup_table(%t, %lut): tensor>, tensor -> tensor> + %res = FHELinalg.apply_multi_lookup_table(%t, %lut): tensor>, tensor -> tensor> ``` The `%luts` argument should be a tensor with M dimension, where the first M-1 dimensions are broadcastable with the N dimensions of the encrypted tensor, @@ -318,7 +318,7 @@ def ApplyMultiLookupTableEintOp : HLFHELinalg_Op<"apply_multi_lookup_table", []> // [0,1] = [1,2] // [3,0] lut [[1,3,5,7], [0,2,4,6]] = [7,0] // [2,3] = [5,6] - "HLFHELinalg.apply_multi_lookup_table"(%t, %luts) : (tensor<3x2x!HLFHE.eint<2>>, tensor<2x4xi64>) -> tensor<3x2x!HLFHE.eint<3>> + "FHELinalg.apply_multi_lookup_table"(%t, %luts) : (tensor<3x2x!FHE.eint<2>>, tensor<2x4xi64>) -> tensor<3x2x!FHE.eint<3>> ``` ```mlir @@ -326,7 +326,7 @@ def ApplyMultiLookupTableEintOp : HLFHELinalg_Op<"apply_multi_lookup_table", []> // Returns the lookup of a vector of 3 encrypted indices of width 2 on a vector of 3 tables of size 4=2² of clear integers. // // [3,0,1] lut [[1,3,5,7], [0,2,4,6], [1,2,3,4]] = [7,0,2] - "HLFHELinalg.apply_multi_lookup_table"(%t, %luts) : (tensor<3x!HLFHE.eint<2>>, tensor<3x4xi64>) -> tensor<3x!HLFHE.eint<3>> + "FHELinalg.apply_multi_lookup_table"(%t, %luts) : (tensor<3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<3x!FHE.eint<3>> ``` }]; @@ -338,11 +338,11 @@ def ApplyMultiLookupTableEintOp : HLFHELinalg_Op<"apply_multi_lookup_table", []> let results = (outs Type.predicate, HasStaticShapePred]>>); let verifier = [{ - return ::mlir::concretelang::HLFHELinalg::verifyApplyMultiLookupTable(*this); + return ::mlir::concretelang::FHELinalg::verifyApplyMultiLookupTable(*this); }]; } -def ApplyMappedLookupTableEintOp : HLFHELinalg_Op<"apply_mapped_lookup_table", []> { +def ApplyMappedLookupTableEintOp : FHELinalg_Op<"apply_mapped_lookup_table", []> { let summary = "Returns a tensor that contains the result of the lookup on a table, using a different lookup table for each element, specified by a map."; let description = [{ @@ -352,7 +352,7 @@ def ApplyMappedLookupTableEintOp : HLFHELinalg_Op<"apply_mapped_lookup_table", [ ```mlir // The result of this operation, is a tensor that contains the result of the lookup on different tables. // i.e. %res[i, ..., k] = %luts[ %map[i, ..., k] ][ %t[i, ..., k] ] - %res = HLFHELinalg.apply_mapped_lookup_table(%t, %luts, %map): tensor>, tensor, tensor -> tensor> + %res = FHELinalg.apply_mapped_lookup_table(%t, %luts, %map): tensor>, tensor, tensor -> tensor> ``` Examples: @@ -363,7 +363,7 @@ def ApplyMappedLookupTableEintOp : HLFHELinalg_Op<"apply_mapped_lookup_table", [ // [0,1] [0, 1] = [1,2] // [3,0] lut [[1,3,5,7], [0,2,4,6]] with [0, 1] = [7,0] // [2,3] [0, 1] = [5,6] - "HLFHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) : (tensor<3x2x!HLFHE.eint<2>>, tensor<2x4xi64>, tensor<3x2xindex>) -> tensor<3x2x!HLFHE.eint<3>> + "FHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) : (tensor<3x2x!FHE.eint<2>>, tensor<2x4xi64>, tensor<3x2xindex>) -> tensor<3x2x!FHE.eint<3>> ``` Others examples: @@ -394,12 +394,12 @@ def ApplyMappedLookupTableEintOp : HLFHELinalg_Op<"apply_mapped_lookup_table", [ let results = (outs Type.predicate, HasStaticShapePred]>>); let verifier = [{ - return ::mlir::concretelang::HLFHELinalg::verifyApplyMappedLookupTable(*this); + return ::mlir::concretelang::FHELinalg::verifyApplyMappedLookupTable(*this); }]; } // Dot product -def Dot : HLFHELinalg_Op<"dot_eint_int"> { +def Dot : FHELinalg_Op<"dot_eint_int"> { let summary = "Returns the encrypted dot product between a vector of encrypted integers and a vector of clean integers."; let description = [{ @@ -408,7 +408,7 @@ def Dot : HLFHELinalg_Op<"dot_eint_int"> { Examples: ```mlir // Returns the dot product of `%a0` with `%a1` - "HLFHELinalg.dot_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<4>>, tensor<4xi5>) -> !HLFHE.eint<4> + "FHELinalg.dot_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<4>>, tensor<4xi5>) -> !FHE.eint<4> ``` }]; @@ -420,11 +420,11 @@ def Dot : HLFHELinalg_Op<"dot_eint_int"> { let results = (outs EncryptedIntegerType:$out); let verifier = [{ - return ::mlir::concretelang::HLFHELinalg::verifyDotEintInt(*this); + return ::mlir::concretelang::FHELinalg::verifyDotEintInt(*this); }]; } -def MatMulEintIntOp : HLFHELinalg_Op<"matmul_eint_int", [TensorBinaryEintInt]> { +def MatMulEintIntOp : FHELinalg_Op<"matmul_eint_int", [TensorBinaryEintInt]> { let summary = "Returns a tensor that contains the result of the matrix multiplication of a matrix of encrypted integers and a matrix of clear integers."; let description = [{ @@ -432,7 +432,7 @@ def MatMulEintIntOp : HLFHELinalg_Op<"matmul_eint_int", [TensorBinaryEintInt]> { The width of the clear integers must be less than or equals to the witdh of encrypted integers. ```mlir - "HLFHELinalg.matmul_eint_int(%a, %b) : (tensor>, tensor) -> tensor>" + "FHELinalg.matmul_eint_int(%a, %b) : (tensor>, tensor) -> tensor>" ``` Examples: @@ -445,7 +445,7 @@ def MatMulEintIntOp : HLFHELinalg_Op<"matmul_eint_int", [TensorBinaryEintInt]> { // [3,4] = [11,18,25] // [5,6] [17,28,39] // - "HLFHELinalg.matmul_eint_int"(%a, %b) : (tensor<3x2x!HLFHE.eint<6>>, tensor<2x3xi7>) -> tensor<3x3x!HLFHE.eint<6>> + "FHELinalg.matmul_eint_int"(%a, %b) : (tensor<3x2x!FHE.eint<6>>, tensor<2x3xi7>) -> tensor<3x3x!FHE.eint<6>> ``` }]; @@ -458,11 +458,11 @@ def MatMulEintIntOp : HLFHELinalg_Op<"matmul_eint_int", [TensorBinaryEintInt]> { let results = (outs Type.predicate, HasStaticShapePred]>>); let verifier = [{ - return ::mlir::concretelang::HLFHELinalg::verifyMatmul(*this); + return ::mlir::concretelang::FHELinalg::verifyMatmul(*this); }]; } -def MatMulIntEintOp : HLFHELinalg_Op<"matmul_int_eint", [TensorBinaryIntEint]> { +def MatMulIntEintOp : FHELinalg_Op<"matmul_int_eint", [TensorBinaryIntEint]> { let summary = "Returns a tensor that contains the result of the matrix multiplication of a matrix of clear integers and a matrix of encrypted integers."; let description = [{ @@ -470,7 +470,7 @@ def MatMulIntEintOp : HLFHELinalg_Op<"matmul_int_eint", [TensorBinaryIntEint]> { The width of the clear integers must be less than or equals to the witdh of encrypted integers. ```mlir - "HLFHELinalg.matmul_int_eint(%a, %b) : (tensor, tensor>) -> tensor>" + "FHELinalg.matmul_int_eint(%a, %b) : (tensor, tensor>) -> tensor>" ``` Examples: @@ -483,7 +483,7 @@ def MatMulIntEintOp : HLFHELinalg_Op<"matmul_int_eint", [TensorBinaryIntEint]> { // [3,4] = [11,18,25] // [5,6] [17,28,39] // - "HLFHELinalg.matmul_int_eint"(%a, %b) : (tensor<3x2xi7>, tensor<2x3x!HLFHE.eint<6>>) -> tensor<3x3x!HLFHE.eint<6>> + "FHELinalg.matmul_int_eint"(%a, %b) : (tensor<3x2xi7>, tensor<2x3x!FHE.eint<6>>) -> tensor<3x3x!FHE.eint<6>> ``` }]; @@ -496,11 +496,11 @@ def MatMulIntEintOp : HLFHELinalg_Op<"matmul_int_eint", [TensorBinaryIntEint]> { let results = (outs Type.predicate, HasStaticShapePred]>>); let verifier = [{ - return ::mlir::concretelang::HLFHELinalg::verifyMatmul(*this); + return ::mlir::concretelang::FHELinalg::verifyMatmul(*this); }]; } -def ZeroOp : HLFHELinalg_Op<"zero", []> { +def ZeroOp : FHELinalg_Op<"zero", []> { let summary = "Creates a new tensor with all elements initialized to an encrypted zero."; let description = [{ @@ -508,7 +508,7 @@ def ZeroOp : HLFHELinalg_Op<"zero", []> { Example: ```mlir - %tensor = "HLFHELinalg.zero"() : () -> tensor<5x!HLFHE.eint<4>> + %tensor = "FHELinalg.zero"() : () -> tensor<5x!FHE.eint<4>> ``` }]; diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h similarity index 62% rename from compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h rename to compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h index 3dead9b1a..437b840ed 100644 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h @@ -1,14 +1,14 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalgTYPES_H -#define CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalgTYPES_H +#ifndef CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalgTYPES_H +#define CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalgTYPES_H #include #include #include #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOpsTypes.h.inc" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOpsTypes.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.td b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.td new file mode 100644 index 000000000..1fe8b5661 --- /dev/null +++ b/compiler/include/concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.td @@ -0,0 +1,11 @@ +#ifndef CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalg_TYPES +#define CONCRETELANG_DIALECT_FHELinalg_IR_FHELinalg_TYPES + +include "concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.td" +include "mlir/IR/BuiltinTypes.td" +include "concretelang/Dialect/FHE/IR/FHETypes.td" + +class FHELinalg_Type traits = []> : + TypeDef { } + +#endif diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/CMakeLists.txt b/compiler/include/concretelang/Dialect/FHELinalg/Transforms/CMakeLists.txt similarity index 59% rename from compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/CMakeLists.txt rename to compiler/include/concretelang/Dialect/FHELinalg/Transforms/CMakeLists.txt index 3364504e9..0eb4173a6 100644 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/CMakeLists.txt +++ b/compiler/include/concretelang/Dialect/FHELinalg/Transforms/CMakeLists.txt @@ -1,3 +1,3 @@ set(LLVM_TARGET_DEFINITIONS Tiling.td) mlir_tablegen(Tiling.h.inc -gen-pass-decls -name Transforms) -add_public_tablegen_target(ConcretelangHLFHELinalgTilingPassIncGen) +add_public_tablegen_target(ConcretelangFHELinalgTilingPassIncGen) diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/Tiling.h b/compiler/include/concretelang/Dialect/FHELinalg/Transforms/Tiling.h similarity index 50% rename from compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/Tiling.h rename to compiler/include/concretelang/Dialect/FHELinalg/Transforms/Tiling.h index 9d894d710..48e685f21 100644 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/Tiling.h +++ b/compiler/include/concretelang/Dialect/FHELinalg/Transforms/Tiling.h @@ -1,21 +1,21 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_HLFHELINALG_TILING_PASS_H -#define CONCRETELANG_HLFHELINALG_TILING_PASS_H +#ifndef CONCRETELANG_FHELINALG_TILING_PASS_H +#define CONCRETELANG_FHELINALG_TILING_PASS_H #include -#include +#include #define GEN_PASS_CLASSES -#include +#include namespace mlir { namespace concretelang { std::unique_ptr> -createHLFHELinalgTilingMarkerPass(llvm::ArrayRef tileSizes); +createFHELinalgTilingMarkerPass(llvm::ArrayRef tileSizes); -std::unique_ptr> createHLFHELinalgTilingPass(); +std::unique_ptr> createFHELinalgTilingPass(); } // namespace concretelang } // namespace mlir diff --git a/compiler/include/concretelang/Dialect/FHELinalg/Transforms/Tiling.td b/compiler/include/concretelang/Dialect/FHELinalg/Transforms/Tiling.td new file mode 100644 index 000000000..034f62314 --- /dev/null +++ b/compiler/include/concretelang/Dialect/FHELinalg/Transforms/Tiling.td @@ -0,0 +1,22 @@ +#ifndef CONCRETELANG_FHELINALG_TILING_PASS +#define CONCRETELANG_FHELINALG_TILING_PASS + +include "mlir/Pass/PassBase.td" + +def FHELinalgTilingMarker : Pass<"fhe-linalg-tiling-marker"> { + let summary = + "Marks FHELinalg operations for tiling using a vector of tile sizes"; + let constructor = "mlir::concretelang::createFHELinalgTilingMarkerPass()"; + let options = []; + let dependentDialects = [ "mlir::concretelang::FHELinalg::FHELinalgDialect" ]; +} + +def FHELinalgTiling : Pass<"fhe-linalg-tiling"> { + let summary = "Performs tiling of FHELinalg operations based on the " + "tile-size attribute"; + let constructor = "mlir::concretelang::createFHELinalgTilingPass()"; + let options = []; + let dependentDialects = [ "mlir::concretelang::FHELinalg::FHELinalgDialect" ]; +} + +#endif diff --git a/compiler/include/concretelang/Dialect/HLFHE/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/HLFHE/IR/CMakeLists.txt deleted file mode 100644 index be658650e..000000000 --- a/compiler/include/concretelang/Dialect/HLFHE/IR/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS HLFHEOps.td) -mlir_tablegen(HLFHEOps.h.inc -gen-op-decls) -mlir_tablegen(HLFHEOps.cpp.inc -gen-op-defs) -mlir_tablegen(HLFHEOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=HLFHE) -mlir_tablegen(HLFHEOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=HLFHE) -mlir_tablegen(HLFHEOpsDialect.h.inc -gen-dialect-decls -dialect=HLFHE) -mlir_tablegen(HLFHEOpsDialect.cpp.inc -gen-dialect-defs -dialect=HLFHE) -add_public_tablegen_target(MLIRHLFHEOpsIncGen) -add_dependencies(mlir-headers MLIRHLFHEOpsIncGen) - -add_concretelang_doc(HLFHEDialect HLFHEDialect concretelang/ -gen-dialect-doc) -add_concretelang_doc(HLFHEOps HLFHEOps concretelang/ -gen-op-doc) -add_concretelang_doc(HLFHETypes HLFHETypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/HLFHELinalg/IR/CMakeLists.txt deleted file mode 100644 index 4395d348e..000000000 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS HLFHELinalgOps.td) -mlir_tablegen(HLFHELinalgOps.h.inc -gen-op-decls) -mlir_tablegen(HLFHELinalgOps.cpp.inc -gen-op-defs) -mlir_tablegen(HLFHELinalgOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=HLFHELinalg) -mlir_tablegen(HLFHELinalgOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=HLFHELinalg) -mlir_tablegen(HLFHELinalgOpsDialect.h.inc -gen-dialect-decls -dialect=HLFHELinalg) -mlir_tablegen(HLFHELinalgOpsDialect.cpp.inc -gen-dialect-defs -dialect=HLFHELinalg) -add_public_tablegen_target(MLIRHLFHELinalgOpsIncGen) -add_dependencies(mlir-headers MLIRHLFHELinalgOpsIncGen) - -add_concretelang_doc(HLFHELinalgDialect HLFHELinalgDialect concretelang/ -gen-dialect-doc) -add_concretelang_doc(HLFHELinalgOps HLFHELinalgOps concretelang/ -gen-op-doc) -add_concretelang_doc(HLFHELinalgTypes HLFHELinalgTypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.td b/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.td deleted file mode 100644 index b708853c7..000000000 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.td +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalg_DIALECT -#define CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalg_DIALECT - -include "mlir/IR/OpBase.td" - -def HLFHELinalg_Dialect : Dialect { - let name = "HLFHELinalg"; - let summary = "High Level Fully Homorphic Encryption Linalg dialect"; - let description = [{ - A dialect for representation of high level linalg operations on fully homomorphic ciphertexts. - }]; - let cppNamespace = "::mlir::concretelang::HLFHELinalg"; -} - -#endif diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.td b/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.td deleted file mode 100644 index ea54a4e47..000000000 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.td +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalg_TYPES -#define CONCRETELANG_DIALECT_HLFHELinalg_IR_HLFHELinalg_TYPES - -include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.td" -include "mlir/IR/BuiltinTypes.td" -include "concretelang/Dialect/HLFHE/IR/HLFHETypes.td" - -class HLFHELinalg_Type traits = []> : - TypeDef { } - -#endif diff --git a/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/Tiling.td b/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/Tiling.td deleted file mode 100644 index 3d93fb0d8..000000000 --- a/compiler/include/concretelang/Dialect/HLFHELinalg/Transforms/Tiling.td +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef CONCRETELANG_HLFHELINALG_TILING_PASS -#define CONCRETELANG_HLFHELINALG_TILING_PASS - -include "mlir/Pass/PassBase.td" - -def HLFHELinalgTilingMarker : Pass<"hlfhe-linalg-tiling-marker"> { - let summary = - "Marks HLFHELinalg operations for tiling using a vector of tile sizes"; - let constructor = "mlir::concretelang::createHLFHELinalgTilingMarkerPass()"; - let options = []; - let dependentDialects = [ "mlir::concretelang::HLFHELinalg::HLFHELinalgDialect" ]; -} - -def HLFHELinalgTiling : Pass<"hlfhe-linalg-tiling"> { - let summary = "Performs tiling of HLFHELinalg operations based on the " - "tile-size attribute"; - let constructor = "mlir::concretelang::createHLFHELinalgTilingPass()"; - let options = []; - let dependentDialects = [ "mlir::concretelang::HLFHELinalg::HLFHELinalgDialect" ]; -} - -#endif diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/LowLFHE/IR/CMakeLists.txt deleted file mode 100644 index cb85ae76d..000000000 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS LowLFHEOps.td) -mlir_tablegen(LowLFHEOps.h.inc -gen-op-decls) -mlir_tablegen(LowLFHEOps.cpp.inc -gen-op-defs) -mlir_tablegen(LowLFHEOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=LowLFHE) -mlir_tablegen(LowLFHEOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=LowLFHE) -mlir_tablegen(LowLFHEOpsDialect.h.inc -gen-dialect-decls -dialect=LowLFHE) -mlir_tablegen(LowLFHEOpsDialect.cpp.inc -gen-dialect-defs -dialect=LowLFHE) -add_public_tablegen_target(MLIRLowLFHEOpsIncGen) -add_dependencies(mlir-headers MLIRLowLFHEOpsIncGen) - -add_concretelang_doc(LowLFHEDialect LowLFHEDialect concretelang/ -gen-dialect-doc) -add_concretelang_doc(LowLFHEOps LowLFHEOps concretelang/ -gen-op-doc) -add_concretelang_doc(LowLFHETypes LowLFHETypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.td b/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.td deleted file mode 100644 index d121cf2e0..000000000 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.td +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHE_DIALECT -#define CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHE_DIALECT - -include "mlir/IR/OpBase.td" - -def LowLFHE_Dialect : Dialect { - let name = "LowLFHE"; - let summary = "Low Level Fully Homorphic Encryption dialect"; - let description = [{ - A dialect for representation of low level operation on fully homomorphic ciphertext. - }]; - let cppNamespace = "::mlir::concretelang::LowLFHE"; -} - -#endif diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/MidLFHE/IR/CMakeLists.txt deleted file mode 100644 index c14c43e0a..000000000 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS MidLFHEOps.td) -mlir_tablegen(MidLFHEOps.h.inc -gen-op-decls) -mlir_tablegen(MidLFHEOps.cpp.inc -gen-op-defs) -mlir_tablegen(MidLFHEOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=MidLFHE) -mlir_tablegen(MidLFHEOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=MidLFHE) -mlir_tablegen(MidLFHEOpsDialect.h.inc -gen-dialect-decls -dialect=MidLFHE) -mlir_tablegen(MidLFHEOpsDialect.cpp.inc -gen-dialect-defs -dialect=MidLFHE) -add_public_tablegen_target(MLIRMidLFHEOpsIncGen) -add_dependencies(mlir-headers MLIRMidLFHEOpsIncGen) - -add_concretelang_doc(MidLFHEDialect MidLFHEDialect concretelang/ -gen-dialect-doc) -add_concretelang_doc(MidLFHEOps MidLFHEOps concretelang/ -gen-op-doc) -add_concretelang_doc(MidLFHETypes MidLFHETypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/RT/Analysis/Autopar.td b/compiler/include/concretelang/Dialect/RT/Analysis/Autopar.td index 7d7287559..8f386df2d 100644 --- a/compiler/include/concretelang/Dialect/RT/Analysis/Autopar.td +++ b/compiler/include/concretelang/Dialect/RT/Analysis/Autopar.td @@ -8,10 +8,10 @@ def BuildDataflowTaskGraph : Pass<"BuildDataflowTaskGraph", "mlir::ModuleOp"> { "Identify profitable dataflow tasks and build DataflowTaskGraph."; let description = [{ - This pass builds a dataflow graph out of a HLFHE program. + This pass builds a dataflow graph out of a FHE program. In its current incarnation, it considers some heavier weight - operations (e.g., HLFHELinalg Dot and Matmult or bootstraps) as + operations (e.g., FHELinalg Dot and Matmult or bootstraps) as candidates for being executed in a discrete task, and then sinks within the task the lighter weight operation that do not increase the graph cut (amount of dependences in or out). @@ -23,21 +23,21 @@ def BuildDataflowTaskGraph : Pass<"BuildDataflowTaskGraph", "mlir::ModuleOp"> { Example: ```mlir - func @main(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - %0 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1) : (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %0 : tensor<3x2x!HLFHE.eint<2>> + func @main(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + %0 = "FHELinalg.matmul_eint_int"(%arg0, %arg1) : (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %0 : tensor<3x2x!FHE.eint<2>> } ``` Will result in generating a dataflow task for the Matmul operation: ```mlir - func @main(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { + func @main(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { %0 = "RT.dataflow_task"(%arg0, %arg1) ( { - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1) : (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - "RT.dataflow_yield"(%1) : (tensor<3x2x!HLFHE.eint<2>>) -> () - }) : (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %0 : tensor<3x2x!HLFHE.eint<2>> + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1) : (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + "RT.dataflow_yield"(%1) : (tensor<3x2x!FHE.eint<2>>) -> () + }) : (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %0 : tensor<3x2x!FHE.eint<2>> } ``` }]; diff --git a/compiler/include/concretelang/Dialect/RT/IR/RTTypes.td b/compiler/include/concretelang/Dialect/RT/IR/RTTypes.td index 4e5dbf957..954920f0e 100644 --- a/compiler/include/concretelang/Dialect/RT/IR/RTTypes.td +++ b/compiler/include/concretelang/Dialect/RT/IR/RTTypes.td @@ -1,5 +1,5 @@ -#ifndef CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_TYPES -#define CONCRETELANG_DIALECT_HLFHE_IR_HLFHE_TYPES +#ifndef CONCRETELANG_DIALECT_FHE_IR_FHE_TYPES +#define CONCRETELANG_DIALECT_FHE_IR_FHE_TYPES include "concretelang/Dialect/RT/IR/RTDialect.td" include "mlir/IR/BuiltinTypes.td" diff --git a/compiler/include/concretelang/Dialect/MidLFHE/CMakeLists.txt b/compiler/include/concretelang/Dialect/TFHE/CMakeLists.txt similarity index 100% rename from compiler/include/concretelang/Dialect/MidLFHE/CMakeLists.txt rename to compiler/include/concretelang/Dialect/TFHE/CMakeLists.txt diff --git a/compiler/include/concretelang/Dialect/TFHE/IR/CMakeLists.txt b/compiler/include/concretelang/Dialect/TFHE/IR/CMakeLists.txt new file mode 100644 index 000000000..62bc71207 --- /dev/null +++ b/compiler/include/concretelang/Dialect/TFHE/IR/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_TARGET_DEFINITIONS TFHEOps.td) +mlir_tablegen(TFHEOps.h.inc -gen-op-decls) +mlir_tablegen(TFHEOps.cpp.inc -gen-op-defs) +mlir_tablegen(TFHEOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=TFHE) +mlir_tablegen(TFHEOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=TFHE) +mlir_tablegen(TFHEOpsDialect.h.inc -gen-dialect-decls -dialect=TFHE) +mlir_tablegen(TFHEOpsDialect.cpp.inc -gen-dialect-defs -dialect=TFHE) +add_public_tablegen_target(MLIRTFHEOpsIncGen) +add_dependencies(mlir-headers MLIRTFHEOpsIncGen) + +add_concretelang_doc(TFHEDialect TFHEDialect concretelang/ -gen-dialect-doc) +add_concretelang_doc(TFHEOps TFHEOps concretelang/ -gen-op-doc) +add_concretelang_doc(TFHETypes TFHETypes concretelang/ -gen-typedef-doc) diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEDialect.h similarity index 66% rename from compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h rename to compiler/include/concretelang/Dialect/TFHE/IR/TFHEDialect.h index 0015eb096..e19384e6b 100644 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h +++ b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEDialect.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHEDIALECT_H -#define CONCRETELANG_DIALECT_LowLFHE_IR_LowLFHEDIALECT_H +#ifndef CONCRETELANG_DIALECT_TFHE_IR_TFHEDIALECT_H +#define CONCRETELANG_DIALECT_TFHE_IR_TFHEDIALECT_H #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" @@ -11,6 +11,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOpsDialect.h.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOpsDialect.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.td b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEDialect.td similarity index 62% rename from compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.td rename to compiler/include/concretelang/Dialect/TFHE/IR/TFHEDialect.td index 0676b7268..83e92c4f1 100644 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.td +++ b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEDialect.td @@ -1,4 +1,4 @@ -//===- MidLFHEDialect.td - MidLFHE dialect ----------------*- tablegen -*-===// +//===- TFHEDialect.td - TFHE dialect ----------------*- tablegen -*-===// // // This file is licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,18 +6,18 @@ // //===----------------------------------------------------------------------===// -#ifndef CONCRETELANG_DIALECT_MidLFHE_IR_MidLFHE_DIALECT -#define CONCRETELANG_DIALECT_MidLFHE_IR_MidLFHE_DIALECT +#ifndef CONCRETELANG_DIALECT_TFHE_IR_TFHE_DIALECT +#define CONCRETELANG_DIALECT_TFHE_IR_TFHE_DIALECT include "mlir/IR/OpBase.td" -def MidLFHE_Dialect : Dialect { - let name = "MidLFHE"; +def TFHE_Dialect : Dialect { + let name = "TFHE"; let summary = "High Level Fully Homorphic Encryption dialect"; let description = [{ A dialect for representation of high level operation on fully homomorphic ciphertext. }]; - let cppNamespace = "::mlir::concretelang::MidLFHE"; + let cppNamespace = "::mlir::concretelang::TFHE"; } #endif diff --git a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEOps.h similarity index 65% rename from compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h rename to compiler/include/concretelang/Dialect/TFHE/IR/TFHEOps.h index c9ff8a468..be337176a 100644 --- a/compiler/include/concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h +++ b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEOps.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_LowLFHE_LowLFHE_OPS_H -#define CONCRETELANG_DIALECT_LowLFHE_LowLFHE_OPS_H +#ifndef CONCRETELANG_DIALECT_TFHE_IR_TFHEOPS_H +#define CONCRETELANG_DIALECT_TFHE_IR_TFHEOPS_H #include #include @@ -10,9 +10,9 @@ #include #include -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" #define GET_OP_CLASSES -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEOps.td b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEOps.td similarity index 61% rename from compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEOps.td rename to compiler/include/concretelang/Dialect/TFHE/IR/TFHEOps.td index f5752a0ba..264567f4c 100644 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHEOps.td +++ b/compiler/include/concretelang/Dialect/TFHE/IR/TFHEOps.td @@ -1,4 +1,4 @@ -//===- MidLFHEOps.td - High level FHE dialect ops ----------------*- tablegen -*-===// +//===- TFHEOps.td - High level FHE dialect ops ----------------*- tablegen -*-===// // // This file is licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,84 +6,84 @@ // //===----------------------------------------------------------------------===// -#ifndef CONCRETELANG_DIALECT_MidLFHE_IR_MidLFHE_OPS -#define CONCRETELANG_DIALECT_MidLFHE_IR_MidLFHE_OPS +#ifndef CONCRETELANG_DIALECT_TFHE_IR_TFHE_OPS +#define CONCRETELANG_DIALECT_TFHE_IR_TFHE_OPS include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Interfaces/ControlFlowInterfaces.td" -include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.td" -include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.td" +include "concretelang/Dialect/TFHE/IR/TFHEDialect.td" +include "concretelang/Dialect/TFHE/IR/TFHETypes.td" -class MidLFHE_Op traits = []> : - Op; +class TFHE_Op traits = []> : + Op; -def ZeroGLWEOp : MidLFHE_Op<"zero"> { +def ZeroGLWEOp : TFHE_Op<"zero"> { let summary = "Returns a trivial encyption of 0"; let arguments = (ins); let results = (outs GLWECipherTextType:$out); } -def AddGLWEIntOp : MidLFHE_Op<"add_glwe_int"> { +def AddGLWEIntOp : TFHE_Op<"add_glwe_int"> { let summary = "Returns the sum of a clear integer and a lwe ciphertext"; let arguments = (ins GLWECipherTextType:$a, AnyInteger:$b); let results = (outs GLWECipherTextType); let verifier = [{ - return mlir::concretelang::MidLFHE::verifyGLWEIntegerOperator(*this); + return mlir::concretelang::TFHE::verifyGLWEIntegerOperator(*this); }]; } -def AddGLWEOp : MidLFHE_Op<"add_glwe"> { +def AddGLWEOp : TFHE_Op<"add_glwe"> { let summary = "Returns the sum of 2 lwe ciphertexts"; let arguments = (ins GLWECipherTextType:$a, GLWECipherTextType:$b); let results = (outs GLWECipherTextType); let verifier = [{ - return ::mlir::concretelang::MidLFHE::verifyBinaryGLWEOperator(*this); + return ::mlir::concretelang::TFHE::verifyBinaryGLWEOperator(*this); }]; } -def SubIntGLWEOp : MidLFHE_Op<"sub_int_glwe"> { +def SubIntGLWEOp : TFHE_Op<"sub_int_glwe"> { let summary = "Substracts an integer and a GLWE ciphertext"; let arguments = (ins AnyInteger:$a, GLWECipherTextType:$b); let results = (outs GLWECipherTextType); let verifier = [{ - return ::mlir::concretelang::MidLFHE::verifyIntegerGLWEOperator(*this); + return ::mlir::concretelang::TFHE::verifyIntegerGLWEOperator(*this); }]; } -def NegGLWEOp : MidLFHE_Op<"neg_glwe"> { +def NegGLWEOp : TFHE_Op<"neg_glwe"> { let summary = "Negates a glwe ciphertext"; let arguments = (ins GLWECipherTextType:$a); let results = (outs GLWECipherTextType); let verifier = [{ - return ::mlir::concretelang::MidLFHE::verifyUnaryGLWEOperator(*this); + return ::mlir::concretelang::TFHE::verifyUnaryGLWEOperator(*this); }]; } -def MulGLWEIntOp : MidLFHE_Op<"mul_glwe_int"> { +def MulGLWEIntOp : TFHE_Op<"mul_glwe_int"> { let summary = "Returns the product of a clear integer and a lwe ciphertext"; let arguments = (ins GLWECipherTextType:$a, AnyInteger:$b); let results = (outs GLWECipherTextType); let verifier = [{ - return mlir::concretelang::MidLFHE::verifyGLWEIntegerOperator(*this); + return mlir::concretelang::TFHE::verifyGLWEIntegerOperator(*this); }]; } -def ApplyLookupTable : MidLFHE_Op<"apply_lookup_table"> { +def ApplyLookupTable : TFHE_Op<"apply_lookup_table"> { let summary = "Applies a lookup table to a GLWE ciphertext"; @@ -96,7 +96,7 @@ def ApplyLookupTable : MidLFHE_Op<"apply_lookup_table"> { let results = (outs GLWECipherTextType); let verifier = [{ - return ::mlir::concretelang::MidLFHE::verifyApplyLookupTable(*this); + return ::mlir::concretelang::TFHE::verifyApplyLookupTable(*this); }]; } diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h b/compiler/include/concretelang/Dialect/TFHE/IR/TFHETypes.h similarity index 70% rename from compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h rename to compiler/include/concretelang/Dialect/TFHE/IR/TFHETypes.h index 0eb06b1f1..f5c8e6f22 100644 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h +++ b/compiler/include/concretelang/Dialect/TFHE/IR/TFHETypes.h @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#ifndef CONCRETELANG_DIALECT_MIDLFHE_IR_MIDLFHETYPES_H -#define CONCRETELANG_DIALECT_MIDLFHE_IR_MIDLFHETYPES_H +#ifndef CONCRETELANG_DIALECT_TFHE_IR_TFHETYPES_H +#define CONCRETELANG_DIALECT_TFHE_IR_TFHETYPES_H #include "llvm/ADT/TypeSwitch.h" #include @@ -11,6 +11,6 @@ #include #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOpsTypes.h.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOpsTypes.h.inc" #endif diff --git a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHETypes.td b/compiler/include/concretelang/Dialect/TFHE/IR/TFHETypes.td similarity index 87% rename from compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHETypes.td rename to compiler/include/concretelang/Dialect/TFHE/IR/TFHETypes.td index c733c8ab5..6e896a31e 100644 --- a/compiler/include/concretelang/Dialect/MidLFHE/IR/MidLFHETypes.td +++ b/compiler/include/concretelang/Dialect/TFHE/IR/TFHETypes.td @@ -1,14 +1,14 @@ -#ifndef CONCRETELANG_DIALECT_MidLFHE_IR_MidLFHE_TYPES -#define CONCRETELANG_DIALECT_MidLFHE_IR_MidLFHE_TYPES +#ifndef CONCRETELANG_DIALECT_TFHE_IR_TFHE_TYPES +#define CONCRETELANG_DIALECT_TFHE_IR_TFHE_TYPES // TODO: MLWE / GSW -include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.td" +include "concretelang/Dialect/TFHE/IR/TFHEDialect.td" include "mlir/IR/BuiltinTypes.td" -class MidLFHE_Type traits = []> : TypeDef { } +class TFHE_Type traits = []> : TypeDef { } -def GLWECipherTextType : MidLFHE_Type<"GLWECipherText", [MemRefElementTypeInterface]> { +def GLWECipherTextType : TFHE_Type<"GLWECipherText", [MemRefElementTypeInterface]> { let mnemonic = "glwe"; let summary = "A GLWE ciphertext"; diff --git a/compiler/include/concretelang/Support/CompilerEngine.h b/compiler/include/concretelang/Support/CompilerEngine.h index e328713b4..5d2fc588b 100644 --- a/compiler/include/concretelang/Support/CompilerEngine.h +++ b/compiler/include/concretelang/Support/CompilerEngine.h @@ -89,22 +89,22 @@ public: ROUND_TRIP, // Read sources and exit before any lowering - HLFHE, + FHE, - // Read sources and lower all HLFHE operations to MidLFHE + // Read sources and lower all FHE operations to TFHE // operations - MIDLFHE, + TFHE, - // Read sources and lower all HLFHE and MidLFHE operations to LowLFHE + // Read sources and lower all FHE and TFHE operations to Concrete // operations - LOWLFHE, + CONCRETE, - // Read sources and lower all HLFHE, MidLFHE and LowLFHE + // 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 HLFHE, MidLFHE and LowLFHE + // 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, @@ -152,14 +152,14 @@ public: void setAutoParallelize(bool v); void setGenerateClientParameters(bool v); void setClientParametersFuncName(const llvm::StringRef &name); - void setHLFHELinalgTileSizes(llvm::ArrayRef sizes); + void setFHELinalgTileSizes(llvm::ArrayRef sizes); void setEnablePass(std::function enablePass); protected: llvm::Optional overrideMaxEintPrecision; llvm::Optional overrideMaxMANP; llvm::Optional clientParametersFuncName; - llvm::Optional> hlfhelinalgTileSizes; + llvm::Optional> fhelinalgTileSizes; bool verifyDiagnostics; bool autoParallelize; diff --git a/compiler/include/concretelang/Support/Pipeline.h b/compiler/include/concretelang/Support/Pipeline.h index f95b7b624..7462d0e60 100644 --- a/compiler/include/concretelang/Support/Pipeline.h +++ b/compiler/include/concretelang/Support/Pipeline.h @@ -19,29 +19,29 @@ mlir::LogicalResult autopar(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass); llvm::Expected> -getFHEConstraintsFromHLFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, +getFHEConstraintsFromFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass); mlir::LogicalResult -tileMarkedHLFHELinalg(mlir::MLIRContext &context, mlir::ModuleOp &module, +tileMarkedFHELinalg(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass); mlir::LogicalResult -markHLFHELinalgForTiling(mlir::MLIRContext &context, mlir::ModuleOp &module, +markFHELinalgForTiling(mlir::MLIRContext &context, mlir::ModuleOp &module, llvm::ArrayRef tileSizes, std::function enablePass); mlir::LogicalResult -lowerHLFHEToMidLFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, +lowerFHEToTFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass); mlir::LogicalResult -lowerMidLFHEToLowLFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, +lowerTFHEToConcrete(mlir::MLIRContext &context, mlir::ModuleOp &module, llvm::Optional &fheContext, std::function enablePass); mlir::LogicalResult -lowerLowLFHEToStd(mlir::MLIRContext &context, mlir::ModuleOp &module, +lowerConcreteToStd(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass); mlir::LogicalResult diff --git a/compiler/lib/Bindings/Python/CMakeLists.txt b/compiler/lib/Bindings/Python/CMakeLists.txt index fd3d323b1..19720ef4f 100644 --- a/compiler/lib/Bindings/Python/CMakeLists.txt +++ b/compiler/lib/Bindings/Python/CMakeLists.txt @@ -11,11 +11,11 @@ declare_mlir_python_extension(ConcretelangBindingsPythonExtension.Core ADD_TO_PARENT ConcretelangBindingsPythonExtension SOURCES ConcretelangModule.cpp - HLFHEModule.cpp + FHEModule.cpp CompilerAPIModule.cpp EMBED_CAPI_LINK_LIBS - CONCRETELANGCAPIHLFHE - CONCRETELANGCAPIHLFHELINALG + CONCRETELANGCAPIFHE + CONCRETELANGCAPIFHELINALG CONCRETELANGCAPISupport ) @@ -42,20 +42,20 @@ declare_mlir_python_sources(ConcretelangBindingsPythonSources.Dialects declare_mlir_dialect_python_bindings( ADD_TO_PARENT ConcretelangBindingsPythonSources.Dialects ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" - CONCRETELANGBindingsPythonHLFHEOps - TD_FILE concrete/lang/dialects/HLFHEOps.td + CONCRETELANGBindingsPythonFHEOps + TD_FILE concrete/lang/dialects/FHEOps.td SOURCES - concrete/lang/dialects/hlfhe.py - DIALECT_NAME HLFHE) + concrete/lang/dialects/fhe.py + DIALECT_NAME FHE) declare_mlir_dialect_python_bindings( ADD_TO_PARENT ConcretelangBindingsPythonSources.Dialects ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" - CONCRETELANGBindingsPythonHLFHELinalgOps - TD_FILE concrete/lang/dialects/HLFHELinalgOps.td + CONCRETELANGBindingsPythonFHELinalgOps + TD_FILE concrete/lang/dialects/FHELinalgOps.td SOURCES - concrete/lang/dialects/hlfhelinalg.py - DIALECT_NAME HLFHELinalg) + concrete/lang/dialects/fhelinalg.py + DIALECT_NAME FHELinalg) ################################################################################ diff --git a/compiler/lib/Bindings/Python/CompilerAPIModule.cpp b/compiler/lib/Bindings/Python/CompilerAPIModule.cpp index 88a7314bf..b3307f5d5 100644 --- a/compiler/lib/Bindings/Python/CompilerAPIModule.cpp +++ b/compiler/lib/Bindings/Python/CompilerAPIModule.cpp @@ -3,7 +3,7 @@ #include "CompilerAPIModule.h" #include "concretelang-c/Support/CompilerEngine.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOpsDialect.h.inc" +#include "concretelang/Dialect/FHE/IR/FHEOpsDialect.h.inc" #include "concretelang/Support/Jit.h" #include "concretelang/Support/JitCompilerEngine.h" #include diff --git a/compiler/lib/Bindings/Python/ConcretelangModule.cpp b/compiler/lib/Bindings/Python/ConcretelangModule.cpp index 03e9bb795..c210baa70 100644 --- a/compiler/lib/Bindings/Python/ConcretelangModule.cpp +++ b/compiler/lib/Bindings/Python/ConcretelangModule.cpp @@ -7,8 +7,8 @@ #include "mlir-c/Bindings/Python/Interop.h" #include "mlir-c/Registration.h" #include "mlir/Bindings/Python/PybindAdaptors.h" -#include "concretelang-c/Dialect/HLFHE.h" -#include "concretelang-c/Dialect/HLFHELinalg.h" +#include "concretelang-c/Dialect/FHE.h" +#include "concretelang-c/Dialect/FHELinalg.h" #include "llvm-c/ErrorHandling.h" #include "llvm/Support/Signals.h" @@ -29,17 +29,17 @@ PYBIND11_MODULE(_concretelang, m) { MlirContext context = mlirPythonCapsuleToContext(wrappedCapsule.ptr()); // Collect Concretelang dialects to register. - MlirDialectHandle hlfhe = mlirGetDialectHandle__hlfhe__(); - mlirDialectHandleRegisterDialect(hlfhe, context); - mlirDialectHandleLoadDialect(hlfhe, context); - MlirDialectHandle hlfhelinalg = mlirGetDialectHandle__hlfhelinalg__(); - mlirDialectHandleRegisterDialect(hlfhelinalg, context); - mlirDialectHandleLoadDialect(hlfhelinalg, context); + MlirDialectHandle fhe = mlirGetDialectHandle__fhe__(); + mlirDialectHandleRegisterDialect(fhe, context); + mlirDialectHandleLoadDialect(fhe, context); + MlirDialectHandle fhelinalg = mlirGetDialectHandle__fhelinalg__(); + mlirDialectHandleRegisterDialect(fhelinalg, context); + mlirDialectHandleLoadDialect(fhelinalg, context); }, "Register Concretelang dialects on a PyMlirContext."); - py::module hlfhe = m.def_submodule("_hlfhe", "HLFHE API"); - mlir::concretelang::python::populateDialectHLFHESubmodule(hlfhe); + py::module fhe = m.def_submodule("_fhe", "FHE API"); + mlir::concretelang::python::populateDialectFHESubmodule(fhe); py::module api = m.def_submodule("_compiler", "Compiler API"); mlir::concretelang::python::populateCompilerAPISubmodule(api); diff --git a/compiler/lib/Bindings/Python/DialectModules.h b/compiler/lib/Bindings/Python/DialectModules.h index cc3c6f417..b078526dd 100644 --- a/compiler/lib/Bindings/Python/DialectModules.h +++ b/compiler/lib/Bindings/Python/DialectModules.h @@ -10,7 +10,7 @@ namespace mlir { namespace concretelang { namespace python { -void populateDialectHLFHESubmodule(pybind11::module &m); +void populateDialectFHESubmodule(pybind11::module &m); } // namespace python } // namespace concretelang diff --git a/compiler/lib/Bindings/Python/HLFHEModule.cpp b/compiler/lib/Bindings/Python/FHEModule.cpp similarity index 76% rename from compiler/lib/Bindings/Python/HLFHEModule.cpp rename to compiler/lib/Bindings/Python/FHEModule.cpp index 755d2abc3..b8ec9ec10 100644 --- a/compiler/lib/Bindings/Python/HLFHEModule.cpp +++ b/compiler/lib/Bindings/Python/FHEModule.cpp @@ -3,7 +3,7 @@ #include "DialectModules.h" -#include "concretelang-c/Dialect/HLFHE.h" +#include "concretelang-c/Dialect/FHE.h" #include "mlir-c/BuiltinAttributes.h" #include "mlir/Bindings/Python/PybindAdaptors.h" @@ -18,13 +18,13 @@ using namespace mlir::concretelang; using namespace mlir::python::adaptors; -/// Populate the hlfhe python module. -void mlir::concretelang::python::populateDialectHLFHESubmodule( +/// Populate the fhe python module. +void mlir::concretelang::python::populateDialectFHESubmodule( pybind11::module &m) { - m.doc() = "HLFHE dialect Python native extension"; + m.doc() = "FHE dialect Python native extension"; mlir_type_subclass(m, "EncryptedIntegerType", - hlfheTypeIsAnEncryptedIntegerType) + fheTypeIsAnEncryptedIntegerType) .def_classmethod("get", [](pybind11::object cls, MlirContext ctx, unsigned width) { // We want the user to receive a python exception for not being able to @@ -33,6 +33,6 @@ void mlir::concretelang::python::populateDialectHLFHESubmodule( throw std::invalid_argument("can't create eint with the given width"); }; return cls( - hlfheEncryptedIntegerTypeGetChecked(ctx, width, emitException)); + fheEncryptedIntegerTypeGetChecked(ctx, width, emitException)); }); } \ No newline at end of file diff --git a/compiler/lib/Bindings/Python/concrete/lang/dialects/FHELinalgOps.td b/compiler/lib/Bindings/Python/concrete/lang/dialects/FHELinalgOps.td new file mode 100644 index 000000000..ef55a7bfe --- /dev/null +++ b/compiler/lib/Bindings/Python/concrete/lang/dialects/FHELinalgOps.td @@ -0,0 +1,7 @@ +#ifndef PYTHON_BINDINGS_FHELINALG_OPS +#define PYTHON_BINDINGS_FHELINALG_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.td" + +#endif diff --git a/compiler/lib/Bindings/Python/concrete/lang/dialects/FHEOps.td b/compiler/lib/Bindings/Python/concrete/lang/dialects/FHEOps.td new file mode 100644 index 000000000..bd2926578 --- /dev/null +++ b/compiler/lib/Bindings/Python/concrete/lang/dialects/FHEOps.td @@ -0,0 +1,7 @@ +#ifndef PYTHON_BINDINGS_FHE_OPS +#define PYTHON_BINDINGS_FHE_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "concretelang/Dialect/FHE/IR/FHEOps.td" + +#endif diff --git a/compiler/lib/Bindings/Python/concrete/lang/dialects/HLFHELinalgOps.td b/compiler/lib/Bindings/Python/concrete/lang/dialects/HLFHELinalgOps.td deleted file mode 100644 index 7c0db2fbe..000000000 --- a/compiler/lib/Bindings/Python/concrete/lang/dialects/HLFHELinalgOps.td +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef PYTHON_BINDINGS_HLFHELINALG_OPS -#define PYTHON_BINDINGS_HLFHELINALG_OPS - -include "mlir/Bindings/Python/Attributes.td" -include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.td" - -#endif diff --git a/compiler/lib/Bindings/Python/concrete/lang/dialects/HLFHEOps.td b/compiler/lib/Bindings/Python/concrete/lang/dialects/HLFHEOps.td deleted file mode 100644 index 23ab36065..000000000 --- a/compiler/lib/Bindings/Python/concrete/lang/dialects/HLFHEOps.td +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef PYTHON_BINDINGS_HLFHE_OPS -#define PYTHON_BINDINGS_HLFHE_OPS - -include "mlir/Bindings/Python/Attributes.td" -include "concretelang/Dialect/HLFHE/IR/HLFHEOps.td" - -#endif diff --git a/compiler/lib/Bindings/Python/concrete/lang/dialects/hlfhe.py b/compiler/lib/Bindings/Python/concrete/lang/dialects/fhe.py similarity index 63% rename from compiler/lib/Bindings/Python/concrete/lang/dialects/hlfhe.py rename to compiler/lib/Bindings/Python/concrete/lang/dialects/fhe.py index de0a65a6f..c808fe8b6 100644 --- a/compiler/lib/Bindings/Python/concrete/lang/dialects/hlfhe.py +++ b/compiler/lib/Bindings/Python/concrete/lang/dialects/fhe.py @@ -1,6 +1,6 @@ # Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. # See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -"""HLFHE dialect module""" -from ._HLFHE_ops_gen import * -from mlir._mlir_libs._concretelang._hlfhe import * +"""FHE dialect module""" +from ._FHE_ops_gen import * +from mlir._mlir_libs._concretelang._fhe import * diff --git a/compiler/lib/Bindings/Python/concrete/lang/dialects/hlfhelinalg.py b/compiler/lib/Bindings/Python/concrete/lang/dialects/fhelinalg.py similarity index 72% rename from compiler/lib/Bindings/Python/concrete/lang/dialects/hlfhelinalg.py rename to compiler/lib/Bindings/Python/concrete/lang/dialects/fhelinalg.py index 9891ee9af..98adf25d0 100644 --- a/compiler/lib/Bindings/Python/concrete/lang/dialects/hlfhelinalg.py +++ b/compiler/lib/Bindings/Python/concrete/lang/dialects/fhelinalg.py @@ -1,5 +1,5 @@ # Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. # See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -"""HLFHELinalg dialect module""" -from ._HLFHELinalg_ops_gen import * +"""FHELinalg dialect module""" +from ._FHELinalg_ops_gen import * diff --git a/compiler/lib/CAPI/Dialect/CMakeLists.txt b/compiler/lib/CAPI/Dialect/CMakeLists.txt index 496981e3c..351d3270e 100644 --- a/compiler/lib/CAPI/Dialect/CMakeLists.txt +++ b/compiler/lib/CAPI/Dialect/CMakeLists.txt @@ -1,2 +1,2 @@ -add_subdirectory(HLFHE) -add_subdirectory(HLFHELinalg) \ No newline at end of file +add_subdirectory(FHE) +add_subdirectory(FHELinalg) \ No newline at end of file diff --git a/compiler/lib/CAPI/Dialect/FHE/CMakeLists.txt b/compiler/lib/CAPI/Dialect/FHE/CMakeLists.txt new file mode 100644 index 000000000..0728893fc --- /dev/null +++ b/compiler/lib/CAPI/Dialect/FHE/CMakeLists.txt @@ -0,0 +1,10 @@ +set(LLVM_OPTIONAL_SOURCES FHE.cpp) + +add_mlir_public_c_api_library(CONCRETELANGCAPIFHE + + FHE.cpp + + LINK_LIBS PUBLIC + MLIRCAPIIR + FHEDialect + ) diff --git a/compiler/lib/CAPI/Dialect/HLFHE/HLFHE.cpp b/compiler/lib/CAPI/Dialect/FHE/FHE.cpp similarity index 67% rename from compiler/lib/CAPI/Dialect/HLFHE/HLFHE.cpp rename to compiler/lib/CAPI/Dialect/FHE/FHE.cpp index 19601acfe..807e9c851 100644 --- a/compiler/lib/CAPI/Dialect/HLFHE/HLFHE.cpp +++ b/compiler/lib/CAPI/Dialect/FHE/FHE.cpp @@ -1,31 +1,31 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#include "concretelang-c/Dialect/HLFHE.h" +#include "concretelang-c/Dialect/FHE.h" #include "mlir/CAPI/IR.h" #include "mlir/CAPI/Registration.h" #include "mlir/CAPI/Support.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHEDialect.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" -using namespace mlir::concretelang::HLFHE; +using namespace mlir::concretelang::FHE; //===----------------------------------------------------------------------===// // Dialect API. //===----------------------------------------------------------------------===// -MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(HLFHE, hlfhe, HLFHEDialect) +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FHE, fhe, FHEDialect) //===----------------------------------------------------------------------===// // Type API. //===----------------------------------------------------------------------===// -bool hlfheTypeIsAnEncryptedIntegerType(MlirType type) { +bool fheTypeIsAnEncryptedIntegerType(MlirType type) { return unwrap(type).isa(); } -MlirType hlfheEncryptedIntegerTypeGetChecked( +MlirType fheEncryptedIntegerTypeGetChecked( MlirContext ctx, unsigned width, mlir::function_ref emitError) { return wrap(EncryptedIntegerType::getChecked(emitError, unwrap(ctx), width)); diff --git a/compiler/lib/CAPI/Dialect/FHELinalg/CMakeLists.txt b/compiler/lib/CAPI/Dialect/FHELinalg/CMakeLists.txt new file mode 100644 index 000000000..3219de675 --- /dev/null +++ b/compiler/lib/CAPI/Dialect/FHELinalg/CMakeLists.txt @@ -0,0 +1,10 @@ +set(LLVM_OPTIONAL_SOURCES FHELinalg.cpp) + +add_mlir_public_c_api_library(CONCRETELANGCAPIFHELINALG + + FHELinalg.cpp + + LINK_LIBS PUBLIC + MLIRCAPIIR + FHELinalgDialect + ) diff --git a/compiler/lib/CAPI/Dialect/HLFHELinalg/HLFHELinalg.cpp b/compiler/lib/CAPI/Dialect/FHELinalg/FHELinalg.cpp similarity index 52% rename from compiler/lib/CAPI/Dialect/HLFHELinalg/HLFHELinalg.cpp rename to compiler/lib/CAPI/Dialect/FHELinalg/FHELinalg.cpp index bdb13d36e..9fbb706b4 100644 --- a/compiler/lib/CAPI/Dialect/HLFHELinalg/HLFHELinalg.cpp +++ b/compiler/lib/CAPI/Dialect/FHELinalg/FHELinalg.cpp @@ -1,19 +1,19 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#include "concretelang-c/Dialect/HLFHELinalg.h" +#include "concretelang-c/Dialect/FHELinalg.h" #include "mlir/CAPI/IR.h" #include "mlir/CAPI/Registration.h" #include "mlir/CAPI/Support.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h" -using namespace mlir::concretelang::HLFHELinalg; +using namespace mlir::concretelang::FHELinalg; //===----------------------------------------------------------------------===// // Dialect API. //===----------------------------------------------------------------------===// -MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(HLFHELinalg, hlfhelinalg, - HLFHELinalgDialect) +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(FHELinalg, fhelinalg, + FHELinalgDialect) diff --git a/compiler/lib/CAPI/Dialect/HLFHE/CMakeLists.txt b/compiler/lib/CAPI/Dialect/HLFHE/CMakeLists.txt deleted file mode 100644 index 2c1984ce2..000000000 --- a/compiler/lib/CAPI/Dialect/HLFHE/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -set(LLVM_OPTIONAL_SOURCES HLFHE.cpp) - -add_mlir_public_c_api_library(CONCRETELANGCAPIHLFHE - - HLFHE.cpp - - LINK_LIBS PUBLIC - MLIRCAPIIR - HLFHEDialect - ) diff --git a/compiler/lib/CAPI/Dialect/HLFHELinalg/CMakeLists.txt b/compiler/lib/CAPI/Dialect/HLFHELinalg/CMakeLists.txt deleted file mode 100644 index 2c7c77373..000000000 --- a/compiler/lib/CAPI/Dialect/HLFHELinalg/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -set(LLVM_OPTIONAL_SOURCES HLFHELinalg.cpp) - -add_mlir_public_c_api_library(CONCRETELANGCAPIHLFHELINALG - - HLFHELinalg.cpp - - LINK_LIBS PUBLIC - MLIRCAPIIR - HLFHELinalgDialect - ) diff --git a/compiler/lib/Conversion/CMakeLists.txt b/compiler/lib/Conversion/CMakeLists.txt index 04d077129..d30b88a76 100644 --- a/compiler/lib/Conversion/CMakeLists.txt +++ b/compiler/lib/Conversion/CMakeLists.txt @@ -1,7 +1,7 @@ -add_subdirectory(HLFHEToMidLFHE) -add_subdirectory(MidLFHEGlobalParametrization) -add_subdirectory(MidLFHEToLowLFHE) -add_subdirectory(HLFHETensorOpsToLinalg) -add_subdirectory(LowLFHEToConcreteCAPI) +add_subdirectory(FHEToTFHE) +add_subdirectory(TFHEGlobalParametrization) +add_subdirectory(TFHEToConcrete) +add_subdirectory(FHETensorOpsToLinalg) +add_subdirectory(ConcreteToConcreteCAPI) add_subdirectory(MLIRLowerableDialectsToLLVM) -add_subdirectory(LowLFHEUnparametrize) +add_subdirectory(ConcreteUnparametrize) diff --git a/compiler/lib/Conversion/ConcreteToConcreteCAPI/CMakeLists.txt b/compiler/lib/Conversion/ConcreteToConcreteCAPI/CMakeLists.txt new file mode 100644 index 000000000..ed61f155f --- /dev/null +++ b/compiler/lib/Conversion/ConcreteToConcreteCAPI/CMakeLists.txt @@ -0,0 +1,16 @@ +add_mlir_dialect_library(ConcreteToConcreteCAPI + ConcreteToConcreteCAPI.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHE + + DEPENDS + ConcreteDialect + MLIRConversionPassIncGen + + LINK_LIBS PUBLIC + MLIRIR + MLIRTransforms +) + +target_link_libraries(ConcreteToConcreteCAPI PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp b/compiler/lib/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI.cpp similarity index 84% rename from compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp rename to compiler/lib/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI.cpp index a61ca14ec..cb4d520fb 100644 --- a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp +++ b/compiler/lib/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI.cpp @@ -10,20 +10,20 @@ #include "mlir/Transforms/DialectConversion.h" #include "concretelang/Conversion/Passes.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteDialect.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #include "concretelang/Support/Constants.h" -class LowLFHEToConcreteCAPITypeConverter : public mlir::TypeConverter { +class ConcreteToConcreteCAPITypeConverter : public mlir::TypeConverter { public: - LowLFHEToConcreteCAPITypeConverter() { + ConcreteToConcreteCAPITypeConverter() { addConversion([](mlir::Type type) { return type; }); - addConversion([&](mlir::concretelang::LowLFHE::PlaintextType type) { + addConversion([&](mlir::concretelang::Concrete::PlaintextType type) { return mlir::IntegerType::get(type.getContext(), 64); }); - addConversion([&](mlir::concretelang::LowLFHE::CleartextType type) { + addConversion([&](mlir::concretelang::Concrete::CleartextType type) { return mlir::IntegerType::get(type.getContext(), 64); }); } @@ -64,56 +64,56 @@ mlir::LogicalResult insertForwardDeclaration(mlir::Operation *op, // allocate them. All the calls to the C API should be done using this generic // types, and casting should then be performed back to the appropriate type. -inline mlir::concretelang::LowLFHE::LweCiphertextType +inline mlir::concretelang::Concrete::LweCiphertextType getGenericLweCiphertextType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::LweCiphertextType::get(context, -1, -1); + return mlir::concretelang::Concrete::LweCiphertextType::get(context, -1, -1); } -inline mlir::concretelang::LowLFHE::GlweCiphertextType +inline mlir::concretelang::Concrete::GlweCiphertextType getGenericGlweCiphertextType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::GlweCiphertextType::get(context); + return mlir::concretelang::Concrete::GlweCiphertextType::get(context); } -inline mlir::concretelang::LowLFHE::PlaintextType +inline mlir::concretelang::Concrete::PlaintextType getGenericPlaintextType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::PlaintextType::get(context, -1); + return mlir::concretelang::Concrete::PlaintextType::get(context, -1); } -inline mlir::concretelang::LowLFHE::PlaintextListType +inline mlir::concretelang::Concrete::PlaintextListType getGenericPlaintextListType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::PlaintextListType::get(context); + return mlir::concretelang::Concrete::PlaintextListType::get(context); } -inline mlir::concretelang::LowLFHE::ForeignPlaintextListType +inline mlir::concretelang::Concrete::ForeignPlaintextListType getGenericForeignPlaintextListType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::ForeignPlaintextListType::get(context); + return mlir::concretelang::Concrete::ForeignPlaintextListType::get(context); } -inline mlir::concretelang::LowLFHE::CleartextType +inline mlir::concretelang::Concrete::CleartextType getGenericCleartextType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::CleartextType::get(context, -1); + return mlir::concretelang::Concrete::CleartextType::get(context, -1); } -inline mlir::concretelang::LowLFHE::LweBootstrapKeyType +inline mlir::concretelang::Concrete::LweBootstrapKeyType getGenericLweBootstrapKeyType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::LweBootstrapKeyType::get(context); + return mlir::concretelang::Concrete::LweBootstrapKeyType::get(context); } -inline mlir::concretelang::LowLFHE::LweKeySwitchKeyType +inline mlir::concretelang::Concrete::LweKeySwitchKeyType getGenericLweKeySwitchKeyType(mlir::MLIRContext *context) { - return mlir::concretelang::LowLFHE::LweKeySwitchKeyType::get(context); + return mlir::concretelang::Concrete::LweKeySwitchKeyType::get(context); } // Get the generic version of the type. // Useful when iterating over a set of types. mlir::Type getGenericType(mlir::Type baseType) { - if (baseType.isa()) { + if (baseType.isa()) { return getGenericLweCiphertextType(baseType.getContext()); } - if (baseType.isa()) { + if (baseType.isa()) { return getGenericPlaintextType(baseType.getContext()); } - if (baseType.isa()) { + if (baseType.isa()) { return getGenericCleartextType(baseType.getContext()); } return baseType; @@ -138,7 +138,7 @@ mlir::LogicalResult insertForwardDeclarations(mlir::Operation *op, auto genericBSKType = getGenericLweBootstrapKeyType(rewriter.getContext()); auto genericKSKType = getGenericLweKeySwitchKeyType(rewriter.getContext()); auto contextType = - mlir::concretelang::LowLFHE::ContextType::get(rewriter.getContext()); + mlir::concretelang::Concrete::ContextType::get(rewriter.getContext()); auto errType = mlir::IndexType::get(rewriter.getContext()); @@ -321,7 +321,7 @@ mlir::LogicalResult insertForwardDeclarations(mlir::Operation *op, return mlir::success(); } -/// LowLFHEOpToConcreteCAPICallPattern match the `Op` Operation and +/// ConcreteOpToConcreteCAPICallPattern match the `Op` Operation and /// replace with a call to `funcName`, the funcName should be an external /// function that was linked later. It insert the forward declaration of the /// private `funcName` if it not already in the symbol table. @@ -336,8 +336,8 @@ mlir::LogicalResult insertForwardDeclarations(mlir::Operation *op, /// call_op(err, out, arg0, arg1); /// ``` template -struct LowLFHEOpToConcreteCAPICallPattern : public mlir::OpRewritePattern { - LowLFHEOpToConcreteCAPICallPattern( +struct ConcreteOpToConcreteCAPICallPattern : public mlir::OpRewritePattern { + ConcreteOpToConcreteCAPICallPattern( mlir::MLIRContext *context, mlir::StringRef funcName, mlir::StringRef allocName, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) @@ -346,11 +346,11 @@ struct LowLFHEOpToConcreteCAPICallPattern : public mlir::OpRewritePattern { mlir::LogicalResult matchAndRewrite(Op op, mlir::PatternRewriter &rewriter) const override { - LowLFHEToConcreteCAPITypeConverter typeConverter; + ConcreteToConcreteCAPITypeConverter typeConverter; mlir::Type resultType = op->getResultTypes().front(); auto lweResultType = - resultType.cast(); + resultType.cast(); // Replace the operation with a call to the `funcName` { // Create the err value @@ -402,21 +402,21 @@ private: std::string allocName; }; -struct LowLFHEZeroOpPattern - : public mlir::OpRewritePattern { - LowLFHEZeroOpPattern( +struct ConcreteZeroOpPattern + : public mlir::OpRewritePattern { + ConcreteZeroOpPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern(context, + : mlir::OpRewritePattern(context, benefit) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::LowLFHE::ZeroLWEOp op, + matchAndRewrite(mlir::concretelang::Concrete::ZeroLWEOp op, mlir::PatternRewriter &rewriter) const override { mlir::Type resultType = op->getResultTypes().front(); auto lweResultType = - resultType.cast(); + resultType.cast(); // Create the err value auto errOp = rewriter.create( op.getLoc(), rewriter.getIndexAttr(0)); @@ -438,16 +438,16 @@ struct LowLFHEZeroOpPattern }; }; -struct LowLFHEEncodeIntOpPattern - : public mlir::OpRewritePattern { - LowLFHEEncodeIntOpPattern( +struct ConcreteEncodeIntOpPattern + : public mlir::OpRewritePattern { + ConcreteEncodeIntOpPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern(context, + : mlir::OpRewritePattern(context, benefit) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::LowLFHE::EncodeIntOp op, + matchAndRewrite(mlir::concretelang::Concrete::EncodeIntOp op, mlir::PatternRewriter &rewriter) const override { { mlir::Value castedInt = rewriter.create( @@ -463,16 +463,16 @@ struct LowLFHEEncodeIntOpPattern }; }; -struct LowLFHEIntToCleartextOpPattern - : public mlir::OpRewritePattern { - LowLFHEIntToCleartextOpPattern( +struct ConcreteIntToCleartextOpPattern + : public mlir::OpRewritePattern { + ConcreteIntToCleartextOpPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, benefit) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::LowLFHE::IntToCleartextOp op, + matchAndRewrite(mlir::concretelang::Concrete::IntToCleartextOp op, mlir::PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp( op, rewriter.getIntegerType(64), op->getOperands().front()); @@ -489,17 +489,17 @@ struct LowLFHEIntToCleartextOpPattern // - construct the GLWE accumulator by adding the plaintext_list to a freshly // allocated GLWE struct GlweFromTableOpPattern - : public mlir::OpRewritePattern { + : public mlir::OpRewritePattern { GlweFromTableOpPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, benefit) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::LowLFHE::GlweFromTable op, + matchAndRewrite(mlir::concretelang::Concrete::GlweFromTable op, mlir::PatternRewriter &rewriter) const override { - LowLFHEToConcreteCAPITypeConverter typeConverter; + ConcreteToConcreteCAPITypeConverter typeConverter; auto errType = mlir::IndexType::get(rewriter.getContext()); // TODO: move this to insertForwardDeclarations @@ -589,8 +589,8 @@ mlir::Value getContextArgument(mlir::Operation *op) { mlir::Value context = block->getArguments().back(); - assert(context.getType().isa() && - "the LowLFHE.context should be the last argument of the enclosing " + assert(context.getType().isa() && + "the Concrete.context should be the last argument of the enclosing " "function of the op"); return context; @@ -606,23 +606,23 @@ mlir::Value getContextArgument(mlir::Operation *op) { // - get the global bootstrapping key // - use the key and the input accumulator (GLWE) to bootstrap the input // ciphertext -struct LowLFHEBootstrapLweOpPattern - : public mlir::OpRewritePattern { - LowLFHEBootstrapLweOpPattern( +struct ConcreteBootstrapLweOpPattern + : public mlir::OpRewritePattern { + ConcreteBootstrapLweOpPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, benefit) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::LowLFHE::BootstrapLweOp op, + matchAndRewrite(mlir::concretelang::Concrete::BootstrapLweOp op, mlir::PatternRewriter &rewriter) const override { auto resultType = op->getResultTypes().front(); auto errOp = rewriter.create( op.getLoc(), rewriter.getIndexAttr(0)); // Get the size from the dimension int64_t outputLweDimension = - resultType.cast() + resultType.cast() .getDimension(); int64_t outputLweSize = outputLweDimension + 1; mlir::Value lweSizeOp = rewriter.create( @@ -670,16 +670,16 @@ struct LowLFHEBootstrapLweOpPattern // - allocate the result LWE ciphertext // - get the global keyswitch key // - use the key to keyswitch the input ciphertext -struct LowLFHEKeySwitchLweOpPattern - : public mlir::OpRewritePattern { - LowLFHEKeySwitchLweOpPattern( +struct ConcreteKeySwitchLweOpPattern + : public mlir::OpRewritePattern { + ConcreteKeySwitchLweOpPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, benefit) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::LowLFHE::KeySwitchLweOp op, + matchAndRewrite(mlir::concretelang::Concrete::KeySwitchLweOp op, mlir::PatternRewriter &rewriter) const override { auto errOp = rewriter.create( op.getLoc(), rewriter.getIndexAttr(0)); @@ -687,7 +687,7 @@ struct LowLFHEKeySwitchLweOpPattern int64_t lweDimension = op.getResult() .getType() - .cast() + .cast() .getDimension(); int64_t lweSize = lweDimension + 1; mlir::Value lweSizeOp = rewriter.create( @@ -724,31 +724,31 @@ struct LowLFHEKeySwitchLweOpPattern }; }; -/// Populate the RewritePatternSet with all patterns that rewrite LowLFHE +/// Populate the RewritePatternSet with all patterns that rewrite Concrete /// operators to the corresponding function call to the `Concrete C API`. -void populateLowLFHEToConcreteCAPICall(mlir::RewritePatternSet &patterns) { - patterns.add>( +void populateConcreteToConcreteCAPICall(mlir::RewritePatternSet &patterns) { + patterns.add>( patterns.getContext(), "add_lwe_ciphertexts_u64", "allocate_lwe_ciphertext_u64"); - patterns.add>( + patterns.add>( patterns.getContext(), "add_plaintext_lwe_ciphertext_u64", "allocate_lwe_ciphertext_u64"); - patterns.add>( + patterns.add>( patterns.getContext(), "mul_cleartext_lwe_ciphertext_u64", "allocate_lwe_ciphertext_u64"); - patterns.add>( + patterns.add>( patterns.getContext(), "negate_lwe_ciphertext_u64", "allocate_lwe_ciphertext_u64"); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); } struct AddRuntimeContextToFuncOpPattern @@ -764,11 +764,11 @@ struct AddRuntimeContextToFuncOpPattern mlir::OpBuilder::InsertionGuard guard(rewriter); mlir::FunctionType oldFuncType = oldFuncOp.getType(); - // Add a LowLFHE.context to the function signature + // Add a Concrete.context to the function signature mlir::SmallVector newInputs(oldFuncType.getInputs().begin(), oldFuncType.getInputs().end()); newInputs.push_back( - rewriter.getType()); + rewriter.getType()); mlir::FunctionType newFuncTy = rewriter.getType( newInputs, oldFuncType.getResults()); // Create the new func @@ -793,20 +793,20 @@ struct AddRuntimeContextToFuncOpPattern return mlir::success(); } - // Legal function are one that are private or has a LowLFHE.context as last + // Legal function are one that are private or has a Concrete.context as last // arguments. static bool isLegal(mlir::FuncOp funcOp) { if (!funcOp.isPublic()) { return true; } // TODO : Don't need to add a runtime context for function that doesn't - // manipulates lowlfhe types. + // manipulates concrete types. // // if (!llvm::any_of(funcOp.getType().getInputs(), [](mlir::Type t) { // if (auto tensorTy = t.dyn_cast_or_null()) { // t = tensorTy.getElementType(); // } - // return llvm::isa( + // return llvm::isa( // t.getDialect()); // })) { // return true; @@ -815,21 +815,21 @@ struct AddRuntimeContextToFuncOpPattern funcOp.getType() .getInputs() .back() - .isa(); + .isa(); } }; namespace { -struct LowLFHEToConcreteCAPIPass - : public LowLFHEToConcreteCAPIBase { +struct ConcreteToConcreteCAPIPass + : public ConcreteToConcreteCAPIBase { void runOnOperation() final; }; } // namespace -void LowLFHEToConcreteCAPIPass::runOnOperation() { +void ConcreteToConcreteCAPIPass::runOnOperation() { mlir::ModuleOp op = getOperation(); - // First of all add the LowLFHE.context to the block arguments of function + // First of all add the Concrete.context to the block arguments of function // that manipulates ciphertexts. { mlir::ConversionTarget target(getContext()); @@ -854,17 +854,17 @@ void LowLFHEToConcreteCAPIPass::runOnOperation() { if (insertForwardDeclarations(op, rewriter).failed()) { this->signalPassFailure(); } - // Rewrite LowLFHE ops to CallOp to the Concrete C API + // Rewrite Concrete ops to CallOp to the Concrete C API { mlir::ConversionTarget target(getContext()); mlir::RewritePatternSet patterns(&getContext()); - target.addIllegalDialect(); + target.addIllegalDialect(); target.addLegalDialect(); - populateLowLFHEToConcreteCAPICall(patterns); + populateConcreteToConcreteCAPICall(patterns); if (mlir::applyPartialConversion(op, target, std::move(patterns)) .failed()) { @@ -876,8 +876,8 @@ void LowLFHEToConcreteCAPIPass::runOnOperation() { namespace mlir { namespace concretelang { std::unique_ptr> -createConvertLowLFHEToConcreteCAPIPass() { - return std::make_unique(); +createConvertConcreteToConcreteCAPIPass() { + return std::make_unique(); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Conversion/ConcreteUnparametrize/CMakeLists.txt b/compiler/lib/Conversion/ConcreteUnparametrize/CMakeLists.txt new file mode 100644 index 000000000..0cec5cab6 --- /dev/null +++ b/compiler/lib/Conversion/ConcreteUnparametrize/CMakeLists.txt @@ -0,0 +1,16 @@ +add_mlir_dialect_library(ConcreteUnparametrize + ConcreteUnparametrize.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHE + + DEPENDS + ConcreteDialect + MLIRConversionPassIncGen + + LINK_LIBS PUBLIC + MLIRIR + MLIRTransforms +) + +target_link_libraries(ConcreteUnparametrize PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/LowLFHEUnparametrize/LowLFHEUnparametrize.cpp b/compiler/lib/Conversion/ConcreteUnparametrize/ConcreteUnparametrize.cpp similarity index 69% rename from compiler/lib/Conversion/LowLFHEUnparametrize/LowLFHEUnparametrize.cpp rename to compiler/lib/Conversion/ConcreteUnparametrize/ConcreteUnparametrize.cpp index 7c1b62a05..1f7dad988 100644 --- a/compiler/lib/Conversion/LowLFHEUnparametrize/LowLFHEUnparametrize.cpp +++ b/compiler/lib/Conversion/ConcreteUnparametrize/ConcreteUnparametrize.cpp @@ -7,32 +7,32 @@ #include "concretelang/Conversion/Passes.h" #include "concretelang/Conversion/Utils/RegionOpTypeConverterPattern.h" #include "concretelang/Conversion/Utils/TensorOpTypeConversion.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteDialect.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #include "concretelang/Dialect/RT/IR/RTOps.h" #include "concretelang/Support/Constants.h" -/// LowLFHEUnparametrizeTypeConverter is a type converter that unparametrize -/// LowLFHE types -class LowLFHEUnparametrizeTypeConverter : public mlir::TypeConverter { +/// ConcreteUnparametrizeTypeConverter is a type converter that unparametrize +/// Concrete types +class ConcreteUnparametrizeTypeConverter : public mlir::TypeConverter { public: - static mlir::Type unparematrizeLowLFHEType(mlir::Type type) { - if (type.isa()) { + static mlir::Type unparematrizeConcreteType(mlir::Type type) { + if (type.isa()) { return mlir::IntegerType::get(type.getContext(), 64); } - if (type.isa()) { + if (type.isa()) { return mlir::IntegerType::get(type.getContext(), 64); } - if (type.isa()) { - return mlir::concretelang::LowLFHE::LweCiphertextType::get(type.getContext(), + if (type.isa()) { + return mlir::concretelang::Concrete::LweCiphertextType::get(type.getContext(), -1, -1); } auto tensorType = type.dyn_cast_or_null(); if (tensorType != nullptr) { auto eltTy0 = tensorType.getElementType(); - auto eltTy1 = unparematrizeLowLFHEType(eltTy0); + auto eltTy1 = unparematrizeConcreteType(eltTy0); if (eltTy0 == eltTy1) { return type; } @@ -41,17 +41,17 @@ public: return type; } - LowLFHEUnparametrizeTypeConverter() { + ConcreteUnparametrizeTypeConverter() { addConversion( - [](mlir::Type type) { return unparematrizeLowLFHEType(type); }); + [](mlir::Type type) { return unparematrizeConcreteType(type); }); } }; /// Replace `%1 = unrealized_conversion_cast %0 : t0 to t1` to `%0` where t0 or -/// t1 are a LowLFHE type. -struct LowLFHEUnrealizedCastReplacementPattern +/// t1 are a Concrete type. +struct ConcreteUnrealizedCastReplacementPattern : public mlir::OpRewritePattern { - LowLFHEUnrealizedCastReplacementPattern( + ConcreteUnrealizedCastReplacementPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) : mlir::OpRewritePattern(context, @@ -60,9 +60,9 @@ struct LowLFHEUnrealizedCastReplacementPattern mlir::LogicalResult matchAndRewrite(mlir::UnrealizedConversionCastOp op, mlir::PatternRewriter &rewriter) const override { - if (mlir::isa( + if (mlir::isa( op.getOperandTypes()[0].getDialect()) || - mlir::isa( + mlir::isa( op.getType(0).getDialect())) { rewriter.replaceOp(op, op.getOperands()); return mlir::success(); @@ -71,21 +71,21 @@ struct LowLFHEUnrealizedCastReplacementPattern }; }; -/// LowLFHEUnparametrizePass remove all parameters of LowLFHE types and remove +/// ConcreteUnparametrizePass remove all parameters of Concrete types and remove /// the unrealized_conversion_cast operation that operates on parametrized -/// LowLFHE types. -struct LowLFHEUnparametrizePass - : public LowLFHEUnparametrizeBase { +/// Concrete types. +struct ConcreteUnparametrizePass + : public ConcreteUnparametrizeBase { void runOnOperation() final; }; -void LowLFHEUnparametrizePass::runOnOperation() { +void ConcreteUnparametrizePass::runOnOperation() { auto op = this->getOperation(); mlir::ConversionTarget target(getContext()); mlir::OwningRewritePatternList patterns(&getContext()); - LowLFHEUnparametrizeTypeConverter converter; + ConcreteUnparametrizeTypeConverter converter; // Conversion of linalg.generic operation target @@ -97,13 +97,13 @@ void LowLFHEUnparametrizePass::runOnOperation() { converter.isLegal(op->getRegion(0).front().getArgumentTypes())); }); patterns.add>( + ConcreteUnparametrizeTypeConverter>>( &getContext(), converter); patterns.add>( + ConcreteUnparametrizeTypeConverter>>( &getContext(), converter); patterns.add>( + ConcreteUnparametrizeTypeConverter>>( &getContext(), converter); // Conversion of function signature and arguments @@ -116,7 +116,7 @@ void LowLFHEUnparametrizePass::runOnOperation() { // Replacement of unrealized_conversion_cast mlir::concretelang::addDynamicallyLegalTypeOp( target, converter); - patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); // Conversion of tensor operators mlir::concretelang::populateWithTensorTypeConverterPatterns(patterns, target, @@ -142,8 +142,8 @@ void LowLFHEUnparametrizePass::runOnOperation() { namespace mlir { namespace concretelang { std::unique_ptr> -createConvertLowLFHEUnparametrizePass() { - return std::make_unique(); +createConvertConcreteUnparametrizePass() { + return std::make_unique(); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Conversion/FHETensorOpsToLinalg/CMakeLists.txt b/compiler/lib/Conversion/FHETensorOpsToLinalg/CMakeLists.txt new file mode 100644 index 000000000..757e373b0 --- /dev/null +++ b/compiler/lib/Conversion/FHETensorOpsToLinalg/CMakeLists.txt @@ -0,0 +1,17 @@ +add_mlir_dialect_library(FHETensorOpsToLinalg + TensorOpsToLinalg.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHE + + DEPENDS + FHEDialect + FHELinalgDialect + MLIRConversionPassIncGen + + LINK_LIBS PUBLIC + MLIRIR + FHEDialect + FHELinalgDialect) + +target_link_libraries(FHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/HLFHETensorOpsToLinalg/TensorOpsToLinalg.cpp b/compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp similarity index 70% rename from compiler/lib/Conversion/HLFHETensorOpsToLinalg/TensorOpsToLinalg.cpp rename to compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp index b6543fa9b..27be19b64 100644 --- a/compiler/lib/Conversion/HLFHETensorOpsToLinalg/TensorOpsToLinalg.cpp +++ b/compiler/lib/Conversion/FHETensorOpsToLinalg/TensorOpsToLinalg.cpp @@ -14,59 +14,59 @@ #include #include "concretelang/Conversion/Passes.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h" +#include "concretelang/Dialect/FHE/IR/FHEDialect.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h" #include "concretelang/Support/Constants.h" struct DotToLinalgGeneric - : public ::mlir::OpRewritePattern { + : public ::mlir::OpRewritePattern { DotToLinalgGeneric(::mlir::MLIRContext *context) - : ::mlir::OpRewritePattern<::mlir::concretelang::HLFHELinalg::Dot>( + : ::mlir::OpRewritePattern<::mlir::concretelang::FHELinalg::Dot>( context, mlir::concretelang::DEFAULT_PATTERN_BENEFIT) {} // This rewrite pattern transforms any instance of - // `HLFHELinalg.dot_eint_int` to an instance of `linalg.generic` with an - // appropriate region using `HLFHE.mul_eint_int` and - // `HLFHE.add_eint` operations, an appropriate specification for the + // `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 = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - // (tensor<4x!HLFHE.eint<0>>, - // tensor<4xi32>) -> (!HLFHE.eint<0>) + // %o = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + // (tensor<4x!FHE.eint<0>>, + // tensor<4xi32>) -> (!FHE.eint<0>) // // becomes: // - // %0 = "HLFHE.zero"() : () -> !HLFHE.eint<0> - // %1 = tensor.from_elements %0 : tensor<1x!HLFHE.eint<0>> + // %0 = "FHE.zero"() : () -> !FHE.eint<0> + // %1 = tensor.from_elements %0 : tensor<1x!FHE.eint<0>> // %2 = linalg.generic { // indexing_maps = [#map0, #map0, #map1], // iterator_types = ["reduction"] // } - // ins(%arg0, %arg1 : tensor<2x!HLFHE.eint<0>>, tensor<2xi32>) - // outs(%1 : tensor<1x!HLFHE.eint<0>>) { - // ^bb0(%arg2: !HLFHE.eint<0>, %arg3: i32, %arg4: !HLFHE.eint<0>): - // %4 = "HLFHE.mul_eint_int"(%arg2, %arg3) : - // (!HLFHE.eint<0>, i32) -> !HLFHE.eint<0> + // ins(%arg0, %arg1 : tensor<2x!FHE.eint<0>>, tensor<2xi32>) + // outs(%1 : 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 = "HLFHE.add_eint"(%4, %arg4) : - // (!HLFHE.eint<0>, !HLFHE.eint<0>) -> !HLFHE.eint<0> + // %5 = "FHE.add_eint"(%4, %arg4) : + // (!FHE.eint<0>, !FHE.eint<0>) -> !FHE.eint<0> // - // linalg.yield %5 : !HLFHE.eint<0> - // } -> tensor<1x!HLFHE.eint<0>> + // linalg.yield %5 : !FHE.eint<0> + // } -> tensor<1x!FHE.eint<0>> // // %c0 = constant 0 : index - // %o = tensor.extract %2[%c0] : tensor<1x!HLFHE.eint<0>> + // %o = tensor.extract %2[%c0] : tensor<1x!FHE.eint<0>> // ::mlir::LogicalResult - matchAndRewrite(::mlir::concretelang::HLFHELinalg::Dot dotOp, + matchAndRewrite(::mlir::concretelang::FHELinalg::Dot dotOp, ::mlir::PatternRewriter &rewriter) const override { // Zero value to initialize accumulator - mlir::Value zeroCst = rewriter.create( + mlir::Value zeroCst = rewriter.create( dotOp.getLoc(), dotOp.lhs().getType().cast().getElementType()); @@ -95,11 +95,11 @@ struct DotToLinalgGeneric auto regBuilder = [&](mlir::OpBuilder &nestedBuilder, mlir::Location nestedLoc, mlir::ValueRange blockArgs) { - mlir::concretelang::HLFHE::MulEintIntOp mul = - nestedBuilder.create( + mlir::concretelang::FHE::MulEintIntOp mul = + nestedBuilder.create( dotOp.getLoc(), blockArgs[0], blockArgs[1]); - mlir::concretelang::HLFHE::AddEintOp add = - nestedBuilder.create( + mlir::concretelang::FHE::AddEintOp add = + nestedBuilder.create( dotOp.getLoc(), mul, blockArgs[2]); nestedBuilder.create(dotOp.getLoc(), @@ -180,16 +180,16 @@ getBroadcastedAffineMapMultiLUT(const mlir::RankedTensorType &resultType, } // This template rewrite pattern transforms any instance of -// operators `HLFHELinalgOp` that implements the broadasting rules to an -// instance of `linalg.generic` with an appropriate region using `HLFHEOp` +// 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 = HLFHELinalg.op(%lhs, %rhs): -// (tensor>, tensor) -// -> tensor> +// %res = FHELinalg.op(%lhs, %rhs): +// (tensor>, tensor) +// -> tensor> // // becomes: // @@ -205,28 +205,28 @@ getBroadcastedAffineMapMultiLUT(const mlir::RankedTensorType &resultType, // iterator_types = ["parallel", ..., "parallel"], // $R" parallel // } // %init = linalg.init_tensor [DR",...,D1"] -// : tensor> +// : tensor> // %res = linalg.generic { -// ins(%lhs, %rhs: tensor>,tensor) -// outs(%init : tensor>) +// ins(%lhs, %rhs: tensor>,tensor) +// outs(%init : tensor>) // { -// ^bb0(%arg0: !HLFHE.eint

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

, T -> -// !HLFHE.eint

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

+// ^bb0(%arg0: !FHE.eint

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

, T -> +// !FHE.eint

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

// } // } // -template -struct HLFHELinalgOpToLinalgGeneric - : public mlir::OpRewritePattern { - HLFHELinalgOpToLinalgGeneric( +template +struct FHELinalgOpToLinalgGeneric + : public mlir::OpRewritePattern { + FHELinalgOpToLinalgGeneric( ::mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : ::mlir::OpRewritePattern(context, benefit) {} + : ::mlir::OpRewritePattern(context, benefit) {} ::mlir::LogicalResult - matchAndRewrite(HLFHELinalgOp linalgOp, + matchAndRewrite(FHELinalgOp linalgOp, ::mlir::PatternRewriter &rewriter) const override { mlir::RankedTensorType resultTy = ((mlir::Type)linalgOp->getResult(0).getType()) @@ -254,11 +254,11 @@ struct HLFHELinalgOpToLinalgGeneric auto bodyBuilder = [&](mlir::OpBuilder &nestedBuilder, mlir::Location nestedLoc, mlir::ValueRange blockArgs) { - HLFHEOp hlfheOp = nestedBuilder.create( + FHEOp fheOp = nestedBuilder.create( linalgOp.getLoc(), blockArgs[0], blockArgs[1]); nestedBuilder.create(linalgOp.getLoc(), - hlfheOp.getResult()); + fheOp.getResult()); }; // Create the `linalg.generic` op @@ -288,9 +288,9 @@ llvm::SmallVector parallelIteratorType(int n) { } // This class rewrite pattern transforms any instance of -// operators `HLFHELinalg.ApplyMappedLookupTableEintOp` that implements the +// operators `FHELinalg.ApplyMappedLookupTableEintOp` that implements the // broadasting rules to an instance of `linalg.generic` with an appropriate -// region using `HLFHE.ApplyLookupTableEintOp` operation, an appropriate +// region using `FHE.ApplyLookupTableEintOp` operation, an appropriate // specification for the iteration dimensions and appropriate operations // managing the accumulator of `linalg.generic`. // @@ -298,20 +298,20 @@ llvm::SmallVector parallelIteratorType(int n) { // because of a bug in lowering this operation. // // Example: -// %res = "HLFHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) -// : (tensor<2x3x!HLFHE.eint<2>>, tensor<5x4xi64>, tensor<2x3xindex>) -// -> tensor<2x3x!HLFHE.eint<2>> +// %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!MidLFHE.glwe<{_,_,_}{2}>> +// %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!MidLFHE.glwe<{_,_,_}{2}>>, tensor<2x3xindex>) outs(%0 : -// tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>>) { -// ^bb0(%arg3: !MidLFHE.glwe<{_,_,_}{2}>, %lut_idx: index, %arg5: -// !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors +// 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> @@ -323,31 +323,31 @@ llvm::SmallVector parallelIteratorType(int n) { // ... // %e3 = tensor.extract %arg5[%lut_idx, %i3] : tensor<5x4xi64> // %lut = tensor.from_elements %e0, ..., %e3 : tensor<4xi64> -// %res = "MidLFHE.apply_lookup_table"(%arg3, %[[LUT]]) +// %res = "TFHE.apply_lookup_table"(%arg3, %[[LUT]]) // {baseLogBS = -1 : i32, baseLogKS = -1 : i32, k = -1 : i32, // levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = // -1 : i32, polynomialSize = -1 : i32} -// : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> -// !MidLFHE.glwe<{_,_,_}{2}> linalg.yield %res : -// !MidLFHE.glwe<{_,_,_}{2}> -// } -> tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>> +// : (!TFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> +// !TFHE.glwe<{_,_,_}{2}> linalg.yield %res : +// !TFHE.glwe<{_,_,_}{2}> +// } -> tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> -namespace HLFHELinalg = mlir::concretelang::HLFHELinalg; +namespace FHELinalg = mlir::concretelang::FHELinalg; -struct HLFHELinalgApplyMappedLookupTableToLinalgGeneric - : public mlir::OpRewritePattern { - HLFHELinalgApplyMappedLookupTableToLinalgGeneric( +struct FHELinalgApplyMappedLookupTableToLinalgGeneric + : public mlir::OpRewritePattern { + FHELinalgApplyMappedLookupTableToLinalgGeneric( ::mlir::MLIRContext *context, mlir::PatternBenefit benefit = 1) - : ::mlir::OpRewritePattern( + : ::mlir::OpRewritePattern( context, benefit) {} ::mlir::LogicalResult - matchAndRewrite(HLFHELinalg::ApplyMappedLookupTableEintOp mappedLookup, + matchAndRewrite(FHELinalg::ApplyMappedLookupTableEintOp mappedLookup, ::mlir::PatternRewriter &rewriter) const override { namespace arith = mlir::arith; namespace linalg = mlir::linalg; namespace tensor = mlir::tensor; - namespace HLFHE = mlir::concretelang::HLFHE; + namespace FHE = mlir::concretelang::FHE; using Values = llvm::SmallVector; using Types = llvm::SmallVector; using AffineMaps = llvm::SmallVector; @@ -421,9 +421,9 @@ struct HLFHELinalgApplyMappedLookupTableToLinalgGeneric lut = nestedBuilder.create(loc, extracts); } // WORKAROUND END // %res1 = apply_lookup_table %arg0 %lut - auto lookup = nestedBuilder.create( + auto lookup = nestedBuilder.create( loc, elementTy, tElmt, lut); - // linalg.yield %res1 : !HLFHE.eint<2> + // linalg.yield %res1 : !FHE.eint<2> nestedBuilder.create(loc, lookup.getResult()); }; @@ -446,16 +446,16 @@ struct HLFHELinalgApplyMappedLookupTableToLinalgGeneric }; // This class rewrite pattern transforms any instance of -// operators `HLFHELinalg.ApplyMultiLookupTableEintOp` that implements the +// operators `FHELinalg.ApplyMultiLookupTableEintOp` that implements the // broadasting rules to an instance of `linalg.generic` with an appropriate -// region using `HLFHE.ApplyLookupTableEintOp` operation, 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 = "HLFHELinalg.apply_multi_lookup_table"(%t, %luts): -// (tensor<4x3x!HLFHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!HLFHE.eint<2>> +// %res = "FHELinalg.apply_multi_lookup_table"(%t, %luts): +// (tensor<4x3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> // // becomes: // @@ -471,50 +471,50 @@ struct HLFHELinalgApplyMappedLookupTableToLinalgGeneric // iterator_types = ["parallel", "parallel"], // } // %init = linalg.init_tensor [4, 3] -// : tensor<4x3x!HLFHE.eint<2>> +// : tensor<4x3x!FHE.eint<2>> // %res = linalg.generic { -// ins(%t, %luts, %luts, %luts, %luts: tensor<4x3x!HLFHE.eint

>, +// ins(%t, %luts, %luts, %luts, %luts: tensor<4x3x!FHE.eint

>, // tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) -// outs(%init : tensor<4x3x!HLFHE.eint<2>>) +// outs(%init : tensor<4x3x!FHE.eint<2>>) // { -// ^bb0(%arg0: !HLFHE.eint<2>, %arg1: i64, %arg2: i64, %arg3: i64, -// %arg4: i64, %arg5: !HLFHE.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 = "MidLFHE.apply_lookup_table"(%arg0, %lut) +// 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} : (!MidLFHE.glwe<{_,_,_}{2}>, -// tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -// linalg.yield %0 : !HLFHE.eint<2> +// i32, polynomialSize = -1 : i32} : (!TFHE.glwe<{_,_,_}{2}>, +// tensor<4xi64>) -> !TFHE.glwe<{_,_,_}{2}> +// linalg.yield %0 : !FHE.eint<2> // } // } // -struct HLFHELinalgApplyMultiLookupTableToLinalgGeneric +struct FHELinalgApplyMultiLookupTableToLinalgGeneric : public mlir::OpRewritePattern< - mlir::concretelang::HLFHELinalg::ApplyMultiLookupTableEintOp> { - HLFHELinalgApplyMultiLookupTableToLinalgGeneric( + mlir::concretelang::FHELinalg::ApplyMultiLookupTableEintOp> { + FHELinalgApplyMultiLookupTableToLinalgGeneric( ::mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) : ::mlir::OpRewritePattern< - mlir::concretelang::HLFHELinalg::ApplyMultiLookupTableEintOp>(context, + mlir::concretelang::FHELinalg::ApplyMultiLookupTableEintOp>(context, benefit) { } ::mlir::LogicalResult matchAndRewrite( - mlir::concretelang::HLFHELinalg::ApplyMultiLookupTableEintOp hlfheLinalgLutOp, + mlir::concretelang::FHELinalg::ApplyMultiLookupTableEintOp fheLinalgLutOp, ::mlir::PatternRewriter &rewriter) const override { mlir::RankedTensorType resultTy = - ((mlir::Type)hlfheLinalgLutOp->getResult(0).getType()) + ((mlir::Type)fheLinalgLutOp->getResult(0).getType()) .cast(); mlir::RankedTensorType tensorTy = - ((mlir::Type)hlfheLinalgLutOp.t().getType()) + ((mlir::Type)fheLinalgLutOp.t().getType()) .cast(); mlir::RankedTensorType lutsTy = - ((mlir::Type)hlfheLinalgLutOp.luts().getType()) + ((mlir::Type)fheLinalgLutOp.luts().getType()) .cast(); // linalg.init_tensor for initial value mlir::Value init = rewriter.create( - hlfheLinalgLutOp.getLoc(), resultTy.getShape(), + fheLinalgLutOp.getLoc(), resultTy.getShape(), resultTy.getElementType()); auto lutsShape = lutsTy.getShape(); @@ -541,51 +541,51 @@ struct HLFHELinalgApplyMultiLookupTableToLinalgGeneric mlir::ValueRange blockArgs) { mlir::tensor::FromElementsOp lut = nestedBuilder.create( - hlfheLinalgLutOp.getLoc(), blockArgs.slice(1, lut_size)); - mlir::concretelang::HLFHE::ApplyLookupTableEintOp lutOp = - nestedBuilder.create( - hlfheLinalgLutOp.getLoc(), resultTy.getElementType(), + fheLinalgLutOp.getLoc(), blockArgs.slice(1, lut_size)); + mlir::concretelang::FHE::ApplyLookupTableEintOp lutOp = + nestedBuilder.create( + fheLinalgLutOp.getLoc(), resultTy.getElementType(), blockArgs[0], lut.result()); - nestedBuilder.create(hlfheLinalgLutOp.getLoc(), + nestedBuilder.create(fheLinalgLutOp.getLoc(), lutOp.getResult()); }; // Create the `linalg.generic` op llvm::SmallVector resTypes{init.getType()}; - llvm::SmallVector ins{hlfheLinalgLutOp.t()}; + llvm::SmallVector ins{fheLinalgLutOp.t()}; ins.reserve(lut_size + 2); // We extract one value at a time from one LUT using different maps, so we // need to pass the LUT `lut_size` time for (auto i = 0; i < lut_size; i++) - ins.push_back(hlfheLinalgLutOp.luts()); + ins.push_back(fheLinalgLutOp.luts()); llvm::SmallVector outs{init}; llvm::StringRef doc{""}; llvm::StringRef call{""}; mlir::linalg::GenericOp genericOp = rewriter.create( - hlfheLinalgLutOp.getLoc(), resTypes, ins, outs, maps, iteratorTypes, + fheLinalgLutOp.getLoc(), resTypes, ins, outs, maps, iteratorTypes, doc, call, bodyBuilder); - rewriter.replaceOp(hlfheLinalgLutOp, {genericOp.getResult(0)}); + rewriter.replaceOp(fheLinalgLutOp, {genericOp.getResult(0)}); return ::mlir::success(); }; }; // This template rewrite pattern transforms any instance of -// operators `HLFHELinalg.apply_lookup_table` that implements the broadasting +// operators `FHELinalg.apply_lookup_table` that implements the broadasting // rules to an instance of `linalg.generic` with an appropriate region using -// `HLFHE.apply_lookup_table` operation, an appropriate specification for the +// `FHE.apply_lookup_table` operation, an appropriate specification for the // iteration dimensions and appropriate operations managing the accumulator of // `linalg.generic`. // // Example: // -// HLFHELinalg.apply_lookup_table(%t, %lut): -// tensor>, tensor -// -> tensor> +// FHELinalg.apply_lookup_table(%t, %lut): +// tensor>, tensor +// -> tensor> // // becomes: // @@ -598,30 +598,30 @@ struct HLFHELinalgApplyMultiLookupTableToLinalgGeneric // iterator_types = ["parallel",..],//N parallel // } // %init = linalg.init_tensor [DN,...,D1] -// : tensor> +// : tensor> // %res = linalg.generic { -// ins(%t: tensor>) -// outs(%init : tensor>) +// ins(%t: tensor>) +// outs(%init : tensor>) // { -// ^bb0(%arg0: !HLFHE.eint

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

, -// tensor<4xi64> -> !HLFHE.eint -// linalg.yield %0 : !HLFHE.eint +// ^bb0(%arg0: !FHE.eint

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

, +// tensor<4xi64> -> !FHE.eint +// linalg.yield %0 : !FHE.eint // } // } // -struct HLFHELinalgApplyLookupTableToLinalgGeneric +struct FHELinalgApplyLookupTableToLinalgGeneric : public mlir::OpRewritePattern< - mlir::concretelang::HLFHELinalg::ApplyLookupTableEintOp> { - HLFHELinalgApplyLookupTableToLinalgGeneric( + mlir::concretelang::FHELinalg::ApplyLookupTableEintOp> { + FHELinalgApplyLookupTableToLinalgGeneric( ::mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) : ::mlir::OpRewritePattern< - mlir::concretelang::HLFHELinalg::ApplyLookupTableEintOp>(context, + mlir::concretelang::FHELinalg::ApplyLookupTableEintOp>(context, benefit) {} ::mlir::LogicalResult - matchAndRewrite(mlir::concretelang::HLFHELinalg::ApplyLookupTableEintOp lutOp, + matchAndRewrite(mlir::concretelang::FHELinalg::ApplyLookupTableEintOp lutOp, ::mlir::PatternRewriter &rewriter) const override { mlir::RankedTensorType resultTy = ((mlir::Type)lutOp->getResult(0).getType()) @@ -649,13 +649,13 @@ struct HLFHELinalgApplyLookupTableToLinalgGeneric auto bodyBuilder = [&](mlir::OpBuilder &nestedBuilder, mlir::Location nestedLoc, mlir::ValueRange blockArgs) { - mlir::concretelang::HLFHE::ApplyLookupTableEintOp hlfheOp = - nestedBuilder.create( + mlir::concretelang::FHE::ApplyLookupTableEintOp fheOp = + nestedBuilder.create( lutOp.getLoc(), resultTy.getElementType(), blockArgs[0], lutOp.lut()); nestedBuilder.create(lutOp.getLoc(), - hlfheOp.getResult()); + fheOp.getResult()); }; // Create the `linalg.generic` op @@ -677,15 +677,15 @@ struct HLFHELinalgApplyLookupTableToLinalgGeneric }; // This template rewrite pattern transforms any instance of -// operators `HLFHELinalg.neg_eint` to an instance of `linalg.generic` with an -// appropriate region using `HLFHE.neg_eint` operation, an appropriate +// 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: // -// HLFHELinalg.neg_eint(%tensor): -// tensor> -> tensor> +// FHELinalg.neg_eint(%tensor): +// tensor> -> tensor> // // becomes: // @@ -698,27 +698,27 @@ struct HLFHELinalgApplyLookupTableToLinalgGeneric // iterator_types = ["parallel",..],//N parallel // } // %init = linalg.init_tensor [DN,...,D1] -// : tensor> +// : tensor> // %res = linalg.generic { -// ins(%tensor: tensor>) -// outs(%init : tensor>) +// ins(%tensor: tensor>) +// outs(%init : tensor>) // { -// ^bb0(%arg0: !HLFHE.eint

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

-> !HLFHE.eint -// linalg.yield %0 : !HLFHE.eint +// ^bb0(%arg0: !FHE.eint

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

-> !FHE.eint +// linalg.yield %0 : !FHE.eint // } // } // -struct HLFHELinalgNegEintToLinalgGeneric - : public mlir::OpRewritePattern { - HLFHELinalgNegEintToLinalgGeneric( +struct FHELinalgNegEintToLinalgGeneric + : public mlir::OpRewritePattern { + FHELinalgNegEintToLinalgGeneric( ::mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : ::mlir::OpRewritePattern( + : ::mlir::OpRewritePattern( context, benefit) {} ::mlir::LogicalResult - matchAndRewrite(mlir::concretelang::HLFHELinalg::NegEintOp negEintOp, + matchAndRewrite(mlir::concretelang::FHELinalg::NegEintOp negEintOp, ::mlir::PatternRewriter &rewriter) const override { mlir::RankedTensorType resultTy = ((mlir::Type)negEintOp->getResult(0).getType()) @@ -746,12 +746,12 @@ struct HLFHELinalgNegEintToLinalgGeneric auto bodyBuilder = [&](mlir::OpBuilder &nestedBuilder, mlir::Location nestedLoc, mlir::ValueRange blockArgs) { - mlir::concretelang::HLFHE::NegEintOp hlfheOp = - nestedBuilder.create( + mlir::concretelang::FHE::NegEintOp fheOp = + nestedBuilder.create( negEintOp.getLoc(), resultTy.getElementType(), blockArgs[0]); nestedBuilder.create(negEintOp.getLoc(), - hlfheOp.getResult()); + fheOp.getResult()); }; // Create the `linalg.generic` op @@ -773,17 +773,17 @@ struct HLFHELinalgNegEintToLinalgGeneric }; // This template rewrite pattern transforms any instance of -// operators `HLFHELinalgMatmulOp` to an instance of `linalg.generic` +// operators `FHELinalgMatmulOp` to an instance of `linalg.generic` // with an appropriate region using a builder that create the multiplication -// operators and `HLFHE.add_eint` operation, an appropriate specification for +// operators and `FHE.add_eint` operation, an appropriate specification for // the iteration dimensions and appropriate operations managing the accumulator // of `linalg.generic`. // // Example: // -// "HLFHELinalg.matmul_eint_int(%a, %b) : -// (tensor>, tensor) -> -// tensor>" +// "FHELinalg.matmul_eint_int(%a, %b) : +// (tensor>, tensor) -> +// tensor>" // // becomes: @@ -799,36 +799,36 @@ struct HLFHELinalgNegEintToLinalgGeneric // } // %init = linalg.generate { // ^bb0(%i : index, %j : index, %k : index): -// %z = "HLFHE.zero" : () -> !HLFHE.eint<2> +// %z = "FHE.zero" : () -> !FHE.eint<2> // linalg.yield %z -// }: tensor> +// }: tensor> // linalg.generic #attributes_0 -// ins(%A, %B : tensor>, +// ins(%A, %B : tensor>, // tensor) -// outs(%C : tensor>) +// outs(%C : tensor>) // { -// ^bb0(%a: !HLFHE.eint

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

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

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

, !HLFHE.eint

) -> !HLFHE.eint

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

+// ^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 HLFHELinalgMatmulToLinalgGeneric - : public mlir::OpRewritePattern { - HLFHELinalgMatmulToLinalgGeneric( +template +struct FHELinalgMatmulToLinalgGeneric + : public mlir::OpRewritePattern { + FHELinalgMatmulToLinalgGeneric( mlir::MLIRContext *context, - std::function createMulOp, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : ::mlir::OpRewritePattern(context, benefit), + : ::mlir::OpRewritePattern(context, benefit), createMulOp(createMulOp) {} ::mlir::LogicalResult - matchAndRewrite(HLFHELinalgMatmulOp matmulOp, + matchAndRewrite(FHELinalgMatmulOp matmulOp, ::mlir::PatternRewriter &rewriter) const override { mlir::Location matmulLoc = matmulOp.getLoc(); mlir::RankedTensorType resultTy = @@ -839,11 +839,11 @@ struct HLFHELinalgMatmulToLinalgGeneric auto generateBody = [&](mlir::OpBuilder &nestedBuilder, mlir::Location nestedLoc, mlir::ValueRange blockArgs) { - // %z = "HLFHE.zero" : () -> !HLFHE.eint<2> - mlir::concretelang::HLFHE::ZeroEintOp zeroOp = - nestedBuilder.create( + // %z = "FHE.zero" : () -> !FHE.eint<2> + mlir::concretelang::FHE::ZeroEintOp zeroOp = + nestedBuilder.create( matmulLoc, resultElementTy); - // linalg.yield %z : !HLFHE.eint

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

nestedBuilder.create(matmulLoc, zeroOp.getResult()); }; @@ -873,16 +873,16 @@ struct HLFHELinalgMatmulToLinalgGeneric auto bodyBuilder = [&](mlir::OpBuilder &nestedBuilder, mlir::Location nestedLoc, mlir::ValueRange blockArgs) { - // "HLFHE.mul_eint_int"(%a, %b) : (!HLFHE.eint

, ip') -> !HLFHE.eint

- mlir::concretelang::HLFHE::MulEintIntOp mulEintIntOp = + // "FHE.mul_eint_int"(%a, %b) : (!FHE.eint

, ip') -> !FHE.eint

+ mlir::concretelang::FHE::MulEintIntOp mulEintIntOp = createMulOp(nestedBuilder, matmulLoc, resultElementTy, blockArgs[0], blockArgs[1]); - // "HLFHE.add_eint"(%c, %d): (!HLFHE.eint

, !HLFHE.eint

) -> - // !HLFHE.eint

- mlir::concretelang::HLFHE::AddEintOp addEintOp = - nestedBuilder.create( + // "FHE.add_eint"(%c, %d): (!FHE.eint

, !FHE.eint

) -> + // !FHE.eint

+ mlir::concretelang::FHE::AddEintOp addEintOp = + nestedBuilder.create( matmulLoc, resultElementTy, blockArgs[2], mulEintIntOp); - // linalg.yield %e : !HLFHE.eint

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

nestedBuilder.create(matmulLoc, addEintOp.getResult()); }; @@ -905,38 +905,38 @@ struct HLFHELinalgMatmulToLinalgGeneric }; private: - std::function createMulOp; }; // This rewrite pattern transforms any instance of operators -// `HLFHELinalg.zero` to an instance of `linalg.generate` with an +// `FHELinalg.zero` to an instance of `linalg.generate` with an // appropriate region yielding a zero value. // // Example: // -// %out = "HLFHELinalg.zero"() : () -> tensor> +// %out = "FHELinalg.zero"() : () -> tensor> // // becomes: // // %0 = tensor.generate { // ^bb0(%arg2: index, %arg3: index): -// %zero = "HLFHE.zero"() : () -> !HLFHE.eint

-// tensor.yield %zero : !HLFHE.eint

-// } : tensor> +// %zero = "FHE.zero"() : () -> !FHE.eint

+// tensor.yield %zero : !FHE.eint

+// } : tensor> // -struct HLFHELinalgZeroToLinalgGenerate - : public mlir::OpRewritePattern { - HLFHELinalgZeroToLinalgGenerate( +struct FHELinalgZeroToLinalgGenerate + : public mlir::OpRewritePattern { + FHELinalgZeroToLinalgGenerate( ::mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : ::mlir::OpRewritePattern(context, + : ::mlir::OpRewritePattern(context, benefit) { } ::mlir::LogicalResult - matchAndRewrite(mlir::concretelang::HLFHELinalg::ZeroOp zeroOp, + matchAndRewrite(mlir::concretelang::FHELinalg::ZeroOp zeroOp, ::mlir::PatternRewriter &rewriter) const override { mlir::RankedTensorType resultTy = zeroOp->getResult(0).getType().cast(); @@ -945,7 +945,7 @@ struct HLFHELinalgZeroToLinalgGenerate mlir::Location nestedLoc, mlir::ValueRange blockArgs) { mlir::Value zeroScalar = - nestedBuilder.create( + nestedBuilder.create( zeroOp.getLoc(), resultTy.getElementType()); nestedBuilder.create(zeroOp.getLoc(), zeroScalar); }; @@ -960,13 +960,13 @@ struct HLFHELinalgZeroToLinalgGenerate }; namespace { -struct HLFHETensorOpsToLinalg - : public HLFHETensorOpsToLinalgBase { +struct FHETensorOpsToLinalg + : public FHETensorOpsToLinalgBase { void runOnFunction() final; }; -void HLFHETensorOpsToLinalg::runOnFunction() { +void FHETensorOpsToLinalg::runOnFunction() { mlir::FuncOp function = this->getFunction(); mlir::ConversionTarget target(getContext()); @@ -974,51 +974,51 @@ void HLFHETensorOpsToLinalg::runOnFunction() { target.addLegalDialect(); target.addLegalDialect(); target.addLegalDialect(); - target.addLegalDialect(); + target.addLegalDialect(); target.addLegalDialect(); target.addLegalDialect(); - target.addIllegalOp(); - target.addIllegalDialect(); + target.addIllegalOp(); + target.addIllegalDialect(); mlir::OwningRewritePatternList patterns(&getContext()); patterns.insert(&getContext()); patterns.insert< - HLFHELinalgOpToLinalgGeneric>( + FHELinalgOpToLinalgGeneric>( &getContext()); patterns.insert< - HLFHELinalgOpToLinalgGeneric>( + FHELinalgOpToLinalgGeneric>( &getContext()); patterns.insert< - HLFHELinalgOpToLinalgGeneric>( + FHELinalgOpToLinalgGeneric>( &getContext()); patterns.insert< - HLFHELinalgOpToLinalgGeneric>( + FHELinalgOpToLinalgGeneric>( &getContext()); - patterns.insert(&getContext()); - patterns.insert(&getContext()); - patterns.insert>( + patterns.insert(&getContext()); + patterns.insert(&getContext()); + patterns.insert>( &getContext(), [](mlir::OpBuilder &builder, mlir::Location loc, mlir::Type type, mlir::Value arg0, mlir::Value arg1) { - return builder.create(loc, type, + return builder.create(loc, type, arg0, arg1); }); - patterns.insert>( + patterns.insert>( &getContext(), [](mlir::OpBuilder &builder, mlir::Location loc, mlir::Type type, mlir::Value arg0, mlir::Value arg1) { - return builder.create(loc, type, + return builder.create(loc, type, arg1, arg0); }); - patterns.insert( + patterns.insert( &getContext()); - patterns.insert( + patterns.insert( &getContext()); - patterns.insert(&getContext()); + patterns.insert(&getContext()); if (mlir::applyPartialConversion(function, target, std::move(patterns)) .failed()) @@ -1029,8 +1029,8 @@ void HLFHETensorOpsToLinalg::runOnFunction() { namespace mlir { namespace concretelang { -std::unique_ptr createConvertHLFHETensorOpsToLinalg() { - return std::make_unique(); +std::unique_ptr createConvertFHETensorOpsToLinalg() { + return std::make_unique(); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Conversion/FHEToTFHE/CMakeLists.txt b/compiler/lib/Conversion/FHEToTFHE/CMakeLists.txt new file mode 100644 index 000000000..81a9efcd1 --- /dev/null +++ b/compiler/lib/Conversion/FHEToTFHE/CMakeLists.txt @@ -0,0 +1,16 @@ +add_mlir_dialect_library(FHEToTFHE + FHEToTFHE.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHE + + DEPENDS + FHEDialect + FHEToTFHEPatternsIncGen + + LINK_LIBS PUBLIC + MLIRIR + MLIRTransforms + MLIRMath) + +target_link_libraries(FHEToTFHE PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/HLFHEToMidLFHE/HLFHEToMidLFHE.cpp b/compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp similarity index 68% rename from compiler/lib/Conversion/HLFHEToMidLFHE/HLFHEToMidLFHE.cpp rename to compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp index f569d75cc..136755492 100644 --- a/compiler/lib/Conversion/HLFHEToMidLFHE/HLFHEToMidLFHE.cpp +++ b/compiler/lib/Conversion/FHEToTFHE/FHEToTFHE.cpp @@ -6,31 +6,31 @@ #include "mlir/Pass/Pass.h" #include "mlir/Transforms/DialectConversion.h" -#include "concretelang/Conversion/HLFHEToMidLFHE/Patterns.h" +#include "concretelang/Conversion/FHEToTFHE/Patterns.h" #include "concretelang/Conversion/Passes.h" #include "concretelang/Conversion/Utils/RegionOpTypeConverterPattern.h" #include "concretelang/Conversion/Utils/TensorOpTypeConversion.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHEDialect.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" +#include "concretelang/Dialect/TFHE/IR/TFHEDialect.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" #include "concretelang/Dialect/RT/IR/RTOps.h" namespace { -struct HLFHEToMidLFHEPass : public HLFHEToMidLFHEBase { +struct FHEToTFHEPass : public FHEToTFHEBase { void runOnOperation() final; }; } // namespace -using mlir::concretelang::HLFHE::EncryptedIntegerType; -using mlir::concretelang::MidLFHE::GLWECipherTextType; +using mlir::concretelang::FHE::EncryptedIntegerType; +using mlir::concretelang::TFHE::GLWECipherTextType; -/// HLFHEToMidLFHETypeConverter is a TypeConverter that transform -/// `HLFHE.eint

` to `MidLFHE.glwe<{_,_,_}{p}>` -class HLFHEToMidLFHETypeConverter : public mlir::TypeConverter { +/// FHEToTFHETypeConverter is a TypeConverter that transform +/// `FHE.eint

` to `TFHE.glwe<{_,_,_}{p}>` +class FHEToTFHETypeConverter : public mlir::TypeConverter { public: - HLFHEToMidLFHETypeConverter() { + FHEToTFHETypeConverter() { addConversion([](mlir::Type type) { return type; }); addConversion([](EncryptedIntegerType type) { return mlir::concretelang::convertTypeEncryptedIntegerToGLWE( @@ -50,17 +50,17 @@ public: } }; -void HLFHEToMidLFHEPass::runOnOperation() { +void FHEToTFHEPass::runOnOperation() { auto op = this->getOperation(); mlir::ConversionTarget target(getContext()); - HLFHEToMidLFHETypeConverter converter; + FHEToTFHETypeConverter converter; // Mark ops from the target dialect as legal operations - target.addLegalDialect(); + target.addLegalDialect(); - // Make sure that no ops from `HLFHE` remain after the lowering - target.addIllegalDialect(); + // Make sure that no ops from `FHE` remain after the lowering + target.addIllegalDialect(); // Make sure that no ops `linalg.generic` that have illegal types target @@ -77,19 +77,19 @@ void HLFHEToMidLFHEPass::runOnOperation() { return converter.isSignatureLegal(funcOp.getType()) && converter.isLegal(&funcOp.getBody()); }); - // Add all patterns required to lower all ops from `HLFHE` to - // `MidLFHE` + // Add all patterns required to lower all ops from `FHE` to + // `TFHE` mlir::OwningRewritePatternList patterns(&getContext()); - populateWithGeneratedHLFHEToMidLFHE(patterns); + populateWithGeneratedFHEToTFHE(patterns); patterns.add>( + FHEToTFHETypeConverter>>( &getContext(), converter); patterns.add>( + FHEToTFHETypeConverter>>( &getContext(), converter); patterns.add>( + FHEToTFHETypeConverter>>( &getContext(), converter); mlir::concretelang::populateWithTensorTypeConverterPatterns(patterns, target, @@ -110,8 +110,8 @@ void HLFHEToMidLFHEPass::runOnOperation() { namespace mlir { namespace concretelang { -std::unique_ptr> createConvertHLFHEToMidLFHEPass() { - return std::make_unique(); +std::unique_ptr> createConvertFHEToTFHEPass() { + return std::make_unique(); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Conversion/HLFHETensorOpsToLinalg/CMakeLists.txt b/compiler/lib/Conversion/HLFHETensorOpsToLinalg/CMakeLists.txt deleted file mode 100644 index 099ce4215..000000000 --- a/compiler/lib/Conversion/HLFHETensorOpsToLinalg/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -add_mlir_dialect_library(HLFHETensorOpsToLinalg - TensorOpsToLinalg.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHE - - DEPENDS - HLFHEDialect - HLFHELinalgDialect - MLIRConversionPassIncGen - - LINK_LIBS PUBLIC - MLIRIR - HLFHEDialect - HLFHELinalgDialect) - -target_link_libraries(HLFHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/HLFHEToMidLFHE/CMakeLists.txt b/compiler/lib/Conversion/HLFHEToMidLFHE/CMakeLists.txt deleted file mode 100644 index 1628073a7..000000000 --- a/compiler/lib/Conversion/HLFHEToMidLFHE/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -add_mlir_dialect_library(HLFHEToMidLFHE - HLFHEToMidLFHE.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHE - - DEPENDS - HLFHEDialect - HLFHEToMidLFHEPatternsIncGen - - LINK_LIBS PUBLIC - MLIRIR - MLIRTransforms - MLIRMath) - -target_link_libraries(HLFHEToMidLFHE PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/CMakeLists.txt b/compiler/lib/Conversion/LowLFHEToConcreteCAPI/CMakeLists.txt deleted file mode 100644 index 7f108edca..000000000 --- a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -add_mlir_dialect_library(LowLFHEToConcreteCAPI - LowLFHEToConcreteCAPI.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHE - - DEPENDS - LowLFHEDialect - MLIRConversionPassIncGen - - LINK_LIBS PUBLIC - MLIRIR - MLIRTransforms -) - -target_link_libraries(LowLFHEToConcreteCAPI PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/LowLFHEUnparametrize/CMakeLists.txt b/compiler/lib/Conversion/LowLFHEUnparametrize/CMakeLists.txt deleted file mode 100644 index 46b50ce54..000000000 --- a/compiler/lib/Conversion/LowLFHEUnparametrize/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -add_mlir_dialect_library(LowLFHEUnparametrize - LowLFHEUnparametrize.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHE - - DEPENDS - LowLFHEDialect - MLIRConversionPassIncGen - - LINK_LIBS PUBLIC - MLIRIR - MLIRTransforms -) - -target_link_libraries(LowLFHEUnparametrize PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp b/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp index 7bf4ba8b0..50a558c3e 100644 --- a/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp +++ b/compiler/lib/Conversion/MLIRLowerableDialectsToLLVM/MLIRLowerableDialectsToLLVM.cpp @@ -21,7 +21,7 @@ #include "llvm/ADT/Sequence.h" #include "concretelang/Conversion/Passes.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #include "concretelang/Dialect/RT/Analysis/Autopar.h" #include "concretelang/Dialect/RT/IR/RTTypes.h" @@ -47,10 +47,10 @@ void MLIRLowerableDialectsToLLVMPass::runOnOperation() { mlir::LowerToLLVMOptions options(&getContext()); mlir::LLVMTypeConverter typeConverter(&getContext(), options); typeConverter.addConversion(convertTypes); - typeConverter.addConversion([&](mlir::concretelang::LowLFHE::PlaintextType type) { + typeConverter.addConversion([&](mlir::concretelang::Concrete::PlaintextType type) { return mlir::IntegerType::get(type.getContext(), 64); }); - typeConverter.addConversion([&](mlir::concretelang::LowLFHE::CleartextType type) { + typeConverter.addConversion([&](mlir::concretelang::Concrete::CleartextType type) { return mlir::IntegerType::get(type.getContext(), 64); }); @@ -72,13 +72,13 @@ void MLIRLowerableDialectsToLLVMPass::runOnOperation() { llvm::Optional MLIRLowerableDialectsToLLVMPass::convertTypes(mlir::Type type) { - if (type.isa() || - type.isa() || - type.isa() || - type.isa() || - type.isa() || - type.isa() || - type.isa() || + if (type.isa() || + type.isa() || + type.isa() || + type.isa() || + type.isa() || + type.isa() || + type.isa() || type.isa()) { return mlir::LLVM::LLVMPointerType::get( mlir::IntegerType::get(type.getContext(), 64)); @@ -88,11 +88,11 @@ MLIRLowerableDialectsToLLVMPass::convertTypes(mlir::Type type) { mlir::LLVMTypeConverter typeConverter(type.getContext(), options); typeConverter.addConversion(convertTypes); typeConverter.addConversion( - [&](mlir::concretelang::LowLFHE::PlaintextType type) { + [&](mlir::concretelang::Concrete::PlaintextType type) { return mlir::IntegerType::get(type.getContext(), 64); }); typeConverter.addConversion( - [&](mlir::concretelang::LowLFHE::CleartextType type) { + [&](mlir::concretelang::Concrete::CleartextType type) { return mlir::IntegerType::get(type.getContext(), 64); }); mlir::Type subtype = diff --git a/compiler/lib/Conversion/MidLFHEGlobalParametrization/CMakeLists.txt b/compiler/lib/Conversion/MidLFHEGlobalParametrization/CMakeLists.txt deleted file mode 100644 index 075c9f2b9..000000000 --- a/compiler/lib/Conversion/MidLFHEGlobalParametrization/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -add_mlir_dialect_library(MidLFHEGlobalParametrization -MidLFHEGlobalParametrization.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/MidLFHE - - DEPENDS - MidLFHEDialect - - LINK_LIBS PUBLIC - MLIRIR - MLIRTransforms -) - -target_link_libraries(MidLFHEGlobalParametrization PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/MidLFHEToLowLFHE/CMakeLists.txt b/compiler/lib/Conversion/MidLFHEToLowLFHE/CMakeLists.txt deleted file mode 100644 index 29ab42339..000000000 --- a/compiler/lib/Conversion/MidLFHEToLowLFHE/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -add_mlir_dialect_library(MidLFHEToLowLFHE - MidLFHEToLowLFHE.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/MidLFHE - - DEPENDS - MidLFHEDialect - LowLFHEDialect - MidLFHEToLowLFHEPatternsIncGen - - LINK_LIBS PUBLIC - MLIRIR - MLIRTransforms - MLIRMath) - -target_link_libraries(MidLFHEToLowLFHE PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/TFHEGlobalParametrization/CMakeLists.txt b/compiler/lib/Conversion/TFHEGlobalParametrization/CMakeLists.txt new file mode 100644 index 000000000..d67d4aa1c --- /dev/null +++ b/compiler/lib/Conversion/TFHEGlobalParametrization/CMakeLists.txt @@ -0,0 +1,15 @@ +add_mlir_dialect_library(TFHEGlobalParametrization +TFHEGlobalParametrization.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/TFHE + + DEPENDS + TFHEDialect + + LINK_LIBS PUBLIC + MLIRIR + MLIRTransforms +) + +target_link_libraries(TFHEGlobalParametrization PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp b/compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp similarity index 71% rename from compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp rename to compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp index 417c9cfc9..ca3fe9758 100644 --- a/compiler/lib/Conversion/MidLFHEGlobalParametrization/MidLFHEGlobalParametrization.cpp +++ b/compiler/lib/Conversion/TFHEGlobalParametrization/TFHEGlobalParametrization.cpp @@ -7,32 +7,32 @@ #include "concretelang/Conversion/Passes.h" #include "concretelang/Conversion/Utils/RegionOpTypeConverterPattern.h" #include "concretelang/Conversion/Utils/TensorOpTypeConversion.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/TFHE/IR/TFHEDialect.h" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" #include "concretelang/Dialect/RT/IR/RTOps.h" #include "concretelang/Support/Constants.h" namespace { -struct MidLFHEGlobalParametrizationPass - : public MidLFHEGlobalParametrizationBase< - MidLFHEGlobalParametrizationPass> { - MidLFHEGlobalParametrizationPass(mlir::concretelang::V0FHEContext &fheContext) +struct TFHEGlobalParametrizationPass + : public TFHEGlobalParametrizationBase< + TFHEGlobalParametrizationPass> { + TFHEGlobalParametrizationPass(mlir::concretelang::V0FHEContext &fheContext) : fheContext(fheContext){}; void runOnOperation() final; mlir::concretelang::V0FHEContext &fheContext; }; } // namespace -using mlir::concretelang::MidLFHE::GLWECipherTextType; +using mlir::concretelang::TFHE::GLWECipherTextType; -/// MidLFHEGlobalParametrizationTypeConverter is a TypeConverter that transform -/// `MidLFHE.glwe<{_,_,_}{p}>` to -/// `MidLFHE.glwe<{glweDimension,polynomialSize,bits}{p'}>` -class MidLFHEGlobalParametrizationTypeConverter : public mlir::TypeConverter { +/// TFHEGlobalParametrizationTypeConverter is a TypeConverter that transform +/// `TFHE.glwe<{_,_,_}{p}>` to +/// `TFHE.glwe<{glweDimension,polynomialSize,bits}{p'}>` +class TFHEGlobalParametrizationTypeConverter : public mlir::TypeConverter { public: - MidLFHEGlobalParametrizationTypeConverter( + TFHEGlobalParametrizationTypeConverter( mlir::concretelang::V0FHEContext &fheContext) { auto convertGLWECiphertextType = [](GLWECipherTextType type, mlir::concretelang::V0FHEContext &fheContext) { @@ -64,8 +64,8 @@ public: }; template -struct MidLFHEOpTypeConversionPattern : public mlir::OpRewritePattern { - MidLFHEOpTypeConversionPattern( +struct TFHEOpTypeConversionPattern : public mlir::OpRewritePattern { + TFHEOpTypeConversionPattern( mlir::MLIRContext *context, mlir::TypeConverter &typeConverter, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) : mlir::OpRewritePattern(context, benefit), @@ -86,18 +86,18 @@ private: mlir::TypeConverter &typeConverter; }; -struct MidLFHEApplyLookupTableParametrizationPattern - : public mlir::OpRewritePattern { - MidLFHEApplyLookupTableParametrizationPattern( +struct TFHEApplyLookupTableParametrizationPattern + : public mlir::OpRewritePattern { + TFHEApplyLookupTableParametrizationPattern( mlir::MLIRContext *context, mlir::TypeConverter &typeConverter, mlir::concretelang::V0Parameter &v0Parameter, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, benefit), typeConverter(typeConverter), v0Parameter(v0Parameter) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::MidLFHE::ApplyLookupTable op, + matchAndRewrite(mlir::concretelang::TFHE::ApplyLookupTable op, mlir::PatternRewriter &rewriter) const override { mlir::SmallVector newResultTypes; if (typeConverter.convertTypes(op->getResultTypes(), newResultTypes) @@ -125,7 +125,7 @@ struct MidLFHEApplyLookupTableParametrizationPattern rewriter.getI32IntegerAttr(v0Parameter.nSmall)), }; - rewriter.replaceOpWithNewOp( + rewriter.replaceOpWithNewOp( op, newResultTypes, op->getOperands(), newAttributes); return mlir::success(); @@ -136,24 +136,24 @@ private: mlir::concretelang::V0Parameter &v0Parameter; }; -struct MidLFHEApplyLookupTablePaddingPattern - : public mlir::OpRewritePattern { - MidLFHEApplyLookupTablePaddingPattern( +struct TFHEApplyLookupTablePaddingPattern + : public mlir::OpRewritePattern { + TFHEApplyLookupTablePaddingPattern( mlir::MLIRContext *context, mlir::PatternBenefit benefit = mlir::concretelang::DEFAULT_PATTERN_BENEFIT) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, benefit), typeConverter(typeConverter), v0Parameter(v0Parameter) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::MidLFHE::ApplyLookupTable op, + matchAndRewrite(mlir::concretelang::TFHE::ApplyLookupTable op, mlir::PatternRewriter &rewriter) const override { auto glweInType = op.getOperandTypes()[0] - .cast(); + .cast(); auto tabulatedLambdaType = op.l_cst().getType().cast(); auto glweOutType = - op.getType().cast(); + op.getType().cast(); auto expectedSize = 1 << glweInType.getP(); if (tabulatedLambdaType.getShape()[0] < expectedSize) { auto constantOp = mlir::dyn_cast_or_null( @@ -188,7 +188,7 @@ struct MidLFHEApplyLookupTablePaddingPattern mlir::SmallVector newResultTypes{op.getType()}; llvm::SmallVector newOperands{op.ct(), newConstantOp}; llvm::ArrayRef newAttrs = op->getAttrs(); - rewriter.replaceOpWithNewOp( + rewriter.replaceOpWithNewOp( op, newResultTypes, newOperands, newAttrs); return mlir::success(); } @@ -202,23 +202,23 @@ private: }; template -void populateWithMidLFHEOpTypeConversionPattern( +void populateWithTFHEOpTypeConversionPattern( mlir::RewritePatternSet &patterns, mlir::ConversionTarget &target, mlir::TypeConverter &typeConverter) { - patterns.add>(patterns.getContext(), + patterns.add>(patterns.getContext(), typeConverter); target.addDynamicallyLegalOp( [&](Op op) { return typeConverter.isLegal(op->getResultTypes()); }); } -void populateWithMidLFHEApplyLookupTableParametrizationPattern( +void populateWithTFHEApplyLookupTableParametrizationPattern( mlir::RewritePatternSet &patterns, mlir::ConversionTarget &target, mlir::TypeConverter &typeConverter, mlir::concretelang::V0Parameter &v0Parameter) { - patterns.add( + patterns.add( patterns.getContext(), typeConverter, v0Parameter); - target.addDynamicallyLegalOp( - [&](mlir::concretelang::MidLFHE::ApplyLookupTable op) { + target.addDynamicallyLegalOp( + [&](mlir::concretelang::TFHE::ApplyLookupTable op) { if (op.glweDimension() != v0Parameter.glweDimension || // TODO remove the shift when we have true polynomial size op.polynomialSize() != (1 << v0Parameter.logPolynomialSize) || @@ -232,50 +232,50 @@ void populateWithMidLFHEApplyLookupTableParametrizationPattern( }); } -void populateWithMidLFHEApplyLookupTablePaddingPattern( +void populateWithTFHEApplyLookupTablePaddingPattern( mlir::RewritePatternSet &patterns, mlir::ConversionTarget &target) { - patterns.add(patterns.getContext()); + patterns.add(patterns.getContext()); target.addLegalOp(); - target.addDynamicallyLegalOp( - [&](mlir::concretelang::MidLFHE::ApplyLookupTable op) { + target.addDynamicallyLegalOp( + [&](mlir::concretelang::TFHE::ApplyLookupTable op) { auto glweInType = op.getOperandTypes()[0] - .cast(); + .cast(); auto tabulatedLambdaType = op.getOperandTypes()[1].cast(); auto glweOutType = - op.getType().cast(); + op.getType().cast(); return tabulatedLambdaType.getShape()[0] == 1 << glweInType.getP(); }); } -/// Populate the RewritePatternSet with all patterns that rewrite LowLFHE +/// Populate the RewritePatternSet with all patterns that rewrite Concrete /// operators to the corresponding function call to the `Concrete C API`. -void populateWithMidLFHEOpTypeConversionPatterns( +void populateWithTFHEOpTypeConversionPatterns( mlir::RewritePatternSet &patterns, mlir::ConversionTarget &target, mlir::TypeConverter &typeConverter, mlir::concretelang::V0Parameter &v0Parameter) { - populateWithMidLFHEOpTypeConversionPattern< - mlir::concretelang::MidLFHE::ZeroGLWEOp>(patterns, target, typeConverter); - populateWithMidLFHEOpTypeConversionPattern< - mlir::concretelang::MidLFHE::AddGLWEIntOp>(patterns, target, typeConverter); - populateWithMidLFHEOpTypeConversionPattern< - mlir::concretelang::MidLFHE::AddGLWEOp>(patterns, target, typeConverter); - populateWithMidLFHEOpTypeConversionPattern< - mlir::concretelang::MidLFHE::SubIntGLWEOp>(patterns, target, typeConverter); - populateWithMidLFHEOpTypeConversionPattern< - mlir::concretelang::MidLFHE::NegGLWEOp>(patterns, target, typeConverter); - populateWithMidLFHEOpTypeConversionPattern< - mlir::concretelang::MidLFHE::MulGLWEIntOp>(patterns, target, typeConverter); - populateWithMidLFHEApplyLookupTableParametrizationPattern( + populateWithTFHEOpTypeConversionPattern< + mlir::concretelang::TFHE::ZeroGLWEOp>(patterns, target, typeConverter); + populateWithTFHEOpTypeConversionPattern< + mlir::concretelang::TFHE::AddGLWEIntOp>(patterns, target, typeConverter); + populateWithTFHEOpTypeConversionPattern< + mlir::concretelang::TFHE::AddGLWEOp>(patterns, target, typeConverter); + populateWithTFHEOpTypeConversionPattern< + mlir::concretelang::TFHE::SubIntGLWEOp>(patterns, target, typeConverter); + populateWithTFHEOpTypeConversionPattern< + mlir::concretelang::TFHE::NegGLWEOp>(patterns, target, typeConverter); + populateWithTFHEOpTypeConversionPattern< + mlir::concretelang::TFHE::MulGLWEIntOp>(patterns, target, typeConverter); + populateWithTFHEApplyLookupTableParametrizationPattern( patterns, target, typeConverter, v0Parameter); } -void MidLFHEGlobalParametrizationPass::runOnOperation() { +void TFHEGlobalParametrizationPass::runOnOperation() { auto op = this->getOperation(); - MidLFHEGlobalParametrizationTypeConverter converter(fheContext); + TFHEGlobalParametrizationTypeConverter converter(fheContext); // Parametrize { @@ -289,17 +289,17 @@ void MidLFHEGlobalParametrizationPass::runOnOperation() { }); mlir::populateFuncOpTypeConversionPattern(patterns, converter); - // Add all patterns to convert MidLFHE types - populateWithMidLFHEOpTypeConversionPatterns(patterns, target, converter, + // Add all patterns to convert TFHE types + populateWithTFHEOpTypeConversionPatterns(patterns, target, converter, fheContext.parameter); patterns.add>( + mlir::linalg::GenericOp, TFHEGlobalParametrizationTypeConverter>>( &getContext(), converter); patterns.add>( + mlir::tensor::GenerateOp, TFHEGlobalParametrizationTypeConverter>>( &getContext(), converter); patterns.add>( + mlir::scf::ForOp, TFHEGlobalParametrizationTypeConverter>>( &getContext(), converter); mlir::concretelang::populateWithTensorTypeConverterPatterns(patterns, target, converter); @@ -322,7 +322,7 @@ void MidLFHEGlobalParametrizationPass::runOnOperation() { mlir::ConversionTarget target(getContext()); mlir::OwningRewritePatternList patterns(&getContext()); - populateWithMidLFHEApplyLookupTablePaddingPattern(patterns, target); + populateWithTFHEApplyLookupTablePaddingPattern(patterns, target); // Apply conversion if (mlir::applyPartialConversion(op, target, std::move(patterns)) @@ -335,9 +335,9 @@ void MidLFHEGlobalParametrizationPass::runOnOperation() { namespace mlir { namespace concretelang { std::unique_ptr> -createConvertMidLFHEGlobalParametrizationPass( +createConvertTFHEGlobalParametrizationPass( mlir::concretelang::V0FHEContext &fheContext) { - return std::make_unique(fheContext); + return std::make_unique(fheContext); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Conversion/TFHEToConcrete/CMakeLists.txt b/compiler/lib/Conversion/TFHEToConcrete/CMakeLists.txt new file mode 100644 index 000000000..80ddce88b --- /dev/null +++ b/compiler/lib/Conversion/TFHEToConcrete/CMakeLists.txt @@ -0,0 +1,17 @@ +add_mlir_dialect_library(TFHEToConcrete + TFHEToConcrete.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/TFHE + + DEPENDS + TFHEDialect + ConcreteDialect + TFHEToConcretePatternsIncGen + + LINK_LIBS PUBLIC + MLIRIR + MLIRTransforms + MLIRMath) + +target_link_libraries(TFHEToConcrete PUBLIC MLIRIR) diff --git a/compiler/lib/Conversion/MidLFHEToLowLFHE/MidLFHEToLowLFHE.cpp b/compiler/lib/Conversion/TFHEToConcrete/TFHEToConcrete.cpp similarity index 68% rename from compiler/lib/Conversion/MidLFHEToLowLFHE/MidLFHEToLowLFHE.cpp rename to compiler/lib/Conversion/TFHEToConcrete/TFHEToConcrete.cpp index 27e33b151..7309f925b 100644 --- a/compiler/lib/Conversion/MidLFHEToLowLFHE/MidLFHEToLowLFHE.cpp +++ b/compiler/lib/Conversion/TFHEToConcrete/TFHEToConcrete.cpp @@ -6,32 +6,32 @@ #include "mlir/Pass/Pass.h" #include "mlir/Transforms/DialectConversion.h" -#include "concretelang/Conversion/MidLFHEToLowLFHE/Patterns.h" +#include "concretelang/Conversion/TFHEToConcrete/Patterns.h" #include "concretelang/Conversion/Passes.h" #include "concretelang/Conversion/Utils/RegionOpTypeConverterPattern.h" #include "concretelang/Conversion/Utils/TensorOpTypeConversion.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteDialect.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" +#include "concretelang/Dialect/TFHE/IR/TFHEDialect.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" #include "concretelang/Dialect/RT/IR/RTOps.h" namespace { -struct MidLFHEToLowLFHEPass - : public MidLFHEToLowLFHEBase { +struct TFHEToConcretePass + : public TFHEToConcreteBase { void runOnOperation() final; }; } // namespace -using mlir::concretelang::LowLFHE::LweCiphertextType; -using mlir::concretelang::MidLFHE::GLWECipherTextType; +using mlir::concretelang::Concrete::LweCiphertextType; +using mlir::concretelang::TFHE::GLWECipherTextType; -/// MidLFHEToLowLFHETypeConverter is a TypeConverter that transform -/// `MidLFHE.glwe<{_,_,_}{p}>` to LowLFHE.lwe_ciphertext -class MidLFHEToLowLFHETypeConverter : public mlir::TypeConverter { +/// TFHEToConcreteTypeConverter is a TypeConverter that transform +/// `TFHE.glwe<{_,_,_}{p}>` to Concrete.lwe_ciphertext +class TFHEToConcreteTypeConverter : public mlir::TypeConverter { public: - MidLFHEToLowLFHETypeConverter() { + TFHEToConcreteTypeConverter() { addConversion([](mlir::Type type) { return type; }); addConversion([&](GLWECipherTextType type) { return mlir::concretelang::convertTypeToLWE(type.getContext(), type); @@ -49,17 +49,17 @@ public: } }; -void MidLFHEToLowLFHEPass::runOnOperation() { +void TFHEToConcretePass::runOnOperation() { auto op = this->getOperation(); mlir::ConversionTarget target(getContext()); - MidLFHEToLowLFHETypeConverter converter; + TFHEToConcreteTypeConverter converter; // Mark ops from the target dialect as legal operations - target.addLegalDialect(); + target.addLegalDialect(); - // Make sure that no ops from `MidLFHE` remain after the lowering - target.addIllegalDialect(); + // Make sure that no ops from `TFHE` remain after the lowering + target.addIllegalDialect(); // Make sure that no ops `linalg.generic` that have illegal types target.addDynamicallyLegalOp>( + TFHEToConcreteTypeConverter>>( &getContext(), converter); patterns.add>( + TFHEToConcreteTypeConverter>>( &getContext(), converter); patterns.add>( + TFHEToConcreteTypeConverter>>( &getContext(), converter); mlir::concretelang::populateWithTensorTypeConverterPatterns(patterns, target, converter); @@ -107,8 +107,8 @@ void MidLFHEToLowLFHEPass::runOnOperation() { namespace mlir { namespace concretelang { -std::unique_ptr> createConvertMidLFHEToLowLFHEPass() { - return std::make_unique(); +std::unique_ptr> createConvertTFHEToConcretePass() { + return std::make_unique(); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Dialect/CMakeLists.txt b/compiler/lib/Dialect/CMakeLists.txt index 3f199807c..22156f5be 100644 --- a/compiler/lib/Dialect/CMakeLists.txt +++ b/compiler/lib/Dialect/CMakeLists.txt @@ -1,5 +1,5 @@ -add_subdirectory(HLFHELinalg) -add_subdirectory(HLFHE) -add_subdirectory(MidLFHE) -add_subdirectory(LowLFHE) +add_subdirectory(FHELinalg) +add_subdirectory(FHE) +add_subdirectory(TFHE) +add_subdirectory(Concrete) add_subdirectory(RT) diff --git a/compiler/lib/Dialect/LowLFHE/CMakeLists.txt b/compiler/lib/Dialect/Concrete/CMakeLists.txt similarity index 100% rename from compiler/lib/Dialect/LowLFHE/CMakeLists.txt rename to compiler/lib/Dialect/Concrete/CMakeLists.txt diff --git a/compiler/lib/Dialect/Concrete/IR/CMakeLists.txt b/compiler/lib/Dialect/Concrete/IR/CMakeLists.txt new file mode 100644 index 000000000..287bff284 --- /dev/null +++ b/compiler/lib/Dialect/Concrete/IR/CMakeLists.txt @@ -0,0 +1,14 @@ +add_mlir_dialect_library(ConcreteDialect + ConcreteDialect.cpp + ConcreteOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/Concrete + + DEPENDS + MLIRConcreteOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR) + +target_link_libraries(ConcreteDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/LowLFHE/IR/LowLFHEDialect.cpp b/compiler/lib/Dialect/Concrete/IR/ConcreteDialect.cpp similarity index 54% rename from compiler/lib/Dialect/LowLFHE/IR/LowLFHEDialect.cpp rename to compiler/lib/Dialect/Concrete/IR/ConcreteDialect.cpp index 36f083e50..303272368 100644 --- a/compiler/lib/Dialect/LowLFHE/IR/LowLFHEDialect.cpp +++ b/compiler/lib/Dialect/Concrete/IR/ConcreteDialect.cpp @@ -1,30 +1,30 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteDialect.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOpsTypes.cpp.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOpsTypes.cpp.inc" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOpsDialect.cpp.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOpsDialect.cpp.inc" -using namespace mlir::concretelang::LowLFHE; +using namespace mlir::concretelang::Concrete; -void LowLFHEDialect::initialize() { +void ConcreteDialect::initialize() { addOperations< #define GET_OP_LIST -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.cpp.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.cpp.inc" >(); addTypes< #define GET_TYPEDEF_LIST -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOpsTypes.cpp.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOpsTypes.cpp.inc" >(); } -::mlir::Type LowLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const { +::mlir::Type ConcreteDialect::parseType(::mlir::DialectAsmParser &parser) const { mlir::Type type; std::string types_str[] = { @@ -40,14 +40,14 @@ void LowLFHEDialect::initialize() { } } - parser.emitError(parser.getCurrentLocation(), "Unknown LowLFHE type"); + parser.emitError(parser.getCurrentLocation(), "Unknown Concrete type"); return type; } -void LowLFHEDialect::printType(::mlir::Type type, +void ConcreteDialect::printType(::mlir::Type type, ::mlir::DialectAsmPrinter &printer) const { if (generatedTypePrinter(type, printer).failed()) - // Calling default printer if failed to print LowLFHE type + // Calling default printer if failed to print Concrete type printer.printType(type); } diff --git a/compiler/lib/Dialect/LowLFHE/IR/LowLFHEOps.cpp b/compiler/lib/Dialect/Concrete/IR/ConcreteOps.cpp similarity index 53% rename from compiler/lib/Dialect/LowLFHE/IR/LowLFHEOps.cpp rename to compiler/lib/Dialect/Concrete/IR/ConcreteOps.cpp index 653f6cdc4..c26a59b2b 100644 --- a/compiler/lib/Dialect/LowLFHE/IR/LowLFHEOps.cpp +++ b/compiler/lib/Dialect/Concrete/IR/ConcreteOps.cpp @@ -1,8 +1,8 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #define GET_OP_CLASSES -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEOps.cpp.inc" +#include "concretelang/Dialect/Concrete/IR/ConcreteOps.cpp.inc" diff --git a/compiler/lib/Dialect/FHE/Analysis/CMakeLists.txt b/compiler/lib/Dialect/FHE/Analysis/CMakeLists.txt new file mode 100644 index 000000000..ac50c758c --- /dev/null +++ b/compiler/lib/Dialect/FHE/Analysis/CMakeLists.txt @@ -0,0 +1,15 @@ +add_mlir_library(FHEDialectAnalysis + MANP.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHE + + DEPENDS + FHEDialect + MANPPassIncGen + + LINK_LIBS PUBLIC + MLIRIR + FHEDialect) + +target_link_libraries(FHEDialectAnalysis PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/HLFHE/Analysis/MANP.cpp b/compiler/lib/Dialect/FHE/Analysis/MANP.cpp similarity index 89% rename from compiler/lib/Dialect/HLFHE/Analysis/MANP.cpp rename to compiler/lib/Dialect/FHE/Analysis/MANP.cpp index c9d1b3ee6..e835270dd 100644 --- a/compiler/lib/Dialect/HLFHE/Analysis/MANP.cpp +++ b/compiler/lib/Dialect/FHE/Analysis/MANP.cpp @@ -2,11 +2,11 @@ // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -24,7 +24,7 @@ #include #define GEN_PASS_CLASSES -#include +#include namespace mlir { namespace concretelang { @@ -43,12 +43,12 @@ static bool isEncryptedFunctionParameter(mlir::Value value) { return false; } - return (value.getType().isa() || + return (value.getType().isa() || (value.getType().isa() && value.getType() .cast() .getElementType() - .isa())); + .isa())); } // Returns the bit width of `value` if `value` is an encrypted integer @@ -57,13 +57,13 @@ static bool isEncryptedFunctionParameter(mlir::Value value) { static unsigned int getEintPrecision(mlir::Value value) { if (auto ty = value.getType() .dyn_cast_or_null< - mlir::concretelang::HLFHE::EncryptedIntegerType>()) { + mlir::concretelang::FHE::EncryptedIntegerType>()) { return ty.getWidth(); } else if (auto tensorTy = value.getType().dyn_cast_or_null()) { if (auto ty = tensorTy.getElementType() .dyn_cast_or_null< - mlir::concretelang::HLFHE::EncryptedIntegerType>()) + mlir::concretelang::FHE::EncryptedIntegerType>()) return ty.getWidth(); } @@ -273,9 +273,9 @@ static llvm::APInt denseDynTensorNorm2Sq(mlir::TensorType tTy, } // Calculates the squared Minimal Arithmetic Noise Padding of an -// `HLFHELinalg.dot_eint_int` operation. +// `FHELinalg.dot_eint_int` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::Dot op, + mlir::concretelang::FHELinalg::Dot op, llvm::ArrayRef *> operandMANPs) { assert(operandMANPs.size() == 2 && operandMANPs[0]->getValue().getMANP().hasValue() && @@ -319,9 +319,9 @@ static llvm::APInt conservativeIntNorm2Sq(mlir::Type t) { } // Calculates the squared Minimal Arithmetic Noise Padding of an -// `HLFHE.add_eint_int` operation. +// `FHE.add_eint_int` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHE::AddEintIntOp op, + mlir::concretelang::FHE::AddEintIntOp op, llvm::ArrayRef *> operandMANPs) { mlir::Type iTy = op->getOpOperand(1).get().getType(); @@ -354,9 +354,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHE.add_eint` operation. +// that is equivalent to an `FHE.add_eint` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHE::AddEintOp op, + mlir::concretelang::FHE::AddEintOp op, llvm::ArrayRef *> operandMANPs) { assert(operandMANPs.size() == 2 && operandMANPs[0]->getValue().getMANP().hasValue() && @@ -371,9 +371,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHE.sub_int_eint` operation. +// that is equivalent to an `FHE.sub_int_eint` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHE::SubIntEintOp op, + mlir::concretelang::FHE::SubIntEintOp op, llvm::ArrayRef *> operandMANPs) { mlir::Type iTy = op->getOpOperand(0).get().getType(); @@ -405,9 +405,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHE.neg_eint` operation. +// that is equivalent to an `FHE.neg_eint` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHE::NegEintOp op, + mlir::concretelang::FHE::NegEintOp op, llvm::ArrayRef *> operandMANPs) { assert( @@ -421,9 +421,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHE.mul_eint_int` operation. +// that is equivalent to an `FHE.mul_eint_int` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHE::MulEintIntOp op, + mlir::concretelang::FHE::MulEintIntOp op, llvm::ArrayRef *> operandMANPs) { mlir::Type iTy = op->getOpOperand(1).get().getType(); @@ -456,9 +456,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of an -// `HLFHELinalg.add_eint_int` operation. +// `FHELinalg.add_eint_int` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::AddEintIntOp op, + mlir::concretelang::FHELinalg::AddEintIntOp op, llvm::ArrayRef *> operandMANPs) { mlir::RankedTensorType op1Ty = @@ -504,7 +504,7 @@ static llvm::APInt getSqMANP( } static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::AddEintOp op, + mlir::concretelang::FHELinalg::AddEintOp op, llvm::ArrayRef *> operandMANPs) { assert(operandMANPs.size() == 2 && operandMANPs[0]->getValue().getMANP().hasValue() && @@ -519,9 +519,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHELinalg.sub_int_eint` operation. +// that is equivalent to an `FHELinalg.sub_int_eint` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::SubIntEintOp op, + mlir::concretelang::FHELinalg::SubIntEintOp op, llvm::ArrayRef *> operandMANPs) { mlir::RankedTensorType op0Ty = @@ -566,9 +566,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHELinalg.neg_eint` operation. +// that is equivalent to an `FHELinalg.neg_eint` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::NegEintOp op, + mlir::concretelang::FHELinalg::NegEintOp op, llvm::ArrayRef *> operandMANPs) { assert( @@ -582,9 +582,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHE.mul_eint_int` operation. +// that is equivalent to an `FHE.mul_eint_int` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::MulEintIntOp op, + mlir::concretelang::FHELinalg::MulEintIntOp op, llvm::ArrayRef *> operandMANPs) { mlir::RankedTensorType op0Ty = @@ -630,9 +630,9 @@ static llvm::APInt getSqMANP( } // Calculates the squared Minimal Arithmetic Noise Padding of a dot operation -// that is equivalent to an `HLFHE.mul_eint_int` operation. +// that is equivalent to an `FHE.mul_eint_int` operation. static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::MatMulEintIntOp op, + mlir::concretelang::FHELinalg::MatMulEintIntOp op, llvm::ArrayRef *> operandMANPs) { mlir::RankedTensorType rhsTy = @@ -684,8 +684,8 @@ static llvm::APInt getSqMANP( // For a dynamic operand conservatively assume that the value is // the maximum for the integer width llvm::APInt rhsNorm = conservativeIntNorm2Sq(iTy); - // For tensor = tensor * tensor they are P HLFHE.mul_eint_int - // and HLFHE.add_eint operations for each elements of the result + // For tensor = tensor * tensor they are P FHE.mul_eint_int + // and FHE.add_eint operations for each elements of the result int64_t P = rhsTy.getShape()[0]; for (int64_t i = 0; i < P; i++) { llvm::APInt mulNorm = APIntWidthExtendUMul(lhsNorm, rhsNorm); @@ -697,7 +697,7 @@ static llvm::APInt getSqMANP( } static llvm::APInt getSqMANP( - mlir::concretelang::HLFHELinalg::MatMulIntEintOp op, + mlir::concretelang::FHELinalg::MatMulIntEintOp op, llvm::ArrayRef *> operandMANPs) { mlir::RankedTensorType rhsTy = @@ -749,8 +749,8 @@ static llvm::APInt getSqMANP( // For a dynamic operand conservatively assume that the value is // the maximum for the integer width llvm::APInt lhsNorm = conservativeIntNorm2Sq(iTy); - // For tensor = tensor * tensor they are P HLFHE.mul_eint_int - // and HLFHE.add_eint operations for each elements of the result + // For tensor = tensor * tensor they are P FHE.mul_eint_int + // and FHE.add_eint operations for each elements of the result int64_t P = rhsTy.getShape()[0]; for (int64_t i = 0; i < P; i++) { llvm::APInt mulNorm = APIntWidthExtendUMul(rhsNorm, lhsNorm); @@ -852,61 +852,61 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { bool isDummy = false; llvm::APInt norm2SqEquiv; - // HLFHE Operators + // FHE Operators if (auto addEintIntOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(addEintIntOp, operands); } else if (auto addEintOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(addEintOp, operands); } else if (auto subIntEintOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(subIntEintOp, operands); } else if (auto negEintOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(negEintOp, operands); } else if (auto mulEintIntOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(mulEintIntOp, operands); - } else if (llvm::isa(op) || - llvm::isa(op) || - llvm::isa(op)) { + } else if (llvm::isa(op) || + llvm::isa(op) || + llvm::isa(op)) { norm2SqEquiv = llvm::APInt{1, 1, false}; } - // HLFHELinalg Operators + // FHELinalg Operators else if (auto dotOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(dotOp, operands); } else if (auto addEintIntOp = - llvm::dyn_cast( + llvm::dyn_cast( op)) { norm2SqEquiv = getSqMANP(addEintIntOp, operands); } else if (auto addEintOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(addEintOp, operands); } else if (auto subIntEintOp = - llvm::dyn_cast( + llvm::dyn_cast( op)) { norm2SqEquiv = getSqMANP(subIntEintOp, operands); } else if (auto negEintOp = - llvm::dyn_cast(op)) { + llvm::dyn_cast(op)) { norm2SqEquiv = getSqMANP(negEintOp, operands); } else if (auto mulEintIntOp = - llvm::dyn_cast( + llvm::dyn_cast( op)) { norm2SqEquiv = getSqMANP(mulEintIntOp, operands); } else if (auto matmulEintIntOp = - llvm::dyn_cast( + llvm::dyn_cast( op)) { norm2SqEquiv = getSqMANP(matmulEintIntOp, operands); } else if (auto matmulIntEintOp = - llvm::dyn_cast( + llvm::dyn_cast( op)) { norm2SqEquiv = getSqMANP(matmulIntEintOp, operands); } else if (llvm::isa< - mlir::concretelang::HLFHELinalg::ApplyLookupTableEintOp, - mlir::concretelang::HLFHELinalg::ApplyMultiLookupTableEintOp, - mlir::concretelang::HLFHELinalg::ApplyMappedLookupTableEintOp>( + mlir::concretelang::FHELinalg::ApplyLookupTableEintOp, + mlir::concretelang::FHELinalg::ApplyMultiLookupTableEintOp, + mlir::concretelang::FHELinalg::ApplyMappedLookupTableEintOp>( op)) { norm2SqEquiv = llvm::APInt{1, 1, false}; } @@ -915,7 +915,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { else if (auto extractOp = llvm::dyn_cast(op)) { if (extractOp.result() .getType() - .isa()) { + .isa()) { norm2SqEquiv = getSqMANP(extractOp, operands); } else { isDummy = true; @@ -928,7 +928,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { .getType() .cast() .getElementType() - .isa()) { + .isa()) { norm2SqEquiv = getSqMANP(extractSliceOp, operands); } else { isDummy = true; @@ -941,7 +941,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { .getType() .cast() .getElementType() - .isa()) { + .isa()) { norm2SqEquiv = getSqMANP(insertSliceOp, operands); } else { isDummy = true; @@ -953,7 +953,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { .getType() .cast() .getElementType() - .isa()) { + .isa()) { norm2SqEquiv = getSqMANP(fromOp, operands); } else { isDummy = true; @@ -966,7 +966,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { .getType() .cast() .getElementType() - .isa()) { + .isa()) { norm2SqEquiv = getSqMANP(reshapeOp, operands); } else { isDummy = true; @@ -979,7 +979,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { .getType() .cast() .getElementType() - .isa()) { + .isa()) { norm2SqEquiv = getSqMANP(reshapeOp, operands); } else { isDummy = true; @@ -988,7 +988,7 @@ struct MANPAnalysis : public mlir::ForwardDataFlowAnalysis { else if (llvm::isa(op)) { isDummy = true; - } else if (llvm::isa( + } else if (llvm::isa( *op->getDialect())) { op->emitError("Unsupported operation"); assert(false && "Unsupported operation"); @@ -1090,15 +1090,15 @@ protected: // Process all results using MANP attribute from MANP pas for (mlir::OpResult res : op->getResults()) { - mlir::concretelang::HLFHE::EncryptedIntegerType eTy = + mlir::concretelang::FHE::EncryptedIntegerType eTy = res.getType() - .dyn_cast_or_null(); + .dyn_cast_or_null(); if (eTy == nullptr) { auto tensorTy = res.getType().dyn_cast_or_null(); if (tensorTy != nullptr) { eTy = tensorTy.getElementType() .dyn_cast_or_null< - mlir::concretelang::HLFHE::EncryptedIntegerType>(); + mlir::concretelang::FHE::EncryptedIntegerType>(); } } diff --git a/compiler/lib/Dialect/HLFHE/CMakeLists.txt b/compiler/lib/Dialect/FHE/CMakeLists.txt similarity index 100% rename from compiler/lib/Dialect/HLFHE/CMakeLists.txt rename to compiler/lib/Dialect/FHE/CMakeLists.txt diff --git a/compiler/lib/Dialect/FHE/IR/CMakeLists.txt b/compiler/lib/Dialect/FHE/IR/CMakeLists.txt new file mode 100644 index 000000000..69cce21a8 --- /dev/null +++ b/compiler/lib/Dialect/FHE/IR/CMakeLists.txt @@ -0,0 +1,14 @@ +add_mlir_dialect_library(FHEDialect + FHEDialect.cpp + FHEOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHE + + DEPENDS + MLIRFHEOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR) + +target_link_libraries(FHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp b/compiler/lib/Dialect/FHE/IR/FHEDialect.cpp similarity index 57% rename from compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp rename to compiler/lib/Dialect/FHE/IR/FHEDialect.cpp index 81174a010..b043d1308 100644 --- a/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp +++ b/compiler/lib/Dialect/FHE/IR/FHEDialect.cpp @@ -1,30 +1,30 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHEDialect.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/HLFHE/IR/HLFHEOpsTypes.cpp.inc" +#include "concretelang/Dialect/FHE/IR/FHEOpsTypes.cpp.inc" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOpsDialect.cpp.inc" +#include "concretelang/Dialect/FHE/IR/FHEOpsDialect.cpp.inc" -using namespace mlir::concretelang::HLFHE; +using namespace mlir::concretelang::FHE; -void HLFHEDialect::initialize() { +void FHEDialect::initialize() { addOperations< #define GET_OP_LIST -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.cpp.inc" +#include "concretelang/Dialect/FHE/IR/FHEOps.cpp.inc" >(); addTypes< #define GET_TYPEDEF_LIST -#include "concretelang/Dialect/HLFHE/IR/HLFHEOpsTypes.cpp.inc" +#include "concretelang/Dialect/FHE/IR/FHEOpsTypes.cpp.inc" >(); } -::mlir::Type HLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const { +::mlir::Type FHEDialect::parseType(::mlir::DialectAsmParser &parser) const { mlir::Type type; if (parser.parseOptionalKeyword("eint").succeeded()) { @@ -40,17 +40,17 @@ void HLFHEDialect::initialize() { return type; } -void HLFHEDialect::printType(::mlir::Type type, +void FHEDialect::printType(::mlir::Type type, ::mlir::DialectAsmPrinter &printer) const { if (generatedTypePrinter(type, printer).failed()) - // Calling default printer if failed to print HLFHE type + // Calling default printer if failed to print FHE type printer.printType(type); } mlir::LogicalResult EncryptedIntegerType::verify( llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, unsigned p) { if (p == 0 || p > 7) { - emitError() << "HLFHE.eint support only precision in ]0;7]"; + emitError() << "FHE.eint support only precision in ]0;7]"; return mlir::failure(); } return mlir::success(); diff --git a/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp b/compiler/lib/Dialect/FHE/IR/FHEOps.cpp similarity index 95% rename from compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp rename to compiler/lib/Dialect/FHE/IR/FHEOps.cpp index bbb002fcd..9639d1681 100644 --- a/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp +++ b/compiler/lib/Dialect/FHE/IR/FHEOps.cpp @@ -4,12 +4,12 @@ #include "mlir/IR/Region.h" #include "mlir/IR/TypeUtilities.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" namespace mlir { namespace concretelang { -namespace HLFHE { +namespace FHE { bool verifyEncryptedIntegerInputAndResultConsistency( ::mlir::OpState &op, EncryptedIntegerType &input, @@ -125,9 +125,9 @@ bool verifyEncryptedIntegerInputsConsistency(::mlir::OpState &op, return mlir::success(); } -} // namespace HLFHE +} // namespace FHE } // namespace concretelang } // namespace mlir #define GET_OP_CLASSES -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.cpp.inc" +#include "concretelang/Dialect/FHE/IR/FHEOps.cpp.inc" diff --git a/compiler/lib/Dialect/HLFHELinalg/CMakeLists.txt b/compiler/lib/Dialect/FHELinalg/CMakeLists.txt similarity index 100% rename from compiler/lib/Dialect/HLFHELinalg/CMakeLists.txt rename to compiler/lib/Dialect/FHELinalg/CMakeLists.txt diff --git a/compiler/lib/Dialect/FHELinalg/IR/CMakeLists.txt b/compiler/lib/Dialect/FHELinalg/IR/CMakeLists.txt new file mode 100644 index 000000000..d45647a4d --- /dev/null +++ b/compiler/lib/Dialect/FHELinalg/IR/CMakeLists.txt @@ -0,0 +1,14 @@ +add_mlir_dialect_library(FHELinalgDialect + FHELinalgDialect.cpp + FHELinalgOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHELinalg + + DEPENDS + MLIRFHELinalgOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR) + +target_link_libraries(FHELinalgDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/FHELinalg/IR/FHELinalgDialect.cpp b/compiler/lib/Dialect/FHELinalg/IR/FHELinalgDialect.cpp new file mode 100644 index 000000000..769db36b6 --- /dev/null +++ b/compiler/lib/Dialect/FHELinalg/IR/FHELinalgDialect.cpp @@ -0,0 +1,25 @@ +// Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. +// See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. + +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgDialect.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h" + +#define GET_TYPEDEF_CLASSES +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOpsTypes.cpp.inc" + +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOpsDialect.cpp.inc" + +using namespace mlir::concretelang::FHELinalg; + +void FHELinalgDialect::initialize() { + addOperations< +#define GET_OP_LIST +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.cpp.inc" + >(); + + addTypes< +#define GET_TYPEDEF_LIST +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOpsTypes.cpp.inc" + >(); +} diff --git a/compiler/lib/Dialect/HLFHELinalg/IR/HLFHELinalgOps.cpp b/compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp similarity index 88% rename from compiler/lib/Dialect/HLFHELinalg/IR/HLFHELinalgOps.cpp rename to compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp index 5aa5b82fb..9485f2af6 100644 --- a/compiler/lib/Dialect/HLFHELinalg/IR/HLFHELinalgOps.cpp +++ b/compiler/lib/Dialect/FHELinalg/IR/FHELinalgOps.cpp @@ -3,9 +3,9 @@ #include "mlir/IR/TypeUtilities.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.h" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgTypes.h" namespace mlir { namespace OpTrait { @@ -111,9 +111,9 @@ LogicalResult verifyTensorBinaryEintInt(mlir::Operation *op) { } auto el0Ty = op0Ty.getElementType() - .dyn_cast_or_null(); + .dyn_cast_or_null(); if (el0Ty == nullptr) { - op->emitOpError() << "should have a !HLFHE.eint as the element type of the " + op->emitOpError() << "should have a !FHE.eint as the element type of the " "tensor of operand #0"; return mlir::failure(); } @@ -151,9 +151,9 @@ LogicalResult verifyTensorBinaryIntEint(mlir::Operation *op) { } auto el1Ty = op1Ty.getElementType() - .dyn_cast_or_null(); + .dyn_cast_or_null(); if (el1Ty == nullptr) { - op->emitOpError() << "should have a !HLFHE.eint as the element type of the " + op->emitOpError() << "should have a !FHE.eint as the element type of the " "tensor of operand #1"; return mlir::failure(); } @@ -179,17 +179,17 @@ LogicalResult verifyTensorBinaryEint(mlir::Operation *op) { } auto el0Ty = op0Ty.getElementType() - .dyn_cast_or_null(); + .dyn_cast_or_null(); if (el0Ty == nullptr) { - op->emitOpError() << "should have a !HLFHE.eint as the element type of the " + op->emitOpError() << "should have a !FHE.eint as the element type of the " "tensor of operand #0"; return mlir::failure(); } auto el1Ty = op1Ty.getElementType() - .dyn_cast_or_null(); + .dyn_cast_or_null(); if (el1Ty == nullptr) { - op->emitOpError() << "should have a !HLFHE.eint as the element type of the " + op->emitOpError() << "should have a !FHE.eint as the element type of the " "tensor of operand #1"; return mlir::failure(); } @@ -214,9 +214,9 @@ LogicalResult verifyTensorUnaryEint(mlir::Operation *op) { } auto el0Ty = op0Ty.getElementType() - .dyn_cast_or_null(); + .dyn_cast_or_null(); if (el0Ty == nullptr) { - op->emitOpError() << "should have a !HLFHE.eint as the element type of the " + op->emitOpError() << "should have a !FHE.eint as the element type of the " "tensor operand"; return mlir::failure(); } @@ -230,12 +230,12 @@ LogicalResult verifyTensorUnaryEint(mlir::Operation *op) { namespace mlir { namespace concretelang { -namespace HLFHELinalg { +namespace FHELinalg { mlir::LogicalResult verifyApplyLookupTable(ApplyLookupTableEintOp &op) { auto tTy = op.t().getType().cast(); auto tEltTy = - tTy.getElementType().cast(); + tTy.getElementType().cast(); auto lutTy = op.lut().getType().cast(); auto lutEltTy = lutTy.getElementType().cast(); auto resultTy = op.getResult().getType().cast(); @@ -261,7 +261,7 @@ mlir::LogicalResult verifyApplyMultiLookupTable(ApplyMultiLookupTableEintOp &op) { auto tTy = op.t().getType().cast(); auto tEltTy = - tTy.getElementType().cast(); + tTy.getElementType().cast(); auto lutTy = op.luts().getType().cast(); auto lutEltTy = lutTy.getElementType().cast(); auto resultTy = op.getResult().getType().cast(); @@ -297,9 +297,9 @@ mlir::IntegerType getClearElmentType(::mlir::Value value) { return getElmentType(value); } -HLFHE::EncryptedIntegerType getEncryptedElmentType(::mlir::Value value) { - using namespace mlir::concretelang::HLFHE; - return getElmentType(value); +FHE::EncryptedIntegerType getEncryptedElmentType(::mlir::Value value) { + using namespace mlir::concretelang::FHE; + return getElmentType(value); } mlir::LogicalResult verifyMapHasRightShape(ApplyMappedLookupTableEintOp &op, @@ -335,7 +335,7 @@ mlir::LogicalResult verifyLutsSize(ApplyMappedLookupTableEintOp &op, if (actual_lut_size == expected_lut_size) { return mlir::success(); } - HLFHE::emitErrorBadLutSize(op, "luts", "ct", expected_lut_size, index_width); + FHE::emitErrorBadLutSize(op, "luts", "ct", expected_lut_size, index_width); return mlir::failure(); } @@ -372,19 +372,19 @@ verifyApplyMappedLookupTable(ApplyMappedLookupTableEintOp &op) { .getType() .cast() .getElementType() - .cast(); + .cast(); auto rhsEltType = op.rhs() .getType() .cast() .getElementType() .cast(); auto resultType = - op.getResult().getType().cast(); - if (!mlir::concretelang::HLFHE::verifyEncryptedIntegerAndIntegerInputsConsistency( + op.getResult().getType().cast(); + if (!mlir::concretelang::FHE::verifyEncryptedIntegerAndIntegerInputsConsistency( op, lhsEltType, rhsEltType)) { return ::mlir::failure(); } - if (!HLFHE::verifyEncryptedIntegerInputAndResultConsistency(op, lhsEltType, + if (!FHE::verifyEncryptedIntegerInputAndResultConsistency(op, lhsEltType, resultType)) { return ::mlir::failure(); } @@ -422,9 +422,9 @@ template mlir::LogicalResult verifyMatmul(MatMulOp &op) { } return mlir::success(); } -} // namespace HLFHELinalg +} // namespace FHELinalg } // namespace concretelang } // namespace mlir #define GET_OP_CLASSES -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.cpp.inc" +#include "concretelang/Dialect/FHELinalg/IR/FHELinalgOps.cpp.inc" diff --git a/compiler/lib/Dialect/FHELinalg/Transforms/CMakeLists.txt b/compiler/lib/Dialect/FHELinalg/Transforms/CMakeLists.txt new file mode 100644 index 000000000..250a81e35 --- /dev/null +++ b/compiler/lib/Dialect/FHELinalg/Transforms/CMakeLists.txt @@ -0,0 +1,15 @@ +add_mlir_library(FHELinalgDialectTransforms + Tiling.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/FHELinalg + + DEPENDS + FHELinalgDialect + ConcretelangFHELinalgTilingPassIncGen + + LINK_LIBS PUBLIC + MLIRIR + FHELinalgDialect) + +target_link_libraries(FHELinalgDialectTransforms PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/HLFHELinalg/Transforms/Tiling.cpp b/compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp similarity index 86% rename from compiler/lib/Dialect/HLFHELinalg/Transforms/Tiling.cpp rename to compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp index d81375c51..786addbb9 100644 --- a/compiler/lib/Dialect/HLFHELinalg/Transforms/Tiling.cpp +++ b/compiler/lib/Dialect/FHELinalg/Transforms/Tiling.cpp @@ -8,10 +8,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace mlir { @@ -103,11 +103,11 @@ mlir::scf::ForOp buildLoopNestWithLoopCarriedDependency( // Marker to avoid infinite recursion of the rewriting pattern static const mlir::StringLiteral kTransformMarker = - "__internal_hlfhe_linalg_tiling_marker__"; + "__internal_fhe_linalg_tiling_marker__"; -// Rewrite an `HLFHELinalg.matmul_eint_int` operation as an equivalent +// 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 `HLFHELinalg.matmul_eint_int` operation that performs +// loops with a `FHELinalg.matmul_eint_int` operation that performs // a matrix multiplication on a single tile. // // The terminology is as follows: @@ -117,21 +117,21 @@ static const mlir::StringLiteral kTransformMarker = // - C: The output matrix of encrypted integers of size `NxK` // // At each iteration of the innermost loop, the generated -// `HLFHELinalg.matmul_eint_int` operation performs a multiplication +// `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::HLFHELinalg::MatMulEintIntOp> { + mlir::concretelang::FHELinalg::MatMulEintIntOp> { public: MatMulTilingPattern(mlir::MLIRContext *context) - : mlir::OpRewritePattern( + : mlir::OpRewritePattern( context, ::mlir::concretelang::DEFAULT_PATTERN_BENEFIT) {} mlir::LogicalResult - matchAndRewrite(mlir::concretelang::HLFHELinalg::MatMulEintIntOp op, + matchAndRewrite(mlir::concretelang::FHELinalg::MatMulEintIntOp op, mlir::PatternRewriter &rewriter) const override { // Avoid infinite recursion by marking each matmul operation and // bailing out for the marker @@ -186,8 +186,8 @@ public: mlir::Value B = op.getOperand(1); // Initialization of the output matrix with zeros - mlir::concretelang::HLFHELinalg::ZeroOp Cinit = - rewriter.create( + mlir::concretelang::FHELinalg::ZeroOp Cinit = + rewriter.create( origLoc, op.getResult().getType()); mlir::TensorType ATTy = A.getType().cast(); @@ -259,8 +259,8 @@ public: {inductionVars[0], inductionVars[2]}); // Multiplication of the tiles - mlir::concretelang::HLFHELinalg::MatMulEintIntOp tiledMul = - builder.create( + mlir::concretelang::FHELinalg::MatMulEintIntOp tiledMul = + builder.create( origLoc, mlir::RankedTensorType::get(llvm::SmallVector{iT, iV}, CTTy.getElementType()), @@ -273,8 +273,8 @@ public: // Add result of the multiplication of the tiles to the // result tile from C - mlir::concretelang::HLFHELinalg::AddEintOp accuTile = - builder.create(origLoc, CTile, + mlir::concretelang::FHELinalg::AddEintOp accuTile = + builder.create(origLoc, CTile, tiledMul); // Write updated C tile back into C @@ -308,10 +308,10 @@ public: } }; -// Perfoms the actual tiling of `HLFHELinalg.matmul_eint_int` +// Perfoms the actual tiling of `FHELinalg.matmul_eint_int` // operations that have been marked with a "tile-sizes" attribute. -class HLFHELinalgTilingPass - : public HLFHELinalgTilingBase { +class FHELinalgTilingPass + : public FHELinalgTilingBase { public: void runOnOperation() override { mlir::Operation *op = getOperation(); @@ -323,18 +323,18 @@ public: this->signalPassFailure(); } - op->walk([](mlir::concretelang::HLFHELinalg::MatMulEintIntOp matmulOp) { + op->walk([](mlir::concretelang::FHELinalg::MatMulEintIntOp matmulOp) { matmulOp.getOperation()->removeAttr(kTransformMarker); }); } }; -// Marks all `HLFHELinalg.matmul_eint_int` operations that with a +// Marks all `FHELinalg.matmul_eint_int` operations that with a // "tile-sizes" attribute containing the specified tile sizes. -class HLFHELinalgTilingMarkerPass - : public HLFHELinalgTilingMarkerBase { +class FHELinalgTilingMarkerPass + : public FHELinalgTilingMarkerBase { public: - HLFHELinalgTilingMarkerPass(llvm::ArrayRef tileSizes) + FHELinalgTilingMarkerPass(llvm::ArrayRef tileSizes) : tileSizes(tileSizes.vec()) {} void runOnOperation() override { @@ -343,7 +343,7 @@ public: mlir::ArrayAttr tileAttr = mlir::Builder(&this->getContext()).getI64ArrayAttr(tileSizes); - op->walk([&](mlir::concretelang::HLFHELinalg::MatMulEintIntOp matmulOp) { + op->walk([&](mlir::concretelang::FHELinalg::MatMulEintIntOp matmulOp) { matmulOp.getOperation()->setAttr("tile-sizes", tileAttr); }); } @@ -353,13 +353,13 @@ protected: }; } // end anonymous namespace -std::unique_ptr> createHLFHELinalgTilingPass() { - return std::make_unique(); +std::unique_ptr> createFHELinalgTilingPass() { + return std::make_unique(); } std::unique_ptr> -createHLFHELinalgTilingMarkerPass(llvm::ArrayRef tileSizes) { - return std::make_unique(tileSizes); +createFHELinalgTilingMarkerPass(llvm::ArrayRef tileSizes) { + return std::make_unique(tileSizes); } } // namespace concretelang } // namespace mlir diff --git a/compiler/lib/Dialect/HLFHE/Analysis/CMakeLists.txt b/compiler/lib/Dialect/HLFHE/Analysis/CMakeLists.txt deleted file mode 100644 index f63ce373b..000000000 --- a/compiler/lib/Dialect/HLFHE/Analysis/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -add_mlir_library(HLFHEDialectAnalysis - MANP.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHE - - DEPENDS - HLFHEDialect - MANPPassIncGen - - LINK_LIBS PUBLIC - MLIRIR - HLFHEDialect) - -target_link_libraries(HLFHEDialectAnalysis PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/HLFHE/IR/CMakeLists.txt b/compiler/lib/Dialect/HLFHE/IR/CMakeLists.txt deleted file mode 100644 index c615091be..000000000 --- a/compiler/lib/Dialect/HLFHE/IR/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_mlir_dialect_library(HLFHEDialect - HLFHEDialect.cpp - HLFHEOps.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHE - - DEPENDS - MLIRHLFHEOpsIncGen - - LINK_LIBS PUBLIC - MLIRIR) - -target_link_libraries(HLFHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/HLFHELinalg/IR/CMakeLists.txt b/compiler/lib/Dialect/HLFHELinalg/IR/CMakeLists.txt deleted file mode 100644 index 6b0624d27..000000000 --- a/compiler/lib/Dialect/HLFHELinalg/IR/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_mlir_dialect_library(HLFHELinalgDialect - HLFHELinalgDialect.cpp - HLFHELinalgOps.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHELinalg - - DEPENDS - MLIRHLFHELinalgOpsIncGen - - LINK_LIBS PUBLIC - MLIRIR) - -target_link_libraries(HLFHELinalgDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.cpp b/compiler/lib/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.cpp deleted file mode 100644 index 156ed9d40..000000000 --- a/compiler/lib/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. -// See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. - -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgDialect.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.h" -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgTypes.h" - -#define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOpsTypes.cpp.inc" - -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOpsDialect.cpp.inc" - -using namespace mlir::concretelang::HLFHELinalg; - -void HLFHELinalgDialect::initialize() { - addOperations< -#define GET_OP_LIST -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOps.cpp.inc" - >(); - - addTypes< -#define GET_TYPEDEF_LIST -#include "concretelang/Dialect/HLFHELinalg/IR/HLFHELinalgOpsTypes.cpp.inc" - >(); -} diff --git a/compiler/lib/Dialect/HLFHELinalg/Transforms/CMakeLists.txt b/compiler/lib/Dialect/HLFHELinalg/Transforms/CMakeLists.txt deleted file mode 100644 index f8d4ea2f7..000000000 --- a/compiler/lib/Dialect/HLFHELinalg/Transforms/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -add_mlir_library(HLFHELinalgDialectTransforms - Tiling.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/HLFHELinalg - - DEPENDS - HLFHELinalgDialect - ConcretelangHLFHELinalgTilingPassIncGen - - LINK_LIBS PUBLIC - MLIRIR - HLFHELinalgDialect) - -target_link_libraries(HLFHELinalgDialectTransforms PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/LowLFHE/IR/CMakeLists.txt b/compiler/lib/Dialect/LowLFHE/IR/CMakeLists.txt deleted file mode 100644 index 43f028251..000000000 --- a/compiler/lib/Dialect/LowLFHE/IR/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_mlir_dialect_library(LowLFHEDialect - LowLFHEDialect.cpp - LowLFHEOps.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/LowLFHE - - DEPENDS - MLIRLowLFHEOpsIncGen - - LINK_LIBS PUBLIC - MLIRIR) - -target_link_libraries(LowLFHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/MidLFHE/IR/CMakeLists.txt b/compiler/lib/Dialect/MidLFHE/IR/CMakeLists.txt deleted file mode 100644 index 9791d34d2..000000000 --- a/compiler/lib/Dialect/MidLFHE/IR/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_mlir_dialect_library(MidLFHEDialect - MidLFHEDialect.cpp - MidLFHEOps.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/MidLFHE - - DEPENDS - MLIRMidLFHEOpsIncGen - - LINK_LIBS PUBLIC - MLIRIR) - -target_link_libraries(MidLFHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp b/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp index 3228bbabe..df7fe352e 100644 --- a/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp +++ b/compiler/lib/Dialect/RT/Analysis/BuildDataflowTaskGraph.cpp @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -40,19 +40,19 @@ namespace { // TODO: adjust these two functions based on cost model static bool isCandidateForTask(Operation *op) { - return isa(op); + return isa(op); } // 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); } @@ -141,7 +141,7 @@ struct BuildDataflowTaskGraphPass // nothing was simplified. Doing this here - rather than later // in the compilation pipeline - allows to take advantage of // higher level semantics which we can attach to operations - // (e.g., NoSideEffect on HLFHE::ZeroEintOp). + // (e.g., NoSideEffect on FHE::ZeroEintOp). IRRewriter rewriter(func->getContext()); (void)mlir::simplifyRegions(rewriter, func->getRegions()); }); diff --git a/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp b/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp index 5d3def8a7..e24934072 100644 --- a/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp +++ b/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp @@ -4,12 +4,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -162,13 +162,13 @@ static mlir::Value getSizeInBytes(Value val, Location loc, OpBuilder builder) { // FHE types are converted to pointers, so we take their size as 8 // bytes until we can get the actual size of the actual types. - if (type.isa() || - type.isa() || - type.isa() || - type.isa() || - type.isa() || - type.isa() || - type.isa()) + if (type.isa() || + type.isa() || + type.isa() || + type.isa() || + type.isa() || + type.isa() || + type.isa()) return builder.create(loc, builder.getI64IntegerAttr(8)); // For all other types, get type size. diff --git a/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp b/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp index f37c22dca..015e09fe6 100644 --- a/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp +++ b/compiler/lib/Dialect/RT/Analysis/LowerRTToLLVMDFRCallsConversionPatterns.cpp @@ -4,12 +4,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/compiler/lib/Dialect/MidLFHE/CMakeLists.txt b/compiler/lib/Dialect/TFHE/CMakeLists.txt similarity index 100% rename from compiler/lib/Dialect/MidLFHE/CMakeLists.txt rename to compiler/lib/Dialect/TFHE/CMakeLists.txt diff --git a/compiler/lib/Dialect/TFHE/IR/CMakeLists.txt b/compiler/lib/Dialect/TFHE/IR/CMakeLists.txt new file mode 100644 index 000000000..205a742e5 --- /dev/null +++ b/compiler/lib/Dialect/TFHE/IR/CMakeLists.txt @@ -0,0 +1,14 @@ +add_mlir_dialect_library(TFHEDialect + TFHEDialect.cpp + TFHEOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/TFHE + + DEPENDS + MLIRTFHEOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR) + +target_link_libraries(TFHEDialect PUBLIC MLIRIR) diff --git a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp b/compiler/lib/Dialect/TFHE/IR/TFHEDialect.cpp similarity index 59% rename from compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp rename to compiler/lib/Dialect/TFHE/IR/TFHEDialect.cpp index e8c7222c3..e43c5c938 100644 --- a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp +++ b/compiler/lib/Dialect/TFHE/IR/TFHEDialect.cpp @@ -1,40 +1,40 @@ // Part of the Concrete Compiler Project, under the BSD3 License with Zama Exceptions. // See https://github.com/zama-ai/homomorphizer/blob/master/LICENSE.txt for license information. -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/TFHE/IR/TFHEDialect.h" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" #define GET_TYPEDEF_CLASSES -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOpsTypes.cpp.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOpsTypes.cpp.inc" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOpsDialect.cpp.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOpsDialect.cpp.inc" -using namespace mlir::concretelang::MidLFHE; +using namespace mlir::concretelang::TFHE; -void MidLFHEDialect::initialize() { +void TFHEDialect::initialize() { addOperations< #define GET_OP_LIST -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.cpp.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.cpp.inc" >(); addTypes< #define GET_TYPEDEF_LIST -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOpsTypes.cpp.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOpsTypes.cpp.inc" >(); } -::mlir::Type MidLFHEDialect::parseType(::mlir::DialectAsmParser &parser) const { +::mlir::Type TFHEDialect::parseType(::mlir::DialectAsmParser &parser) const { if (parser.parseOptionalKeyword("glwe").succeeded()) return GLWECipherTextType::parse(parser); - parser.emitError(parser.getCurrentLocation(), "Unknown MidLFHE type"); + parser.emitError(parser.getCurrentLocation(), "Unknown TFHE type"); return ::mlir::Type(); } -void MidLFHEDialect::printType(::mlir::Type type, +void TFHEDialect::printType(::mlir::Type type, ::mlir::DialectAsmPrinter &printer) const { - mlir::concretelang::MidLFHE::GLWECipherTextType glwe = - type.dyn_cast_or_null(); + mlir::concretelang::TFHE::GLWECipherTextType glwe = + type.dyn_cast_or_null(); if (glwe != nullptr) { glwe.print(printer); return; diff --git a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp b/compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp similarity index 87% rename from compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp rename to compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp index 9d7a7a7b4..369716329 100644 --- a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEOps.cpp +++ b/compiler/lib/Dialect/TFHE/IR/TFHEOps.cpp @@ -3,13 +3,13 @@ #include "mlir/IR/Region.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEOps.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHEOps.h" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" namespace mlir { namespace concretelang { -namespace MidLFHE { +namespace TFHE { void emitOpErrorForIncompatibleGLWEParameter(mlir::OpState &op, llvm::Twine parameter) { @@ -50,8 +50,8 @@ mlir::LogicalResult _verifyGLWEIntegerOperator(mlir::OpState &op, } // verifyGLWEIntegerOperator verify parameters of operators that has the -// following signature (!MidLFHE.glwe<{dim,poly,bits}{p}>, ip+1) -> -// (!MidLFHE.glwe<{dim,poly,bits}{p}>)) +// 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(); @@ -63,8 +63,8 @@ mlir::LogicalResult verifyGLWEIntegerOperator(Operator &op) { } // verifyIntegerGLWEOperator verify parameters of operators that has the -// following signature (ip+1, !MidLFHE.glwe<{dim,poly,bits}{p}>) -> -// (!MidLFHE.glwe<{dim,poly,bits}{p}>)) +// 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(); @@ -76,9 +76,9 @@ mlir::LogicalResult verifyIntegerGLWEOperator(Operator &op) { } // verifyBinaryGLWEOperator verify parameters of operators that has the -// following signature (!MidLFHE.glwe<{dim,poly,bits}{p}>, -// !MidLFHE.glwe<{dim,poly,bits}{p}>) -> -// (!MidLFHE.glwe<{dim,poly,bits}{p}>)) +// 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(); @@ -110,8 +110,8 @@ mlir::LogicalResult verifyBinaryGLWEOperator(Operator &op) { } // verifyUnaryGLWEOperator verify parameters of operators that has the following -// signature (!MidLFHE.glwe<{dim,poly,bits}{p}>) -> -// (!MidLFHE.glwe<{dim,poly,bits}{p}>)) +// 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(); @@ -153,7 +153,7 @@ mlir::LogicalResult verifyApplyLookupTable(ApplyLookupTable &op) { auto expectedSize = 1 << width; mlir::SmallVector expectedShape{expectedSize}; if (!l_cst.hasStaticShape(expectedShape)) { - HLFHE::emitErrorBadLutSize(op, "l_cst", "ct", expectedSize, width); + FHE::emitErrorBadLutSize(op, "l_cst", "ct", expectedSize, width); return mlir::failure(); } if (!l_cst.getElementType().isInteger(64)) { @@ -163,9 +163,9 @@ mlir::LogicalResult verifyApplyLookupTable(ApplyLookupTable &op) { return mlir::success(); } -} // namespace MidLFHE +} // namespace TFHE } // namespace concretelang } // namespace mlir #define GET_OP_CLASSES -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEOps.cpp.inc" +#include "concretelang/Dialect/TFHE/IR/TFHEOps.cpp.inc" diff --git a/compiler/lib/Support/CMakeLists.txt b/compiler/lib/Support/CMakeLists.txt index 4493557a6..2b4174a87 100644 --- a/compiler/lib/Support/CMakeLists.txt +++ b/compiler/lib/Support/CMakeLists.txt @@ -21,13 +21,13 @@ add_mlir_library(ConcretelangSupport MLIRConversionPassIncGen LINK_LIBS PUBLIC - HLFHELinalgDialect - HLFHELinalgDialectTransforms - HLFHETensorOpsToLinalg - HLFHEToMidLFHE - LowLFHEUnparametrize + FHELinalgDialect + FHELinalgDialectTransforms + FHETensorOpsToLinalg + FHEToTFHE + ConcreteUnparametrize MLIRLowerableDialectsToLLVM - HLFHEDialectAnalysis + FHEDialectAnalysis RTDialectAnalysis MLIRExecutionEngine diff --git a/compiler/lib/Support/ClientParameters.cpp b/compiler/lib/Support/ClientParameters.cpp index c9930eea4..d70a48089 100644 --- a/compiler/lib/Support/ClientParameters.cpp +++ b/compiler/lib/Support/ClientParameters.cpp @@ -6,7 +6,7 @@ #include -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" #include "concretelang/Support/ClientParameters.h" #include "concretelang/Support/V0Curves.h" @@ -40,9 +40,9 @@ llvm::Expected gateFromMLIRType(std::string secretKeyID, }, }; } - if (type.isa()) { + if (type.isa()) { // TODO - Get the width from the LWECiphertextType instead of global - // precision (could be possible after merge lowlfhe-ciphertext-parameter) + // precision (could be possible after merge concrete-ciphertext-parameter) return CircuitGate{ .encryption = llvm::Optional({ .secretKeyID = secretKeyID, @@ -129,7 +129,7 @@ createClientParametersForV0(V0FHEContext fheContext, llvm::StringRef name, // Create input and output circuit gate parameters auto funcType = (*funcOp).getType(); bool hasContext = - funcType.getInputs().back().isa(); + funcType.getInputs().back().isa(); for (auto inType = funcType.getInputs().begin(); inType < funcType.getInputs().end() - hasContext; inType++) { auto gate = gateFromMLIRType("big", precision, encryptionVariance, *inType); diff --git a/compiler/lib/Support/CompilerEngine.cpp b/compiler/lib/Support/CompilerEngine.cpp index c9805442f..a470eeb33 100644 --- a/compiler/lib/Support/CompilerEngine.cpp +++ b/compiler/lib/Support/CompilerEngine.cpp @@ -13,10 +13,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -48,13 +48,13 @@ mlir::MLIRContext *CompilationContext::getMLIRContext() { this->mlirContext = new mlir::MLIRContext(); this->mlirContext->getOrLoadDialect(); - this->mlirContext->getOrLoadDialect(); + this->mlirContext->getOrLoadDialect(); this->mlirContext - ->getOrLoadDialect(); + ->getOrLoadDialect(); this->mlirContext - ->getOrLoadDialect(); + ->getOrLoadDialect(); this->mlirContext - ->getOrLoadDialect(); + ->getOrLoadDialect(); this->mlirContext->getOrLoadDialect(); this->mlirContext->getOrLoadDialect(); this->mlirContext->getOrLoadDialect(); @@ -103,8 +103,8 @@ void CompilerEngine::setClientParametersFuncName(const llvm::StringRef &name) { this->clientParametersFuncName = name.str(); } -void CompilerEngine::setHLFHELinalgTileSizes(llvm::ArrayRef sizes) { - this->hlfhelinalgTileSizes = sizes.vec(); +void CompilerEngine::setFHELinalgTileSizes(llvm::ArrayRef sizes) { + this->fhelinalgTileSizes = sizes.vec(); } void CompilerEngine::setEnablePass( @@ -112,7 +112,7 @@ void CompilerEngine::setEnablePass( this->enablePass = enablePass; } -// Returns the overwritten V0FHEConstraint or try to compute them from HLFHE +// Returns the overwritten V0FHEConstraint or try to compute them from FHE llvm::Expected> CompilerEngine::getV0FHEConstraint(CompilationResult &res) { mlir::MLIRContext &mlirContext = *this->compilationContext->getMLIRContext(); @@ -125,10 +125,10 @@ CompilerEngine::getV0FHEConstraint(CompilationResult &res) { this->overrideMaxMANP.getValue(), this->overrideMaxEintPrecision.getValue()}; } - // Else compute constraint from HLFHE + // Else compute constraint from FHE llvm::Expected> fheConstraintsOrErr = - mlir::concretelang::pipeline::getFHEConstraintsFromHLFHE( + mlir::concretelang::pipeline::getFHEConstraintsFromFHE( mlirContext, module, enablePass); if (auto err = fheConstraintsOrErr.takeError()) @@ -202,22 +202,22 @@ CompilerEngine::compile(llvm::SourceMgr &sm, Target target, OptionalLib lib) { if (target == Target::ROUND_TRIP) return std::move(res); - // HLFHE High level pass to determine FHE parameters + // FHE High level pass to determine FHE parameters if (auto err = this->determineFHEParameters(res)) return std::move(err); - // HLFHELinalg tiling - if (this->hlfhelinalgTileSizes) { - if (mlir::concretelang::pipeline::markHLFHELinalgForTiling( - mlirContext, module, *this->hlfhelinalgTileSizes, enablePass) + // FHELinalg tiling + if (this->fhelinalgTileSizes) { + if (mlir::concretelang::pipeline::markFHELinalgForTiling( + mlirContext, module, *this->fhelinalgTileSizes, enablePass) .failed()) - return errorDiag("Marking of HLFHELinalg operations for tiling failed"); + return errorDiag("Marking of FHELinalg operations for tiling failed"); } - if (mlir::concretelang::pipeline::tileMarkedHLFHELinalg(mlirContext, module, + if (mlir::concretelang::pipeline::tileMarkedFHELinalg(mlirContext, module, enablePass) .failed()) { - return errorDiag("Tiling of HLFHELinalg operations failed"); + return errorDiag("Tiling of FHELinalg operations failed"); } // Auto parallelization @@ -227,32 +227,32 @@ CompilerEngine::compile(llvm::SourceMgr &sm, Target target, OptionalLib lib) { return StreamStringError("Auto parallelization failed"); } - if (target == Target::HLFHE) + if (target == Target::FHE) return std::move(res); - // HLFHE -> MidLFHE - if (mlir::concretelang::pipeline::lowerHLFHEToMidLFHE(mlirContext, module, + // FHE -> TFHE + if (mlir::concretelang::pipeline::lowerFHEToTFHE(mlirContext, module, enablePass) .failed()) { - return errorDiag("Lowering from HLFHE to MidLFHE failed"); + return errorDiag("Lowering from FHE to TFHE failed"); } - if (target == Target::MIDLFHE) + if (target == Target::TFHE) return std::move(res); - // MidLFHE -> LowLFHE - if (mlir::concretelang::pipeline::lowerMidLFHEToLowLFHE( + // TFHE -> Concrete + if (mlir::concretelang::pipeline::lowerTFHEToConcrete( mlirContext, module, res.fheContext, this->enablePass) .failed()) { - return errorDiag("Lowering from MidLFHE to LowLFHE failed"); + return errorDiag("Lowering from TFHE to Concrete failed"); } - if (target == Target::LOWLFHE) + if (target == Target::CONCRETE) return std::move(res); - // LowLFHE -> Canonical dialects - if (mlir::concretelang::pipeline::lowerLowLFHEToStd(mlirContext, module, + // Concrete -> Canonical dialects + if (mlir::concretelang::pipeline::lowerConcreteToStd(mlirContext, module, enablePass) .failed()) { - return errorDiag("Lowering from LowLFHE to canonical MLIR dialects failed"); + return errorDiag("Lowering from Concrete to canonical MLIR dialects failed"); } if (target == Target::STD) return std::move(res); diff --git a/compiler/lib/Support/Pipeline.cpp b/compiler/lib/Support/Pipeline.cpp index 22bbfe12e..252e679b4 100644 --- a/compiler/lib/Support/Pipeline.cpp +++ b/compiler/lib/Support/Pipeline.cpp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -59,14 +59,14 @@ addPotentiallyNestedPass(mlir::PassManager &pm, std::unique_ptr pass, } llvm::Expected> -getFHEConstraintsFromHLFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, +getFHEConstraintsFromFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass) { llvm::Optional oMax2norm; llvm::Optional oMaxWidth; mlir::PassManager pm(&context); - pipelinePrinting("ComputeFHEConstraintOnHLFHE", pm, context); + pipelinePrinting("ComputeFHEConstraintOnFHE", pm, context); addPotentiallyNestedPass(pm, mlir::concretelang::createMANPPass(), enablePass); addPotentiallyNestedPass( pm, @@ -118,70 +118,70 @@ mlir::LogicalResult autopar(mlir::MLIRContext &context, mlir::ModuleOp &module, } mlir::LogicalResult -tileMarkedHLFHELinalg(mlir::MLIRContext &context, mlir::ModuleOp &module, +tileMarkedFHELinalg(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass) { mlir::PassManager pm(&context); - pipelinePrinting("TileMarkedHLFHELinalg", pm, context); - addPotentiallyNestedPass(pm, mlir::concretelang::createHLFHELinalgTilingPass(), + pipelinePrinting("TileMarkedFHELinalg", pm, context); + addPotentiallyNestedPass(pm, mlir::concretelang::createFHELinalgTilingPass(), enablePass); return pm.run(module.getOperation()); } mlir::LogicalResult -markHLFHELinalgForTiling(mlir::MLIRContext &context, mlir::ModuleOp &module, +markFHELinalgForTiling(mlir::MLIRContext &context, mlir::ModuleOp &module, llvm::ArrayRef tileSizes, std::function enablePass) { mlir::PassManager pm(&context); - pipelinePrinting("MarkHLFHELinalgForTiling", pm, context); - addPotentiallyNestedPass(pm, createHLFHELinalgTilingMarkerPass(tileSizes), + pipelinePrinting("MarkFHELinalgForTiling", pm, context); + addPotentiallyNestedPass(pm, createFHELinalgTilingMarkerPass(tileSizes), enablePass); return pm.run(module.getOperation()); } mlir::LogicalResult -lowerHLFHEToMidLFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, +lowerFHEToTFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass) { mlir::PassManager pm(&context); - pipelinePrinting("HLFHEToMidLFHE", pm, context); + pipelinePrinting("FHEToTFHE", pm, context); addPotentiallyNestedPass( - pm, mlir::concretelang::createConvertHLFHETensorOpsToLinalg(), enablePass); + pm, mlir::concretelang::createConvertFHETensorOpsToLinalg(), enablePass); addPotentiallyNestedPass( - pm, mlir::concretelang::createConvertHLFHEToMidLFHEPass(), enablePass); + pm, mlir::concretelang::createConvertFHEToTFHEPass(), enablePass); return pm.run(module.getOperation()); } mlir::LogicalResult -lowerMidLFHEToLowLFHE(mlir::MLIRContext &context, mlir::ModuleOp &module, +lowerTFHEToConcrete(mlir::MLIRContext &context, mlir::ModuleOp &module, llvm::Optional &fheContext, std::function enablePass) { mlir::PassManager pm(&context); - pipelinePrinting("MidLFHEToLowLFHE", pm, context); + pipelinePrinting("TFHEToConcrete", pm, context); if (fheContext.hasValue()) { addPotentiallyNestedPass( pm, - mlir::concretelang::createConvertMidLFHEGlobalParametrizationPass( + mlir::concretelang::createConvertTFHEGlobalParametrizationPass( fheContext.getValue()), enablePass); } addPotentiallyNestedPass( - pm, mlir::concretelang::createConvertMidLFHEToLowLFHEPass(), enablePass); + pm, mlir::concretelang::createConvertTFHEToConcretePass(), enablePass); return pm.run(module.getOperation()); } mlir::LogicalResult -lowerLowLFHEToStd(mlir::MLIRContext &context, mlir::ModuleOp &module, +lowerConcreteToStd(mlir::MLIRContext &context, mlir::ModuleOp &module, std::function enablePass) { mlir::PassManager pm(&context); - pipelinePrinting("LowLFHEToStd", pm, context); + pipelinePrinting("ConcreteToStd", pm, context); addPotentiallyNestedPass( - pm, mlir::concretelang::createConvertLowLFHEToConcreteCAPIPass(), enablePass); + pm, mlir::concretelang::createConvertConcreteToConcreteCAPIPass(), enablePass); return pm.run(module.getOperation()); } @@ -191,9 +191,9 @@ lowerStdToLLVMDialect(mlir::MLIRContext &context, mlir::ModuleOp &module, mlir::PassManager pm(&context); pipelinePrinting("StdToLLVM", pm, context); - // Unparametrize LowLFHE + // Unparametrize Concrete addPotentiallyNestedPass( - pm, mlir::concretelang::createConvertLowLFHEUnparametrizePass(), enablePass); + pm, mlir::concretelang::createConvertConcreteUnparametrizePass(), enablePass); // Bufferize addPotentiallyNestedPass(pm, mlir::createTensorConstantBufferizePass(), diff --git a/compiler/src/CMakeLists.txt b/compiler/src/CMakeLists.txt index 8e9919af6..53a785091 100644 --- a/compiler/src/CMakeLists.txt +++ b/compiler/src/CMakeLists.txt @@ -12,9 +12,9 @@ if(CONCRETELANG_PARALLEL_EXECUTION_ENABLED) ${conversion_libs} MLIRTransforms - LowLFHEDialect - MidLFHEDialect - HLFHEDialect + ConcreteDialect + TFHEDialect + FHEDialect MLIRIR MLIRLLVMIR @@ -35,9 +35,9 @@ else() ${conversion_libs} MLIRTransforms - LowLFHEDialect - MidLFHEDialect - HLFHEDialect + ConcreteDialect + TFHEDialect + FHEDialect MLIRIR MLIRLLVMIR diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp index cd18bda75..f0a13bd01 100644 --- a/compiler/src/main.cpp +++ b/compiler/src/main.cpp @@ -20,12 +20,12 @@ #include "mlir/IR/BuiltinOps.h" #include "concretelang/Conversion/Passes.h" #include "concretelang/Conversion/Utils/GlobalFHEContext.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHEDialect.h" -#include "concretelang/Dialect/HLFHE/IR/HLFHETypes.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHEDialect.h" -#include "concretelang/Dialect/LowLFHE/IR/LowLFHETypes.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHEDialect.h" -#include "concretelang/Dialect/MidLFHE/IR/MidLFHETypes.h" +#include "concretelang/Dialect/FHE/IR/FHEDialect.h" +#include "concretelang/Dialect/FHE/IR/FHETypes.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteDialect.h" +#include "concretelang/Dialect/Concrete/IR/ConcreteTypes.h" +#include "concretelang/Dialect/TFHE/IR/TFHEDialect.h" +#include "concretelang/Dialect/TFHE/IR/TFHETypes.h" #include "concretelang/Dialect/RT/IR/RTDialect.h" #include "concretelang/Support/Error.h" #include "concretelang/Support/JitCompilerEngine.h" @@ -36,9 +36,9 @@ enum Action { ROUND_TRIP, - DUMP_HLFHE, - DUMP_MIDLFHE, - DUMP_LOWLFHE, + DUMP_FHE, + DUMP_TFHE, + DUMP_CONCRETE, DUMP_STD, DUMP_LLVM_DIALECT, DUMP_LLVM_IR, @@ -93,12 +93,12 @@ static llvm::cl::opt action( llvm::cl::values( clEnumValN(Action::ROUND_TRIP, "roundtrip", "Parse input module and regenerate textual representation")), - llvm::cl::values(clEnumValN(Action::DUMP_HLFHE, "dump-hlfhe", - "Dump HLFHE module")), - llvm::cl::values(clEnumValN(Action::DUMP_MIDLFHE, "dump-midlfhe", - "Lower to MidLFHE and dump result")), - llvm::cl::values(clEnumValN(Action::DUMP_LOWLFHE, "dump-lowlfhe", - "Lower to LowLFHE and dump result")), + llvm::cl::values(clEnumValN(Action::DUMP_FHE, "dump-fhe", + "Dump FHE module")), + llvm::cl::values(clEnumValN(Action::DUMP_TFHE, "dump-tfhe", + "Lower to TFHE and dump result")), + llvm::cl::values(clEnumValN(Action::DUMP_CONCRETE, "dump-concrete", + "Lower to Concrete and dump result")), llvm::cl::values(clEnumValN(Action::DUMP_STD, "dump-std", "Lower to std and dump result")), llvm::cl::values(clEnumValN(Action::DUMP_LLVM_DIALECT, "dump-llvm-dialect", @@ -155,10 +155,10 @@ llvm::cl::opt, false, OptionalSizeTParser> assumeMaxMANP( llvm::cl::desc( "Assume a maximum for the Minimum Arithmetic Noise Padding")); -llvm::cl::list hlfhelinalgTileSizes( - "hlfhelinalg-tile-sizes", +llvm::cl::list fhelinalgTileSizes( + "fhelinalg-tile-sizes", llvm::cl::desc( - "Force tiling of HLFHELinalg operation with the given tile sizes"), + "Force tiling of FHELinalg operation with the given tile sizes"), llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::CommaSeparated); } // namespace cmdline @@ -217,8 +217,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, // designates the function to JIT compile. This function is invoked // using the parameters given in `jitArgs`. // -// The parameter `parametrizeMidLFHE` defines, whether the -// parametrization pass for MidLFHE is executed. If the `action` does +// 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. // @@ -240,7 +240,7 @@ mlir::LogicalResult processInputBuffer( llvm::ArrayRef jitArgs, llvm::Optional overrideMaxEintPrecision, llvm::Optional overrideMaxMANP, bool verifyDiagnostics, - llvm::Optional> hlfhelinalgTileSizes, + llvm::Optional> fhelinalgTileSizes, bool autoParallelize, llvm::Optional keySetCache, llvm::raw_ostream &os, @@ -266,8 +266,8 @@ mlir::LogicalResult processInputBuffer( if (overrideMaxMANP.hasValue()) ce.setMaxMANP(overrideMaxMANP.getValue()); - if (hlfhelinalgTileSizes.hasValue()) - ce.setHLFHELinalgTileSizes(*hlfhelinalgTileSizes); + if (fhelinalgTileSizes.hasValue()) + ce.setFHELinalgTileSizes(*fhelinalgTileSizes); if (action == Action::JIT_INVOKE) { llvm::Expected lambdaOrErr = @@ -297,14 +297,14 @@ mlir::LogicalResult processInputBuffer( case Action::ROUND_TRIP: target = mlir::concretelang::CompilerEngine::Target::ROUND_TRIP; break; - case Action::DUMP_HLFHE: - target = mlir::concretelang::CompilerEngine::Target::HLFHE; + case Action::DUMP_FHE: + target = mlir::concretelang::CompilerEngine::Target::FHE; break; - case Action::DUMP_MIDLFHE: - target = mlir::concretelang::CompilerEngine::Target::MIDLFHE; + case Action::DUMP_TFHE: + target = mlir::concretelang::CompilerEngine::Target::TFHE; break; - case Action::DUMP_LOWLFHE: - target = mlir::concretelang::CompilerEngine::Target::LOWLFHE; + case Action::DUMP_CONCRETE: + target = mlir::concretelang::CompilerEngine::Target::CONCRETE; break; case Action::DUMP_STD: target = mlir::concretelang::CompilerEngine::Target::STD; @@ -380,10 +380,10 @@ mlir::LogicalResult compilerMain(int argc, char **argv) { } // Convert tile sizes to `Optional` - llvm::Optional> hlfhelinalgTileSizes; + llvm::Optional> fhelinalgTileSizes; - if (!cmdline::hlfhelinalgTileSizes.empty()) - hlfhelinalgTileSizes.emplace(cmdline::hlfhelinalgTileSizes); + if (!cmdline::fhelinalgTileSizes.empty()) + fhelinalgTileSizes.emplace(cmdline::fhelinalgTileSizes); llvm::Optional jitKeySetCache; if (!cmdline::jitKeySetCachePath.empty()) { @@ -424,7 +424,7 @@ mlir::LogicalResult compilerMain(int argc, char **argv) { std::move(inputBuffer), fileName, cmdline::action, cmdline::jitFuncName, cmdline::jitArgs, cmdline::assumeMaxEintPrecision, cmdline::assumeMaxMANP, - cmdline::verifyDiagnostics, hlfhelinalgTileSizes, + cmdline::verifyDiagnostics, fhelinalgTileSizes, cmdline::autoParallelize, jitKeySetCache, os, outputLib); }; auto &os = output->os(); diff --git a/compiler/test_python.py b/compiler/test_python.py index 7ad642c5f..71c9c3ed6 100755 --- a/compiler/test_python.py +++ b/compiler/test_python.py @@ -1,5 +1,5 @@ import concretelang -import concretelang.dialects.hlfhe as hlfhe +import concretelang.dialects.fhe as fhe import mlir.dialects.builtin as builtin import mlir.dialects.std as std from mlir.ir import * @@ -11,7 +11,7 @@ def main(): concretelang.register_dialects(ctx) module = Module.create() - eint6 = hlfhe.EncryptedIntegerType.get(ctx, 6) + eint6 = fhe.EncryptedIntegerType.get(ctx, 6) with InsertionPoint(module.body): func_types = [MemRefType.get((10, 10), eint6) for _ in range(2)] @builtin.FuncOp.from_py_func(*func_types) @@ -20,10 +20,10 @@ def main(): print(module) m = """ - func @main(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { + func @main(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { %0 = constant 1 : i3 - %1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i3) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> + %1 = "FHE.add_eint_int"(%arg0, %0): (!FHE.eint<2>, i3) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> }""" ## Working when HFLFHE and MLIR aren't linked concretelang.compiler.round_trip("module{}") diff --git a/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/bootstrap.mlir b/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/bootstrap.mlir new file mode 100644 index 000000000..208df2eef --- /dev/null +++ b/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/bootstrap.mlir @@ -0,0 +1,22 @@ +// RUN: concretecompiler --passes concrete-to-concrete-c-api --action=dump-std %s 2>&1| FileCheck %s + +// CHECK-LABEL: module +// CHECK: func private @keyswitch_lwe_u64(index, !Concrete.lwe_key_switch_key, !Concrete.lwe_ciphertext<_,_>, !Concrete.lwe_ciphertext<_,_>) +// CHECK: func private @get_keyswitch_key(!Concrete.context) -> !Concrete.lwe_key_switch_key +// CHECK: func private @bootstrap_lwe_u64(index, !Concrete.lwe_bootstrap_key, !Concrete.lwe_ciphertext<_,_>, !Concrete.lwe_ciphertext<_,_>, !Concrete.glwe_ciphertext) +// CHECK: func private @get_bootstrap_key(!Concrete.context) -> !Concrete.lwe_bootstrap_key +// CHECK: func private @allocate_lwe_ciphertext_u64(index, index) -> !Concrete.lwe_ciphertext<_,_> +// CHECK-LABEL: func @bootstrap_lwe(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: !Concrete.glwe_ciphertext, %arg2: !Concrete.context) -> !Concrete.lwe_ciphertext<1024,4> +func @bootstrap_lwe(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<1024,4> { + // CHECK-NEXT: %[[ERR:.*]] = arith.constant 0 : index + // CHECK-NEXT: %[[C0:.*]] = arith.constant 1025 : index + // CHECK-NEXT: %[[V1:.*]] = call @allocate_lwe_ciphertext_u64(%[[ERR]], %[[C0]]) : (index, index) -> !Concrete.lwe_ciphertext<_,_> + // CHECK-NEXT: %[[V2:.*]] = call @get_bootstrap_key(%arg2) : (!Concrete.context) -> !Concrete.lwe_bootstrap_key + // CHECK-NEXT: %[[V3:.*]] = builtin.unrealized_conversion_cast %arg0 : !Concrete.lwe_ciphertext<1024,4> to !Concrete.lwe_ciphertext<_,_> + // CHECK-NEXT: %[[V4:.*]] = builtin.unrealized_conversion_cast %arg1 : !Concrete.glwe_ciphertext to !Concrete.glwe_ciphertext + // CHECK-NEXT: call @bootstrap_lwe_u64(%[[ERR]], %[[V2]], %[[V1]], %[[V3]], %[[V4]]) : (index, !Concrete.lwe_bootstrap_key, !Concrete.lwe_ciphertext<_,_>, !Concrete.lwe_ciphertext<_,_>, !Concrete.glwe_ciphertext) -> () + // CHECK-NEXT: %[[RES:.*]] = builtin.unrealized_conversion_cast %[[V1]] : !Concrete.lwe_ciphertext<_,_> to !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[RES]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "Concrete.bootstrap_lwe"(%arg0, %arg1) {baseLog = 2 : i32, glweDimension = 1 : i32, level = 3 : i32, polynomialSize = 1024 : i32} : (!Concrete.lwe_ciphertext<1024,4>, !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<1024,4> + return %1: !Concrete.lwe_ciphertext<1024,4> +} diff --git a/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/glwe_from_table.mlir b/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/glwe_from_table.mlir new file mode 100644 index 000000000..38d1fcbe4 --- /dev/null +++ b/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/glwe_from_table.mlir @@ -0,0 +1,25 @@ +// RUN: concretecompiler --passes concrete-to-concrete-c-api --action=dump-std %s 2>&1| FileCheck %s + +// CHECK-LABEL: module +// CHECK: func private @runtime_foreign_plaintext_list_u64(index, tensor<16xi64>, i64, i32) -> !Concrete.foreign_plaintext_list +// CHECK: func private @add_plaintext_list_glwe_ciphertext_u64(index, !Concrete.glwe_ciphertext, !Concrete.glwe_ciphertext, !Concrete.plaintext_list) +// CHECK: func private @fill_plaintext_list_with_expansion_u64(index, !Concrete.plaintext_list, !Concrete.foreign_plaintext_list) +// CHECK: func private @allocate_plaintext_list_u64(index, i32) -> !Concrete.plaintext_list +// CHECK: func private @allocate_glwe_ciphertext_u64(index, i32, i32) -> !Concrete.glwe_ciphertext +// CHECK-LABEL: func @glwe_from_table(%arg0: tensor<16xi64>, %arg1: !Concrete.context) -> !Concrete.glwe_ciphertext +func @glwe_from_table(%arg0: tensor<16xi64>) -> !Concrete.glwe_ciphertext { + // CHECK-NEXT: %[[V0:.*]] = arith.constant 0 : index + // CHECK-NEXT: %[[C0:.*]] = arith.constant 2 : i32 + // CHECK-NEXT: %[[C1:.*]] = arith.constant 1024 : i32 + // CHECK-NEXT: %[[V1:.*]] = call @allocate_glwe_ciphertext_u64(%[[V0]], %[[C0]], %[[C1]]) : (index, i32, i32) -> !Concrete.glwe_ciphertext + // CHECK-NEXT: %[[V2:.*]] = call @allocate_glwe_ciphertext_u64(%[[V0]], %[[C0]], %[[C1]]) : (index, i32, i32) -> !Concrete.glwe_ciphertext + // CHECK-NEXT: %[[V3:.*]] = call @allocate_plaintext_list_u64(%[[V0]], %[[C1]]) : (index, i32) -> !Concrete.plaintext_list + // CHECK-NEXT: %[[C2:.*]] = arith.constant 16 : i64 + // CHECK-NEXT: %[[C3:.*]] = arith.constant 4 : i32 + // CHECK-NEXT: %[[V4:.*]] = call @runtime_foreign_plaintext_list_u64(%[[V0]], %arg0, %[[C2]], %[[C3]]) : (index, tensor<16xi64>, i64, i32) -> !Concrete.foreign_plaintext_list + // CHECK-NEXT: call @fill_plaintext_list_with_expansion_u64(%[[V0]], %[[V3]], %[[V4]]) : (index, !Concrete.plaintext_list, !Concrete.foreign_plaintext_list) -> () + // CHECK-NEXT: call @add_plaintext_list_glwe_ciphertext_u64(%[[V0]], %[[V1]], %[[V2]], %[[V3]]) : (index, !Concrete.glwe_ciphertext, !Concrete.glwe_ciphertext, !Concrete.plaintext_list) -> () + // CHECK-NEXT: return %[[V1]] : !Concrete.glwe_ciphertext + %1 = "Concrete.glwe_from_table"(%arg0) {glweDimension = 1 : i32, p = 4 : i32, polynomialSize = 1024 : i32} : (tensor<16xi64>) -> !Concrete.glwe_ciphertext + return %1: !Concrete.glwe_ciphertext +} diff --git a/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/keyswitch_lwe.mlir b/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/keyswitch_lwe.mlir new file mode 100644 index 000000000..cb6cf87fe --- /dev/null +++ b/compiler/tests/Conversion/ConcreteToConcreteCAPI/ConcreteToConcreteCAPI/keyswitch_lwe.mlir @@ -0,0 +1,21 @@ +// RUN: concretecompiler --passes concrete-to-concrete-c-api --action=dump-std %s 2>&1| FileCheck %s + +// CHECK-LABEL: module +// CHECK: func private @keyswitch_lwe_u64(index, !Concrete.lwe_key_switch_key, !Concrete.lwe_ciphertext<_,_>, !Concrete.lwe_ciphertext<_,_>) +// CHECK: func private @get_keyswitch_key(!Concrete.context) -> !Concrete.lwe_key_switch_key +// CHECK: func private @bootstrap_lwe_u64(index, !Concrete.lwe_bootstrap_key, !Concrete.lwe_ciphertext<_,_>, !Concrete.lwe_ciphertext<_,_>, !Concrete.glwe_ciphertext) +// CHECK: func private @get_bootstrap_key(!Concrete.context) -> !Concrete.lwe_bootstrap_key +// CHECK: func private @allocate_lwe_ciphertext_u64(index, index) -> !Concrete.lwe_ciphertext<_,_> +// CHECK-LABEL: func @keyswitch_lwe(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: !Concrete.context) -> !Concrete.lwe_ciphertext<1024,4> +func @keyswitch_lwe(%arg0: !Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<1024,4> { + // CHECK-NEXT: %[[ERR:.*]] = arith.constant 0 : index + // CHECK-NEXT: %[[C0:.*]] = arith.constant 1025 : index + // CHECK-NEXT: %[[V1:.*]] = call @allocate_lwe_ciphertext_u64(%[[ERR]], %[[C0]]) : (index, index) -> !Concrete.lwe_ciphertext<_,_> + // CHECK-NEXT: %[[V2:.*]] = call @get_keyswitch_key(%arg1) : (!Concrete.context) -> !Concrete.lwe_key_switch_key + // CHECK-NEXT: %[[V3:.*]] = builtin.unrealized_conversion_cast %arg0 : !Concrete.lwe_ciphertext<1024,4> to !Concrete.lwe_ciphertext<_,_> + // CHECK-NEXT: call @keyswitch_lwe_u64(%[[ERR]], %[[V2]], %[[V1]], %[[V3]]) : (index, !Concrete.lwe_key_switch_key, !Concrete.lwe_ciphertext<_,_>, !Concrete.lwe_ciphertext<_,_>) -> () + // CHECK-NEXT: %[[RES:.*]] = builtin.unrealized_conversion_cast %[[V1]] : !Concrete.lwe_ciphertext<_,_> to !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[RES]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "Concrete.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, inputLweSize = 1 : i32, level = 3 : i32, outputLweSize = 1 : i32} : (!Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<1024,4> + return %1: !Concrete.lwe_ciphertext<1024,4> +} diff --git a/compiler/tests/Conversion/ConcreteUnparametrize/ConcreteUnparametrize/func.mlir b/compiler/tests/Conversion/ConcreteUnparametrize/ConcreteUnparametrize/func.mlir new file mode 100644 index 000000000..40c67ef41 --- /dev/null +++ b/compiler/tests/Conversion/ConcreteUnparametrize/ConcreteUnparametrize/func.mlir @@ -0,0 +1,7 @@ +// RUN: concretecompiler --passes concrete-unparametrize --action=dump-llvm-dialect %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @main(%arg0: !Concrete.lwe_ciphertext<_,_>) -> !Concrete.lwe_ciphertext<_,_> +func @main(%arg0: !Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<1024,4> { + // CHECK-NEXT: return %arg0 : !Concrete.lwe_ciphertext<_,_> + return %arg0: !Concrete.lwe_ciphertext<1024,4> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/ConcreteUnparametrize/ConcreteUnparametrize/unrealized_conversion_cast.mlir b/compiler/tests/Conversion/ConcreteUnparametrize/ConcreteUnparametrize/unrealized_conversion_cast.mlir new file mode 100644 index 000000000..a38b249ec --- /dev/null +++ b/compiler/tests/Conversion/ConcreteUnparametrize/ConcreteUnparametrize/unrealized_conversion_cast.mlir @@ -0,0 +1,8 @@ +// RUN: concretecompiler --passes concrete-unparametrize --action=dump-llvm-dialect %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @main(%arg0: !Concrete.lwe_ciphertext<_,_>) -> !Concrete.lwe_ciphertext<_,_> +func @main(%arg0: !Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<_,_> { + // CHECK-NEXT: return %arg0 : !Concrete.lwe_ciphertext<_,_> + %0 = builtin.unrealized_conversion_cast %arg0 : !Concrete.lwe_ciphertext<1024,4> to !Concrete.lwe_ciphertext<_,_> + return %0: !Concrete.lwe_ciphertext<_,_> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_lookup_table.mlir b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_lookup_table.mlir new file mode 100644 index 000000000..cb4e96515 --- /dev/null +++ b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_lookup_table.mlir @@ -0,0 +1,19 @@ +// RUN: concretecompiler %s --action=dump-tfhe --passes fhe-tensor-ops-to-linalg 2>&1 | FileCheck %s + +// CHECK: #map = affine_map<(d0, d1, d2) -> (d0, d1, d2)> +// CHECK-NEXT: module { +// CHECK-NEXT: func @apply_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!FHE.eint<2>> { +// CHECK-NEXT: %0 = linalg.init_tensor [2, 3, 4] : tensor<2x3x4x!FHE.eint<2>> +// CHECK-NEXT: %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel", "parallel"]} ins(%arg0 : tensor<2x3x4x!FHE.eint<2>>) outs(%0 : tensor<2x3x4x!FHE.eint<2>>) { +// CHECK-NEXT: ^bb0(%arg2: !FHE.eint<2>, %arg3: !FHE.eint<2>): // no predecessors +// CHECK-NEXT: %2 = "FHE.apply_lookup_table"(%arg2, %arg1) : (!FHE.eint<2>, tensor<4xi64>) -> !FHE.eint<2> +// CHECK-NEXT: linalg.yield %2 : !FHE.eint<2> +// CHECK-NEXT: } -> tensor<2x3x4x!FHE.eint<2>> +// CHECK-NEXT: return %1 : tensor<2x3x4x!FHE.eint<2>> +// CHECK-NEXT: } +// CHECK-NEXT: } + +func @apply_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + %1 = "FHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<4xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_multi_lut_to_linalg.mlir b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_multi_lut_to_linalg.mlir new file mode 100644 index 000000000..c9c1c0ade --- /dev/null +++ b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_multi_lut_to_linalg.mlir @@ -0,0 +1,23 @@ +// RUN: concretecompiler %s --action=dump-tfhe 2>&1 | FileCheck %s + +//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> +//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d0, d1, 0)> +//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d0, d1, 1)> +//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d0, d1, 2)> +//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d0, d1, 3)> +//CHECK-NEXT: module { +//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x4x!TFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> { +//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 4] : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>) outs(%[[V0]] : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>>) { +//CHECK-NEXT: ^bb0(%arg2: !TFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> +//CHECK-NEXT: %[[V3:.*]] = "TFHE.apply_lookup_table"(%arg2, %[[V2]]) {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}> +//CHECK-NEXT: linalg.yield %[[V3]] : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } -> tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: return %[[V1]] : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: } +//CHECK-NEXT: } +func @multi_lut(%arg0: tensor<4x4x!FHE.eint<2>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!FHE.eint<2>> { + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x4x!FHE.eint<2>>, tensor<4x4x4xi64>) -> tensor<4x4x!FHE.eint<2>> + return %1: tensor<4x4x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_multi_lut_to_linalg_broadcast.mlir b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_multi_lut_to_linalg_broadcast.mlir new file mode 100644 index 000000000..ec42085c1 --- /dev/null +++ b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/apply_multi_lut_to_linalg_broadcast.mlir @@ -0,0 +1,23 @@ +// RUN: concretecompiler %s --action=dump-tfhe 2>&1 | FileCheck %s + +//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> +//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d1, 0)> +//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d1, 1)> +//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d1, 2)> +//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d1, 3)> +//CHECK-NEXT: module { +//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x3x!TFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> { +//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 3] : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) outs(%[[V0]] : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>>) { +//CHECK-NEXT: ^bb0(%arg2: !TFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> +//CHECK-NEXT: %[[V3:.*]] = "TFHE.apply_lookup_table"(%arg2, %[[V2]]) {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}> +//CHECK-NEXT: linalg.yield %[[V3]] : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } -> tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: return %[[V1]] : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: } +//CHECK-NEXT: } +func @multi_lut(%arg0: tensor<4x3x!FHE.eint<2>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> + return %1: tensor<4x3x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/matmul_eint_int.mlir b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/matmul_eint_int.mlir new file mode 100644 index 000000000..cd14ab63f --- /dev/null +++ b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/matmul_eint_int.mlir @@ -0,0 +1,25 @@ +// RUN: concretecompiler %s --action=dump-tfhe --passes fhe-tensor-ops-to-linalg 2>&1 | FileCheck %s + +// CHECK: #map0 = affine_map<(d0, d1, d2) -> (d0, d2)> +// CHECK-NEXT: #map1 = affine_map<(d0, d1, d2) -> (d2, d1)> +// CHECK-NEXT: #map2 = affine_map<(d0, d1, d2) -> (d0, d1)> +// CHECK-NEXT: module { +// CHECK-NEXT: func @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { +// CHECK-NEXT: %0 = tensor.generate { +// CHECK-NEXT: ^bb0(%arg2: index, %arg3: index): // no predecessors +// CHECK-NEXT: %2 = "FHE.zero"() : () -> !FHE.eint<2> +// CHECK-NEXT: tensor.yield %2 : !FHE.eint<2> +// CHECK-NEXT: } : tensor<3x2x!FHE.eint<2>> +// CHECK-NEXT: %1 = linalg.generic {indexing_maps = [#map0, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"]} ins(%arg0, %arg1 : tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) outs(%0 : tensor<3x2x!FHE.eint<2>>) { +// CHECK-NEXT: ^bb0(%arg2: !FHE.eint<2>, %arg3: i3, %arg4: !FHE.eint<2>): // no predecessors +// CHECK-NEXT: %2 = "FHE.mul_eint_int"(%arg2, %arg3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> +// CHECK-NEXT: %3 = "FHE.add_eint"(%arg4, %2) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> +// CHECK-NEXT: linalg.yield %3 : !FHE.eint<2> +// CHECK-NEXT: } -> tensor<3x2x!FHE.eint<2>> +// CHECK-NEXT: return %1 : tensor<3x2x!FHE.eint<2>> +// CHECK-NEXT: } +// CHECK-NEXT: } +func @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/neg_eint.mlir b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/neg_eint.mlir new file mode 100644 index 000000000..72259f0fb --- /dev/null +++ b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/neg_eint.mlir @@ -0,0 +1,19 @@ +// RUN: concretecompiler %s --action=dump-tfhe --passes fhe-tensor-ops-to-linalg 2>&1 | FileCheck %s + +// CHECK: #map = affine_map<(d0, d1, d2) -> (d0, d1, d2)> +// CHECK-NEXT: module { +// CHECK-NEXT: func @neg_eint(%arg0: tensor<2x3x4x!FHE.eint<2>>) -> tensor<2x3x4x!FHE.eint<2>> { +// CHECK-NEXT: %0 = linalg.init_tensor [2, 3, 4] : tensor<2x3x4x!FHE.eint<2>> +// CHECK-NEXT: %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel", "parallel"]} ins(%arg0 : tensor<2x3x4x!FHE.eint<2>>) outs(%0 : tensor<2x3x4x!FHE.eint<2>>) { +// CHECK-NEXT: ^bb0(%arg1: !FHE.eint<2>, %arg2: !FHE.eint<2>): // no predecessors +// CHECK-NEXT: %2 = "FHE.neg_eint"(%arg1) : (!FHE.eint<2>) -> !FHE.eint<2> +// CHECK-NEXT: linalg.yield %2 : !FHE.eint<2> +// CHECK-NEXT: } -> tensor<2x3x4x!FHE.eint<2>> +// CHECK-NEXT: return %1 : tensor<2x3x4x!FHE.eint<2>> +// CHECK-NEXT: } +// CHECK-NEXT: } + +func @neg_eint(%arg0: tensor<2x3x4x!FHE.eint<2>>) -> tensor<2x3x4x!FHE.eint<2>> { + %1 = "FHELinalg.neg_eint"(%arg0): (tensor<2x3x4x!FHE.eint<2>>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/zero.mlir b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/zero.mlir new file mode 100644 index 000000000..9eb002577 --- /dev/null +++ b/compiler/tests/Conversion/FHELinalgToLinalg/FHELinalgToLinalg/zero.mlir @@ -0,0 +1,14 @@ +// RUN: concretecompiler %s --action=dump-tfhe --passes fhe-tensor-ops-to-linalg 2>&1 | FileCheck %s + +// CHECK: func @zero(%arg0: !FHE.eint<2>) -> tensor<3x2x!FHE.eint<2>> { +// CHECK-NEXT: %[[v0:.*]] = tensor.generate { +// CHECK-NEXT: ^bb0(%arg1: index, %arg2: index): // no predecessors +// CHECK-NEXT: %[[yld:.*]] = "FHE.zero"() : () -> !FHE.eint<2> +// CHECK-NEXT: tensor.yield %[[yld]] : !FHE.eint<2> +// CHECK-NEXT: } : tensor<3x2x!FHE.eint<2>> +// CHECK-NEXT: return %[[v0]] : tensor<3x2x!FHE.eint<2>> +// CHECK-NEXT: } +func @zero(%arg0: !FHE.eint<2>) -> tensor<3x2x!FHE.eint<2>> { + %1 = "FHELinalg.zero"(): () -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/add_eint.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/add_eint.mlir new file mode 100644 index 000000000..a0aa0bc7d --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/add_eint.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_eint(%arg0: !TFHE.glwe<{_,_,_}{7}>, %arg1: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @add_eint(%arg0: !FHE.eint<7>, %arg1: !FHE.eint<7>) -> !FHE.eint<7> { + // CHECK-NEXT: %[[V1:.*]] = "TFHE.add_glwe"(%arg0, %arg1) : (!TFHE.glwe<{_,_,_}{7}>, !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: return %[[V1]] : !TFHE.glwe<{_,_,_}{7}> + + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> +} diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/add_eint_int.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/add_eint_int.mlir new file mode 100644 index 000000000..781590c24 --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/add_eint_int.mlir @@ -0,0 +1,12 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_eint_int(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @add_eint_int(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "TFHE.add_glwe_int"(%arg0, %[[V1]]) : (!TFHE.glwe<{_,_,_}{7}>, i8) -> !TFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: return %[[V2]] : !TFHE.glwe<{_,_,_}{7}> + + %0 = arith.constant 1 : i8 + %1 = "FHE.add_eint_int"(%arg0, %0): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> +} diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/apply_univariate.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/apply_univariate.mlir new file mode 100644 index 000000000..6183171c5 --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/apply_univariate.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK-LABEL: func @apply_lookup_table(%arg0: !TFHE.glwe<{_,_,_}{2}>, %arg1: tensor<4xi64>) -> !TFHE.glwe<{_,_,_}{2}> +func @apply_lookup_table(%arg0: !FHE.eint<2>, %arg1: tensor<4xi64>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = "TFHE.apply_lookup_table"(%arg0, %arg1) {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}> + // CHECK-NEXT: return %[[V1]] : !TFHE.glwe<{_,_,_}{2}> + + %1 = "FHE.apply_lookup_table"(%arg0, %arg1): (!FHE.eint<2>, tensor<4xi64>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/apply_univariate_cst.mlir similarity index 77% rename from compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir rename to compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/apply_univariate_cst.mlir index 7bacf2c53..9726240e1 100644 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate_cst.mlir +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/apply_univariate_cst.mlir @@ -1,11 +1,11 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s -// CHECK-LABEL: func @apply_lookup_table_cst(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @apply_lookup_table_cst(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { +// CHECK-LABEL: func @apply_lookup_table_cst(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @apply_lookup_table_cst(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { // CHECK-NEXT: %[[TABLE:.*]] = arith.constant dense<"0x00000000000000000100000000000000020000000000000003000000000000000400000000000000050000000000000006000000000000000700000000000000080000000000000009000000000000000A000000000000000B000000000000000C000000000000000D000000000000000E000000000000000F0000000000000010000000000000001100000000000000120000000000000013000000000000001400000000000000150000000000000016000000000000001700000000000000180000000000000019000000000000001A000000000000001B000000000000001C000000000000001D000000000000001E000000000000001F0000000000000020000000000000002100000000000000220000000000000023000000000000002400000000000000250000000000000026000000000000002700000000000000280000000000000029000000000000002A000000000000002B000000000000002C000000000000002D000000000000002E000000000000002F0000000000000030000000000000003100000000000000320000000000000033000000000000003400000000000000350000000000000036000000000000003700000000000000380000000000000039000000000000003A000000000000003B000000000000003C000000000000003D000000000000003E000000000000003F0000000000000040000000000000004100000000000000420000000000000043000000000000004400000000000000450000000000000046000000000000004700000000000000480000000000000049000000000000004A000000000000004B000000000000004C000000000000004D000000000000004E000000000000004F0000000000000050000000000000005100000000000000520000000000000053000000000000005400000000000000550000000000000056000000000000005700000000000000580000000000000059000000000000005A000000000000005B000000000000005C000000000000005D000000000000005E000000000000005F0000000000000060000000000000006100000000000000620000000000000063000000000000006400000000000000650000000000000066000000000000006700000000000000680000000000000069000000000000006A000000000000006B000000000000006C000000000000006D000000000000006E000000000000006F0000000000000070000000000000007100000000000000720000000000000073000000000000007400000000000000750000000000000076000000000000007700000000000000780000000000000079000000000000007A000000000000007B000000000000007C000000000000007D000000000000007E000000000000007F00000000000000"> : tensor<128xi64> - // CHECK-NEXT: %[[V0:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %[[TABLE]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{7}>, tensor<128xi64>) -> !MidLFHE.glwe<{_,_,_}{7}> - // CHECK-NEXT: return %[[V0]] : !MidLFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: %[[V0:.*]] = "TFHE.apply_lookup_table"(%arg0, %[[TABLE]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!TFHE.glwe<{_,_,_}{7}>, tensor<128xi64>) -> !TFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: return %[[V0]] : !TFHE.glwe<{_,_,_}{7}> %tlu = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]> : tensor<128xi64> - %1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<7>, tensor<128xi64>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + %1 = "FHE.apply_lookup_table"(%arg0, %tlu): (!FHE.eint<7>, tensor<128xi64>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/linalg_generic.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/linalg_generic.mlir new file mode 100644 index 000000000..4b37e55ba --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/linalg_generic.mlir @@ -0,0 +1,29 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK: #map0 = affine_map<(d0) -> (d0)> +// CHECK-NEXT: #map1 = affine_map<(d0) -> (0)> +// CHECK-NEXT: module { +// CHECK-NEXT: func @linalg_generic(%arg0: tensor<2x!TFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<2xi3>, %arg2: tensor<1x!TFHE.glwe<{_,_,_}{2}>>) { +// CHECK-NEXT: %0 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!TFHE.glwe<{_,_,_}{2}>>, tensor<2xi3>) outs(%arg2 : tensor<1x!TFHE.glwe<{_,_,_}{2}>>) { +// CHECK-NEXT: ^bb0(%arg3: !TFHE.glwe<{_,_,_}{2}>, %arg4: i3, %arg5: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +// CHECK-NEXT: %1 = "TFHE.mul_glwe_int"(%arg3, %arg4) : (!TFHE.glwe<{_,_,_}{2}>, i3) -> !TFHE.glwe<{_,_,_}{2}> +// CHECK-NEXT: %2 = "TFHE.add_glwe"(%1, %arg5) : (!TFHE.glwe<{_,_,_}{2}>, !TFHE.glwe<{_,_,_}{2}>) -> !TFHE.glwe<{_,_,_}{2}> +// CHECK-NEXT: linalg.yield %2 : !TFHE.glwe<{_,_,_}{2}> +// CHECK-NEXT: } -> tensor<1x!TFHE.glwe<{_,_,_}{2}>> +// CHECK-NEXT: return +// CHECK-NEXT: } +// CHECK-NEXT: } + +#map0 = affine_map<(d0) -> (d0)> +#map1 = affine_map<(d0) -> (0)> +module { + func @linalg_generic(%arg0: tensor<2x!FHE.eint<2>>, %arg1: tensor<2xi3>, %acc: tensor<1x!FHE.eint<2>>) { + %2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!FHE.eint<2>>, tensor<2xi3>) outs(%acc : tensor<1x!FHE.eint<2>>) { + ^bb0(%arg2: !FHE.eint<2>, %arg3: i3, %arg4: !FHE.eint<2>): // no predecessors + %4 = "FHE.mul_eint_int"(%arg2, %arg3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %5 = "FHE.add_eint"(%4, %arg4) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + linalg.yield %5 : !FHE.eint<2> + } -> tensor<1x!FHE.eint<2>> + return + } +} diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/mul_eint_int.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/mul_eint_int.mlir new file mode 100644 index 000000000..8e63c56a4 --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/mul_eint_int.mlir @@ -0,0 +1,12 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK-LABEL: func @mul_eint_int(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @mul_eint_int(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "TFHE.mul_glwe_int"(%arg0, %[[V1]]) : (!TFHE.glwe<{_,_,_}{7}>, i8) -> !TFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: return %[[V2]] : !TFHE.glwe<{_,_,_}{7}> + + %0 = arith.constant 1 : i8 + %1 = "FHE.mul_eint_int"(%arg0, %0): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> +} diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/neg_eint.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/neg_eint.mlir new file mode 100644 index 000000000..f2fdbc6f6 --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/neg_eint.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK-LABEL: func @neg_eint(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @neg_eint(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + // CHECK-NEXT: %[[V1:.*]] = "TFHE.neg_glwe"(%arg0) : (!TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: return %[[V1]] : !TFHE.glwe<{_,_,_}{7}> + + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> +} diff --git a/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/sub_int_eint.mlir b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/sub_int_eint.mlir new file mode 100644 index 000000000..aaec42031 --- /dev/null +++ b/compiler/tests/Conversion/FHEToTFHE/FHEToTFHE/sub_int_eint.mlir @@ -0,0 +1,12 @@ +// RUN: concretecompiler %s --passes fhe-to-tfhe --action=dump-tfhe 2>&1| FileCheck %s + +// CHECK-LABEL: func @sub_int_eint(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @sub_int_eint(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "TFHE.sub_int_glwe"(%[[V1]], %arg0) : (i8, !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> + // CHECK-NEXT: return %[[V2]] : !TFHE.glwe<{_,_,_}{7}> + + %0 = arith.constant 1 : i8 + %1 = "FHE.sub_int_eint"(%0, %arg0): (i8, !FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> +} diff --git a/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_lookup_table.mlir b/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_lookup_table.mlir deleted file mode 100644 index 288120d03..000000000 --- a/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_lookup_table.mlir +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe --passes hlfhe-tensor-ops-to-linalg 2>&1 | FileCheck %s - -// CHECK: #map = affine_map<(d0, d1, d2) -> (d0, d1, d2)> -// CHECK-NEXT: module { -// CHECK-NEXT: func @apply_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %0 = linalg.init_tensor [2, 3, 4] : tensor<2x3x4x!HLFHE.eint<2>> -// CHECK-NEXT: %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel", "parallel"]} ins(%arg0 : tensor<2x3x4x!HLFHE.eint<2>>) outs(%0 : tensor<2x3x4x!HLFHE.eint<2>>) { -// CHECK-NEXT: ^bb0(%arg2: !HLFHE.eint<2>, %arg3: !HLFHE.eint<2>): // no predecessors -// CHECK-NEXT: %2 = "HLFHE.apply_lookup_table"(%arg2, %arg1) : (!HLFHE.eint<2>, tensor<4xi64>) -> !HLFHE.eint<2> -// CHECK-NEXT: linalg.yield %2 : !HLFHE.eint<2> -// CHECK-NEXT: } -> tensor<2x3x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %1 : tensor<2x3x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -// CHECK-NEXT: } - -func @apply_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<4xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_multi_lut_to_linalg.mlir b/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_multi_lut_to_linalg.mlir deleted file mode 100644 index 99b712933..000000000 --- a/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_multi_lut_to_linalg.mlir +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe 2>&1 | FileCheck %s - -//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> -//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d0, d1, 0)> -//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d0, d1, 1)> -//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d0, d1, 2)> -//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d0, d1, 3)> -//CHECK-NEXT: module { -//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> { -//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 4] : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>) outs(%[[V0]] : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>>) { -//CHECK-NEXT: ^bb0(%arg2: !MidLFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> -//CHECK-NEXT: %[[V3:.*]] = "MidLFHE.apply_lookup_table"(%arg2, %[[V2]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: linalg.yield %[[V3]] : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -> tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: return %[[V1]] : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: } -//CHECK-NEXT: } -func @multi_lut(%arg0: tensor<4x4x!HLFHE.eint<2>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x4x!HLFHE.eint<2>>, tensor<4x4x4xi64>) -> tensor<4x4x!HLFHE.eint<2>> - return %1: tensor<4x4x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_multi_lut_to_linalg_broadcast.mlir b/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_multi_lut_to_linalg_broadcast.mlir deleted file mode 100644 index 7f52b68f7..000000000 --- a/compiler/tests/Conversion/HLFHELinalgToLinalg/apply_multi_lut_to_linalg_broadcast.mlir +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe 2>&1 | FileCheck %s - -//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> -//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d1, 0)> -//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d1, 1)> -//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d1, 2)> -//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d1, 3)> -//CHECK-NEXT: module { -//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> { -//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 3] : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) outs(%[[V0]] : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>>) { -//CHECK-NEXT: ^bb0(%arg2: !MidLFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> -//CHECK-NEXT: %[[V3:.*]] = "MidLFHE.apply_lookup_table"(%arg2, %[[V2]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: linalg.yield %[[V3]] : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -> tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: return %[[V1]] : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: } -//CHECK-NEXT: } -func @multi_lut(%arg0: tensor<4x3x!HLFHE.eint<2>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x3x!HLFHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!HLFHE.eint<2>> - return %1: tensor<4x3x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/HLFHELinalgToLinalg/matmul_eint_int.mlir b/compiler/tests/Conversion/HLFHELinalgToLinalg/matmul_eint_int.mlir deleted file mode 100644 index b24c647bd..000000000 --- a/compiler/tests/Conversion/HLFHELinalgToLinalg/matmul_eint_int.mlir +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe --passes hlfhe-tensor-ops-to-linalg 2>&1 | FileCheck %s - -// CHECK: #map0 = affine_map<(d0, d1, d2) -> (d0, d2)> -// CHECK-NEXT: #map1 = affine_map<(d0, d1, d2) -> (d2, d1)> -// CHECK-NEXT: #map2 = affine_map<(d0, d1, d2) -> (d0, d1)> -// CHECK-NEXT: module { -// CHECK-NEXT: func @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { -// CHECK-NEXT: %0 = tensor.generate { -// CHECK-NEXT: ^bb0(%arg2: index, %arg3: index): // no predecessors -// CHECK-NEXT: %2 = "HLFHE.zero"() : () -> !HLFHE.eint<2> -// CHECK-NEXT: tensor.yield %2 : !HLFHE.eint<2> -// CHECK-NEXT: } : tensor<3x2x!HLFHE.eint<2>> -// CHECK-NEXT: %1 = linalg.generic {indexing_maps = [#map0, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"]} ins(%arg0, %arg1 : tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) outs(%0 : tensor<3x2x!HLFHE.eint<2>>) { -// CHECK-NEXT: ^bb0(%arg2: !HLFHE.eint<2>, %arg3: i3, %arg4: !HLFHE.eint<2>): // no predecessors -// CHECK-NEXT: %2 = "HLFHE.mul_eint_int"(%arg2, %arg3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> -// CHECK-NEXT: %3 = "HLFHE.add_eint"(%arg4, %2) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> -// CHECK-NEXT: linalg.yield %3 : !HLFHE.eint<2> -// CHECK-NEXT: } -> tensor<3x2x!HLFHE.eint<2>> -// CHECK-NEXT: return %1 : tensor<3x2x!HLFHE.eint<2>> -// CHECK-NEXT: } -// CHECK-NEXT: } -func @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/HLFHELinalgToLinalg/neg_eint.mlir b/compiler/tests/Conversion/HLFHELinalgToLinalg/neg_eint.mlir deleted file mode 100644 index aec38462a..000000000 --- a/compiler/tests/Conversion/HLFHELinalgToLinalg/neg_eint.mlir +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe --passes hlfhe-tensor-ops-to-linalg 2>&1 | FileCheck %s - -// CHECK: #map = affine_map<(d0, d1, d2) -> (d0, d1, d2)> -// CHECK-NEXT: module { -// CHECK-NEXT: func @neg_eint(%arg0: tensor<2x3x4x!HLFHE.eint<2>>) -> tensor<2x3x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %0 = linalg.init_tensor [2, 3, 4] : tensor<2x3x4x!HLFHE.eint<2>> -// CHECK-NEXT: %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel", "parallel"]} ins(%arg0 : tensor<2x3x4x!HLFHE.eint<2>>) outs(%0 : tensor<2x3x4x!HLFHE.eint<2>>) { -// CHECK-NEXT: ^bb0(%arg1: !HLFHE.eint<2>, %arg2: !HLFHE.eint<2>): // no predecessors -// CHECK-NEXT: %2 = "HLFHE.neg_eint"(%arg1) : (!HLFHE.eint<2>) -> !HLFHE.eint<2> -// CHECK-NEXT: linalg.yield %2 : !HLFHE.eint<2> -// CHECK-NEXT: } -> tensor<2x3x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %1 : tensor<2x3x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -// CHECK-NEXT: } - -func @neg_eint(%arg0: tensor<2x3x4x!HLFHE.eint<2>>) -> tensor<2x3x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.neg_eint"(%arg0): (tensor<2x3x4x!HLFHE.eint<2>>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/HLFHELinalgToLinalg/zero.mlir b/compiler/tests/Conversion/HLFHELinalgToLinalg/zero.mlir deleted file mode 100644 index f00f5b25f..000000000 --- a/compiler/tests/Conversion/HLFHELinalgToLinalg/zero.mlir +++ /dev/null @@ -1,14 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe --passes hlfhe-tensor-ops-to-linalg 2>&1 | FileCheck %s - -// CHECK: func @zero(%arg0: !HLFHE.eint<2>) -> tensor<3x2x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[v0:.*]] = tensor.generate { -// CHECK-NEXT: ^bb0(%arg1: index, %arg2: index): // no predecessors -// CHECK-NEXT: %[[yld:.*]] = "HLFHE.zero"() : () -> !HLFHE.eint<2> -// CHECK-NEXT: tensor.yield %[[yld]] : !HLFHE.eint<2> -// CHECK-NEXT: } : tensor<3x2x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[v0]] : tensor<3x2x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @zero(%arg0: !HLFHE.eint<2>) -> tensor<3x2x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.zero"(): () -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/add_eint.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/add_eint.mlir deleted file mode 100644 index 4da435a3c..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/add_eint.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_eint(%arg0: !MidLFHE.glwe<{_,_,_}{7}>, %arg1: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @add_eint(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.add_glwe"(%arg0, %arg1) : (!MidLFHE.glwe<{_,_,_}{7}>, !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> - // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{_,_,_}{7}> - - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/add_eint_int.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/add_eint_int.mlir deleted file mode 100644 index 3bb974fa8..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/add_eint_int.mlir +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_eint_int(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @add_eint_int(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "MidLFHE.add_glwe_int"(%arg0, %[[V1]]) : (!MidLFHE.glwe<{_,_,_}{7}>, i8) -> !MidLFHE.glwe<{_,_,_}{7}> - // CHECK-NEXT: return %[[V2]] : !MidLFHE.glwe<{_,_,_}{7}> - - %0 = arith.constant 1 : i8 - %1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir deleted file mode 100644 index 4fa98e937..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/apply_univariate.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK-LABEL: func @apply_lookup_table(%arg0: !MidLFHE.glwe<{_,_,_}{2}>, %arg1: tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<4xi64>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> - // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{_,_,_}{2}> - - %1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, tensor<4xi64>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/linalg_generic.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/linalg_generic.mlir deleted file mode 100644 index 72ebeecf7..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/linalg_generic.mlir +++ /dev/null @@ -1,29 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK: #map0 = affine_map<(d0) -> (d0)> -// CHECK-NEXT: #map1 = affine_map<(d0) -> (0)> -// CHECK-NEXT: module { -// CHECK-NEXT: func @linalg_generic(%arg0: tensor<2x!MidLFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<2xi3>, %arg2: tensor<1x!MidLFHE.glwe<{_,_,_}{2}>>) { -// CHECK-NEXT: %0 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<2xi3>) outs(%arg2 : tensor<1x!MidLFHE.glwe<{_,_,_}{2}>>) { -// CHECK-NEXT: ^bb0(%arg3: !MidLFHE.glwe<{_,_,_}{2}>, %arg4: i3, %arg5: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -// CHECK-NEXT: %1 = "MidLFHE.mul_glwe_int"(%arg3, %arg4) : (!MidLFHE.glwe<{_,_,_}{2}>, i3) -> !MidLFHE.glwe<{_,_,_}{2}> -// CHECK-NEXT: %2 = "MidLFHE.add_glwe"(%1, %arg5) : (!MidLFHE.glwe<{_,_,_}{2}>, !MidLFHE.glwe<{_,_,_}{2}>) -> !MidLFHE.glwe<{_,_,_}{2}> -// CHECK-NEXT: linalg.yield %2 : !MidLFHE.glwe<{_,_,_}{2}> -// CHECK-NEXT: } -> tensor<1x!MidLFHE.glwe<{_,_,_}{2}>> -// CHECK-NEXT: return -// CHECK-NEXT: } -// CHECK-NEXT: } - -#map0 = affine_map<(d0) -> (d0)> -#map1 = affine_map<(d0) -> (0)> -module { - func @linalg_generic(%arg0: tensor<2x!HLFHE.eint<2>>, %arg1: tensor<2xi3>, %acc: tensor<1x!HLFHE.eint<2>>) { - %2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!HLFHE.eint<2>>, tensor<2xi3>) outs(%acc : tensor<1x!HLFHE.eint<2>>) { - ^bb0(%arg2: !HLFHE.eint<2>, %arg3: i3, %arg4: !HLFHE.eint<2>): // no predecessors - %4 = "HLFHE.mul_eint_int"(%arg2, %arg3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %5 = "HLFHE.add_eint"(%4, %arg4) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - linalg.yield %5 : !HLFHE.eint<2> - } -> tensor<1x!HLFHE.eint<2>> - return - } -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/mul_eint_int.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/mul_eint_int.mlir deleted file mode 100644 index fb337e685..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/mul_eint_int.mlir +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK-LABEL: func @mul_eint_int(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @mul_eint_int(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "MidLFHE.mul_glwe_int"(%arg0, %[[V1]]) : (!MidLFHE.glwe<{_,_,_}{7}>, i8) -> !MidLFHE.glwe<{_,_,_}{7}> - // CHECK-NEXT: return %[[V2]] : !MidLFHE.glwe<{_,_,_}{7}> - - %0 = arith.constant 1 : i8 - %1 = "HLFHE.mul_eint_int"(%arg0, %0): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/neg_eint.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/neg_eint.mlir deleted file mode 100644 index 1124ad293..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/neg_eint.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK-LABEL: func @neg_eint(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @neg_eint(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.neg_glwe"(%arg0) : (!MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> - // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{_,_,_}{7}> - - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> -} diff --git a/compiler/tests/Conversion/HLFHEToMidLFHE/sub_int_eint.mlir b/compiler/tests/Conversion/HLFHEToMidLFHE/sub_int_eint.mlir deleted file mode 100644 index e1ded8af4..000000000 --- a/compiler/tests/Conversion/HLFHEToMidLFHE/sub_int_eint.mlir +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: concretecompiler %s --passes hlfhe-to-midlfhe --action=dump-midlfhe 2>&1| FileCheck %s - -// CHECK-LABEL: func @sub_int_eint(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @sub_int_eint(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "MidLFHE.sub_int_glwe"(%[[V1]], %arg0) : (i8, !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> - // CHECK-NEXT: return %[[V2]] : !MidLFHE.glwe<{_,_,_}{7}> - - %0 = arith.constant 1 : i8 - %1 = "HLFHE.sub_int_eint"(%0, %arg0): (i8, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> -} diff --git a/compiler/tests/Conversion/LowLFHEToConcreteCAPI/bootstrap.mlir b/compiler/tests/Conversion/LowLFHEToConcreteCAPI/bootstrap.mlir deleted file mode 100644 index 144ecce08..000000000 --- a/compiler/tests/Conversion/LowLFHEToConcreteCAPI/bootstrap.mlir +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: concretecompiler --passes lowlfhe-to-concrete-c-api --action=dump-std %s 2>&1| FileCheck %s - -// CHECK-LABEL: module -// CHECK: func private @keyswitch_lwe_u64(index, !LowLFHE.lwe_key_switch_key, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.lwe_ciphertext<_,_>) -// CHECK: func private @get_keyswitch_key(!LowLFHE.context) -> !LowLFHE.lwe_key_switch_key -// CHECK: func private @bootstrap_lwe_u64(index, !LowLFHE.lwe_bootstrap_key, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.glwe_ciphertext) -// CHECK: func private @get_bootstrap_key(!LowLFHE.context) -> !LowLFHE.lwe_bootstrap_key -// CHECK: func private @allocate_lwe_ciphertext_u64(index, index) -> !LowLFHE.lwe_ciphertext<_,_> -// CHECK-LABEL: func @bootstrap_lwe(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: !LowLFHE.glwe_ciphertext, %arg2: !LowLFHE.context) -> !LowLFHE.lwe_ciphertext<1024,4> -func @bootstrap_lwe(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<1024,4> { - // CHECK-NEXT: %[[ERR:.*]] = arith.constant 0 : index - // CHECK-NEXT: %[[C0:.*]] = arith.constant 1025 : index - // CHECK-NEXT: %[[V1:.*]] = call @allocate_lwe_ciphertext_u64(%[[ERR]], %[[C0]]) : (index, index) -> !LowLFHE.lwe_ciphertext<_,_> - // CHECK-NEXT: %[[V2:.*]] = call @get_bootstrap_key(%arg2) : (!LowLFHE.context) -> !LowLFHE.lwe_bootstrap_key - // CHECK-NEXT: %[[V3:.*]] = builtin.unrealized_conversion_cast %arg0 : !LowLFHE.lwe_ciphertext<1024,4> to !LowLFHE.lwe_ciphertext<_,_> - // CHECK-NEXT: %[[V4:.*]] = builtin.unrealized_conversion_cast %arg1 : !LowLFHE.glwe_ciphertext to !LowLFHE.glwe_ciphertext - // CHECK-NEXT: call @bootstrap_lwe_u64(%[[ERR]], %[[V2]], %[[V1]], %[[V3]], %[[V4]]) : (index, !LowLFHE.lwe_bootstrap_key, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.glwe_ciphertext) -> () - // CHECK-NEXT: %[[RES:.*]] = builtin.unrealized_conversion_cast %[[V1]] : !LowLFHE.lwe_ciphertext<_,_> to !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[RES]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "LowLFHE.bootstrap_lwe"(%arg0, %arg1) {baseLog = 2 : i32, glweDimension = 1 : i32, level = 3 : i32, polynomialSize = 1024 : i32} : (!LowLFHE.lwe_ciphertext<1024,4>, !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<1024,4> - return %1: !LowLFHE.lwe_ciphertext<1024,4> -} diff --git a/compiler/tests/Conversion/LowLFHEToConcreteCAPI/glwe_from_table.mlir b/compiler/tests/Conversion/LowLFHEToConcreteCAPI/glwe_from_table.mlir deleted file mode 100644 index 72f638114..000000000 --- a/compiler/tests/Conversion/LowLFHEToConcreteCAPI/glwe_from_table.mlir +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: concretecompiler --passes lowlfhe-to-concrete-c-api --action=dump-std %s 2>&1| FileCheck %s - -// CHECK-LABEL: module -// CHECK: func private @runtime_foreign_plaintext_list_u64(index, tensor<16xi64>, i64, i32) -> !LowLFHE.foreign_plaintext_list -// CHECK: func private @add_plaintext_list_glwe_ciphertext_u64(index, !LowLFHE.glwe_ciphertext, !LowLFHE.glwe_ciphertext, !LowLFHE.plaintext_list) -// CHECK: func private @fill_plaintext_list_with_expansion_u64(index, !LowLFHE.plaintext_list, !LowLFHE.foreign_plaintext_list) -// CHECK: func private @allocate_plaintext_list_u64(index, i32) -> !LowLFHE.plaintext_list -// CHECK: func private @allocate_glwe_ciphertext_u64(index, i32, i32) -> !LowLFHE.glwe_ciphertext -// CHECK-LABEL: func @glwe_from_table(%arg0: tensor<16xi64>, %arg1: !LowLFHE.context) -> !LowLFHE.glwe_ciphertext -func @glwe_from_table(%arg0: tensor<16xi64>) -> !LowLFHE.glwe_ciphertext { - // CHECK-NEXT: %[[V0:.*]] = arith.constant 0 : index - // CHECK-NEXT: %[[C0:.*]] = arith.constant 2 : i32 - // CHECK-NEXT: %[[C1:.*]] = arith.constant 1024 : i32 - // CHECK-NEXT: %[[V1:.*]] = call @allocate_glwe_ciphertext_u64(%[[V0]], %[[C0]], %[[C1]]) : (index, i32, i32) -> !LowLFHE.glwe_ciphertext - // CHECK-NEXT: %[[V2:.*]] = call @allocate_glwe_ciphertext_u64(%[[V0]], %[[C0]], %[[C1]]) : (index, i32, i32) -> !LowLFHE.glwe_ciphertext - // CHECK-NEXT: %[[V3:.*]] = call @allocate_plaintext_list_u64(%[[V0]], %[[C1]]) : (index, i32) -> !LowLFHE.plaintext_list - // CHECK-NEXT: %[[C2:.*]] = arith.constant 16 : i64 - // CHECK-NEXT: %[[C3:.*]] = arith.constant 4 : i32 - // CHECK-NEXT: %[[V4:.*]] = call @runtime_foreign_plaintext_list_u64(%[[V0]], %arg0, %[[C2]], %[[C3]]) : (index, tensor<16xi64>, i64, i32) -> !LowLFHE.foreign_plaintext_list - // CHECK-NEXT: call @fill_plaintext_list_with_expansion_u64(%[[V0]], %[[V3]], %[[V4]]) : (index, !LowLFHE.plaintext_list, !LowLFHE.foreign_plaintext_list) -> () - // CHECK-NEXT: call @add_plaintext_list_glwe_ciphertext_u64(%[[V0]], %[[V1]], %[[V2]], %[[V3]]) : (index, !LowLFHE.glwe_ciphertext, !LowLFHE.glwe_ciphertext, !LowLFHE.plaintext_list) -> () - // CHECK-NEXT: return %[[V1]] : !LowLFHE.glwe_ciphertext - %1 = "LowLFHE.glwe_from_table"(%arg0) {glweDimension = 1 : i32, p = 4 : i32, polynomialSize = 1024 : i32} : (tensor<16xi64>) -> !LowLFHE.glwe_ciphertext - return %1: !LowLFHE.glwe_ciphertext -} diff --git a/compiler/tests/Conversion/LowLFHEToConcreteCAPI/keyswitch_lwe.mlir b/compiler/tests/Conversion/LowLFHEToConcreteCAPI/keyswitch_lwe.mlir deleted file mode 100644 index 0d4e4f333..000000000 --- a/compiler/tests/Conversion/LowLFHEToConcreteCAPI/keyswitch_lwe.mlir +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: concretecompiler --passes lowlfhe-to-concrete-c-api --action=dump-std %s 2>&1| FileCheck %s - -// CHECK-LABEL: module -// CHECK: func private @keyswitch_lwe_u64(index, !LowLFHE.lwe_key_switch_key, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.lwe_ciphertext<_,_>) -// CHECK: func private @get_keyswitch_key(!LowLFHE.context) -> !LowLFHE.lwe_key_switch_key -// CHECK: func private @bootstrap_lwe_u64(index, !LowLFHE.lwe_bootstrap_key, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.glwe_ciphertext) -// CHECK: func private @get_bootstrap_key(!LowLFHE.context) -> !LowLFHE.lwe_bootstrap_key -// CHECK: func private @allocate_lwe_ciphertext_u64(index, index) -> !LowLFHE.lwe_ciphertext<_,_> -// CHECK-LABEL: func @keyswitch_lwe(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: !LowLFHE.context) -> !LowLFHE.lwe_ciphertext<1024,4> -func @keyswitch_lwe(%arg0: !LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> { - // CHECK-NEXT: %[[ERR:.*]] = arith.constant 0 : index - // CHECK-NEXT: %[[C0:.*]] = arith.constant 1025 : index - // CHECK-NEXT: %[[V1:.*]] = call @allocate_lwe_ciphertext_u64(%[[ERR]], %[[C0]]) : (index, index) -> !LowLFHE.lwe_ciphertext<_,_> - // CHECK-NEXT: %[[V2:.*]] = call @get_keyswitch_key(%arg1) : (!LowLFHE.context) -> !LowLFHE.lwe_key_switch_key - // CHECK-NEXT: %[[V3:.*]] = builtin.unrealized_conversion_cast %arg0 : !LowLFHE.lwe_ciphertext<1024,4> to !LowLFHE.lwe_ciphertext<_,_> - // CHECK-NEXT: call @keyswitch_lwe_u64(%[[ERR]], %[[V2]], %[[V1]], %[[V3]]) : (index, !LowLFHE.lwe_key_switch_key, !LowLFHE.lwe_ciphertext<_,_>, !LowLFHE.lwe_ciphertext<_,_>) -> () - // CHECK-NEXT: %[[RES:.*]] = builtin.unrealized_conversion_cast %[[V1]] : !LowLFHE.lwe_ciphertext<_,_> to !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[RES]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, inputLweSize = 1 : i32, level = 3 : i32, outputLweSize = 1 : i32} : (!LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> - return %1: !LowLFHE.lwe_ciphertext<1024,4> -} diff --git a/compiler/tests/Conversion/LowLFHEUnparametrize/func.mlir b/compiler/tests/Conversion/LowLFHEUnparametrize/func.mlir deleted file mode 100644 index 7158beaad..000000000 --- a/compiler/tests/Conversion/LowLFHEUnparametrize/func.mlir +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: concretecompiler --passes lowlfhe-unparametrize --action=dump-llvm-dialect %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @main(%arg0: !LowLFHE.lwe_ciphertext<_,_>) -> !LowLFHE.lwe_ciphertext<_,_> -func @main(%arg0: !LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> { - // CHECK-NEXT: return %arg0 : !LowLFHE.lwe_ciphertext<_,_> - return %arg0: !LowLFHE.lwe_ciphertext<1024,4> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/LowLFHEUnparametrize/unrealized_conversion_cast.mlir b/compiler/tests/Conversion/LowLFHEUnparametrize/unrealized_conversion_cast.mlir deleted file mode 100644 index 5c2813985..000000000 --- a/compiler/tests/Conversion/LowLFHEUnparametrize/unrealized_conversion_cast.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: concretecompiler --passes lowlfhe-unparametrize --action=dump-llvm-dialect %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @main(%arg0: !LowLFHE.lwe_ciphertext<_,_>) -> !LowLFHE.lwe_ciphertext<_,_> -func @main(%arg0: !LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<_,_> { - // CHECK-NEXT: return %arg0 : !LowLFHE.lwe_ciphertext<_,_> - %0 = builtin.unrealized_conversion_cast %arg0 : !LowLFHE.lwe_ciphertext<1024,4> to !LowLFHE.lwe_ciphertext<_,_> - return %0: !LowLFHE.lwe_ciphertext<_,_> -} \ No newline at end of file diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/add_glwe.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/add_glwe.mlir deleted file mode 100644 index 8192199ee..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/add_glwe.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_glwe(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @add_glwe(%arg0: !MidLFHE.glwe<{2048,1,64}{7}>, %arg1: !MidLFHE.glwe<{2048,1,64}{7}>) -> !MidLFHE.glwe<{2048,1,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.add_lwe_ciphertexts"(%arg0, %arg1) : (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %0 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{2048,1,64}{7}>, !MidLFHE.glwe<{2048,1,64}{7}>) -> (!MidLFHE.glwe<{2048,1,64}{7}>) - return %0: !MidLFHE.glwe<{2048,1,64}{7}> -} diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/add_glwe_int.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/add_glwe_int.mlir deleted file mode 100644 index 7ab9e554a..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/add_glwe_int.mlir +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_glwe_const_int(%arg0: !LowLFHE.lwe_ciphertext<1024,7>) -> !LowLFHE.lwe_ciphertext<1024,7> -func @add_glwe_const_int(%arg0: !MidLFHE.glwe<{1024,1,64}{7}>) -> !MidLFHE.glwe<{1024,1,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.encode_int"(%[[V1]]) : (i8) -> !LowLFHE.plaintext<8> - // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.add_plaintext_lwe_ciphertext"(%arg0, %[[V2]]) : (!LowLFHE.lwe_ciphertext<1024,7>, !LowLFHE.plaintext<8>) -> !LowLFHE.lwe_ciphertext<1024,7> - // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<1024,7> - %0 = arith.constant 1 : i8 - %1 = "MidLFHE.add_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,1,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,1,64}{7}>) - return %1: !MidLFHE.glwe<{1024,1,64}{7}> -} - - -// CHECK-LABEL: func @add_glwe_int(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: i5) -> !LowLFHE.lwe_ciphertext<1024,4> -func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,1,64}{4}>, %arg1: i5) -> !MidLFHE.glwe<{1024,1,64}{4}> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.encode_int"(%arg1) : (i5) -> !LowLFHE.plaintext<5> - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.add_plaintext_lwe_ciphertext"(%arg0, %[[V1]]) : (!LowLFHE.lwe_ciphertext<1024,4>, !LowLFHE.plaintext<5>) -> !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[V2]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "MidLFHE.add_glwe_int"(%arg0, %arg1): (!MidLFHE.glwe<{1024,1,64}{4}>, i5) -> (!MidLFHE.glwe<{1024,1,64}{4}>) - return %1: !MidLFHE.glwe<{1024,1,64}{4}> -} diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir deleted file mode 100644 index 6e91e8b8e..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table.mlir +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @apply_lookup_table(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: tensor<16xi64>) -> !LowLFHE.lwe_ciphertext<1024,4> -func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,1,64}{4}>, %arg1: tensor<16xi64>) -> !MidLFHE.glwe<{1024,1,64}{4}> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.glwe_from_table"(%arg1) {glweDimension = 1 : i32, p = 4 : i32, polynomialSize = 1024 : i32} : (tensor<16xi64>) -> !LowLFHE.glwe_ciphertext - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, level = 3 : i32} : (!LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<600,4> - // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.bootstrap_lwe"(%[[V2]], %[[V1]]) {baseLog = 4 : i32, glweDimension = 1 : i32, level = 5 : i32, polynomialSize = 1024 : i32} : (!LowLFHE.lwe_ciphertext<600,4>, !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1){glweDimension=1:i32, polynomialSize=1024:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32, outputSizeKS=600:i32}: (!MidLFHE.glwe<{1024,1,64}{4}>, tensor<16xi64>) -> (!MidLFHE.glwe<{1024,1,64}{4}>) - return %1: !MidLFHE.glwe<{1024,1,64}{4}> -} diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir deleted file mode 100644 index ecde7dcc3..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/apply_lookup_table_cst.mlir +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @apply_lookup_table_cst(%arg0: !LowLFHE.lwe_ciphertext<2048,4>) -> !LowLFHE.lwe_ciphertext<2048,4> -func @apply_lookup_table_cst(%arg0: !MidLFHE.glwe<{2048,1,64}{4}>) -> !MidLFHE.glwe<{2048,1,64}{4}> { - // CHECK-NEXT: %[[TABLE:.*]] = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]> : tensor<16xi64> - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.glwe_from_table"(%[[TABLE]]) {glweDimension = 1 : i32, p = 4 : i32, polynomialSize = 2048 : i32} : (tensor<16xi64>) -> !LowLFHE.glwe_ciphertext - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, level = 3 : i32} : (!LowLFHE.lwe_ciphertext<2048,4>) -> !LowLFHE.lwe_ciphertext<600,4> - // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.bootstrap_lwe"(%[[V2]], %[[V1]]) {baseLog = 4 : i32, glweDimension = 1 : i32, level = 5 : i32, polynomialSize = 2048 : i32} : (!LowLFHE.lwe_ciphertext<600,4>, !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<2048,4> - // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<2048,4> - %tlu = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]> : tensor<16xi64> - %1 = "MidLFHE.apply_lookup_table"(%arg0, %tlu){glweDimension=1:i32, polynomialSize=2048:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32, outputSizeKS=600:i32}: (!MidLFHE.glwe<{2048,1,64}{4}>, tensor<16xi64>) -> (!MidLFHE.glwe<{2048,1,64}{4}>) - return %1: !MidLFHE.glwe<{2048,1,64}{4}> -} diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/mul_glwe_int.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/mul_glwe_int.mlir deleted file mode 100644 index 9f90590fd..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/mul_glwe_int.mlir +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @mul_glwe_const_int(%arg0: !LowLFHE.lwe_ciphertext<1024,7>) -> !LowLFHE.lwe_ciphertext<1024,7> -func @mul_glwe_const_int(%arg0: !MidLFHE.glwe<{1024,1,64}{7}>) -> !MidLFHE.glwe<{1024,1,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.int_to_cleartext"(%[[V1]]) : (i8) -> !LowLFHE.cleartext<8> - // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.mul_cleartext_lwe_ciphertext"(%arg0, %[[V2]]) : (!LowLFHE.lwe_ciphertext<1024,7>, !LowLFHE.cleartext<8>) -> !LowLFHE.lwe_ciphertext<1024,7> - // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<1024,7> - %0 = arith.constant 1 : i8 - %1 = "MidLFHE.mul_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,1,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,1,64}{7}>) - return %1: !MidLFHE.glwe<{1024,1,64}{7}> -} - - -// CHECK-LABEL: func @mul_glwe_int(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: i5) -> !LowLFHE.lwe_ciphertext<1024,4> -func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,1,64}{4}>, %arg1: i5) -> !MidLFHE.glwe<{1024,1,64}{4}> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.int_to_cleartext"(%arg1) : (i5) -> !LowLFHE.cleartext<5> - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.mul_cleartext_lwe_ciphertext"(%arg0, %[[V1]]) : (!LowLFHE.lwe_ciphertext<1024,4>, !LowLFHE.cleartext<5>) -> !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[V2]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "MidLFHE.mul_glwe_int"(%arg0, %arg1): (!MidLFHE.glwe<{1024,1,64}{4}>, i5) -> (!MidLFHE.glwe<{1024,1,64}{4}>) - return %1: !MidLFHE.glwe<{1024,1,64}{4}> -} diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/neg_glwe.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/neg_glwe.mlir deleted file mode 100644 index e0bffe3a4..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/neg_glwe.mlir +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @neg_glwe(%arg0: !LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> -func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,1,64}{4}>) -> !MidLFHE.glwe<{1024,1,64}{4}> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.negate_lwe_ciphertext"(%arg0) : (!LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,1,64}{4}>) -> (!MidLFHE.glwe<{1024,1,64}{4}>) - return %1: !MidLFHE.glwe<{1024,1,64}{4}> -} diff --git a/compiler/tests/Conversion/MidLFHEToLowLFHE/sub_int_glwe.mlir b/compiler/tests/Conversion/MidLFHEToLowLFHE/sub_int_glwe.mlir deleted file mode 100644 index 1f638da33..000000000 --- a/compiler/tests/Conversion/MidLFHEToLowLFHE/sub_int_glwe.mlir +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: concretecompiler --passes midlfhe-to-lowlfhe --action=dump-lowlfhe %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @sub_const_int_glwe(%arg0: !LowLFHE.lwe_ciphertext<1024,7>) -> !LowLFHE.lwe_ciphertext<1024,7> -func @sub_const_int_glwe(%arg0: !MidLFHE.glwe<{1024,1,64}{7}>) -> !MidLFHE.glwe<{1024,1,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[NEG:.*]] = "LowLFHE.negate_lwe_ciphertext"(%arg0) : (!LowLFHE.lwe_ciphertext<1024,7>) -> !LowLFHE.lwe_ciphertext<1024,7> - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.encode_int"(%[[V1]]) : (i8) -> !LowLFHE.plaintext<8> - // CHECK-NEXT: %[[V3:.*]] = "LowLFHE.add_plaintext_lwe_ciphertext"(%[[NEG]], %[[V2]]) : (!LowLFHE.lwe_ciphertext<1024,7>, !LowLFHE.plaintext<8>) -> !LowLFHE.lwe_ciphertext<1024,7> - // CHECK-NEXT: return %[[V3]] : !LowLFHE.lwe_ciphertext<1024,7> - %0 = arith.constant 1 : i8 - %1 = "MidLFHE.sub_int_glwe"(%0, %arg0): (i8, !MidLFHE.glwe<{1024,1,64}{7}>) -> (!MidLFHE.glwe<{1024,1,64}{7}>) - return %1: !MidLFHE.glwe<{1024,1,64}{7}> -} - -// CHECK-LABEL: func @sub_int_glwe(%arg0: !LowLFHE.lwe_ciphertext<1024,4>, %arg1: i5) -> !LowLFHE.lwe_ciphertext<1024,4> -func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,1,64}{4}>, %arg1: i5) -> !MidLFHE.glwe<{1024,1,64}{4}> { - // CHECK-NEXT: %[[NEG:.*]] = "LowLFHE.negate_lwe_ciphertext"(%arg0) : (!LowLFHE.lwe_ciphertext<1024,4>) -> !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.encode_int"(%arg1) : (i5) -> !LowLFHE.plaintext<5> - // CHECK-NEXT: %[[V2:.*]] = "LowLFHE.add_plaintext_lwe_ciphertext"(%[[NEG]], %[[V1]]) : (!LowLFHE.lwe_ciphertext<1024,4>, !LowLFHE.plaintext<5>) -> !LowLFHE.lwe_ciphertext<1024,4> - // CHECK-NEXT: return %[[V2]] : !LowLFHE.lwe_ciphertext<1024,4> - %1 = "MidLFHE.sub_int_glwe"(%arg1, %arg0): (i5, !MidLFHE.glwe<{1024,1,64}{4}>) -> (!MidLFHE.glwe<{1024,1,64}{4}>) - return %1: !MidLFHE.glwe<{1024,1,64}{4}> -} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/add_glwe.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/add_glwe.mlir new file mode 100644 index 000000000..4896fbd2f --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/add_glwe.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_glwe(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> +func @add_glwe(%arg0: !TFHE.glwe<{2048,1,64}{7}>, %arg1: !TFHE.glwe<{2048,1,64}{7}>) -> !TFHE.glwe<{2048,1,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.add_lwe_ciphertexts"(%arg0, %arg1) : (!Concrete.lwe_ciphertext<2048,7>, !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %0 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{2048,1,64}{7}>, !TFHE.glwe<{2048,1,64}{7}>) -> (!TFHE.glwe<{2048,1,64}{7}>) + return %0: !TFHE.glwe<{2048,1,64}{7}> +} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/add_glwe_int.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/add_glwe_int.mlir new file mode 100644 index 000000000..4a0f2f2d6 --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/add_glwe_int.mlir @@ -0,0 +1,22 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_glwe_const_int(%arg0: !Concrete.lwe_ciphertext<1024,7>) -> !Concrete.lwe_ciphertext<1024,7> +func @add_glwe_const_int(%arg0: !TFHE.glwe<{1024,1,64}{7}>) -> !TFHE.glwe<{1024,1,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "Concrete.encode_int"(%[[V1]]) : (i8) -> !Concrete.plaintext<8> + // CHECK-NEXT: %[[V3:.*]] = "Concrete.add_plaintext_lwe_ciphertext"(%arg0, %[[V2]]) : (!Concrete.lwe_ciphertext<1024,7>, !Concrete.plaintext<8>) -> !Concrete.lwe_ciphertext<1024,7> + // CHECK-NEXT: return %[[V3]] : !Concrete.lwe_ciphertext<1024,7> + %0 = arith.constant 1 : i8 + %1 = "TFHE.add_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,1,64}{7}>, i8) -> (!TFHE.glwe<{1024,1,64}{7}>) + return %1: !TFHE.glwe<{1024,1,64}{7}> +} + + +// CHECK-LABEL: func @add_glwe_int(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: i5) -> !Concrete.lwe_ciphertext<1024,4> +func @add_glwe_int(%arg0: !TFHE.glwe<{1024,1,64}{4}>, %arg1: i5) -> !TFHE.glwe<{1024,1,64}{4}> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.encode_int"(%arg1) : (i5) -> !Concrete.plaintext<5> + // CHECK-NEXT: %[[V2:.*]] = "Concrete.add_plaintext_lwe_ciphertext"(%arg0, %[[V1]]) : (!Concrete.lwe_ciphertext<1024,4>, !Concrete.plaintext<5>) -> !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[V2]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "TFHE.add_glwe_int"(%arg0, %arg1): (!TFHE.glwe<{1024,1,64}{4}>, i5) -> (!TFHE.glwe<{1024,1,64}{4}>) + return %1: !TFHE.glwe<{1024,1,64}{4}> +} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/apply_lookup_table.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/apply_lookup_table.mlir new file mode 100644 index 000000000..1e4d597c6 --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/apply_lookup_table.mlir @@ -0,0 +1,11 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @apply_lookup_table(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: tensor<16xi64>) -> !Concrete.lwe_ciphertext<1024,4> +func @apply_lookup_table(%arg0: !TFHE.glwe<{1024,1,64}{4}>, %arg1: tensor<16xi64>) -> !TFHE.glwe<{1024,1,64}{4}> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.glwe_from_table"(%arg1) {glweDimension = 1 : i32, p = 4 : i32, polynomialSize = 1024 : i32} : (tensor<16xi64>) -> !Concrete.glwe_ciphertext + // CHECK-NEXT: %[[V2:.*]] = "Concrete.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, level = 3 : i32} : (!Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<600,4> + // CHECK-NEXT: %[[V3:.*]] = "Concrete.bootstrap_lwe"(%[[V2]], %[[V1]]) {baseLog = 4 : i32, glweDimension = 1 : i32, level = 5 : i32, polynomialSize = 1024 : i32} : (!Concrete.lwe_ciphertext<600,4>, !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[V3]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "TFHE.apply_lookup_table"(%arg0, %arg1){glweDimension=1:i32, polynomialSize=1024:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32, outputSizeKS=600:i32}: (!TFHE.glwe<{1024,1,64}{4}>, tensor<16xi64>) -> (!TFHE.glwe<{1024,1,64}{4}>) + return %1: !TFHE.glwe<{1024,1,64}{4}> +} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/apply_lookup_table_cst.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/apply_lookup_table_cst.mlir new file mode 100644 index 000000000..de447fc64 --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/apply_lookup_table_cst.mlir @@ -0,0 +1,13 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @apply_lookup_table_cst(%arg0: !Concrete.lwe_ciphertext<2048,4>) -> !Concrete.lwe_ciphertext<2048,4> +func @apply_lookup_table_cst(%arg0: !TFHE.glwe<{2048,1,64}{4}>) -> !TFHE.glwe<{2048,1,64}{4}> { + // CHECK-NEXT: %[[TABLE:.*]] = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]> : tensor<16xi64> + // CHECK-NEXT: %[[V1:.*]] = "Concrete.glwe_from_table"(%[[TABLE]]) {glweDimension = 1 : i32, p = 4 : i32, polynomialSize = 2048 : i32} : (tensor<16xi64>) -> !Concrete.glwe_ciphertext + // CHECK-NEXT: %[[V2:.*]] = "Concrete.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, level = 3 : i32} : (!Concrete.lwe_ciphertext<2048,4>) -> !Concrete.lwe_ciphertext<600,4> + // CHECK-NEXT: %[[V3:.*]] = "Concrete.bootstrap_lwe"(%[[V2]], %[[V1]]) {baseLog = 4 : i32, glweDimension = 1 : i32, level = 5 : i32, polynomialSize = 2048 : i32} : (!Concrete.lwe_ciphertext<600,4>, !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<2048,4> + // CHECK-NEXT: return %[[V3]] : !Concrete.lwe_ciphertext<2048,4> + %tlu = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]> : tensor<16xi64> + %1 = "TFHE.apply_lookup_table"(%arg0, %tlu){glweDimension=1:i32, polynomialSize=2048:i32, levelKS=3:i32, baseLogKS=2:i32, levelBS=5:i32, baseLogBS=4:i32, outputSizeKS=600:i32}: (!TFHE.glwe<{2048,1,64}{4}>, tensor<16xi64>) -> (!TFHE.glwe<{2048,1,64}{4}>) + return %1: !TFHE.glwe<{2048,1,64}{4}> +} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/mul_glwe_int.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/mul_glwe_int.mlir new file mode 100644 index 000000000..859285549 --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/mul_glwe_int.mlir @@ -0,0 +1,22 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @mul_glwe_const_int(%arg0: !Concrete.lwe_ciphertext<1024,7>) -> !Concrete.lwe_ciphertext<1024,7> +func @mul_glwe_const_int(%arg0: !TFHE.glwe<{1024,1,64}{7}>) -> !TFHE.glwe<{1024,1,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "Concrete.int_to_cleartext"(%[[V1]]) : (i8) -> !Concrete.cleartext<8> + // CHECK-NEXT: %[[V3:.*]] = "Concrete.mul_cleartext_lwe_ciphertext"(%arg0, %[[V2]]) : (!Concrete.lwe_ciphertext<1024,7>, !Concrete.cleartext<8>) -> !Concrete.lwe_ciphertext<1024,7> + // CHECK-NEXT: return %[[V3]] : !Concrete.lwe_ciphertext<1024,7> + %0 = arith.constant 1 : i8 + %1 = "TFHE.mul_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,1,64}{7}>, i8) -> (!TFHE.glwe<{1024,1,64}{7}>) + return %1: !TFHE.glwe<{1024,1,64}{7}> +} + + +// CHECK-LABEL: func @mul_glwe_int(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: i5) -> !Concrete.lwe_ciphertext<1024,4> +func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,1,64}{4}>, %arg1: i5) -> !TFHE.glwe<{1024,1,64}{4}> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.int_to_cleartext"(%arg1) : (i5) -> !Concrete.cleartext<5> + // CHECK-NEXT: %[[V2:.*]] = "Concrete.mul_cleartext_lwe_ciphertext"(%arg0, %[[V1]]) : (!Concrete.lwe_ciphertext<1024,4>, !Concrete.cleartext<5>) -> !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[V2]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "TFHE.mul_glwe_int"(%arg0, %arg1): (!TFHE.glwe<{1024,1,64}{4}>, i5) -> (!TFHE.glwe<{1024,1,64}{4}>) + return %1: !TFHE.glwe<{1024,1,64}{4}> +} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/neg_glwe.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/neg_glwe.mlir new file mode 100644 index 000000000..843e68958 --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/neg_glwe.mlir @@ -0,0 +1,9 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @neg_glwe(%arg0: !Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<1024,4> +func @neg_glwe(%arg0: !TFHE.glwe<{1024,1,64}{4}>) -> !TFHE.glwe<{1024,1,64}{4}> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.negate_lwe_ciphertext"(%arg0) : (!Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "TFHE.neg_glwe"(%arg0): (!TFHE.glwe<{1024,1,64}{4}>) -> (!TFHE.glwe<{1024,1,64}{4}>) + return %1: !TFHE.glwe<{1024,1,64}{4}> +} diff --git a/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/sub_int_glwe.mlir b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/sub_int_glwe.mlir new file mode 100644 index 000000000..b1374fff3 --- /dev/null +++ b/compiler/tests/Conversion/TFHEToConcrete/TFHEToConcrete/sub_int_glwe.mlir @@ -0,0 +1,23 @@ +// RUN: concretecompiler --passes tfhe-to-concrete --action=dump-concrete %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @sub_const_int_glwe(%arg0: !Concrete.lwe_ciphertext<1024,7>) -> !Concrete.lwe_ciphertext<1024,7> +func @sub_const_int_glwe(%arg0: !TFHE.glwe<{1024,1,64}{7}>) -> !TFHE.glwe<{1024,1,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[NEG:.*]] = "Concrete.negate_lwe_ciphertext"(%arg0) : (!Concrete.lwe_ciphertext<1024,7>) -> !Concrete.lwe_ciphertext<1024,7> + // CHECK-NEXT: %[[V2:.*]] = "Concrete.encode_int"(%[[V1]]) : (i8) -> !Concrete.plaintext<8> + // CHECK-NEXT: %[[V3:.*]] = "Concrete.add_plaintext_lwe_ciphertext"(%[[NEG]], %[[V2]]) : (!Concrete.lwe_ciphertext<1024,7>, !Concrete.plaintext<8>) -> !Concrete.lwe_ciphertext<1024,7> + // CHECK-NEXT: return %[[V3]] : !Concrete.lwe_ciphertext<1024,7> + %0 = arith.constant 1 : i8 + %1 = "TFHE.sub_int_glwe"(%0, %arg0): (i8, !TFHE.glwe<{1024,1,64}{7}>) -> (!TFHE.glwe<{1024,1,64}{7}>) + return %1: !TFHE.glwe<{1024,1,64}{7}> +} + +// CHECK-LABEL: func @sub_int_glwe(%arg0: !Concrete.lwe_ciphertext<1024,4>, %arg1: i5) -> !Concrete.lwe_ciphertext<1024,4> +func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,1,64}{4}>, %arg1: i5) -> !TFHE.glwe<{1024,1,64}{4}> { + // CHECK-NEXT: %[[NEG:.*]] = "Concrete.negate_lwe_ciphertext"(%arg0) : (!Concrete.lwe_ciphertext<1024,4>) -> !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: %[[V1:.*]] = "Concrete.encode_int"(%arg1) : (i5) -> !Concrete.plaintext<5> + // CHECK-NEXT: %[[V2:.*]] = "Concrete.add_plaintext_lwe_ciphertext"(%[[NEG]], %[[V1]]) : (!Concrete.lwe_ciphertext<1024,4>, !Concrete.plaintext<5>) -> !Concrete.lwe_ciphertext<1024,4> + // CHECK-NEXT: return %[[V2]] : !Concrete.lwe_ciphertext<1024,4> + %1 = "TFHE.sub_int_glwe"(%arg1, %arg0): (i5, !TFHE.glwe<{1024,1,64}{4}>) -> (!TFHE.glwe<{1024,1,64}{4}>) + return %1: !TFHE.glwe<{1024,1,64}{4}> +} diff --git a/compiler/tests/Dialect/Concrete/Concrete/ops.mlir b/compiler/tests/Dialect/Concrete/Concrete/ops.mlir new file mode 100644 index 000000000..4a3e54fb9 --- /dev/null +++ b/compiler/tests/Dialect/Concrete/Concrete/ops.mlir @@ -0,0 +1,74 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_lwe_ciphertexts(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> +func @add_lwe_ciphertexts(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.add_lwe_ciphertexts"(%arg0, %arg1) : (!Concrete.lwe_ciphertext<2048,7>, !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %1 = "Concrete.add_lwe_ciphertexts"(%arg0, %arg1): (!Concrete.lwe_ciphertext<2048,7>, !Concrete.lwe_ciphertext<2048,7>) -> (!Concrete.lwe_ciphertext<2048,7>) + return %1: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @add_plaintext_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.plaintext<5>) -> !Concrete.lwe_ciphertext<2048,7> +func @add_plaintext_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.plaintext<5>) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.add_plaintext_lwe_ciphertext"(%arg0, %arg1) : (!Concrete.lwe_ciphertext<2048,7>, !Concrete.plaintext<5>) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %1 = "Concrete.add_plaintext_lwe_ciphertext"(%arg0, %arg1): (!Concrete.lwe_ciphertext<2048,7>, !Concrete.plaintext<5>) -> (!Concrete.lwe_ciphertext<2048,7>) + return %1: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @mul_cleartext_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.cleartext<7>) -> !Concrete.lwe_ciphertext<2048,7> +func @mul_cleartext_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.cleartext<7>) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.mul_cleartext_lwe_ciphertext"(%arg0, %arg1) : (!Concrete.lwe_ciphertext<2048,7>, !Concrete.cleartext<7>) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %1 = "Concrete.mul_cleartext_lwe_ciphertext"(%arg0, %arg1): (!Concrete.lwe_ciphertext<2048,7>, !Concrete.cleartext<7>) -> (!Concrete.lwe_ciphertext<2048,7>) + return %1: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @negate_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> +func @negate_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.negate_lwe_ciphertext"(%arg0) : (!Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %1 = "Concrete.negate_lwe_ciphertext"(%arg0): (!Concrete.lwe_ciphertext<2048,7>) -> (!Concrete.lwe_ciphertext<2048,7>) + return %1: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @bootstrap_lwe(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<2048,7> +func @bootstrap_lwe(%arg0: !Concrete.lwe_ciphertext<2048,7>, %arg1: !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.bootstrap_lwe"(%arg0, %arg1) {baseLog = -1 : i32, glweDimension = 1 : i32, level = -1 : i32, polynomialSize = 1024 : i32} : (!Concrete.lwe_ciphertext<2048,7>, !Concrete.glwe_ciphertext) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %1 = "Concrete.bootstrap_lwe"(%arg0, %arg1) {baseLog = -1 : i32, glweDimension = 1 : i32, level = -1 : i32, polynomialSize = 1024 : i32} : (!Concrete.lwe_ciphertext<2048,7>, !Concrete.glwe_ciphertext) -> (!Concrete.lwe_ciphertext<2048,7>) + return %1: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @keyswitch_lwe(%arg0: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> +func @keyswitch_lwe(%arg0: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, level = 3 : i32} : (!Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> + // CHECK-NEXT: return %[[V1]] : !Concrete.lwe_ciphertext<2048,7> + + %1 = "Concrete.keyswitch_lwe"(%arg0){baseLog = 2 : i32, level = 3 : i32}: (!Concrete.lwe_ciphertext<2048,7>) -> (!Concrete.lwe_ciphertext<2048,7>) + return %1: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @encode_int(%arg0: i6) -> !Concrete.plaintext<6> +func @encode_int(%arg0: i6) -> (!Concrete.plaintext<6>) { + // CHECK-NEXT: %[[V1:.*]] = "Concrete.encode_int"(%arg0) : (i6) -> !Concrete.plaintext<6> + // CHECK-NEXT: return %[[V1]] : !Concrete.plaintext<6> + + %0 = "Concrete.encode_int"(%arg0): (i6) -> !Concrete.plaintext<6> + return %0: !Concrete.plaintext<6> +} + +// CHECK-LABEL: func @int_to_cleartext() -> !Concrete.cleartext<6> +func @int_to_cleartext() -> !Concrete.cleartext<6> { + // CHECK-NEXT: %[[V0:.*]] = arith.constant 5 : i6 + // CHECK-NEXT: %[[V1:.*]] = "Concrete.int_to_cleartext"(%[[V0]]) : (i6) -> !Concrete.cleartext<6> + // CHECK-NEXT: return %[[V1]] : !Concrete.cleartext<6> + %0 = arith.constant 5 : i6 + %1 = "Concrete.int_to_cleartext"(%0) : (i6) -> !Concrete.cleartext<6> + return %1 : !Concrete.cleartext<6> +} diff --git a/compiler/tests/Dialect/Concrete/Concrete/types.mlir b/compiler/tests/Dialect/Concrete/Concrete/types.mlir new file mode 100644 index 000000000..c17f352c9 --- /dev/null +++ b/compiler/tests/Dialect/Concrete/Concrete/types.mlir @@ -0,0 +1,44 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + + +// CHECK-LABEL: func @type_plaintext(%arg0: !Concrete.plaintext<7>) -> !Concrete.plaintext<7> +func @type_plaintext(%arg0: !Concrete.plaintext<7>) -> !Concrete.plaintext<7> { + // CHECK-NEXT: return %arg0 : !Concrete.plaintext<7> + return %arg0: !Concrete.plaintext<7> +} + +// CHECK-LABEL: func @type_plaintext_list(%arg0: !Concrete.plaintext_list) -> !Concrete.plaintext_list +func @type_plaintext_list(%arg0: !Concrete.plaintext_list) -> !Concrete.plaintext_list { + // CHECK-NEXT: return %arg0 : !Concrete.plaintext_list + return %arg0: !Concrete.plaintext_list +} + +// CHECK-LABEL: func @type_foreign_plaintext_list(%arg0: !Concrete.foreign_plaintext_list) -> !Concrete.foreign_plaintext_list +func @type_foreign_plaintext_list(%arg0: !Concrete.foreign_plaintext_list) -> !Concrete.foreign_plaintext_list { + // CHECK-NEXT: return %arg0 : !Concrete.foreign_plaintext_list + return %arg0: !Concrete.foreign_plaintext_list +} + +// CHECK-LABEL: func @type_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> +func @type_lwe_ciphertext(%arg0: !Concrete.lwe_ciphertext<2048,7>) -> !Concrete.lwe_ciphertext<2048,7> { + // CHECK-NEXT: return %arg0 : !Concrete.lwe_ciphertext<2048,7> + return %arg0: !Concrete.lwe_ciphertext<2048,7> +} + +// CHECK-LABEL: func @type_lwe_key_switch_key(%arg0: !Concrete.lwe_key_switch_key) -> !Concrete.lwe_key_switch_key +func @type_lwe_key_switch_key(%arg0: !Concrete.lwe_key_switch_key) -> !Concrete.lwe_key_switch_key { + // CHECK-NEXT: return %arg0 : !Concrete.lwe_key_switch_key + return %arg0: !Concrete.lwe_key_switch_key +} + +// CHECK-LABEL: func @type_lwe_bootstrap_key(%arg0: !Concrete.lwe_bootstrap_key) -> !Concrete.lwe_bootstrap_key +func @type_lwe_bootstrap_key(%arg0: !Concrete.lwe_bootstrap_key) -> !Concrete.lwe_bootstrap_key { + // CHECK-NEXT: return %arg0 : !Concrete.lwe_bootstrap_key + return %arg0: !Concrete.lwe_bootstrap_key +} + +// CHECK-LABEL: func @type_cleartext(%arg0: !Concrete.cleartext<5>) -> !Concrete.cleartext<5> +func @type_cleartext(%arg0: !Concrete.cleartext<5>) -> !Concrete.cleartext<5> { + // CHECK-NEXT: return %arg0 : !Concrete.cleartext<5> + return %arg0: !Concrete.cleartext<5> +} diff --git a/compiler/tests/Dialect/FHE/FHE/Analysis/MANP.mlir b/compiler/tests/Dialect/FHE/FHE/Analysis/MANP.mlir new file mode 100644 index 000000000..4da67cdf5 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/Analysis/MANP.mlir @@ -0,0 +1,202 @@ +// RUN: concretecompiler --passes MANP --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s + +func @single_zero() -> !FHE.eint<2> +{ + // CHECK: %[[ret:.*]] = "FHE.zero"() {MANP = 1 : ui{{[[0-9]+}}} : () -> !FHE.eint<2> + %0 = "FHE.zero"() : () -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_cst_add_eint_int(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + %cst = arith.constant 3 : i3 + + // CHECK: %[[ret:.*]] = "FHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%e, %cst) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_dyn_add_eint_int(%e: !FHE.eint<2>, %i: i3) -> !FHE.eint<2> +{ + // CHECK: %[[ret:.*]] = "FHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%e, %i) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_add_eint(%e0: !FHE.eint<2>, %e1: !FHE.eint<2>) -> !FHE.eint<2> +{ + // CHECK: %[[ret:.*]] = "FHE.add_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + %0 = "FHE.add_eint"(%e0, %e1) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_cst_sub_int_eint(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + %cst = arith.constant 3 : i3 + + // CHECK: %[[ret:.*]] = "FHE.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (i3, !FHE.eint<2>) -> !FHE.eint<2> + %0 = "FHE.sub_int_eint"(%cst, %e) : (i3, !FHE.eint<2>) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_dyn_sub_int_eint(%e: !FHE.eint<2>, %i: i3) -> !FHE.eint<2> +{ + // CHECK: %[[ret:.*]] = "FHE.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (i3, !FHE.eint<2>) -> !FHE.eint<2> + %0 = "FHE.sub_int_eint"(%i, %e) : (i3, !FHE.eint<2>) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_neg_eint(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + // CHECK: %[[ret:.*]] = "FHE.neg_eint"(%[[op0:.*]]) {MANP = 1 : ui{{[0-9]+}}} : (!FHE.eint<2>) -> !FHE.eint<2> + %0 = "FHE.neg_eint"(%e) : (!FHE.eint<2>) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_cst_mul_eint_int(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + %cst = arith.constant 3 : i3 + + // %0 = "FHE.mul_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 3 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.mul_eint_int"(%e, %cst) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_dyn_mul_eint_int(%e: !FHE.eint<2>, %i: i3) -> !FHE.eint<2> +{ + // CHECK: %[[ret:.*]] = "FHE.mul_eint_int"([[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.mul_eint_int"(%e, %i) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_apply_lookup_table(%arg0: !FHE.eint<2>, %arg1: tensor<4xi64>) -> !FHE.eint<2> { + // CHECK: %[[ret:.*]] = "FHE.apply_lookup_table"(%[[op0:.*]], %[[op1:.*]]) {MANP = 1 : ui{{[0-9]+}}} : (!FHE.eint<2>, tensor<4xi64>) -> !FHE.eint<2> + %1 = "FHE.apply_lookup_table"(%arg0, %arg1): (!FHE.eint<2>, tensor<4xi64>) -> !FHE.eint<2> + return %1: !FHE.eint<2> +} + +// ----- + +func @chain_add_eint_int(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + %cst0 = arith.constant 3 : i3 + %cst1 = arith.constant 7 : i3 + %cst2 = arith.constant 2 : i3 + %cst3 = arith.constant 1 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%e, %cst0) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V1:.*]] = "FHE.add_eint_int"(%[[V0]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %1 = "FHE.add_eint_int"(%0, %cst1) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V2:.*]] = "FHE.add_eint_int"(%[[V1]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %2 = "FHE.add_eint_int"(%1, %cst2) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V3:.*]] = "FHE.add_eint_int"(%[[V2]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %3 = "FHE.add_eint_int"(%2, %cst3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + return %3 : !FHE.eint<2> +} + +// ----- + +func @dag_add_eint_int(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + %Acst0 = arith.constant 3 : i3 + %Acst1 = arith.constant 7 : i3 + %Acst2 = arith.constant 2 : i3 + %Acst3 = arith.constant 1 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %A0 = "FHE.add_eint_int"(%e, %Acst0) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V1:.*]] = "FHE.add_eint_int"(%[[V0]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %A1 = "FHE.add_eint_int"(%A0, %Acst1) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V2:.*]] = "FHE.add_eint_int"(%[[V1]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %A2 = "FHE.add_eint_int"(%A1, %Acst2) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V3:.*]] = "FHE.add_eint_int"(%[[V2]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %A3 = "FHE.add_eint_int"(%A2, %Acst3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + %Bcst0 = arith.constant 1 : i3 + %Bcst1 = arith.constant 5 : i3 + %Bcst2 = arith.constant 2 : i3 + %Bcst3 = arith.constant 7 : i3 + %Bcst4 = arith.constant 4 : i3 + %Bcst5 = arith.constant 7 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %B0 = "FHE.add_eint_int"(%e, %Bcst0) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V1:.*]] = "FHE.add_eint_int"(%[[V0]], %[[op1:.*]]) {MANP = 6 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %B1 = "FHE.add_eint_int"(%B0, %Bcst1) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V2:.*]] = "FHE.add_eint_int"(%[[V1]], %[[op1:.*]]) {MANP = 6 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %B2 = "FHE.add_eint_int"(%B1, %Bcst2) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V3:.*]] = "FHE.add_eint_int"(%[[V2]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %B3 = "FHE.add_eint_int"(%B2, %Bcst3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V4:.*]] = "FHE.add_eint_int"(%[[V3]], %[[op1:.*]]) {MANP = 10 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %B4 = "FHE.add_eint_int"(%B3, %Bcst4) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[V5:.*]] = "FHE.add_eint_int"(%[[V4]], %[[op1:.*]]) {MANP = 13 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %B5 = "FHE.add_eint_int"(%B4, %Bcst5) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + // CHECK-NEXT: %[[V6:.*]] = "FHE.add_eint"(%[[V5]], %[[op1:.*]]) {MANP = 15 : ui{{[0-9]+}}} : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + %res = "FHE.add_eint"(%B5, %A3) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + + return %A3 : !FHE.eint<2> +} + +// ----- + +func @chain_add_eint(%e0: !FHE.eint<2>, %e1: !FHE.eint<2>, %e2: !FHE.eint<2>, %e3: !FHE.eint<2>, %e4: !FHE.eint<2>) -> !FHE.eint<2> +{ + // CHECK: %[[V0:.*]] = "FHE.add_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + %0 = "FHE.add_eint"(%e0, %e1) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + + // CHECK-NEXT: %[[V1:.*]] = "FHE.add_eint"(%[[V0]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + %1 = "FHE.add_eint"(%0, %e2) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + + // CHECK-NEXT: %[[V2:.*]] = "FHE.add_eint"(%[[V1]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + %2 = "FHE.add_eint"(%1, %e3) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + + // CHECK-NEXT: %[[V3:.*]] = "FHE.add_eint"(%[[V2]], %[[op1:.*]]) {MANP = 3 : ui{{[0-9]+}}} : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + %3 = "FHE.add_eint"(%2, %e4) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + + return %3 : !FHE.eint<2> +} + + +// ----- + +func @chain_add_eint_neg_eint(%e: !FHE.eint<2>) -> !FHE.eint<2> +{ + %cst0 = arith.constant 3 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%e, %cst0) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: %[[ret:.*]] = "FHE.neg_eint"(%[[V0]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>) -> !FHE.eint<2> + %1 = "FHE.neg_eint"(%0) : (!FHE.eint<2>) -> !FHE.eint<2> + + return %1 : !FHE.eint<2> +} \ No newline at end of file diff --git a/compiler/tests/Dialect/FHE/FHE/Analysis/MANP_linalg.mlir b/compiler/tests/Dialect/FHE/FHE/Analysis/MANP_linalg.mlir new file mode 100644 index 000000000..e95c8fa62 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/Analysis/MANP_linalg.mlir @@ -0,0 +1,392 @@ +// RUN: concretecompiler --passes MANP --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s + +func @single_cst_add_eint_int(%t: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + %cst = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> + + // CHECK: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.add_eint_int"(%t, %cst) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_dyn_add_eint_int(%e: tensor<8x!FHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!FHE.eint<2>> +{ + // CHECK: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.add_eint_int"(%e, %i) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_add_eint(%e0: tensor<8x!FHE.eint<2>>, %e1: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + // CHECK: %[[ret:.*]] = "FHELinalg.add_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.add_eint"(%e0, %e1) : (tensor<8x!FHE.eint<2>>, tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_cst_sub_int_eint(%e: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + %cst = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> + + // CHECK: %[[ret:.*]] = "FHELinalg.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8xi3>, tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.sub_int_eint"(%cst, %e) : (tensor<8xi3>, tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_neg_eint(%e: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + // CHECK: %[[ret:.*]] = "FHELinalg.neg_eint"(%[[op0:.*]]) {MANP = 1 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.neg_eint"(%e) : (tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_dyn_sub_int_eint(%e: tensor<8x!FHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!FHE.eint<2>> +{ + // CHECK: %[[ret:.*]] = "FHELinalg.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (tensor<8xi3>, tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.sub_int_eint"(%i, %e) : (tensor<8xi3>, tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_cst_mul_eint_int(%e: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + %cst = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> + + // %0 = "FHELinalg.mul_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 3 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.mul_eint_int"(%e, %cst) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @single_dyn_mul_eint_int(%e: tensor<8x!FHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!FHE.eint<2>> +{ + // CHECK: %[[ret:.*]] = "FHELinalg.mul_eint_int"([[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.mul_eint_int"(%e, %i) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @chain_add_eint_int(%e: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + %cst0 = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> + %cst1 = arith.constant dense<[0, 7, 2, 5, 6, 2, 1, 7]> : tensor<8xi3> + %cst2 = arith.constant dense<[0, 1, 2, 0, 1, 2, 0, 1]> : tensor<8xi3> + %cst3 = arith.constant dense<[0, 1, 1, 0, 0, 1, 0, 1]> : tensor<8xi3> + // CHECK: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.add_eint_int"(%e, %cst0) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + // CHECK-NEXT: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %1 = "FHELinalg.add_eint_int"(%0, %cst1) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + // CHECK-NEXT: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %2 = "FHELinalg.add_eint_int"(%1, %cst2) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + // CHECK-NEXT: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %3 = "FHELinalg.add_eint_int"(%2, %cst3) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + return %3 : tensor<8x!FHE.eint<2>> +} + +// ----- + +func @chain_add_eint_int_neg_eint(%e: tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> +{ + %cst0 = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> + // CHECK: %[[ret:.*]] = "FHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.add_eint_int"(%e, %cst0) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + // CHECK-NEXT: %[[ret:.*]] = "FHELinalg.neg_eint"(%[[op0:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + %1 = "FHELinalg.neg_eint"(%0) : (tensor<8x!FHE.eint<2>>) -> tensor<8x!FHE.eint<2>> + return %1 : tensor<8x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.apply_multi_lookup_table +///////////////////////////////////////////////// + +func @apply_lookup_table(%t: tensor<3x3x!FHE.eint<2>>) -> tensor<3x3x!FHE.eint<3>> { + %lut = arith.constant dense<[1,3,5,7]> : tensor<4xi64> + // CHECK: %[[RES:.*]] = "FHELinalg.apply_lookup_table"(%[[T:.*]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<3x3x!FHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!FHE.eint<3>> + %res = "FHELinalg.apply_lookup_table"(%t, %lut) : (tensor<3x3x!FHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!FHE.eint<3>> + return %res : tensor<3x3x!FHE.eint<3>> +} + +// ----- + +func @apply_lookup_table_after_op(%t: tensor<8x!FHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!FHE.eint<3>> { + %lut = arith.constant dense<[1,3,5,7]> : tensor<4xi64> + // CHECK: %[[V0:.*]] = "FHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.mul_eint_int"(%t, %i) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + // CHECK-NEXT: %[[RES:.*]] = "FHELinalg.apply_lookup_table"(%[[V0]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<8x!FHE.eint<2>>, tensor<4xi64>) -> tensor<8x!FHE.eint<3>> + %res = "FHELinalg.apply_lookup_table"(%0, %lut) : (tensor<8x!FHE.eint<2>>, tensor<4xi64>) -> tensor<8x!FHE.eint<3>> + return %res : tensor<8x!FHE.eint<3>> +} + +// ----- + + +func @apply_multi_lookup_table(%t: tensor<3x3x!FHE.eint<2>>, %luts: tensor<3x3x4xi64>) -> tensor<3x3x!FHE.eint<3>> { + // CHECK: %[[RES:.*]] = "FHELinalg.apply_multi_lookup_table"(%[[T:.*]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<3x3x!FHE.eint<2>>, tensor<3x3x4xi64>) -> tensor<3x3x!FHE.eint<3>> + %res = "FHELinalg.apply_multi_lookup_table"(%t, %luts) : (tensor<3x3x!FHE.eint<2>>, tensor<3x3x4xi64>) -> tensor<3x3x!FHE.eint<3>> + return %res : tensor<3x3x!FHE.eint<3>> +} + +// ----- + +func @apply_multi_lookup_table_after_op(%t: tensor<8x!FHE.eint<2>>, %i: tensor<8xi3>, %luts: tensor<8x4xi64>) -> tensor<8x!FHE.eint<3>> { + // CHECK: %[[V0:.*]] = "FHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.mul_eint_int"(%t, %i) : (tensor<8x!FHE.eint<2>>, tensor<8xi3>) -> tensor<8x!FHE.eint<2>> + // CHECK-NEXT: %[[RES:.*]] = "FHELinalg.apply_multi_lookup_table"(%[[V0]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<8x!FHE.eint<2>>, tensor<8x4xi64>) -> tensor<8x!FHE.eint<3>> + %res = "FHELinalg.apply_multi_lookup_table"(%0, %luts) : (tensor<8x!FHE.eint<2>>, tensor<8x4xi64>) -> tensor<8x!FHE.eint<3>> + return %res : tensor<8x!FHE.eint<3>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.dot_eint_int +///////////////////////////////////////////////// + +func @single_cst_dot(%t: tensor<4x!FHE.eint<2>>) -> !FHE.eint<2> +{ + %cst = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi3> + // sqrt(1^2*1 + 2^2*1 + 3^2*1 + 4^2*1) = 5.477225575 + // CHECK: %[[V0:.*]] = "FHELinalg.dot_eint_int"(%[[T:.*]], %[[CST:.*]]) {MANP = 6 : ui{{[[0-9]+}}} : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<2> + %0 = "FHELinalg.dot_eint_int"(%t, %cst) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<2> + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_dyn_dot(%t: tensor<4x!FHE.eint<2>>, %dyn: tensor<4xi3>) -> !FHE.eint<2> +{ + // sqrt(1*(2^3-1)^2*4) = 14 + // CHECK: %[[V0:.*]] = "FHELinalg.dot_eint_int"([[T:.*]], %[[DYN:.*]]) {MANP = 14 : ui{{[[0-9]+}}} : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<2> + %0 = "FHELinalg.dot_eint_int"(%t, %dyn) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<2> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @single_cst_dot_after_op(%t: tensor<4x!FHE.eint<2>>, %i: tensor<4xi3>) -> !FHE.eint<2> +{ + // sqrt((2^3)^2*1) = sqrt(64) = 8 + // CHECK: %[[V0:.*]] = "FHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} + %0 = "FHELinalg.mul_eint_int"(%t, %i) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> + + %cst = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi3> + // sqrt(1^2*64 + 2^2*64 + 3^2*64 + 4^2*64) = sqrt(1920) = 43.8178046 + // CHECK: %[[V1:.*]] = "FHELinalg.dot_eint_int"(%[[V0]], %[[CST:.*]]) {MANP = 44 : ui{{[[0-9]+}}} + %1 = "FHELinalg.dot_eint_int"(%0, %cst) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<2> + + return %1 : !FHE.eint<2> +} + +// ----- + +func @single_dyn_dot_after_op(%t: tensor<4x!FHE.eint<2>>, %i: tensor<4xi3>) -> !FHE.eint<2> +{ + // sqrt((2^3)^2*1) = sqrt(64) = 8 + // CHECK: %[[V0:.*]] = "FHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} + %0 = "FHELinalg.mul_eint_int"(%t, %i) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> + + // sqrt(4*(2^3-1)^2*64) = sqrt(12544) = 112 + // CHECK: %[[V1:.*]] = "FHELinalg.dot_eint_int"(%[[V0]], %[[I]]) {MANP = 112 : ui{{[[0-9]+}}} + %1 = "FHELinalg.dot_eint_int"(%0, %i) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<2> + + return %1 : !FHE.eint<2> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.matmul_ent_int +///////////////////////////////////////////////// + +func @matmul_eint_int_dyn_p_1(%arg0: tensor<3x1x!FHE.eint<2>>, %arg1: tensor<1x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 + // manp(add_eint(mul, acc)) = 64 + 1 = 65 + // ceil(sqrt(65)) = 9 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 9 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x1x!FHE.eint<2>>, tensor<1x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int_dyn_p_2(%arg0: tensor<3x2x!FHE.eint<2>>, %arg1: tensor<2x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 + // manp(add_eint(mul, acc)) = 64 + 1 = 65 + // p = 1 + // manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 + // manp(add_eint(mul, acc)) = 64 + 65 = 129 + // ceil(sqrt(129)) = 12 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 12 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x2x!FHE.eint<2>>, tensor<2x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int_cst_p_1(%arg0: tensor<3x1x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + %0 = arith.constant dense<[[3, 1]]> : tensor<1x2xi3> + // c(m,n) = a(m,p) * b(p,n) the max cst is used for n = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 + // manp(add_eint(mul, acc)) = 9 + 1 = 10 + // ceil(sqrt(10)) = 4 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 4 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %0): (tensor<3x1x!FHE.eint<2>>, tensor<1x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int_cst_p_2_n_0(%arg0: tensor<3x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + %0 = arith.constant dense<[[4, 1],[3, 1]]> : tensor<2x2xi3> + // c(m,n) = a(m,p) * b(p,n) the max csts [4,3] are used for n = 0 + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 + // manp(add_eint(mul, acc)) = 9 + 1 = 10 + // p = 1 + // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 17 + // manp(add_eint(mul, acc)) = 17 + 9 = 26 + // ceil(sqrt(26)) = 6 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 6 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %0): (tensor<3x2x!FHE.eint<2>>, tensor<2x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int_cst_p_2_n_1(%arg0: tensor<3x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + %0 = arith.constant dense<[[1, 4],[3, 1]]> : tensor<2x2xi3> + // c(m,n) = a(m,p) * b(p,n) the max csts [4,1] are used for n = 1 + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 16 + // manp(add_eint(mul, acc)) = 16 + 1 = 17 + // p = 1 + // mul = manp(mul_eint_int(eint<2>, 1) = 1 * 1^2 = 1 + // manp(add_eint(mul, acc)) = 1 + 17 = 18 + // ceil(sqrt(18)) = 5 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 5 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %0): (tensor<3x2x!FHE.eint<2>>, tensor<2x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.matmul_int_eint +///////////////////////////////////////////////// + +// ----- + +func @matmul_int_eint_dyn_p_1(%arg0: tensor<3x1xi3>, %arg1: tensor<1x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 + // manp(add_eint(mul, acc)) = 64 + 1 = 65 + // ceil(sqrt(65)) = 9 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 9 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x1xi3>, tensor<1x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint_dyn_p_2(%arg0: tensor<3x2xi3>, %arg1: tensor<2x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 + // manp(add_eint(mul, acc)) = 64 + 1 = 65 + // p = 1 + // manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 + // manp(add_eint(mul, acc)) = 64 + 65 = 129 + // ceil(sqrt(129)) = 12 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 12 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x2xi3>, tensor<2x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint_cst_p_1(%arg0: tensor<1x3x!FHE.eint<2>>) -> tensor<2x3x!FHE.eint<2>> { + %0 = arith.constant dense<[[3], [1]]> : tensor<2x1xi3> + // c(m,n) = a(m,p) * b(p,n) the max cst is used for m = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 + // manp(add_eint(mul, acc)) = 9 + 1 = 10 + // ceil(sqrt(10)) = 4 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 4 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_int_eint"(%0, %arg0): (tensor<2x1xi3>, tensor<1x3x!FHE.eint<2>>) -> tensor<2x3x!FHE.eint<2>> + return %1 : tensor<2x3x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint_cst_p_2_n_0(%arg0: tensor<2x3x!FHE.eint<2>>) -> tensor<2x3x!FHE.eint<2>> { + %0 = arith.constant dense<[[3, 4],[1, 1]]> : tensor<2x2xi3> + // c(m,n) = a(m,p) * b(p,n) the max csts [4,3] are used for m = 0 + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 + // manp(add_eint(mul, acc)) = 9 + 1 = 10 + // p = 1 + // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 17 + // manp(add_eint(mul, acc)) = 17 + 9 = 26 + // ceil(sqrt(26)) = 6 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 6 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_int_eint"(%0, %arg0): (tensor<2x2xi3>, tensor<2x3x!FHE.eint<2>>) -> tensor<2x3x!FHE.eint<2>> + return %1 : tensor<2x3x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint_cst_p_2_n_1(%arg0: tensor<2x3x!FHE.eint<2>>) -> tensor<2x3x!FHE.eint<2>> { + %0 = arith.constant dense<[[4, 1],[3, 1]]> : tensor<2x2xi3> + // c(m,n) = a(m,p) * b(p,n) the max csts [4,1] are used for m = 1 + // p = 0 + // acc = manp(0) = 1 + // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 16 + // manp(add_eint(mul, acc)) = 16 + 1 = 17 + // p = 1 + // mul = manp(mul_eint_int(eint<2>, 1) = 1 * 1^2 = 1 + // manp(add_eint(mul, acc)) = 1 + 17 = 18 + // ceil(sqrt(18)) = 5 + // CHECK: %[[V1:.*]] = "FHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 5 : ui{{[0-9]+}}} + %1 = "FHELinalg.matmul_int_eint"(%0, %arg0): (tensor<2x2xi3>, tensor<2x3x!FHE.eint<2>>) -> tensor<2x3x!FHE.eint<2>> + return %1 : tensor<2x3x!FHE.eint<2>> +} + +// ----- + +func @zero() -> tensor<8x!FHE.eint<2>> +{ + // CHECK: %[[ret:.*]] = "FHELinalg.zero"() {MANP = 1 : ui{{[0-9]+}}} : () -> tensor<8x!FHE.eint<2>> + %0 = "FHELinalg.zero"() : () -> tensor<8x!FHE.eint<2>> + + return %0 : tensor<8x!FHE.eint<2>> +} diff --git a/compiler/tests/Dialect/FHE/FHE/Analysis/MANP_tensor.mlir b/compiler/tests/Dialect/FHE/FHE/Analysis/MANP_tensor.mlir new file mode 100644 index 000000000..d5f0d631a --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/Analysis/MANP_tensor.mlir @@ -0,0 +1,160 @@ +// RUN: concretecompiler --passes MANP --action=dump-fhe --split-input-file %s 2>&1 | FileCheck %s + +func @tensor_from_elements_1(%a: !FHE.eint<2>, %b: !FHE.eint<2>, %c: !FHE.eint<2>, %d: !FHE.eint<2>) -> tensor<4x!FHE.eint<2>> +{ + // The MANP value is 1 as all operands are function arguments + // CHECK: %[[ret:.*]] = tensor.from_elements %[[a:.*]], %[[b:.*]], %[[c:.*]], %[[d:.*]] {MANP = 1 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<2>> + %0 = tensor.from_elements %a, %b, %c, %d : tensor<4x!FHE.eint<2>> + + return %0 : tensor<4x!FHE.eint<2>> +} + +// ----- + +func @tensor_from_elements_2(%a: !FHE.eint<2>, %b: !FHE.eint<2>, %c: !FHE.eint<2>, %d: !FHE.eint<2>) -> tensor<4x!FHE.eint<2>> +{ + %cst = arith.constant 3 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[a:.*]], %[[cst:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%a, %cst) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + + // The MANP value is 4, i.e. the max of all of its operands + // CHECK: %[[V1:.*]] = tensor.from_elements %[[V0]], %[[b:.*]], %[[c:.*]], %[[d:.*]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<2>> + %1 = tensor.from_elements %0, %b, %c, %d : tensor<4x!FHE.eint<2>> + + return %1 : tensor<4x!FHE.eint<2>> +} + +// ----- + +func @tensor_extract_1(%t: tensor<4x!FHE.eint<2>>) -> !FHE.eint<2> +{ + %cst = arith.constant 1 : index + + // The MANP value is 1 as the tensor operand is a function argument + // CHECK: %[[ret:.*]] = tensor.extract %[[t:.*]][%[[c1:.*]]] {MANP = 1 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<2>> + %0 = tensor.extract %t[%cst] : tensor<4x!FHE.eint<2>> + + return %0 : !FHE.eint<2> +} + +// ----- + +func @tensor_extract_2(%a: !FHE.eint<2>) -> !FHE.eint<2> +{ + %c1 = arith.constant 1 : index + %c3 = arith.constant 3 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[a:.*]], %[[c1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%a, %c3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK: %[[V1:.*]] = tensor.from_elements %[[V0]], %[[a:.*]], %[[a:.*]], %[[a:.*]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<2>> + %1 = tensor.from_elements %0, %a, %a, %a : tensor<4x!FHE.eint<2>> + // CHECK: %[[ret:.*]] = tensor.extract %[[V1]][%[[c3:.*]]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<2>> + %2 = tensor.extract %1[%c1] : tensor<4x!FHE.eint<2>> + + return %2 : !FHE.eint<2> +} + +// ----- + +func @tensor_extract_slice_1(%t: tensor<2x10x!FHE.eint<2>>) -> tensor<1x5x!FHE.eint<2>> +{ + // CHECK: %[[V0:.*]] = tensor.extract_slice %[[t:.*]][1, 5] [1, 5] [1, 1] {MANP = 1 : ui{{[[0-9]+}}} : tensor<2x10x!FHE.eint<2>> to tensor<1x5x!FHE.eint<2>> + %0 = tensor.extract_slice %t[1, 5] [1, 5] [1, 1] : tensor<2x10x!FHE.eint<2>> to tensor<1x5x!FHE.eint<2>> + + return %0 : tensor<1x5x!FHE.eint<2>> +} + +// ----- + +func @tensor_extract_slice_2(%a: !FHE.eint<2>) -> tensor<2x!FHE.eint<2>> +{ + %c3 = arith.constant 3 : i3 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[a:.*]], %[[c1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<2>, i3) -> !FHE.eint<2> + %0 = "FHE.add_eint_int"(%a, %c3) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK: %[[V1:.*]] = tensor.from_elements %[[V0]], %[[a:.*]], %[[a:.*]], %[[a:.*]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<2>> + %1 = tensor.from_elements %0, %a, %a, %a : tensor<4x!FHE.eint<2>> + // CHECK: tensor.extract_slice %[[V1]][2] [2] [1] {MANP = 4 : ui{{[0-9]+}}} : tensor<4x!FHE.eint<2>> to tensor<2x!FHE.eint<2>> + %2 = tensor.extract_slice %1[2] [2] [1] : tensor<4x!FHE.eint<2>> to tensor<2x!FHE.eint<2>> + + return %2 : tensor<2x!FHE.eint<2>> +} + +// ----- + +func @tensor_insert_slice_1(%t0: tensor<2x10x!FHE.eint<2>>, %t1: tensor<2x2x!FHE.eint<2>>) -> tensor<2x10x!FHE.eint<2>> +{ + // %[[V0:.*]] = tensor.insert_slice %[[t1:.*]] into %[[t0:.*]][0, 5] [2, 2] [1, 1] {MANP = 1 : ui{{[[0-9]+}}} : tensor<2x2x!FHE.eint<2>> into tensor<2x10x!FHE.eint<2>> + %0 = tensor.insert_slice %t1 into %t0[0, 5] [2, 2] [1, 1] : tensor<2x2x!FHE.eint<2>> into tensor<2x10x!FHE.eint<2>> + + return %0 : tensor<2x10x!FHE.eint<2>> +} + +// ----- + +func @tensor_insert_slice_2(%a: !FHE.eint<5>) -> tensor<4x!FHE.eint<5>> +{ + %c3 = arith.constant 3 : i6 + %c6 = arith.constant 6 : i6 + + // CHECK: %[[V0:.*]] = "FHE.add_eint_int"(%[[a:.*]], %[[c3:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!FHE.eint<5>, i6) -> !FHE.eint<5> + %v0 = "FHE.add_eint_int"(%a, %c3) : (!FHE.eint<5>, i6) -> !FHE.eint<5> + // CHECK: %[[V1:.*]] = "FHE.add_eint_int"(%[[a:.*]], %[[c6:.*]]) {MANP = 7 : ui{{[0-9]+}}} : (!FHE.eint<5>, i6) -> !FHE.eint<5> + %v1 = "FHE.add_eint_int"(%a, %c6) : (!FHE.eint<5>, i6) -> !FHE.eint<5> + + // CHECK: %[[T0:.*]] = tensor.from_elements %[[V0]], %[[V0]], %[[V0]], %[[V0]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!FHE.eint<5>> + %t0 = tensor.from_elements %v0, %v0, %v0, %v0 : tensor<4x!FHE.eint<5>> + + // CHECK: %[[T1:.*]] = tensor.from_elements %[[V1]], %[[V1]] {MANP = 7 : ui{{[[0-9]+}}} : tensor<2x!FHE.eint<5>> + %t1 = tensor.from_elements %v1, %v1 : tensor<2x!FHE.eint<5>> + + // CHECK: %[[T2:.*]] = tensor.insert_slice %[[T1]] into %[[T0]][0] [2] [1] {MANP = 7 : ui{{[[0-9]+}}} : tensor<2x!FHE.eint<5>> into tensor<4x!FHE.eint<5>> + %t2 = tensor.insert_slice %t1 into %t0[0] [2] [1] : tensor<2x!FHE.eint<5>> into tensor<4x!FHE.eint<5>> + + // CHECK: %[[T3:.*]] = tensor.from_elements %[[V0]], %[[V0]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<2x!FHE.eint<5>> + %t3 = tensor.from_elements %v0, %v0 : tensor<2x!FHE.eint<5>> + + // CHECK: %[[T4:.*]] = tensor.insert_slice %[[T3]] into %[[T2]][0] [2] [1] {MANP = 7 : ui{{[[0-9]+}}} : tensor<2x!FHE.eint<5>> into tensor<4x!FHE.eint<5>> + %t4 = tensor.insert_slice %t3 into %t2[0] [2] [1] : tensor<2x!FHE.eint<5>> into tensor<4x!FHE.eint<5>> + + return %t0 : tensor<4x!FHE.eint<5>> +} + +// ----- + +func @tensor_collapse_shape_1(%a: tensor<2x2x4x!FHE.eint<6>>) -> tensor<2x8x!FHE.eint<6>> { + // CHECK: linalg.tensor_collapse_shape %[[A:.*]] [[X:.*]] {MANP = 1 : ui{{[0-9]+}}} + %0 = linalg.tensor_collapse_shape %a [[0],[1,2]] : tensor<2x2x4x!FHE.eint<6>> into tensor<2x8x!FHE.eint<6>> + return %0 : tensor<2x8x!FHE.eint<6>> +} + +// ----- + +func @tensor_collapse_shape_2(%a: tensor<2x2x4x!FHE.eint<2>>, %b: tensor<2x2x4xi3>) -> tensor<2x8x!FHE.eint<2>> +{ + // CHECK: "FHELinalg.add_eint_int"(%[[A:.*]], %[[B:.*]]) {MANP = 9 : ui{{[0-9]+}}} + %0 = "FHELinalg.add_eint_int"(%a, %b) : (tensor<2x2x4x!FHE.eint<2>>, tensor<2x2x4xi3>) -> tensor<2x2x4x!FHE.eint<2>> + // CHECK-NEXT: linalg.tensor_collapse_shape %[[A:.*]] [[X:.*]] {MANP = 9 : ui{{[0-9]+}}} + %1 = linalg.tensor_collapse_shape %0 [[0],[1,2]] : tensor<2x2x4x!FHE.eint<2>> into tensor<2x8x!FHE.eint<2>> + return %1 : tensor<2x8x!FHE.eint<2>> +} + +// ----- + +func @tensor_expand_shape_1(%a: tensor<2x8x!FHE.eint<6>>) -> tensor<2x2x4x!FHE.eint<6>> { + // CHECK: linalg.tensor_expand_shape %[[A:.*]] [[X:.*]] {MANP = 1 : ui{{[0-9]+}}} + %0 = linalg.tensor_expand_shape %a [[0],[1,2]] : tensor<2x8x!FHE.eint<6>> into tensor<2x2x4x!FHE.eint<6>> + return %0 : tensor<2x2x4x!FHE.eint<6>> +} + +// ----- + +func @tensor_expand_shape_2(%a: tensor<2x8x!FHE.eint<2>>, %b: tensor<2x8xi3>) -> tensor<2x2x4x!FHE.eint<2>> +{ + // CHECK: "FHELinalg.add_eint_int"(%[[A:.*]], %[[B:.*]]) {MANP = 9 : ui{{[0-9]+}}} + %0 = "FHELinalg.add_eint_int"(%a, %b) : (tensor<2x8x!FHE.eint<2>>, tensor<2x8xi3>) -> tensor<2x8x!FHE.eint<2>> + // CHECK-NEXT: linalg.tensor_expand_shape %[[A:.*]] [[X:.*]] {MANP = 9 : ui{{[0-9]+}}} + %1 = linalg.tensor_expand_shape %0 [[0],[1,2]] : tensor<2x8x!FHE.eint<2>> into tensor<2x2x4x!FHE.eint<2>> + return %1 : tensor<2x2x4x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Dialect/HLFHE/eint_error_p_too_big.mlir b/compiler/tests/Dialect/FHE/FHE/eint_error_p_too_big.mlir similarity index 79% rename from compiler/tests/Dialect/HLFHE/eint_error_p_too_big.mlir rename to compiler/tests/Dialect/FHE/FHE/eint_error_p_too_big.mlir index 16a2ff815..c5002b90f 100644 --- a/compiler/tests/Dialect/HLFHE/eint_error_p_too_big.mlir +++ b/compiler/tests/Dialect/FHE/FHE/eint_error_p_too_big.mlir @@ -1,6 +1,6 @@ // RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s // CHECK-LABEL: eint support only precision in ]0;7] -func @test(%arg0: !HLFHE.eint<8>) { +func @test(%arg0: !FHE.eint<8>) { return } diff --git a/compiler/tests/Dialect/HLFHE/eint_error_p_too_small.mlir b/compiler/tests/Dialect/FHE/FHE/eint_error_p_too_small.mlir similarity index 79% rename from compiler/tests/Dialect/HLFHE/eint_error_p_too_small.mlir rename to compiler/tests/Dialect/FHE/FHE/eint_error_p_too_small.mlir index 08dca3235..fd694ed5e 100644 --- a/compiler/tests/Dialect/HLFHE/eint_error_p_too_small.mlir +++ b/compiler/tests/Dialect/FHE/FHE/eint_error_p_too_small.mlir @@ -1,6 +1,6 @@ // RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s // CHECK-LABEL: eint support only precision in ]0;7] -func @test(%arg0: !HLFHE.eint<0>) { +func @test(%arg0: !FHE.eint<0>) { return } diff --git a/compiler/tests/Dialect/FHE/FHE/op_add_eint_err_inputs.mlir b/compiler/tests/Dialect/FHE/FHE/op_add_eint_err_inputs.mlir new file mode 100644 index 000000000..a716023de --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_add_eint_err_inputs.mlir @@ -0,0 +1,7 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.add_eint' op should have the width of encrypted inputs equals +func @add_eint(%arg0: !FHE.eint<2>, %arg1: !FHE.eint<3>) -> !FHE.eint<2> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<2>, !FHE.eint<3>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_add_eint_err_result.mlir b/compiler/tests/Dialect/FHE/FHE/op_add_eint_err_result.mlir new file mode 100644 index 000000000..8d3b1da82 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_add_eint_err_result.mlir @@ -0,0 +1,7 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.add_eint' op should have the width of encrypted inputs and result equals +func @add_eint(%arg0: !FHE.eint<2>, %arg1: !FHE.eint<2>) -> !FHE.eint<3> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<2>, !FHE.eint<2>) -> (!FHE.eint<3>) + return %1: !FHE.eint<3> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_add_eint_int_err_inputs.mlir b/compiler/tests/Dialect/FHE/FHE/op_add_eint_int_err_inputs.mlir new file mode 100644 index 000000000..3d9343e74 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_add_eint_int_err_inputs.mlir @@ -0,0 +1,8 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.add_eint_int' op should have the width of plain input equals to width of encrypted input + 1 +func @add_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + %0 = arith.constant 1 : i4 + %1 = "FHE.add_eint_int"(%arg0, %0): (!FHE.eint<2>, i4) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_add_eint_int_err_result.mlir b/compiler/tests/Dialect/FHE/FHE/op_add_eint_int_err_result.mlir new file mode 100644 index 000000000..cdb16b952 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_add_eint_int_err_result.mlir @@ -0,0 +1,8 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.add_eint_int' op should have the width of encrypted inputs and result equals +func @add_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<3> { + %0 = arith.constant 1 : i2 + %1 = "FHE.add_eint_int"(%arg0, %0): (!FHE.eint<2>, i2) -> (!FHE.eint<3>) + return %1: !FHE.eint<3> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_apply_lookup_table_bad_dimension.mlir b/compiler/tests/Dialect/FHE/FHE/op_apply_lookup_table_bad_dimension.mlir new file mode 100644 index 000000000..8739451ac --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_apply_lookup_table_bad_dimension.mlir @@ -0,0 +1,7 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.apply_lookup_table' op : `l_cst` (operand #2) inner dimension should have size 4(=2^2) to match `ct` (operand #1) elements bitwidth (2) +func @apply_lookup_table(%arg0: !FHE.eint<2>, %arg1: tensor<8xi3>) -> !FHE.eint<2> { + %1 = "FHE.apply_lookup_table"(%arg0, %arg1): (!FHE.eint<2>, tensor<8xi3>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_mul_eint_int_err_inputs.mlir b/compiler/tests/Dialect/FHE/FHE/op_mul_eint_int_err_inputs.mlir new file mode 100644 index 000000000..6a33f02d6 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_mul_eint_int_err_inputs.mlir @@ -0,0 +1,8 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.mul_eint_int' op should have the width of plain input equals to width of encrypted input + 1 +func @mul_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + %0 = arith.constant 1 : i4 + %1 = "FHE.mul_eint_int"(%arg0, %0): (!FHE.eint<2>, i4) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_mul_eint_int_err_result.mlir b/compiler/tests/Dialect/FHE/FHE/op_mul_eint_int_err_result.mlir new file mode 100644 index 000000000..59d87070f --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_mul_eint_int_err_result.mlir @@ -0,0 +1,8 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.mul_eint_int' op should have the width of encrypted inputs and result equals +func @mul_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<3> { + %0 = arith.constant 1 : i2 + %1 = "FHE.mul_eint_int"(%arg0, %0): (!FHE.eint<2>, i2) -> (!FHE.eint<3>) + return %1: !FHE.eint<3> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_neg_eint_err_result.mlir b/compiler/tests/Dialect/FHE/FHE/op_neg_eint_err_result.mlir new file mode 100644 index 000000000..4adadca04 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_neg_eint_err_result.mlir @@ -0,0 +1,7 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.neg_eint' op should have the width of encrypted inputs and result equals +func @sub_int_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<3> { + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<2>) -> (!FHE.eint<3>) + return %1: !FHE.eint<3> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_sub_int_eint_err_inputs.mlir b/compiler/tests/Dialect/FHE/FHE/op_sub_int_eint_err_inputs.mlir new file mode 100644 index 000000000..2051528de --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_sub_int_eint_err_inputs.mlir @@ -0,0 +1,8 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.sub_int_eint' op should have the width of plain input equals to width of encrypted input + 1 +func @sub_int_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + %0 = arith.constant 1 : i4 + %1 = "FHE.sub_int_eint"(%0, %arg0): (i4, !FHE.eint<2>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHE/FHE/op_sub_int_eint_err_result.mlir b/compiler/tests/Dialect/FHE/FHE/op_sub_int_eint_err_result.mlir new file mode 100644 index 000000000..bd322690d --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/op_sub_int_eint_err_result.mlir @@ -0,0 +1,8 @@ +// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: 'FHE.sub_int_eint' op should have the width of encrypted inputs and result equals +func @sub_int_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<3> { + %0 = arith.constant 1 : i2 + %1 = "FHE.sub_int_eint"(%0, %arg0): (i2, !FHE.eint<2>) -> (!FHE.eint<3>) + return %1: !FHE.eint<3> +} diff --git a/compiler/tests/Dialect/FHE/FHE/ops.mlir b/compiler/tests/Dialect/FHE/FHE/ops.mlir new file mode 100644 index 000000000..8f28a851b --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/ops.mlir @@ -0,0 +1,70 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @zero() -> !FHE.eint<2> +func @zero() -> !FHE.eint<2> { + // CHECK-NEXT: %[[RET:.*]] = "FHE.zero"() : () -> !FHE.eint<2> + // CHECK-NEXT: return %[[RET]] : !FHE.eint<2> + + %1 = "FHE.zero"() : () -> !FHE.eint<2> + return %1: !FHE.eint<2> +} + +// CHECK-LABEL: func @add_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> +func @add_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i3 + // CHECK-NEXT: %[[V2:.*]] = "FHE.add_eint_int"(%arg0, %[[V1]]) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: return %[[V2]] : !FHE.eint<2> + + %0 = arith.constant 1 : i3 + %1 = "FHE.add_eint_int"(%arg0, %0): (!FHE.eint<2>, i3) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} + +// CHECK-LABEL: func @sub_int_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<2> +func @sub_int_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i3 + // CHECK-NEXT: %[[V2:.*]] = "FHE.sub_int_eint"(%[[V1]], %arg0) : (i3, !FHE.eint<2>) -> !FHE.eint<2> + // CHECK-NEXT: return %[[V2]] : !FHE.eint<2> + + %0 = arith.constant 1 : i3 + %1 = "FHE.sub_int_eint"(%0, %arg0): (i3, !FHE.eint<2>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} + +// CHECK-LABEL: func @neg_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<2> +func @neg_eint(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = "FHE.neg_eint"(%arg0) : (!FHE.eint<2>) -> !FHE.eint<2> + // CHECK-NEXT: return %[[V1]] : !FHE.eint<2> + + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<2>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} + +// CHECK-LABEL: func @mul_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> +func @mul_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i3 + // CHECK-NEXT: %[[V2:.*]] = "FHE.mul_eint_int"(%arg0, %[[V1]]) : (!FHE.eint<2>, i3) -> !FHE.eint<2> + // CHECK-NEXT: return %[[V2]] : !FHE.eint<2> + + %0 = arith.constant 1 : i3 + %1 = "FHE.mul_eint_int"(%arg0, %0): (!FHE.eint<2>, i3) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} + +// CHECK-LABEL: func @add_eint(%arg0: !FHE.eint<2>, %arg1: !FHE.eint<2>) -> !FHE.eint<2> +func @add_eint(%arg0: !FHE.eint<2>, %arg1: !FHE.eint<2>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = "FHE.add_eint"(%arg0, %arg1) : (!FHE.eint<2>, !FHE.eint<2>) -> !FHE.eint<2> + // CHECK-NEXT: return %[[V1]] : !FHE.eint<2> + + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<2>, !FHE.eint<2>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} + +// CHECK-LABEL: func @apply_lookup_table(%arg0: !FHE.eint<2>, %arg1: tensor<4xi64>) -> !FHE.eint<2> +func @apply_lookup_table(%arg0: !FHE.eint<2>, %arg1: tensor<4xi64>) -> !FHE.eint<2> { + // CHECK-NEXT: %[[V1:.*]] = "FHE.apply_lookup_table"(%arg0, %arg1) : (!FHE.eint<2>, tensor<4xi64>) -> !FHE.eint<2> + // CHECK-NEXT: return %[[V1]] : !FHE.eint<2> + + %1 = "FHE.apply_lookup_table"(%arg0, %arg1): (!FHE.eint<2>, tensor<4xi64>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> +} \ No newline at end of file diff --git a/compiler/tests/Dialect/FHE/FHE/types.mlir b/compiler/tests/Dialect/FHE/FHE/types.mlir new file mode 100644 index 000000000..84c508786 --- /dev/null +++ b/compiler/tests/Dialect/FHE/FHE/types.mlir @@ -0,0 +1,6 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @memref_arg(%arg0: memref<2x!FHE.eint<7>> +func @memref_arg(%arg0: memref<2x!FHE.eint<7>>) { + return +} diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_mapped_lut_to_linalg.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_mapped_lut_to_linalg.mlir new file mode 100644 index 000000000..a74672da6 --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_mapped_lut_to_linalg.mlir @@ -0,0 +1,31 @@ +// RUN: concretecompiler %s --action=dump-tfhe 2>&1 | FileCheck %s + + +//CHECK-LABEL: #map = affine_map<(d0, d1) -> (d0, d1)> +//CHECK-NEXT:module { +//CHECK-NEXT: func @mapped_lut(%arg0: tensor<2x3x!TFHE.glwe<{_,_,_}{2}>>, %[[LUTS:.*]]: tensor<5x4xi64>, %arg2: tensor<2x3xindex>) -> tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> { +//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [2, 3] : tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %[[V1:.*]] = 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}>>) { +//CHECK-NEXT: ^bb0(%arg3: !TFHE.glwe<{_,_,_}{2}>, %[[LUTIDX:.*]]: index, %arg5: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +//DISABLED-CHECK-NEXT: %[[V3:.*]] = tensor.extract_slice %arg1[%[[LUTIDX]], 0] [1, 4] [1, 1] : tensor<5x4xi64> to tensor<4xi64> +//WORKAROUND BEGIN +//CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : index +//CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +//CHECK-NEXT: %[[C2:.*]] = arith.constant 2 : index +//CHECK-NEXT: %[[C3:.*]] = arith.constant 3 : index +//CHECK-NEXT: %[[E0:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C0]]] : tensor<5x4xi64> +//CHECK-NEXT: %[[E1:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C1]]] : tensor<5x4xi64> +//CHECK-NEXT: %[[E2:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C2]]] : tensor<5x4xi64> +//CHECK-NEXT: %[[E3:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C3]]] : tensor<5x4xi64> +//CHECK-NEXT: %[[LUT:.*]] = tensor.from_elements %[[E0]], %[[E1]], %[[E2]], %[[E3]] : tensor<4xi64> +//WORKAROUND END +//CHECK-NEXT: %[[V4:.*]] = "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}> +//CHECK-NEXT: linalg.yield %[[V4]] : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } -> tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: return %[[V1]] : tensor<2x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: } +//CHECK-NEXT: } +func @mapped_lut(%t: tensor<2x3x!FHE.eint<2>>, %luts: tensor<5x4xi64>, %map: tensor<2x3xindex>) -> tensor<2x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_mapped_lookup_table"(%t, %luts, %map): (tensor<2x3x!FHE.eint<2>>, tensor<5x4xi64>, tensor<2x3xindex>) -> tensor<2x3x!FHE.eint<2>> + return %1: tensor<2x3x!FHE.eint<2>> +} diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_multi_lut_to_linalg.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_multi_lut_to_linalg.mlir new file mode 100644 index 000000000..c9c1c0ade --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_multi_lut_to_linalg.mlir @@ -0,0 +1,23 @@ +// RUN: concretecompiler %s --action=dump-tfhe 2>&1 | FileCheck %s + +//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> +//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d0, d1, 0)> +//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d0, d1, 1)> +//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d0, d1, 2)> +//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d0, d1, 3)> +//CHECK-NEXT: module { +//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x4x!TFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> { +//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 4] : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>) outs(%[[V0]] : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>>) { +//CHECK-NEXT: ^bb0(%arg2: !TFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> +//CHECK-NEXT: %[[V3:.*]] = "TFHE.apply_lookup_table"(%arg2, %[[V2]]) {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}> +//CHECK-NEXT: linalg.yield %[[V3]] : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } -> tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: return %[[V1]] : tensor<4x4x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: } +//CHECK-NEXT: } +func @multi_lut(%arg0: tensor<4x4x!FHE.eint<2>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!FHE.eint<2>> { + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x4x!FHE.eint<2>>, tensor<4x4x4xi64>) -> tensor<4x4x!FHE.eint<2>> + return %1: tensor<4x4x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_multi_lut_to_linalg_broadcast.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_multi_lut_to_linalg_broadcast.mlir new file mode 100644 index 000000000..ec42085c1 --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/apply_multi_lut_to_linalg_broadcast.mlir @@ -0,0 +1,23 @@ +// RUN: concretecompiler %s --action=dump-tfhe 2>&1 | FileCheck %s + +//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> +//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d1, 0)> +//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d1, 1)> +//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d1, 2)> +//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d1, 3)> +//CHECK-NEXT: module { +//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x3x!TFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> { +//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 3] : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) outs(%[[V0]] : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>>) { +//CHECK-NEXT: ^bb0(%arg2: !TFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> +//CHECK-NEXT: %[[V3:.*]] = "TFHE.apply_lookup_table"(%arg2, %[[V2]]) {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}> +//CHECK-NEXT: linalg.yield %[[V3]] : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } -> tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: return %[[V1]] : tensor<4x3x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: } +//CHECK-NEXT: } +func @multi_lut(%arg0: tensor<4x3x!FHE.eint<2>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!FHE.eint<2>> + return %1: tensor<4x3x!FHE.eint<2>> +} \ No newline at end of file diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/dot.invalid.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/dot.invalid.mlir new file mode 100644 index 000000000..066d84e6d --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/dot.invalid.mlir @@ -0,0 +1,69 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// Incompatible shapes +func @dot_incompatible_shapes( + %arg0: tensor<5x!FHE.eint<5>>, + %arg1: tensor<4xi32>) -> !FHE.eint<5> +{ + // expected-error @+1 {{'FHELinalg.dot_eint_int' op arguments have incompatible shapes}} + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<5x!FHE.eint<5>>, tensor<4xi32>) -> !FHE.eint<5> + + return %ret : !FHE.eint<5> +} + +// ----- + +// Incompatible input types +func @dot_incompatible_input_types( + %arg0: tensor<5x!FHE.eint<2>>, + %arg1: tensor<4xf32>) -> !FHE.eint<2> +{ + // expected-error @+1 {{'FHELinalg.dot_eint_int' op operand #1 must}} + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<5x!FHE.eint<2>>, tensor<4xf32>) -> !FHE.eint<2> + + return %ret : !FHE.eint<2> +} + +// ----- + +// Wrong number of dimensions +func @dot_num_dims( + %arg0: tensor<2x4x!FHE.eint<2>>, + %arg1: tensor<2x4xi3>) -> !FHE.eint<2> +{ + // expected-error @+1 {{'FHELinalg.dot_eint_int' op operand #0}} + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<2x4x!FHE.eint<2>>, tensor<2x4xi3>) -> !FHE.eint<2> + + return %ret : !FHE.eint<2> +} + +// ----- + +// Wrong returns type +func @dot_incompatible_return( + %arg0: tensor<4x!FHE.eint<2>>, + %arg1: tensor<4xi3>) -> !FHE.eint<3> +{ + // expected-error @+1 {{'FHELinalg.dot_eint_int' op should have the width of encrypted inputs and result equals}} + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> !FHE.eint<3> + + return %ret : !FHE.eint<3> +} + +// ----- + +// Wrong integer size +func @dot_incompatible_int( + %arg0: tensor<4x!FHE.eint<2>>, + %arg1: tensor<4xi4>) -> !FHE.eint<2> +{ + // expected-error @+1 {{'FHELinalg.dot_eint_int' op should have the width of plain input equals to width of encrypted input + 1}} + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<2>>, tensor<4xi4>) -> !FHE.eint<2> + + return %ret : !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/ops.invalid.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/ops.invalid.mlir new file mode 100644 index 000000000..3f537748b --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/ops.invalid.mlir @@ -0,0 +1,292 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +///////////////////////////////////////////////// +// FHELinalg.add_eint_int +///////////////////////////////////////////////// + +// Incompatible dimension of operands +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!FHE.eint<2>> + return %1 : tensor<2x2x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible dimension of result +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint_int' op has the dimension #3 of the result incompatible with operands dimension, got 10 expect 2}} + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!FHE.eint<2>> + return %1 : tensor<2x10x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible number of dimension between operands and result +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint_int' op should have the number of dimensions of the result equal to the highest number of dimensions of operands, got 3 expect 4}} + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x3x4x!FHE.eint<2>> + return %1 : tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible width between clear and encrypted witdh +func @main(%a0: tensor<2x3x4x!FHE.eint<2>>, %a1: tensor<2x3x4xi4>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint_int' op should have the width of integer values less or equals than the width of encrypted values + 1}} + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x3x4x!FHE.eint<2>>, tensor<2x3x4xi4>) -> tensor<2x3x4x!FHE.eint<2>> + return %1 : tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.add_eint +///////////////////////////////////////////////// + +// Incompatible dimension of operands +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4x!FHE.eint<2>>) -> tensor<2x2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4x!FHE.eint<2>>) -> tensor<2x2x3x4x!FHE.eint<2>> + return %1 : tensor<2x2x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible dimension of result +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4x!FHE.eint<2>>) -> tensor<2x10x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint' op has the dimension #3 of the result incompatible with operands dimension, got 10 expect 2}} + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4x!FHE.eint<2>>) -> tensor<2x10x3x4x!FHE.eint<2>> + return %1 : tensor<2x10x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible number of dimension between operands and result +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4x!FHE.eint<2>>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint' op should have the number of dimensions of the result equal to the highest number of dimensions of operands, got 3 expect 4}} + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4x!FHE.eint<2>>) -> tensor<2x3x4x!FHE.eint<2>> + return %1 : tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible width between clear and encrypted witdh +func @main(%a0: tensor<2x3x4x!FHE.eint<2>>, %a1: tensor<2x3x4x!FHE.eint<3>>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint' op should have the width of encrypted equals, got 3 expect 2}} + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<2x3x4x!FHE.eint<2>>, tensor<2x3x4x!FHE.eint<3>>) -> tensor<2x3x4x!FHE.eint<2>> + return %1 : tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.mul_eint_int +///////////////////////////////////////////////// + +// Incompatible dimension of operands +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.mul_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!FHE.eint<2>> + return %1 : tensor<2x2x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible dimension of result +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.mul_eint_int' op has the dimension #3 of the result incompatible with operands dimension, got 10 expect 2}} + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!FHE.eint<2>> + return %1 : tensor<2x10x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible number of dimension between operands and result +func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.mul_eint_int' op should have the number of dimensions of the result equal to the highest number of dimensions of operands, got 3 expect 4}} + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x3x4x!FHE.eint<2>> + return %1 : tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +// Incompatible width between clear and encrypted witdh +func @main(%a0: tensor<2x3x4x!FHE.eint<2>>, %a1: tensor<2x3x4xi4>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.mul_eint_int' op should have the width of integer values less or equals than the width of encrypted values + 1}} + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x3x4x!FHE.eint<2>>, tensor<2x3x4xi4>) -> tensor<2x3x4x!FHE.eint<2>> + return %1 : tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.apply_lookup_table +///////////////////////////////////////////////// + +func @apply_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<4xi32>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.apply_lookup_table' op should have as operand #2 a tensor<2^pxi64>, where p is the width of the encrypted integer of the operand #1,expect tensor <4xi64>}} + %1 = "FHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<4xi32>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +func @apply_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<12xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.apply_lookup_table' op should have as operand #2 a tensor<2^pxi64>, where p is the width of the encrypted integer of the operand #1,expect tensor <4xi64>}} + %1 = "FHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<12xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +func @apply_lookup_table(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.apply_lookup_table' op should have same shapes for operand #1 and the result}} + %1 = "FHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<3x4x!FHE.eint<2>>, tensor<4xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.apply_multi_lookup_table +///////////////////////////////////////////////// + +func @apply_multi_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<2x6xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.apply_multi_lookup_table' op should have as operand #2 a tensor, where p is the width of the encrypted integer of the operand #1,expect tensor }} + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<2x6xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +// ----- + + +///////////////////////////////////////////////// +// FHELinalg.apply_mapped_lookup_table +///////////////////////////////////////////////// +func @apply_mapped_lookup_table_bad_lut_size_127_vs_128( + %input: tensor<2x3x4x!FHE.eint<7>>, + %luts: tensor<127xi64>, + %map: tensor<2x3x4xindex> +) -> tensor<2x3x4x!FHE.eint<7>> { + // expected-error @+1 {{'FHELinalg.apply_mapped_lookup_table' op : `luts` (operand #2) inner dimension should have size 128(=2^7) to match `ct` (operand #1) elements bitwidth (7)}} + %1 = "FHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!FHE.eint<7>>, tensor<127xi64>, tensor<2x3x4xindex>) -> tensor<2x3x4x!FHE.eint<7>> + return %1: tensor<2x3x4x!FHE.eint<7>> +} + +// ----- + +func @apply_mapped_lookup_table_bad_map_size( + %input: tensor<2x3x4x!FHE.eint<7>>, + %luts: tensor<128xi64>, + %map: tensor<2x3xindex> +) -> tensor<2x3x4x!FHE.eint<7>> { + // expected-error @+1 {{'FHELinalg.apply_mapped_lookup_table' op : 't' (operand #1) rank (=3) differs from 'lut_map.getName()' (operand #3) rank (=2)}} + %1 = "FHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!FHE.eint<7>>, tensor<128xi64>, tensor<2x3xindex>) -> tensor<2x3x4x!FHE.eint<7>> + return %1: tensor<2x3x4x!FHE.eint<7>> +} + +// ----- + +func @apply_mapped_lookup_table_bad_map_elmt_type( + %input: tensor<2x3x4x!FHE.eint<7>>, + %luts: tensor<128xi64>, + %map: tensor<2x3xindex> +) -> tensor<2x3x4x!FHE.eint<7>> { + // expected-error @+1 {{'FHELinalg.apply_mapped_lookup_table' op : 't' (operand #1) rank (=3) differs from 'lut_map.getName()' (operand #3) rank (=2)}} + %1 = "FHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!FHE.eint<7>>, tensor<128xi64>, tensor<2x3xindex>) -> tensor<2x3x4x!FHE.eint<7>> + return %1: tensor<2x3x4x!FHE.eint<7>> +} + + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.matmul_eint_int +///////////////////////////////////////////////// + +func @matmul_eint_int(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_eint_int' op should have 2D tensors as operands}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<2x4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_eint_int' op should have 2D tensors as operands}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!FHE.eint<2>>, tensor<2x4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<5x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_eint_int' op should have the dimension #0 of operand #1equals to the dimension #1 of operand #0, expect 4 got 5}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!FHE.eint<2>>, tensor<5x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<4x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_eint_int' op should have the result shape compatible with operands shape, expect 3x2 as the shape of the result}} + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<4x2x!FHE.eint<2>> + return %1 : tensor<4x2x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.matmul_int_eint +///////////////////////////////////////////////// + +func @matmul_int_eint(%arg0: tensor<2x3x4xi3>, %arg1: tensor<4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_int_eint' op should have 2D tensors as operands}} + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<2x3x4xi3>, tensor<4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<2x4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_int_eint' op should have 2D tensors as operands}} + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<2x4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<5x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_int_eint' op should have the dimension #0 of operand #1equals to the dimension #1 of operand #0, expect 4 got 5}} + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<5x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +// ----- + +func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<4x2x!FHE.eint<2>>) -> tensor<4x2x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.matmul_int_eint' op should have the result shape compatible with operands shape, expect 3x2 as the shape of the result}} + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<4x2x!FHE.eint<2>>) -> tensor<4x2x!FHE.eint<2>> + return %1 : tensor<4x2x!FHE.eint<2>> +} + +// ----- + +///////////////////////////////////////////////// +// FHELinalg.zero +///////////////////////////////////////////////// + +func @zero_1D_scalar() -> tensor<4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.zero' op}} + %0 = "FHELinalg.zero"() : () -> !FHE.eint<2> + return %0 : !FHE.eint<2> +} + +// ----- + +func @zero_plaintext() -> tensor<4x9xi32> { + // expected-error @+1 {{'FHELinalg.zero' op}} + %0 = "FHELinalg.zero"() : () -> tensor<4x9xi32> + return %0 : tensor<4x9xi32> +} diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/ops.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/ops.mlir new file mode 100644 index 000000000..f718d8f1f --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/ops.mlir @@ -0,0 +1,369 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +///////////////////////////////////////////////// +// FHELinalg.add_eint_int +///////////////////////////////////////////////// + +// 1D tensor +// CHECK: func @add_eint_int_1D(%[[a0:.*]]: tensor<4x!FHE.eint<2>>, %[[a1:.*]]: tensor<4xi3>) -> tensor<4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<4x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_int_1D(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> + return %1: tensor<4x!FHE.eint<2>> +} + +// 2D tensor +// CHECK: func @add_eint_int_2D(%[[a0:.*]]: tensor<2x4x!FHE.eint<2>>, %[[a1:.*]]: tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<2x4x!FHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_int_2D(%a0: tensor<2x4x!FHE.eint<2>>, %a1: tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x4x!FHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> + return %1: tensor<2x4x!FHE.eint<2>> +} + +// 10D tensor +// CHECK: func @add_eint_int_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_int_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, %a1: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> + return %1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +} + +// Broadcasting with tensor with dimensions equals to one +// CHECK: func @add_eint_int_broadcast_1(%[[a0:.*]]: tensor<1x4x5x!FHE.eint<2>>, %[[a1:.*]]: tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x4x5x!FHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_int_broadcast_1(%a0: tensor<1x4x5x!FHE.eint<2>>, %a1: tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<1x4x5x!FHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> + return %1: tensor<3x4x5x!FHE.eint<2>> +} + +// Broadcasting with a tensor less dimensions of another +// CHECK: func @add_eint_int_broadcast_2(%[[a0:.*]]: tensor<4x!FHE.eint<2>>, %[[a1:.*]]: tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!FHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_int_broadcast_2(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> { + %1 ="FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> + return %1: tensor<3x4x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.add_eint +///////////////////////////////////////////////// + +// 1D tensor +// CHECK: func @add_eint_1D(%[[a0:.*]]: tensor<4x!FHE.eint<2>>, %[[a1:.*]]: tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<4x!FHE.eint<2>>, tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<4x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_1D(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> + return %1: tensor<4x!FHE.eint<2>> +} + +// 2D tensor +// CHECK: func @add_eint_2D(%[[a0:.*]]: tensor<2x4x!FHE.eint<2>>, %[[a1:.*]]: tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<2x4x!FHE.eint<2>>, tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_2D(%a0: tensor<2x4x!FHE.eint<2>>, %a1: tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<2x4x!FHE.eint<2>>, tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> + return %1: tensor<2x4x!FHE.eint<2>> +} + +// 10D tensor +// CHECK: func @add_eint_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, %a1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> + return %1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +} + +// Broadcasting with tensor with dimensions equals to one +// CHECK: func @add_eint_broadcast_1(%[[a0:.*]]: tensor<1x4x5x!FHE.eint<2>>, %[[a1:.*]]: tensor<3x4x1x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<1x4x5x!FHE.eint<2>>, tensor<3x4x1x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_broadcast_1(%a0: tensor<1x4x5x!FHE.eint<2>>, %a1: tensor<3x4x1x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint"(%a0, %a1) : (tensor<1x4x5x!FHE.eint<2>>, tensor<3x4x1x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> + return %1: tensor<3x4x5x!FHE.eint<2>> +} + +// Broadcasting with a tensor less dimensions of another +// CHECK: func @add_eint_broadcast_2(%[[a0:.*]]: tensor<4x!FHE.eint<2>>, %[[a1:.*]]: tensor<3x4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<4x!FHE.eint<2>>, tensor<3x4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @add_eint_broadcast_2(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<3x4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> { + %1 ="FHELinalg.add_eint"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<3x4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> + return %1: tensor<3x4x!FHE.eint<2>> +} + + +///////////////////////////////////////////////// +// FHELinalg.sub_eint_int +///////////////////////////////////////////////// + +// 1D tensor +// CHECK: func @sub_int_eint_1D(%[[a0:.*]]: tensor<4xi3>, %[[a1:.*]]: tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<4xi3>, tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<4x!FHE.eint<2>> +// CHECK-NEXT: } +func @sub_int_eint_1D(%a0: tensor<4xi3>, %a1: tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> { + %1 = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4xi3>, tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> + return %1: tensor<4x!FHE.eint<2>> +} + +// 2D tensor +// CHECK: func @sub_int_eint_2D(%[[a0:.*]]: tensor<2x4xi3>, %[[a1:.*]]: tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<2x4xi3>, tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @sub_int_eint_2D(%a0: tensor<2x4xi3>, %a1: tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> { + %1 = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<2x4xi3>, tensor<2x4x!FHE.eint<2>>) -> tensor<2x4x!FHE.eint<2>> + return %1: tensor<2x4x!FHE.eint<2>> +} + +// 10D tensor +// CHECK: func @sub_int_eint_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10xi3>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10xi3>, tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: } +func @sub_int_eint_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10xi3>, %a1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { + %1 = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10xi3>, tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> + return %1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +} + +// Broadcasting with tensor with dimensions equals to one +// CHECK: func @sub_int_eint_broadcast_1(%[[a0:.*]]: tensor<3x4x1xi3>, %[[a1:.*]]: tensor<1x4x5x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<3x4x1xi3>, tensor<1x4x5x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: } +func @sub_int_eint_broadcast_1(%a0: tensor<3x4x1xi3>, %a1: tensor<1x4x5x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> { + %1 = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x4x1xi3>, tensor<1x4x5x!FHE.eint<2>>) -> tensor<3x4x5x!FHE.eint<2>> + return %1: tensor<3x4x5x!FHE.eint<2>> +} + +// Broadcasting with a tensor less dimensions of another +// CHECK: func @sub_int_eint_broadcast_2(%[[a0:.*]]: tensor<3x4xi3>, %[[a1:.*]]: tensor<4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<3x4xi3>, tensor<4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @sub_int_eint_broadcast_2(%a0: tensor<3x4xi3>, %a1: tensor<4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> { + %1 ="FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x4xi3>, tensor<4x!FHE.eint<2>>) -> tensor<3x4x!FHE.eint<2>> + return %1: tensor<3x4x!FHE.eint<2>> +} + + +///////////////////////////////////////////////// +// FHELinalg.neg_eint +///////////////////////////////////////////////// + +// 1D tensor +// CHECK: func @neg_eint_1D(%[[a0:.*]]: tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.neg_eint"(%[[a0]]) : (tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<4x!FHE.eint<2>> +// CHECK-NEXT: } +func @neg_eint_1D(%a0: tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> { + %1 = "FHELinalg.neg_eint"(%a0) : (tensor<4x!FHE.eint<2>>) -> tensor<4x!FHE.eint<2>> + return %1: tensor<4x!FHE.eint<2>> +} + +// 1D tensor +// CHECK: func @neg_eint_2D(%[[a0:.*]]: tensor<4x4x!FHE.eint<2>>) -> tensor<4x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.neg_eint"(%[[a0]]) : (tensor<4x4x!FHE.eint<2>>) -> tensor<4x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<4x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @neg_eint_2D(%a0: tensor<4x4x!FHE.eint<2>>) -> tensor<4x4x!FHE.eint<2>> { + %1 = "FHELinalg.neg_eint"(%a0) : (tensor<4x4x!FHE.eint<2>>) -> tensor<4x4x!FHE.eint<2>> + return %1: tensor<4x4x!FHE.eint<2>> +} + +// 10D tensor +// CHECK: func @neg_eint_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.neg_eint"(%[[a0]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: } +func @neg_eint_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { + %1 = "FHELinalg.neg_eint"(%a0) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> + return %1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +} + + +///////////////////////////////////////////////// +// FHELinalg.mul_eint_int +///////////////////////////////////////////////// + +// 1D tensor +// CHECK: func @mul_eint_int_1D(%[[a0:.*]]: tensor<4x!FHE.eint<2>>, %[[a1:.*]]: tensor<4xi3>) -> tensor<4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<4x!FHE.eint<2>> +// CHECK-NEXT: } +func @mul_eint_int_1D(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!FHE.eint<2>> { + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> + return %1: tensor<4x!FHE.eint<2>> +} + +// 2D tensor +// CHECK: func @mul_eint_int_2D(%[[a0:.*]]: tensor<2x4x!FHE.eint<2>>, %[[a1:.*]]: tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<2x4x!FHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<2x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @mul_eint_int_2D(%a0: tensor<2x4x!FHE.eint<2>>, %a1: tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> { + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x4x!FHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!FHE.eint<2>> + return %1: tensor<2x4x!FHE.eint<2>> +} + +// 10D tensor +// CHECK: func @mul_eint_int_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +// CHECK-NEXT: } +func @mul_eint_int_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, %a1: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> { + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> + return %1: tensor<1x2x3x4x5x6x7x8x9x10x!FHE.eint<2>> +} + +// Broadcasting with tensor with dimensions equals to one +// CHECK: func @mul_eint_int_broadcast_1(%[[a0:.*]]: tensor<1x4x5x!FHE.eint<2>>, %[[a1:.*]]: tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x4x5x!FHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!FHE.eint<2>> +// CHECK-NEXT: } +func @mul_eint_int_broadcast_1(%a0: tensor<1x4x5x!FHE.eint<2>>, %a1: tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> { + %1 = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<1x4x5x!FHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!FHE.eint<2>> + return %1: tensor<3x4x5x!FHE.eint<2>> +} + +// Broadcasting with a tensor less dimensions of another +// CHECK: func @mul_eint_int_broadcast_2(%[[a0:.*]]: tensor<4x!FHE.eint<2>>, %[[a1:.*]]: tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> { +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!FHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: return %[[V0]] : tensor<3x4x!FHE.eint<2>> +// CHECK-NEXT: } +func @mul_eint_int_broadcast_2(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> { + %1 ="FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!FHE.eint<2>> + return %1: tensor<3x4x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.apply_lookup_table +///////////////////////////////////////////////// + +// CHECK-LABEL: func @apply_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!FHE.eint<2>> +func @apply_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + // CHECK-NEXT: %[[V1:.*]] = "FHELinalg.apply_lookup_table"(%arg0, %arg1) : (tensor<2x3x4x!FHE.eint<2>>, tensor<4xi64>) -> tensor<2x3x4x!FHE.eint<2>> + // CHECK-NEXT: return %[[V1]] : tensor<2x3x4x!FHE.eint<2>> + + %1 = "FHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<4xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.apply_multi_lookup_table +///////////////////////////////////////////////// + +// CHECK-LABEL: func @apply_multi_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<2x3x4xi64>) -> tensor<2x3x4x!FHE.eint<2>> +func @apply_multi_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<2x3x4xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + // CHECK-NEXT: %[[V1:.*]] = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1) : (tensor<2x3x4x!FHE.eint<2>>, tensor<2x3x4xi64>) -> tensor<2x3x4x!FHE.eint<2>> + // CHECK-NEXT: return %[[V1]] : tensor<2x3x4x!FHE.eint<2>> + + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<2x3x4xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +// CHECK-LABEL: func @apply_multi_lookup_table_broadcast(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<2x4xi64>) -> tensor<2x3x4x!FHE.eint<2>> +func @apply_multi_lookup_table_broadcast(%arg0: tensor<2x3x4x!FHE.eint<2>>, %arg1: tensor<2x4xi64>) -> tensor<2x3x4x!FHE.eint<2>> { + // CHECK-NEXT: %[[V1:.*]] = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1) : (tensor<2x3x4x!FHE.eint<2>>, tensor<2x4xi64>) -> tensor<2x3x4x!FHE.eint<2>> + // CHECK-NEXT: return %[[V1]] : tensor<2x3x4x!FHE.eint<2>> + + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!FHE.eint<2>>, tensor<2x4xi64>) -> (tensor<2x3x4x!FHE.eint<2>>) + return %1: tensor<2x3x4x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.apply_mapped_lookup_table +///////////////////////////////////////////////// + +// CHECK-LABEL: func @apply_mapped_lookup_table(%arg0: tensor<2x3x4x!FHE.eint<7>>, %arg1: tensor<10x128xi64>, %arg2: tensor<2x3x4xindex>) -> tensor<2x3x4x!FHE.eint<7>> { +func @apply_mapped_lookup_table( + %input: tensor<2x3x4x!FHE.eint<7>>, + %luts: tensor<10x128xi64>, + %map: tensor<2x3x4xindex> +) -> tensor<2x3x4x!FHE.eint<7>> { + // CHECK-NEXT: %0 = "FHELinalg.apply_mapped_lookup_table"(%arg0, %arg1, %arg2) : (tensor<2x3x4x!FHE.eint<7>>, tensor<10x128xi64>, tensor<2x3x4xindex>) -> tensor<2x3x4x!FHE.eint<7>> + // CHECK-NEXT: return %0 : tensor<2x3x4x!FHE.eint<7>> + %0 = "FHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!FHE.eint<7>>, tensor<10x128xi64>, tensor<2x3x4xindex>) -> (tensor<2x3x4x!FHE.eint<7>>) + return %0: tensor<2x3x4x!FHE.eint<7>> +} + +///////////////////////////////////////////////// +// FHELinalg.dot_eint_int +///////////////////////////////////////////////// + +// CHECK-LABEL: func @dot_eint_int(%arg0: tensor<2x!FHE.eint<2>>, %arg1: tensor<2xi3>) -> !FHE.eint<2> +func @dot_eint_int(%arg0: tensor<2x!FHE.eint<2>>, + %arg1: tensor<2xi3>) -> !FHE.eint<2> +{ + // CHECK-NEXT: %[[RET:.*]] = "FHELinalg.dot_eint_int"(%arg0, %arg1) : (tensor<2x!FHE.eint<2>>, tensor<2xi3>) -> !FHE.eint<2> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<2x!FHE.eint<2>>, tensor<2xi3>) -> !FHE.eint<2> + + //CHECK-NEXT: return %[[RET]] : !FHE.eint<2> + return %ret : !FHE.eint<2> +} + +///////////////////////////////////////////////// +// FHELinalg.matmul_eint_int +///////////////////////////////////////////////// + +// CHECK-LABEL: @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> +func @matmul_eint_int(%arg0: tensor<3x4x!FHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> { + // CHECK-NEXT: %[[V1:.*]] = "FHELinalg.matmul_eint_int"(%arg0, %arg1) : (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + // CHECK-NEXT: return %[[V1]] : tensor<3x2x!FHE.eint<2>> + + %1 = "FHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!FHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.matmul_int_eint +///////////////////////////////////////////////// + +// CHECK-LABEL: @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> +func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> { + // CHECK-NEXT: %[[V1:.*]] = "FHELinalg.matmul_int_eint"(%arg0, %arg1) : (tensor<3x4xi3>, tensor<4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + // CHECK-NEXT: return %[[V1]] : tensor<3x2x!FHE.eint<2>> + + %1 = "FHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<4x2x!FHE.eint<2>>) -> tensor<3x2x!FHE.eint<2>> + return %1 : tensor<3x2x!FHE.eint<2>> +} + +///////////////////////////////////////////////// +// FHELinalg.zero +///////////////////////////////////////////////// + +// CHECK: func @zero_1D() -> tensor<4x!FHE.eint<2>> { +// CHECK-NEXT: %[[v0:.*]] = "FHELinalg.zero"() : () -> tensor<4x!FHE.eint<2>> +// CHECK-NEXT: return %[[v0]] : tensor<4x!FHE.eint<2>> +// CHECK-NEXT: } +func @zero_1D() -> tensor<4x!FHE.eint<2>> { + %0 = "FHELinalg.zero"() : () -> tensor<4x!FHE.eint<2>> + return %0 : tensor<4x!FHE.eint<2>> +} + +// CHECK: func @zero_2D() -> tensor<4x9x!FHE.eint<2>> { +// CHECK-NEXT: %[[v0:.*]] = "FHELinalg.zero"() : () -> tensor<4x9x!FHE.eint<2>> +// CHECK-NEXT: return %[[v0]] : tensor<4x9x!FHE.eint<2>> +// CHECK-NEXT: } +func @zero_2D() -> tensor<4x9x!FHE.eint<2>> { + %0 = "FHELinalg.zero"() : () -> tensor<4x9x!FHE.eint<2>> + return %0 : tensor<4x9x!FHE.eint<2>> +} diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/tensor-ops-to-linalg.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/tensor-ops-to-linalg.mlir new file mode 100644 index 000000000..4d0290dac --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/tensor-ops-to-linalg.mlir @@ -0,0 +1,26 @@ +// RUN: concretecompiler %s --action=dump-tfhe 2>&1 | FileCheck %s + +//CHECK: #map0 = affine_map<(d0) -> (d0)> +//CHECK-NEXT: #map1 = affine_map<(d0) -> (0)> +//CHECK-NEXT: module { +//CHECK-NEXT: func @dot_eint_int(%arg0: tensor<2x!TFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<2xi3>) -> !TFHE.glwe<{_,_,_}{2}> { +//CHECK-NEXT: %0 = "TFHE.zero"() : () -> !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: %1 = tensor.from_elements %0 : tensor<1x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!TFHE.glwe<{_,_,_}{2}>>, tensor<2xi3>) outs(%1 : tensor<1x!TFHE.glwe<{_,_,_}{2}>>) { +//CHECK-NEXT: ^bb0(%arg2: !TFHE.glwe<{_,_,_}{2}>, %arg3: i3, %arg4: !TFHE.glwe<{_,_,_}{2}>): // no predecessors +//CHECK-NEXT: %4 = "TFHE.mul_glwe_int"(%arg2, %arg3) : (!TFHE.glwe<{_,_,_}{2}>, i3) -> !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: %5 = "TFHE.add_glwe"(%4, %arg4) : (!TFHE.glwe<{_,_,_}{2}>, !TFHE.glwe<{_,_,_}{2}>) -> !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: linalg.yield %5 : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } -> tensor<1x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: %c0 = arith.constant 0 : index +//CHECK-NEXT: %3 = tensor.extract %2[%c0] : tensor<1x!TFHE.glwe<{_,_,_}{2}>> +//CHECK-NEXT: return %3 : !TFHE.glwe<{_,_,_}{2}> +//CHECK-NEXT: } +//CHECK-NEXT: } +func @dot_eint_int(%arg0: tensor<2x!FHE.eint<2>>, + %arg1: tensor<2xi3>) -> !FHE.eint<2> +{ + %o = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<2x!FHE.eint<2>>, tensor<2xi3>) -> !FHE.eint<2> + return %o : !FHE.eint<2> +} diff --git a/compiler/tests/Dialect/FHELinalg/FHELinalg/tiling.mlir b/compiler/tests/Dialect/FHELinalg/FHELinalg/tiling.mlir new file mode 100644 index 000000000..4d74250e2 --- /dev/null +++ b/compiler/tests/Dialect/FHELinalg/FHELinalg/tiling.mlir @@ -0,0 +1,60 @@ +// RUN: concretecompiler --action=dump-fhe %s 2>&1 --split-input-file | FileCheck %s + +// CHECK: func @tiled_2x2(%[[Varg0:.*]]: tensor<8x4x!FHE.eint<6>>, %[[Varg1:.*]]: tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> { +// CHECK-NEXT: %[[Vc2:.*]] = arith.constant 2 : index +// CHECK-NEXT: %[[Vc0:.*]] = arith.constant 0 : index +// CHECK-NEXT: %[[Vc8:.*]] = arith.constant 8 : index +// CHECK-NEXT: %[[Vc4:.*]] = arith.constant 4 : index +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.zero"() : () -> tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V1:.*]] = scf.for %[[Varg2:.*]] = %[[Vc0]] to %[[Vc8]] step %[[Vc2]] iter_args(%[[Varg3:.*]] = %[[V0]]) -> (tensor<8x2x!FHE.eint<6>>) { +// CHECK-NEXT: %[[V2:.*]] = scf.for %[[Varg4:.*]] = %[[Vc0]] to %[[Vc4]] step %[[Vc2]] iter_args(%[[Varg5:.*]] = %[[Varg3]]) -> (tensor<8x2x!FHE.eint<6>>) { +// CHECK-NEXT: %[[V3:.*]] = scf.for %[[Varg6:.*]] = %[[Vc0]] to %[[Vc2]] step %[[Vc2]] iter_args(%[[Varg7:.*]] = %[[Varg5]]) -> (tensor<8x2x!FHE.eint<6>>) { +// CHECK-NEXT: %[[V4:.*]] = tensor.extract_slice %[[Varg0]][%[[Varg2]], %[[Varg4]]] [2, 2] [1, 1] : tensor<8x4x!FHE.eint<6>> to tensor<2x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V5:.*]] = tensor.extract_slice %[[Varg1]][%[[Varg4]], %[[Varg6]]] [2, 2] [1, 1] : tensor<4x2xi7> to tensor<2x2xi7> +// CHECK-NEXT: %[[V6:.*]] = tensor.extract_slice %[[Varg7]][%[[Varg2]], %[[Varg6]]] [2, 2] [1, 1] : tensor<8x2x!FHE.eint<6>> to tensor<2x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V7:.*]] = "FHELinalg.matmul_eint_int"(%[[V4]], %[[V5]]) : (tensor<2x2x!FHE.eint<6>>, tensor<2x2xi7>) -> tensor<2x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V8:.*]] = "FHELinalg.add_eint"(%[[V6]], %[[V7]]) : (tensor<2x2x!FHE.eint<6>>, tensor<2x2x!FHE.eint<6>>) -> tensor<2x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V9:.*]] = tensor.insert_slice %[[V8]] into %[[Varg7]][%[[Varg2]], %[[Varg6]]] [2, 2] [1, 1] : tensor<2x2x!FHE.eint<6>> into tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: scf.yield %[[V9]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +// CHECK-NEXT: scf.yield %[[V3]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +// CHECK-NEXT: scf.yield %[[V2]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +// CHECK-NEXT: return %[[V1]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +func @tiled_2x2(%a: tensor<8x4x!FHE.eint<6>>, %b: tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> { + %0 = "FHELinalg.matmul_eint_int"(%a, %b) { "tile-sizes" = [2,2,2] } : (tensor<8x4x!FHE.eint<6>>, tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> + return %0 : tensor<8x2x!FHE.eint<6>> +} + +// ----- + +// CHECK: func @tiled_one_big_tile(%[[Varg0:.*]]: tensor<8x4x!FHE.eint<6>>, %[[Varg1:.*]]: tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> { +// CHECK-NEXT: %[[Vc8:.*]] = arith.constant 8 : index +// CHECK-NEXT: %[[Vc4:.*]] = arith.constant 4 : index +// CHECK-NEXT: %[[Vc2:.*]] = arith.constant 2 : index +// CHECK-NEXT: %[[Vc0:.*]] = arith.constant 0 : index +// CHECK-NEXT: %[[V0:.*]] = "FHELinalg.zero"() : () -> tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V1:.*]] = scf.for %[[Varg2:.*]] = %[[Vc0]] to %[[Vc8]] step %[[Vc8]] iter_args(%[[Varg3:.*]] = %[[V0]]) -> (tensor<8x2x!FHE.eint<6>>) { +// CHECK-NEXT: %[[V2:.*]] = scf.for %[[Varg4:.*]] = %[[Vc0]] to %[[Vc4]] step %[[Vc4]] iter_args(%[[Varg5:.*]] = %[[Varg3]]) -> (tensor<8x2x!FHE.eint<6>>) { +// CHECK-NEXT: %[[V3:.*]] = scf.for %[[Varg6:.*]] = %[[Vc0]] to %[[Vc2]] step %[[Vc2]] iter_args(%[[Varg7:.*]] = %[[Varg5]]) -> (tensor<8x2x!FHE.eint<6>>) { +// CHECK-NEXT: %[[V4:.*]] = tensor.extract_slice %[[Varg0]][%[[Varg2]], %[[Varg4]]] [8, 4] [1, 1] : tensor<8x4x!FHE.eint<6>> to tensor<8x4x!FHE.eint<6>> +// CHECK-NEXT: %[[V5:.*]] = tensor.extract_slice %[[Varg1]][%[[Varg4]], %[[Varg6]]] [4, 2] [1, 1] : tensor<4x2xi7> to tensor<4x2xi7> +// CHECK-NEXT: %[[V6:.*]] = tensor.extract_slice %[[Varg7]][%[[Varg2]], %[[Varg6]]] [8, 2] [1, 1] : tensor<8x2x!FHE.eint<6>> to tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V7:.*]] = "FHELinalg.matmul_eint_int"(%[[V4]], %[[V5]]) : (tensor<8x4x!FHE.eint<6>>, tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V8:.*]] = "FHELinalg.add_eint"(%[[V6]], %[[V7]]) : (tensor<8x2x!FHE.eint<6>>, tensor<8x2x!FHE.eint<6>>) -> tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: %[[V9:.*]] = tensor.insert_slice %[[V8]] into %[[Varg7]][%[[Varg2]], %[[Varg6]]] [8, 2] [1, 1] : tensor<8x2x!FHE.eint<6>> into tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: scf.yield %[[V9]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +// CHECK-NEXT: scf.yield %[[V3]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +// CHECK-NEXT: scf.yield %[[V2]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +// CHECK-NEXT: return %[[V1]] : tensor<8x2x!FHE.eint<6>> +// CHECK-NEXT: } +func @tiled_one_big_tile(%a: tensor<8x4x!FHE.eint<6>>, %b: tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> { + %0 = "FHELinalg.matmul_eint_int"(%a, %b) { "tile-sizes" = [8,4,2] } : (tensor<8x4x!FHE.eint<6>>, tensor<4x2xi7>) -> tensor<8x2x!FHE.eint<6>> + return %0 : tensor<8x2x!FHE.eint<6>> +} + diff --git a/compiler/tests/Dialect/HLFHE/Analysis/MANP.mlir b/compiler/tests/Dialect/HLFHE/Analysis/MANP.mlir deleted file mode 100644 index d7d1ad050..000000000 --- a/compiler/tests/Dialect/HLFHE/Analysis/MANP.mlir +++ /dev/null @@ -1,202 +0,0 @@ -// RUN: concretecompiler --passes MANP --action=dump-hlfhe --split-input-file %s 2>&1 | FileCheck %s - -func @single_zero() -> !HLFHE.eint<2> -{ - // CHECK: %[[ret:.*]] = "HLFHE.zero"() {MANP = 1 : ui{{[[0-9]+}}} : () -> !HLFHE.eint<2> - %0 = "HLFHE.zero"() : () -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_cst_add_eint_int(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %cst = arith.constant 3 : i3 - - // CHECK: %[[ret:.*]] = "HLFHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%e, %cst) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_dyn_add_eint_int(%e: !HLFHE.eint<2>, %i: i3) -> !HLFHE.eint<2> -{ - // CHECK: %[[ret:.*]] = "HLFHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%e, %i) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_add_eint(%e0: !HLFHE.eint<2>, %e1: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - // CHECK: %[[ret:.*]] = "HLFHE.add_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint"(%e0, %e1) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_cst_sub_int_eint(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %cst = arith.constant 3 : i3 - - // CHECK: %[[ret:.*]] = "HLFHE.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (i3, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %0 = "HLFHE.sub_int_eint"(%cst, %e) : (i3, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_dyn_sub_int_eint(%e: !HLFHE.eint<2>, %i: i3) -> !HLFHE.eint<2> -{ - // CHECK: %[[ret:.*]] = "HLFHE.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (i3, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %0 = "HLFHE.sub_int_eint"(%i, %e) : (i3, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_neg_eint(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - // CHECK: %[[ret:.*]] = "HLFHE.neg_eint"(%[[op0:.*]]) {MANP = 1 : ui{{[0-9]+}}} : (!HLFHE.eint<2>) -> !HLFHE.eint<2> - %0 = "HLFHE.neg_eint"(%e) : (!HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_cst_mul_eint_int(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %cst = arith.constant 3 : i3 - - // %0 = "HLFHE.mul_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 3 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.mul_eint_int"(%e, %cst) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_dyn_mul_eint_int(%e: !HLFHE.eint<2>, %i: i3) -> !HLFHE.eint<2> -{ - // CHECK: %[[ret:.*]] = "HLFHE.mul_eint_int"([[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.mul_eint_int"(%e, %i) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<4xi64>) -> !HLFHE.eint<2> { - // CHECK: %[[ret:.*]] = "HLFHE.apply_lookup_table"(%[[op0:.*]], %[[op1:.*]]) {MANP = 1 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, tensor<4xi64>) -> !HLFHE.eint<2> - %1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, tensor<4xi64>) -> !HLFHE.eint<2> - return %1: !HLFHE.eint<2> -} - -// ----- - -func @chain_add_eint_int(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %cst0 = arith.constant 3 : i3 - %cst1 = arith.constant 7 : i3 - %cst2 = arith.constant 2 : i3 - %cst3 = arith.constant 1 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%e, %cst0) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.add_eint_int"(%[[V0]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %1 = "HLFHE.add_eint_int"(%0, %cst1) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.add_eint_int"(%[[V1]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %2 = "HLFHE.add_eint_int"(%1, %cst2) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V3:.*]] = "HLFHE.add_eint_int"(%[[V2]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %3 = "HLFHE.add_eint_int"(%2, %cst3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - return %3 : !HLFHE.eint<2> -} - -// ----- - -func @dag_add_eint_int(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %Acst0 = arith.constant 3 : i3 - %Acst1 = arith.constant 7 : i3 - %Acst2 = arith.constant 2 : i3 - %Acst3 = arith.constant 1 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %A0 = "HLFHE.add_eint_int"(%e, %Acst0) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.add_eint_int"(%[[V0]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %A1 = "HLFHE.add_eint_int"(%A0, %Acst1) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.add_eint_int"(%[[V1]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %A2 = "HLFHE.add_eint_int"(%A1, %Acst2) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V3:.*]] = "HLFHE.add_eint_int"(%[[V2]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %A3 = "HLFHE.add_eint_int"(%A2, %Acst3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - %Bcst0 = arith.constant 1 : i3 - %Bcst1 = arith.constant 5 : i3 - %Bcst2 = arith.constant 2 : i3 - %Bcst3 = arith.constant 7 : i3 - %Bcst4 = arith.constant 4 : i3 - %Bcst5 = arith.constant 7 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %B0 = "HLFHE.add_eint_int"(%e, %Bcst0) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.add_eint_int"(%[[V0]], %[[op1:.*]]) {MANP = 6 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %B1 = "HLFHE.add_eint_int"(%B0, %Bcst1) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.add_eint_int"(%[[V1]], %[[op1:.*]]) {MANP = 6 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %B2 = "HLFHE.add_eint_int"(%B1, %Bcst2) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V3:.*]] = "HLFHE.add_eint_int"(%[[V2]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %B3 = "HLFHE.add_eint_int"(%B2, %Bcst3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V4:.*]] = "HLFHE.add_eint_int"(%[[V3]], %[[op1:.*]]) {MANP = 10 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %B4 = "HLFHE.add_eint_int"(%B3, %Bcst4) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[V5:.*]] = "HLFHE.add_eint_int"(%[[V4]], %[[op1:.*]]) {MANP = 13 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %B5 = "HLFHE.add_eint_int"(%B4, %Bcst5) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - // CHECK-NEXT: %[[V6:.*]] = "HLFHE.add_eint"(%[[V5]], %[[op1:.*]]) {MANP = 15 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %res = "HLFHE.add_eint"(%B5, %A3) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %A3 : !HLFHE.eint<2> -} - -// ----- - -func @chain_add_eint(%e0: !HLFHE.eint<2>, %e1: !HLFHE.eint<2>, %e2: !HLFHE.eint<2>, %e3: !HLFHE.eint<2>, %e4: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - // CHECK: %[[V0:.*]] = "HLFHE.add_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint"(%e0, %e1) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.add_eint"(%[[V0]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %1 = "HLFHE.add_eint"(%0, %e2) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.add_eint"(%[[V1]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %2 = "HLFHE.add_eint"(%1, %e3) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - // CHECK-NEXT: %[[V3:.*]] = "HLFHE.add_eint"(%[[V2]], %[[op1:.*]]) {MANP = 3 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - %3 = "HLFHE.add_eint"(%2, %e4) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %3 : !HLFHE.eint<2> -} - - -// ----- - -func @chain_add_eint_neg_eint(%e: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %cst0 = arith.constant 3 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%e, %cst0) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: %[[ret:.*]] = "HLFHE.neg_eint"(%[[V0]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>) -> !HLFHE.eint<2> - %1 = "HLFHE.neg_eint"(%0) : (!HLFHE.eint<2>) -> !HLFHE.eint<2> - - return %1 : !HLFHE.eint<2> -} \ No newline at end of file diff --git a/compiler/tests/Dialect/HLFHE/Analysis/MANP_linalg.mlir b/compiler/tests/Dialect/HLFHE/Analysis/MANP_linalg.mlir deleted file mode 100644 index 6cd6ab428..000000000 --- a/compiler/tests/Dialect/HLFHE/Analysis/MANP_linalg.mlir +++ /dev/null @@ -1,392 +0,0 @@ -// RUN: concretecompiler --passes MANP --action=dump-hlfhe --split-input-file %s 2>&1 | FileCheck %s - -func @single_cst_add_eint_int(%t: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - %cst = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> - - // CHECK: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.add_eint_int"(%t, %cst) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_dyn_add_eint_int(%e: tensor<8x!HLFHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> -{ - // CHECK: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.add_eint_int"(%e, %i) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_add_eint(%e0: tensor<8x!HLFHE.eint<2>>, %e1: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - // CHECK: %[[ret:.*]] = "HLFHELinalg.add_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 2 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.add_eint"(%e0, %e1) : (tensor<8x!HLFHE.eint<2>>, tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_cst_sub_int_eint(%e: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - %cst = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> - - // CHECK: %[[ret:.*]] = "HLFHELinalg.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8xi3>, tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.sub_int_eint"(%cst, %e) : (tensor<8xi3>, tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_neg_eint(%e: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - // CHECK: %[[ret:.*]] = "HLFHELinalg.neg_eint"(%[[op0:.*]]) {MANP = 1 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.neg_eint"(%e) : (tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_dyn_sub_int_eint(%e: tensor<8x!HLFHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> -{ - // CHECK: %[[ret:.*]] = "HLFHELinalg.sub_int_eint"(%[[op0:.*]], %[[op1:.*]]) {MANP = 9 : ui{{[0-9]+}}} : (tensor<8xi3>, tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.sub_int_eint"(%i, %e) : (tensor<8xi3>, tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_cst_mul_eint_int(%e: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - %cst = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> - - // %0 = "HLFHELinalg.mul_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 3 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.mul_eint_int"(%e, %cst) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @single_dyn_mul_eint_int(%e: tensor<8x!HLFHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> -{ - // CHECK: %[[ret:.*]] = "HLFHELinalg.mul_eint_int"([[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.mul_eint_int"(%e, %i) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @chain_add_eint_int(%e: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - %cst0 = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> - %cst1 = arith.constant dense<[0, 7, 2, 5, 6, 2, 1, 7]> : tensor<8xi3> - %cst2 = arith.constant dense<[0, 1, 2, 0, 1, 2, 0, 1]> : tensor<8xi3> - %cst3 = arith.constant dense<[0, 1, 1, 0, 0, 1, 0, 1]> : tensor<8xi3> - // CHECK: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.add_eint_int"(%e, %cst0) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - // CHECK-NEXT: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %1 = "HLFHELinalg.add_eint_int"(%0, %cst1) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - // CHECK-NEXT: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %2 = "HLFHELinalg.add_eint_int"(%1, %cst2) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - // CHECK-NEXT: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %3 = "HLFHELinalg.add_eint_int"(%2, %cst3) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - return %3 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -func @chain_add_eint_int_neg_eint(%e: tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> -{ - %cst0 = arith.constant dense<[0, 1, 2, 3, 3, 2, 1, 0]> : tensor<8xi3> - // CHECK: %[[ret:.*]] = "HLFHELinalg.add_eint_int"(%[[op0:.*]], %[[op1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.add_eint_int"(%e, %cst0) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - // CHECK-NEXT: %[[ret:.*]] = "HLFHELinalg.neg_eint"(%[[op0:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - %1 = "HLFHELinalg.neg_eint"(%0) : (tensor<8x!HLFHE.eint<2>>) -> tensor<8x!HLFHE.eint<2>> - return %1 : tensor<8x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.apply_multi_lookup_table -///////////////////////////////////////////////// - -func @apply_lookup_table(%t: tensor<3x3x!HLFHE.eint<2>>) -> tensor<3x3x!HLFHE.eint<3>> { - %lut = arith.constant dense<[1,3,5,7]> : tensor<4xi64> - // CHECK: %[[RES:.*]] = "HLFHELinalg.apply_lookup_table"(%[[T:.*]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<3x3x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!HLFHE.eint<3>> - %res = "HLFHELinalg.apply_lookup_table"(%t, %lut) : (tensor<3x3x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!HLFHE.eint<3>> - return %res : tensor<3x3x!HLFHE.eint<3>> -} - -// ----- - -func @apply_lookup_table_after_op(%t: tensor<8x!HLFHE.eint<2>>, %i: tensor<8xi3>) -> tensor<8x!HLFHE.eint<3>> { - %lut = arith.constant dense<[1,3,5,7]> : tensor<4xi64> - // CHECK: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.mul_eint_int"(%t, %i) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - // CHECK-NEXT: %[[RES:.*]] = "HLFHELinalg.apply_lookup_table"(%[[V0]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<8x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<8x!HLFHE.eint<3>> - %res = "HLFHELinalg.apply_lookup_table"(%0, %lut) : (tensor<8x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<8x!HLFHE.eint<3>> - return %res : tensor<8x!HLFHE.eint<3>> -} - -// ----- - - -func @apply_multi_lookup_table(%t: tensor<3x3x!HLFHE.eint<2>>, %luts: tensor<3x3x4xi64>) -> tensor<3x3x!HLFHE.eint<3>> { - // CHECK: %[[RES:.*]] = "HLFHELinalg.apply_multi_lookup_table"(%[[T:.*]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<3x3x!HLFHE.eint<2>>, tensor<3x3x4xi64>) -> tensor<3x3x!HLFHE.eint<3>> - %res = "HLFHELinalg.apply_multi_lookup_table"(%t, %luts) : (tensor<3x3x!HLFHE.eint<2>>, tensor<3x3x4xi64>) -> tensor<3x3x!HLFHE.eint<3>> - return %res : tensor<3x3x!HLFHE.eint<3>> -} - -// ----- - -func @apply_multi_lookup_table_after_op(%t: tensor<8x!HLFHE.eint<2>>, %i: tensor<8xi3>, %luts: tensor<8x4xi64>) -> tensor<8x!HLFHE.eint<3>> { - // CHECK: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.mul_eint_int"(%t, %i) : (tensor<8x!HLFHE.eint<2>>, tensor<8xi3>) -> tensor<8x!HLFHE.eint<2>> - // CHECK-NEXT: %[[RES:.*]] = "HLFHELinalg.apply_multi_lookup_table"(%[[V0]], %[[LUT:.*]]) {MANP = 1 : ui1} : (tensor<8x!HLFHE.eint<2>>, tensor<8x4xi64>) -> tensor<8x!HLFHE.eint<3>> - %res = "HLFHELinalg.apply_multi_lookup_table"(%0, %luts) : (tensor<8x!HLFHE.eint<2>>, tensor<8x4xi64>) -> tensor<8x!HLFHE.eint<3>> - return %res : tensor<8x!HLFHE.eint<3>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.dot_eint_int -///////////////////////////////////////////////// - -func @single_cst_dot(%t: tensor<4x!HLFHE.eint<2>>) -> !HLFHE.eint<2> -{ - %cst = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi3> - // sqrt(1^2*1 + 2^2*1 + 3^2*1 + 4^2*1) = 5.477225575 - // CHECK: %[[V0:.*]] = "HLFHELinalg.dot_eint_int"(%[[T:.*]], %[[CST:.*]]) {MANP = 6 : ui{{[[0-9]+}}} : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<2> - %0 = "HLFHELinalg.dot_eint_int"(%t, %cst) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<2> - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_dyn_dot(%t: tensor<4x!HLFHE.eint<2>>, %dyn: tensor<4xi3>) -> !HLFHE.eint<2> -{ - // sqrt(1*(2^3-1)^2*4) = 14 - // CHECK: %[[V0:.*]] = "HLFHELinalg.dot_eint_int"([[T:.*]], %[[DYN:.*]]) {MANP = 14 : ui{{[[0-9]+}}} : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<2> - %0 = "HLFHELinalg.dot_eint_int"(%t, %dyn) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<2> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @single_cst_dot_after_op(%t: tensor<4x!HLFHE.eint<2>>, %i: tensor<4xi3>) -> !HLFHE.eint<2> -{ - // sqrt((2^3)^2*1) = sqrt(64) = 8 - // CHECK: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} - %0 = "HLFHELinalg.mul_eint_int"(%t, %i) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> - - %cst = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi3> - // sqrt(1^2*64 + 2^2*64 + 3^2*64 + 4^2*64) = sqrt(1920) = 43.8178046 - // CHECK: %[[V1:.*]] = "HLFHELinalg.dot_eint_int"(%[[V0]], %[[CST:.*]]) {MANP = 44 : ui{{[[0-9]+}}} - %1 = "HLFHELinalg.dot_eint_int"(%0, %cst) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<2> - - return %1 : !HLFHE.eint<2> -} - -// ----- - -func @single_dyn_dot_after_op(%t: tensor<4x!HLFHE.eint<2>>, %i: tensor<4xi3>) -> !HLFHE.eint<2> -{ - // sqrt((2^3)^2*1) = sqrt(64) = 8 - // CHECK: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"([[T:.*]], %[[I:.*]]) {MANP = 8 : ui{{[0-9]+}}} - %0 = "HLFHELinalg.mul_eint_int"(%t, %i) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> - - // sqrt(4*(2^3-1)^2*64) = sqrt(12544) = 112 - // CHECK: %[[V1:.*]] = "HLFHELinalg.dot_eint_int"(%[[V0]], %[[I]]) {MANP = 112 : ui{{[[0-9]+}}} - %1 = "HLFHELinalg.dot_eint_int"(%0, %i) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<2> - - return %1 : !HLFHE.eint<2> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.matmul_ent_int -///////////////////////////////////////////////// - -func @matmul_eint_int_dyn_p_1(%arg0: tensor<3x1x!HLFHE.eint<2>>, %arg1: tensor<1x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 - // manp(add_eint(mul, acc)) = 64 + 1 = 65 - // ceil(sqrt(65)) = 9 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 9 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x1x!HLFHE.eint<2>>, tensor<1x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int_dyn_p_2(%arg0: tensor<3x2x!HLFHE.eint<2>>, %arg1: tensor<2x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 - // manp(add_eint(mul, acc)) = 64 + 1 = 65 - // p = 1 - // manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 - // manp(add_eint(mul, acc)) = 64 + 65 = 129 - // ceil(sqrt(129)) = 12 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 12 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x2x!HLFHE.eint<2>>, tensor<2x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int_cst_p_1(%arg0: tensor<3x1x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - %0 = arith.constant dense<[[3, 1]]> : tensor<1x2xi3> - // c(m,n) = a(m,p) * b(p,n) the max cst is used for n = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 - // manp(add_eint(mul, acc)) = 9 + 1 = 10 - // ceil(sqrt(10)) = 4 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 4 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %0): (tensor<3x1x!HLFHE.eint<2>>, tensor<1x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int_cst_p_2_n_0(%arg0: tensor<3x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - %0 = arith.constant dense<[[4, 1],[3, 1]]> : tensor<2x2xi3> - // c(m,n) = a(m,p) * b(p,n) the max csts [4,3] are used for n = 0 - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 - // manp(add_eint(mul, acc)) = 9 + 1 = 10 - // p = 1 - // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 17 - // manp(add_eint(mul, acc)) = 17 + 9 = 26 - // ceil(sqrt(26)) = 6 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 6 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %0): (tensor<3x2x!HLFHE.eint<2>>, tensor<2x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int_cst_p_2_n_1(%arg0: tensor<3x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - %0 = arith.constant dense<[[1, 4],[3, 1]]> : tensor<2x2xi3> - // c(m,n) = a(m,p) * b(p,n) the max csts [4,1] are used for n = 1 - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 16 - // manp(add_eint(mul, acc)) = 16 + 1 = 17 - // p = 1 - // mul = manp(mul_eint_int(eint<2>, 1) = 1 * 1^2 = 1 - // manp(add_eint(mul, acc)) = 1 + 17 = 18 - // ceil(sqrt(18)) = 5 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_eint_int"(%[[A0:.*]], %[[A1:.*]]) {MANP = 5 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %0): (tensor<3x2x!HLFHE.eint<2>>, tensor<2x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.matmul_int_eint -///////////////////////////////////////////////// - -// ----- - -func @matmul_int_eint_dyn_p_1(%arg0: tensor<3x1xi3>, %arg1: tensor<1x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 - // manp(add_eint(mul, acc)) = 64 + 1 = 65 - // ceil(sqrt(65)) = 9 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 9 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x1xi3>, tensor<1x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint_dyn_p_2(%arg0: tensor<3x2xi3>, %arg1: tensor<2x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 - // manp(add_eint(mul, acc)) = 64 + 1 = 65 - // p = 1 - // manp(mul_eint_int(eint<2>, i3) = 1 * (2^3)^2 = 64 - // manp(add_eint(mul, acc)) = 64 + 65 = 129 - // ceil(sqrt(129)) = 12 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 12 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x2xi3>, tensor<2x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint_cst_p_1(%arg0: tensor<1x3x!HLFHE.eint<2>>) -> tensor<2x3x!HLFHE.eint<2>> { - %0 = arith.constant dense<[[3], [1]]> : tensor<2x1xi3> - // c(m,n) = a(m,p) * b(p,n) the max cst is used for m = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 - // manp(add_eint(mul, acc)) = 9 + 1 = 10 - // ceil(sqrt(10)) = 4 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 4 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_int_eint"(%0, %arg0): (tensor<2x1xi3>, tensor<1x3x!HLFHE.eint<2>>) -> tensor<2x3x!HLFHE.eint<2>> - return %1 : tensor<2x3x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint_cst_p_2_n_0(%arg0: tensor<2x3x!HLFHE.eint<2>>) -> tensor<2x3x!HLFHE.eint<2>> { - %0 = arith.constant dense<[[3, 4],[1, 1]]> : tensor<2x2xi3> - // c(m,n) = a(m,p) * b(p,n) the max csts [4,3] are used for m = 0 - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, 3) = 1 * 3^2 = 9 - // manp(add_eint(mul, acc)) = 9 + 1 = 10 - // p = 1 - // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 17 - // manp(add_eint(mul, acc)) = 17 + 9 = 26 - // ceil(sqrt(26)) = 6 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 6 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_int_eint"(%0, %arg0): (tensor<2x2xi3>, tensor<2x3x!HLFHE.eint<2>>) -> tensor<2x3x!HLFHE.eint<2>> - return %1 : tensor<2x3x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint_cst_p_2_n_1(%arg0: tensor<2x3x!HLFHE.eint<2>>) -> tensor<2x3x!HLFHE.eint<2>> { - %0 = arith.constant dense<[[4, 1],[3, 1]]> : tensor<2x2xi3> - // c(m,n) = a(m,p) * b(p,n) the max csts [4,1] are used for m = 1 - // p = 0 - // acc = manp(0) = 1 - // mul = manp(mul_eint_int(eint<2>, 4) = 1 * 4^2 = 16 - // manp(add_eint(mul, acc)) = 16 + 1 = 17 - // p = 1 - // mul = manp(mul_eint_int(eint<2>, 1) = 1 * 1^2 = 1 - // manp(add_eint(mul, acc)) = 1 + 17 = 18 - // ceil(sqrt(18)) = 5 - // CHECK: %[[V1:.*]] = "HLFHELinalg.matmul_int_eint"(%[[A0:.*]], %[[A1:.*]]) {MANP = 5 : ui{{[0-9]+}}} - %1 = "HLFHELinalg.matmul_int_eint"(%0, %arg0): (tensor<2x2xi3>, tensor<2x3x!HLFHE.eint<2>>) -> tensor<2x3x!HLFHE.eint<2>> - return %1 : tensor<2x3x!HLFHE.eint<2>> -} - -// ----- - -func @zero() -> tensor<8x!HLFHE.eint<2>> -{ - // CHECK: %[[ret:.*]] = "HLFHELinalg.zero"() {MANP = 1 : ui{{[0-9]+}}} : () -> tensor<8x!HLFHE.eint<2>> - %0 = "HLFHELinalg.zero"() : () -> tensor<8x!HLFHE.eint<2>> - - return %0 : tensor<8x!HLFHE.eint<2>> -} diff --git a/compiler/tests/Dialect/HLFHE/Analysis/MANP_tensor.mlir b/compiler/tests/Dialect/HLFHE/Analysis/MANP_tensor.mlir deleted file mode 100644 index 98d51daba..000000000 --- a/compiler/tests/Dialect/HLFHE/Analysis/MANP_tensor.mlir +++ /dev/null @@ -1,160 +0,0 @@ -// RUN: concretecompiler --passes MANP --action=dump-hlfhe --split-input-file %s 2>&1 | FileCheck %s - -func @tensor_from_elements_1(%a: !HLFHE.eint<2>, %b: !HLFHE.eint<2>, %c: !HLFHE.eint<2>, %d: !HLFHE.eint<2>) -> tensor<4x!HLFHE.eint<2>> -{ - // The MANP value is 1 as all operands are function arguments - // CHECK: %[[ret:.*]] = tensor.from_elements %[[a:.*]], %[[b:.*]], %[[c:.*]], %[[d:.*]] {MANP = 1 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<2>> - %0 = tensor.from_elements %a, %b, %c, %d : tensor<4x!HLFHE.eint<2>> - - return %0 : tensor<4x!HLFHE.eint<2>> -} - -// ----- - -func @tensor_from_elements_2(%a: !HLFHE.eint<2>, %b: !HLFHE.eint<2>, %c: !HLFHE.eint<2>, %d: !HLFHE.eint<2>) -> tensor<4x!HLFHE.eint<2>> -{ - %cst = arith.constant 3 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[a:.*]], %[[cst:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%a, %cst) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - - // The MANP value is 4, i.e. the max of all of its operands - // CHECK: %[[V1:.*]] = tensor.from_elements %[[V0]], %[[b:.*]], %[[c:.*]], %[[d:.*]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<2>> - %1 = tensor.from_elements %0, %b, %c, %d : tensor<4x!HLFHE.eint<2>> - - return %1 : tensor<4x!HLFHE.eint<2>> -} - -// ----- - -func @tensor_extract_1(%t: tensor<4x!HLFHE.eint<2>>) -> !HLFHE.eint<2> -{ - %cst = arith.constant 1 : index - - // The MANP value is 1 as the tensor operand is a function argument - // CHECK: %[[ret:.*]] = tensor.extract %[[t:.*]][%[[c1:.*]]] {MANP = 1 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<2>> - %0 = tensor.extract %t[%cst] : tensor<4x!HLFHE.eint<2>> - - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @tensor_extract_2(%a: !HLFHE.eint<2>) -> !HLFHE.eint<2> -{ - %c1 = arith.constant 1 : index - %c3 = arith.constant 3 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[a:.*]], %[[c1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%a, %c3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK: %[[V1:.*]] = tensor.from_elements %[[V0]], %[[a:.*]], %[[a:.*]], %[[a:.*]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<2>> - %1 = tensor.from_elements %0, %a, %a, %a : tensor<4x!HLFHE.eint<2>> - // CHECK: %[[ret:.*]] = tensor.extract %[[V1]][%[[c3:.*]]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<2>> - %2 = tensor.extract %1[%c1] : tensor<4x!HLFHE.eint<2>> - - return %2 : !HLFHE.eint<2> -} - -// ----- - -func @tensor_extract_slice_1(%t: tensor<2x10x!HLFHE.eint<2>>) -> tensor<1x5x!HLFHE.eint<2>> -{ - // CHECK: %[[V0:.*]] = tensor.extract_slice %[[t:.*]][1, 5] [1, 5] [1, 1] {MANP = 1 : ui{{[[0-9]+}}} : tensor<2x10x!HLFHE.eint<2>> to tensor<1x5x!HLFHE.eint<2>> - %0 = tensor.extract_slice %t[1, 5] [1, 5] [1, 1] : tensor<2x10x!HLFHE.eint<2>> to tensor<1x5x!HLFHE.eint<2>> - - return %0 : tensor<1x5x!HLFHE.eint<2>> -} - -// ----- - -func @tensor_extract_slice_2(%a: !HLFHE.eint<2>) -> tensor<2x!HLFHE.eint<2>> -{ - %c3 = arith.constant 3 : i3 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[a:.*]], %[[c1:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - %0 = "HLFHE.add_eint_int"(%a, %c3) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK: %[[V1:.*]] = tensor.from_elements %[[V0]], %[[a:.*]], %[[a:.*]], %[[a:.*]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<2>> - %1 = tensor.from_elements %0, %a, %a, %a : tensor<4x!HLFHE.eint<2>> - // CHECK: tensor.extract_slice %[[V1]][2] [2] [1] {MANP = 4 : ui{{[0-9]+}}} : tensor<4x!HLFHE.eint<2>> to tensor<2x!HLFHE.eint<2>> - %2 = tensor.extract_slice %1[2] [2] [1] : tensor<4x!HLFHE.eint<2>> to tensor<2x!HLFHE.eint<2>> - - return %2 : tensor<2x!HLFHE.eint<2>> -} - -// ----- - -func @tensor_insert_slice_1(%t0: tensor<2x10x!HLFHE.eint<2>>, %t1: tensor<2x2x!HLFHE.eint<2>>) -> tensor<2x10x!HLFHE.eint<2>> -{ - // %[[V0:.*]] = tensor.insert_slice %[[t1:.*]] into %[[t0:.*]][0, 5] [2, 2] [1, 1] {MANP = 1 : ui{{[[0-9]+}}} : tensor<2x2x!HLFHE.eint<2>> into tensor<2x10x!HLFHE.eint<2>> - %0 = tensor.insert_slice %t1 into %t0[0, 5] [2, 2] [1, 1] : tensor<2x2x!HLFHE.eint<2>> into tensor<2x10x!HLFHE.eint<2>> - - return %0 : tensor<2x10x!HLFHE.eint<2>> -} - -// ----- - -func @tensor_insert_slice_2(%a: !HLFHE.eint<5>) -> tensor<4x!HLFHE.eint<5>> -{ - %c3 = arith.constant 3 : i6 - %c6 = arith.constant 6 : i6 - - // CHECK: %[[V0:.*]] = "HLFHE.add_eint_int"(%[[a:.*]], %[[c3:.*]]) {MANP = 4 : ui{{[0-9]+}}} : (!HLFHE.eint<5>, i6) -> !HLFHE.eint<5> - %v0 = "HLFHE.add_eint_int"(%a, %c3) : (!HLFHE.eint<5>, i6) -> !HLFHE.eint<5> - // CHECK: %[[V1:.*]] = "HLFHE.add_eint_int"(%[[a:.*]], %[[c6:.*]]) {MANP = 7 : ui{{[0-9]+}}} : (!HLFHE.eint<5>, i6) -> !HLFHE.eint<5> - %v1 = "HLFHE.add_eint_int"(%a, %c6) : (!HLFHE.eint<5>, i6) -> !HLFHE.eint<5> - - // CHECK: %[[T0:.*]] = tensor.from_elements %[[V0]], %[[V0]], %[[V0]], %[[V0]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<4x!HLFHE.eint<5>> - %t0 = tensor.from_elements %v0, %v0, %v0, %v0 : tensor<4x!HLFHE.eint<5>> - - // CHECK: %[[T1:.*]] = tensor.from_elements %[[V1]], %[[V1]] {MANP = 7 : ui{{[[0-9]+}}} : tensor<2x!HLFHE.eint<5>> - %t1 = tensor.from_elements %v1, %v1 : tensor<2x!HLFHE.eint<5>> - - // CHECK: %[[T2:.*]] = tensor.insert_slice %[[T1]] into %[[T0]][0] [2] [1] {MANP = 7 : ui{{[[0-9]+}}} : tensor<2x!HLFHE.eint<5>> into tensor<4x!HLFHE.eint<5>> - %t2 = tensor.insert_slice %t1 into %t0[0] [2] [1] : tensor<2x!HLFHE.eint<5>> into tensor<4x!HLFHE.eint<5>> - - // CHECK: %[[T3:.*]] = tensor.from_elements %[[V0]], %[[V0]] {MANP = 4 : ui{{[[0-9]+}}} : tensor<2x!HLFHE.eint<5>> - %t3 = tensor.from_elements %v0, %v0 : tensor<2x!HLFHE.eint<5>> - - // CHECK: %[[T4:.*]] = tensor.insert_slice %[[T3]] into %[[T2]][0] [2] [1] {MANP = 7 : ui{{[[0-9]+}}} : tensor<2x!HLFHE.eint<5>> into tensor<4x!HLFHE.eint<5>> - %t4 = tensor.insert_slice %t3 into %t2[0] [2] [1] : tensor<2x!HLFHE.eint<5>> into tensor<4x!HLFHE.eint<5>> - - return %t0 : tensor<4x!HLFHE.eint<5>> -} - -// ----- - -func @tensor_collapse_shape_1(%a: tensor<2x2x4x!HLFHE.eint<6>>) -> tensor<2x8x!HLFHE.eint<6>> { - // CHECK: linalg.tensor_collapse_shape %[[A:.*]] [[X:.*]] {MANP = 1 : ui{{[0-9]+}}} - %0 = linalg.tensor_collapse_shape %a [[0],[1,2]] : tensor<2x2x4x!HLFHE.eint<6>> into tensor<2x8x!HLFHE.eint<6>> - return %0 : tensor<2x8x!HLFHE.eint<6>> -} - -// ----- - -func @tensor_collapse_shape_2(%a: tensor<2x2x4x!HLFHE.eint<2>>, %b: tensor<2x2x4xi3>) -> tensor<2x8x!HLFHE.eint<2>> -{ - // CHECK: "HLFHELinalg.add_eint_int"(%[[A:.*]], %[[B:.*]]) {MANP = 9 : ui{{[0-9]+}}} - %0 = "HLFHELinalg.add_eint_int"(%a, %b) : (tensor<2x2x4x!HLFHE.eint<2>>, tensor<2x2x4xi3>) -> tensor<2x2x4x!HLFHE.eint<2>> - // CHECK-NEXT: linalg.tensor_collapse_shape %[[A:.*]] [[X:.*]] {MANP = 9 : ui{{[0-9]+}}} - %1 = linalg.tensor_collapse_shape %0 [[0],[1,2]] : tensor<2x2x4x!HLFHE.eint<2>> into tensor<2x8x!HLFHE.eint<2>> - return %1 : tensor<2x8x!HLFHE.eint<2>> -} - -// ----- - -func @tensor_expand_shape_1(%a: tensor<2x8x!HLFHE.eint<6>>) -> tensor<2x2x4x!HLFHE.eint<6>> { - // CHECK: linalg.tensor_expand_shape %[[A:.*]] [[X:.*]] {MANP = 1 : ui{{[0-9]+}}} - %0 = linalg.tensor_expand_shape %a [[0],[1,2]] : tensor<2x8x!HLFHE.eint<6>> into tensor<2x2x4x!HLFHE.eint<6>> - return %0 : tensor<2x2x4x!HLFHE.eint<6>> -} - -// ----- - -func @tensor_expand_shape_2(%a: tensor<2x8x!HLFHE.eint<2>>, %b: tensor<2x8xi3>) -> tensor<2x2x4x!HLFHE.eint<2>> -{ - // CHECK: "HLFHELinalg.add_eint_int"(%[[A:.*]], %[[B:.*]]) {MANP = 9 : ui{{[0-9]+}}} - %0 = "HLFHELinalg.add_eint_int"(%a, %b) : (tensor<2x8x!HLFHE.eint<2>>, tensor<2x8xi3>) -> tensor<2x8x!HLFHE.eint<2>> - // CHECK-NEXT: linalg.tensor_expand_shape %[[A:.*]] [[X:.*]] {MANP = 9 : ui{{[0-9]+}}} - %1 = linalg.tensor_expand_shape %0 [[0],[1,2]] : tensor<2x8x!HLFHE.eint<2>> into tensor<2x2x4x!HLFHE.eint<2>> - return %1 : tensor<2x2x4x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Dialect/HLFHE/op_add_eint_err_inputs.mlir b/compiler/tests/Dialect/HLFHE/op_add_eint_err_inputs.mlir deleted file mode 100644 index 3cf0a89f0..000000000 --- a/compiler/tests/Dialect/HLFHE/op_add_eint_err_inputs.mlir +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.add_eint' op should have the width of encrypted inputs equals -func @add_eint(%arg0: !HLFHE.eint<2>, %arg1: !HLFHE.eint<3>) -> !HLFHE.eint<2> { - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<2>, !HLFHE.eint<3>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHE/op_add_eint_err_result.mlir b/compiler/tests/Dialect/HLFHE/op_add_eint_err_result.mlir deleted file mode 100644 index fb7f6bc6e..000000000 --- a/compiler/tests/Dialect/HLFHE/op_add_eint_err_result.mlir +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.add_eint' op should have the width of encrypted inputs and result equals -func @add_eint(%arg0: !HLFHE.eint<2>, %arg1: !HLFHE.eint<2>) -> !HLFHE.eint<3> { - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<2>, !HLFHE.eint<2>) -> (!HLFHE.eint<3>) - return %1: !HLFHE.eint<3> -} diff --git a/compiler/tests/Dialect/HLFHE/op_add_eint_int_err_inputs.mlir b/compiler/tests/Dialect/HLFHE/op_add_eint_int_err_inputs.mlir deleted file mode 100644 index 989730cde..000000000 --- a/compiler/tests/Dialect/HLFHE/op_add_eint_int_err_inputs.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.add_eint_int' op should have the width of plain input equals to width of encrypted input + 1 -func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - %0 = arith.constant 1 : i4 - %1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i4) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHE/op_add_eint_int_err_result.mlir b/compiler/tests/Dialect/HLFHE/op_add_eint_int_err_result.mlir deleted file mode 100644 index 720b81fdd..000000000 --- a/compiler/tests/Dialect/HLFHE/op_add_eint_int_err_result.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.add_eint_int' op should have the width of encrypted inputs and result equals -func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<3> { - %0 = arith.constant 1 : i2 - %1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i2) -> (!HLFHE.eint<3>) - return %1: !HLFHE.eint<3> -} diff --git a/compiler/tests/Dialect/HLFHE/op_apply_lookup_table_bad_dimension.mlir b/compiler/tests/Dialect/HLFHE/op_apply_lookup_table_bad_dimension.mlir deleted file mode 100644 index c7699de08..000000000 --- a/compiler/tests/Dialect/HLFHE/op_apply_lookup_table_bad_dimension.mlir +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.apply_lookup_table' op : `l_cst` (operand #2) inner dimension should have size 4(=2^2) to match `ct` (operand #1) elements bitwidth (2) -func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<8xi3>) -> !HLFHE.eint<2> { - %1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, tensor<8xi3>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHE/op_mul_eint_int_err_inputs.mlir b/compiler/tests/Dialect/HLFHE/op_mul_eint_int_err_inputs.mlir deleted file mode 100644 index 24cd43707..000000000 --- a/compiler/tests/Dialect/HLFHE/op_mul_eint_int_err_inputs.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.mul_eint_int' op should have the width of plain input equals to width of encrypted input + 1 -func @mul_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - %0 = arith.constant 1 : i4 - %1 = "HLFHE.mul_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i4) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHE/op_mul_eint_int_err_result.mlir b/compiler/tests/Dialect/HLFHE/op_mul_eint_int_err_result.mlir deleted file mode 100644 index 6da320f91..000000000 --- a/compiler/tests/Dialect/HLFHE/op_mul_eint_int_err_result.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.mul_eint_int' op should have the width of encrypted inputs and result equals -func @mul_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<3> { - %0 = arith.constant 1 : i2 - %1 = "HLFHE.mul_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i2) -> (!HLFHE.eint<3>) - return %1: !HLFHE.eint<3> -} diff --git a/compiler/tests/Dialect/HLFHE/op_neg_eint_err_result.mlir b/compiler/tests/Dialect/HLFHE/op_neg_eint_err_result.mlir deleted file mode 100644 index 06fab3d11..000000000 --- a/compiler/tests/Dialect/HLFHE/op_neg_eint_err_result.mlir +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.neg_eint' op should have the width of encrypted inputs and result equals -func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<3> { - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<2>) -> (!HLFHE.eint<3>) - return %1: !HLFHE.eint<3> -} diff --git a/compiler/tests/Dialect/HLFHE/op_sub_int_eint_err_inputs.mlir b/compiler/tests/Dialect/HLFHE/op_sub_int_eint_err_inputs.mlir deleted file mode 100644 index e59caa810..000000000 --- a/compiler/tests/Dialect/HLFHE/op_sub_int_eint_err_inputs.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.sub_int_eint' op should have the width of plain input equals to width of encrypted input + 1 -func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - %0 = arith.constant 1 : i4 - %1 = "HLFHE.sub_int_eint"(%0, %arg0): (i4, !HLFHE.eint<2>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHE/op_sub_int_eint_err_result.mlir b/compiler/tests/Dialect/HLFHE/op_sub_int_eint_err_result.mlir deleted file mode 100644 index db82ee008..000000000 --- a/compiler/tests/Dialect/HLFHE/op_sub_int_eint_err_result.mlir +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: not concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: error: 'HLFHE.sub_int_eint' op should have the width of encrypted inputs and result equals -func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<3> { - %0 = arith.constant 1 : i2 - %1 = "HLFHE.sub_int_eint"(%0, %arg0): (i2, !HLFHE.eint<2>) -> (!HLFHE.eint<3>) - return %1: !HLFHE.eint<3> -} diff --git a/compiler/tests/Dialect/HLFHE/ops.mlir b/compiler/tests/Dialect/HLFHE/ops.mlir deleted file mode 100644 index a960d87ac..000000000 --- a/compiler/tests/Dialect/HLFHE/ops.mlir +++ /dev/null @@ -1,70 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @zero() -> !HLFHE.eint<2> -func @zero() -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[RET:.*]] = "HLFHE.zero"() : () -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[RET]] : !HLFHE.eint<2> - - %1 = "HLFHE.zero"() : () -> !HLFHE.eint<2> - return %1: !HLFHE.eint<2> -} - -// CHECK-LABEL: func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> -func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i3 - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.add_eint_int"(%arg0, %[[V1]]) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[V2]] : !HLFHE.eint<2> - - %0 = arith.constant 1 : i3 - %1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i3) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} - -// CHECK-LABEL: func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> -func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i3 - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.sub_int_eint"(%[[V1]], %arg0) : (i3, !HLFHE.eint<2>) -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[V2]] : !HLFHE.eint<2> - - %0 = arith.constant 1 : i3 - %1 = "HLFHE.sub_int_eint"(%0, %arg0): (i3, !HLFHE.eint<2>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} - -// CHECK-LABEL: func @neg_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> -func @neg_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.neg_eint"(%arg0) : (!HLFHE.eint<2>) -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[V1]] : !HLFHE.eint<2> - - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<2>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} - -// CHECK-LABEL: func @mul_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> -func @mul_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i3 - // CHECK-NEXT: %[[V2:.*]] = "HLFHE.mul_eint_int"(%arg0, %[[V1]]) : (!HLFHE.eint<2>, i3) -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[V2]] : !HLFHE.eint<2> - - %0 = arith.constant 1 : i3 - %1 = "HLFHE.mul_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i3) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} - -// CHECK-LABEL: func @add_eint(%arg0: !HLFHE.eint<2>, %arg1: !HLFHE.eint<2>) -> !HLFHE.eint<2> -func @add_eint(%arg0: !HLFHE.eint<2>, %arg1: !HLFHE.eint<2>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.add_eint"(%arg0, %arg1) : (!HLFHE.eint<2>, !HLFHE.eint<2>) -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[V1]] : !HLFHE.eint<2> - - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<2>, !HLFHE.eint<2>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} - -// CHECK-LABEL: func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<4xi64>) -> !HLFHE.eint<2> -func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<4xi64>) -> !HLFHE.eint<2> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHE.apply_lookup_table"(%arg0, %arg1) : (!HLFHE.eint<2>, tensor<4xi64>) -> !HLFHE.eint<2> - // CHECK-NEXT: return %[[V1]] : !HLFHE.eint<2> - - %1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, tensor<4xi64>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> -} \ No newline at end of file diff --git a/compiler/tests/Dialect/HLFHE/types.mlir b/compiler/tests/Dialect/HLFHE/types.mlir deleted file mode 100644 index 3a992013e..000000000 --- a/compiler/tests/Dialect/HLFHE/types.mlir +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @memref_arg(%arg0: memref<2x!HLFHE.eint<7>> -func @memref_arg(%arg0: memref<2x!HLFHE.eint<7>>) { - return -} diff --git a/compiler/tests/Dialect/HLFHELinalg/apply_mapped_lut_to_linalg.mlir b/compiler/tests/Dialect/HLFHELinalg/apply_mapped_lut_to_linalg.mlir deleted file mode 100644 index dfc3a4912..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/apply_mapped_lut_to_linalg.mlir +++ /dev/null @@ -1,31 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe 2>&1 | FileCheck %s - - -//CHECK-LABEL: #map = affine_map<(d0, d1) -> (d0, d1)> -//CHECK-NEXT:module { -//CHECK-NEXT: func @mapped_lut(%arg0: tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>>, %[[LUTS:.*]]: tensor<5x4xi64>, %arg2: tensor<2x3xindex>) -> tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>> { -//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [2, 3] : tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg2 : tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<2x3xindex>) outs(%0 : tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>>) { -//CHECK-NEXT: ^bb0(%arg3: !MidLFHE.glwe<{_,_,_}{2}>, %[[LUTIDX:.*]]: index, %arg5: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -//DISABLED-CHECK-NEXT: %[[V3:.*]] = tensor.extract_slice %arg1[%[[LUTIDX]], 0] [1, 4] [1, 1] : tensor<5x4xi64> to tensor<4xi64> -//WORKAROUND BEGIN -//CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : index -//CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index -//CHECK-NEXT: %[[C2:.*]] = arith.constant 2 : index -//CHECK-NEXT: %[[C3:.*]] = arith.constant 3 : index -//CHECK-NEXT: %[[E0:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C0]]] : tensor<5x4xi64> -//CHECK-NEXT: %[[E1:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C1]]] : tensor<5x4xi64> -//CHECK-NEXT: %[[E2:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C2]]] : tensor<5x4xi64> -//CHECK-NEXT: %[[E3:.*]] = tensor.extract %[[LUTS]][%[[LUTIDX]], %[[C3]]] : tensor<5x4xi64> -//CHECK-NEXT: %[[LUT:.*]] = tensor.from_elements %[[E0]], %[[E1]], %[[E2]], %[[E3]] : tensor<4xi64> -//WORKAROUND END -//CHECK-NEXT: %[[V4:.*]] = "MidLFHE.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} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: linalg.yield %[[V4]] : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -> tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: return %[[V1]] : tensor<2x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: } -//CHECK-NEXT: } -func @mapped_lut(%t: tensor<2x3x!HLFHE.eint<2>>, %luts: tensor<5x4xi64>, %map: tensor<2x3xindex>) -> tensor<2x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_mapped_lookup_table"(%t, %luts, %map): (tensor<2x3x!HLFHE.eint<2>>, tensor<5x4xi64>, tensor<2x3xindex>) -> tensor<2x3x!HLFHE.eint<2>> - return %1: tensor<2x3x!HLFHE.eint<2>> -} diff --git a/compiler/tests/Dialect/HLFHELinalg/apply_multi_lut_to_linalg.mlir b/compiler/tests/Dialect/HLFHELinalg/apply_multi_lut_to_linalg.mlir deleted file mode 100644 index 99b712933..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/apply_multi_lut_to_linalg.mlir +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe 2>&1 | FileCheck %s - -//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> -//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d0, d1, 0)> -//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d0, d1, 1)> -//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d0, d1, 2)> -//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d0, d1, 3)> -//CHECK-NEXT: module { -//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> { -//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 4] : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>, tensor<4x4x4xi64>) outs(%[[V0]] : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>>) { -//CHECK-NEXT: ^bb0(%arg2: !MidLFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> -//CHECK-NEXT: %[[V3:.*]] = "MidLFHE.apply_lookup_table"(%arg2, %[[V2]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: linalg.yield %[[V3]] : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -> tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: return %[[V1]] : tensor<4x4x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: } -//CHECK-NEXT: } -func @multi_lut(%arg0: tensor<4x4x!HLFHE.eint<2>>, %arg1: tensor<4x4x4xi64>) -> tensor<4x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x4x!HLFHE.eint<2>>, tensor<4x4x4xi64>) -> tensor<4x4x!HLFHE.eint<2>> - return %1: tensor<4x4x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Dialect/HLFHELinalg/apply_multi_lut_to_linalg_broadcast.mlir b/compiler/tests/Dialect/HLFHELinalg/apply_multi_lut_to_linalg_broadcast.mlir deleted file mode 100644 index 7f52b68f7..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/apply_multi_lut_to_linalg_broadcast.mlir +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe 2>&1 | FileCheck %s - -//CHECK-LABEL: #map0 = affine_map<(d0, d1) -> (d0, d1)> -//CHECK-NEXT: #map1 = affine_map<(d0, d1) -> (d1, 0)> -//CHECK-NEXT: #map2 = affine_map<(d0, d1) -> (d1, 1)> -//CHECK-NEXT: #map3 = affine_map<(d0, d1) -> (d1, 2)> -//CHECK-NEXT: #map4 = affine_map<(d0, d1) -> (d1, 3)> -//CHECK-NEXT: module { -//CHECK-NEXT: func @multi_lut(%arg0: tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> { -//CHECK-NEXT: %[[V0:.*]] = linalg.init_tensor [4, 3] : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %[[V1:.*]] = linalg.generic {indexing_maps = [#map0, #map1, #map2, #map3, #map4, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg0, %arg1, %arg1, %arg1, %arg1 : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>, tensor<3x4xi64>) outs(%[[V0]] : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>>) { -//CHECK-NEXT: ^bb0(%arg2: !MidLFHE.glwe<{_,_,_}{2}>, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -//CHECK-NEXT: %[[V2:.*]] = tensor.from_elements %arg3, %arg4, %arg5, %arg6 : tensor<4xi64> -//CHECK-NEXT: %[[V3:.*]] = "MidLFHE.apply_lookup_table"(%arg2, %[[V2]]) {baseLogBS = -1 : i32, baseLogKS = -1 : i32, glweDimension = -1 : i32, levelBS = -1 : i32, levelKS = -1 : i32, outputSizeKS = -1 : i32, polynomialSize = -1 : i32} : (!MidLFHE.glwe<{_,_,_}{2}>, tensor<4xi64>) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: linalg.yield %[[V3]] : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -> tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: return %[[V1]] : tensor<4x3x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: } -//CHECK-NEXT: } -func @multi_lut(%arg0: tensor<4x3x!HLFHE.eint<2>>, %arg1: tensor<3x4xi64>) -> tensor<4x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<4x3x!HLFHE.eint<2>>, tensor<3x4xi64>) -> tensor<4x3x!HLFHE.eint<2>> - return %1: tensor<4x3x!HLFHE.eint<2>> -} \ No newline at end of file diff --git a/compiler/tests/Dialect/HLFHELinalg/dot.invalid.mlir b/compiler/tests/Dialect/HLFHELinalg/dot.invalid.mlir deleted file mode 100644 index 083cff379..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/dot.invalid.mlir +++ /dev/null @@ -1,69 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// Incompatible shapes -func @dot_incompatible_shapes( - %arg0: tensor<5x!HLFHE.eint<5>>, - %arg1: tensor<4xi32>) -> !HLFHE.eint<5> -{ - // expected-error @+1 {{'HLFHELinalg.dot_eint_int' op arguments have incompatible shapes}} - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<5x!HLFHE.eint<5>>, tensor<4xi32>) -> !HLFHE.eint<5> - - return %ret : !HLFHE.eint<5> -} - -// ----- - -// Incompatible input types -func @dot_incompatible_input_types( - %arg0: tensor<5x!HLFHE.eint<2>>, - %arg1: tensor<4xf32>) -> !HLFHE.eint<2> -{ - // expected-error @+1 {{'HLFHELinalg.dot_eint_int' op operand #1 must}} - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<5x!HLFHE.eint<2>>, tensor<4xf32>) -> !HLFHE.eint<2> - - return %ret : !HLFHE.eint<2> -} - -// ----- - -// Wrong number of dimensions -func @dot_num_dims( - %arg0: tensor<2x4x!HLFHE.eint<2>>, - %arg1: tensor<2x4xi3>) -> !HLFHE.eint<2> -{ - // expected-error @+1 {{'HLFHELinalg.dot_eint_int' op operand #0}} - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4xi3>) -> !HLFHE.eint<2> - - return %ret : !HLFHE.eint<2> -} - -// ----- - -// Wrong returns type -func @dot_incompatible_return( - %arg0: tensor<4x!HLFHE.eint<2>>, - %arg1: tensor<4xi3>) -> !HLFHE.eint<3> -{ - // expected-error @+1 {{'HLFHELinalg.dot_eint_int' op should have the width of encrypted inputs and result equals}} - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> !HLFHE.eint<3> - - return %ret : !HLFHE.eint<3> -} - -// ----- - -// Wrong integer size -func @dot_incompatible_int( - %arg0: tensor<4x!HLFHE.eint<2>>, - %arg1: tensor<4xi4>) -> !HLFHE.eint<2> -{ - // expected-error @+1 {{'HLFHELinalg.dot_eint_int' op should have the width of plain input equals to width of encrypted input + 1}} - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<2>>, tensor<4xi4>) -> !HLFHE.eint<2> - - return %ret : !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHELinalg/ops.invalid.mlir b/compiler/tests/Dialect/HLFHELinalg/ops.invalid.mlir deleted file mode 100644 index ab31ec55b..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/ops.invalid.mlir +++ /dev/null @@ -1,292 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -///////////////////////////////////////////////// -// HLFHELinalg.add_eint_int -///////////////////////////////////////////////// - -// Incompatible dimension of operands -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x2x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible dimension of result -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint_int' op has the dimension #3 of the result incompatible with operands dimension, got 10 expect 2}} - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x10x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible number of dimension between operands and result -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint_int' op should have the number of dimensions of the result equal to the highest number of dimensions of operands, got 3 expect 4}} - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible width between clear and encrypted witdh -func @main(%a0: tensor<2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x3x4xi4>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint_int' op should have the width of integer values less or equals than the width of encrypted values + 1}} - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x3x4xi4>) -> tensor<2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.add_eint -///////////////////////////////////////////////// - -// Incompatible dimension of operands -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4x!HLFHE.eint<2>>) -> tensor<2x2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4x!HLFHE.eint<2>>) -> tensor<2x2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x2x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible dimension of result -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4x!HLFHE.eint<2>>) -> tensor<2x10x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint' op has the dimension #3 of the result incompatible with operands dimension, got 10 expect 2}} - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4x!HLFHE.eint<2>>) -> tensor<2x10x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x10x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible number of dimension between operands and result -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4x!HLFHE.eint<2>>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint' op should have the number of dimensions of the result equal to the highest number of dimensions of operands, got 3 expect 4}} - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4x!HLFHE.eint<2>>) -> tensor<2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible width between clear and encrypted witdh -func @main(%a0: tensor<2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x3x4x!HLFHE.eint<3>>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint' op should have the width of encrypted equals, got 3 expect 2}} - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x3x4x!HLFHE.eint<3>>) -> tensor<2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.mul_eint_int -///////////////////////////////////////////////// - -// Incompatible dimension of operands -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.mul_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x2x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible dimension of result -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.mul_eint_int' op has the dimension #3 of the result incompatible with operands dimension, got 10 expect 2}} - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x10x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x10x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible number of dimension between operands and result -func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.mul_eint_int' op should have the number of dimensions of the result equal to the highest number of dimensions of operands, got 3 expect 4}} - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -// Incompatible width between clear and encrypted witdh -func @main(%a0: tensor<2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x3x4xi4>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.mul_eint_int' op should have the width of integer values less or equals than the width of encrypted values + 1}} - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x3x4xi4>) -> tensor<2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.apply_lookup_table -///////////////////////////////////////////////// - -func @apply_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<4xi32>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.apply_lookup_table' op should have as operand #2 a tensor<2^pxi64>, where p is the width of the encrypted integer of the operand #1,expect tensor <4xi64>}} - %1 = "HLFHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<4xi32>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -func @apply_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<12xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.apply_lookup_table' op should have as operand #2 a tensor<2^pxi64>, where p is the width of the encrypted integer of the operand #1,expect tensor <4xi64>}} - %1 = "HLFHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<12xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -func @apply_lookup_table(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.apply_lookup_table' op should have same shapes for operand #1 and the result}} - %1 = "HLFHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<3x4x!HLFHE.eint<2>>, tensor<4xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.apply_multi_lookup_table -///////////////////////////////////////////////// - -func @apply_multi_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<2x6xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.apply_multi_lookup_table' op should have as operand #2 a tensor, where p is the width of the encrypted integer of the operand #1,expect tensor }} - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x6xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -// ----- - - -///////////////////////////////////////////////// -// HLFHELinalg.apply_mapped_lookup_table -///////////////////////////////////////////////// -func @apply_mapped_lookup_table_bad_lut_size_127_vs_128( - %input: tensor<2x3x4x!HLFHE.eint<7>>, - %luts: tensor<127xi64>, - %map: tensor<2x3x4xindex> -) -> tensor<2x3x4x!HLFHE.eint<7>> { - // expected-error @+1 {{'HLFHELinalg.apply_mapped_lookup_table' op : `luts` (operand #2) inner dimension should have size 128(=2^7) to match `ct` (operand #1) elements bitwidth (7)}} - %1 = "HLFHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!HLFHE.eint<7>>, tensor<127xi64>, tensor<2x3x4xindex>) -> tensor<2x3x4x!HLFHE.eint<7>> - return %1: tensor<2x3x4x!HLFHE.eint<7>> -} - -// ----- - -func @apply_mapped_lookup_table_bad_map_size( - %input: tensor<2x3x4x!HLFHE.eint<7>>, - %luts: tensor<128xi64>, - %map: tensor<2x3xindex> -) -> tensor<2x3x4x!HLFHE.eint<7>> { - // expected-error @+1 {{'HLFHELinalg.apply_mapped_lookup_table' op : 't' (operand #1) rank (=3) differs from 'lut_map.getName()' (operand #3) rank (=2)}} - %1 = "HLFHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!HLFHE.eint<7>>, tensor<128xi64>, tensor<2x3xindex>) -> tensor<2x3x4x!HLFHE.eint<7>> - return %1: tensor<2x3x4x!HLFHE.eint<7>> -} - -// ----- - -func @apply_mapped_lookup_table_bad_map_elmt_type( - %input: tensor<2x3x4x!HLFHE.eint<7>>, - %luts: tensor<128xi64>, - %map: tensor<2x3xindex> -) -> tensor<2x3x4x!HLFHE.eint<7>> { - // expected-error @+1 {{'HLFHELinalg.apply_mapped_lookup_table' op : 't' (operand #1) rank (=3) differs from 'lut_map.getName()' (operand #3) rank (=2)}} - %1 = "HLFHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!HLFHE.eint<7>>, tensor<128xi64>, tensor<2x3xindex>) -> tensor<2x3x4x!HLFHE.eint<7>> - return %1: tensor<2x3x4x!HLFHE.eint<7>> -} - - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.matmul_eint_int -///////////////////////////////////////////////// - -func @matmul_eint_int(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_eint_int' op should have 2D tensors as operands}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<2x4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_eint_int' op should have 2D tensors as operands}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!HLFHE.eint<2>>, tensor<2x4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<5x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_eint_int' op should have the dimension #0 of operand #1equals to the dimension #1 of operand #0, expect 4 got 5}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!HLFHE.eint<2>>, tensor<5x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<4x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_eint_int' op should have the result shape compatible with operands shape, expect 3x2 as the shape of the result}} - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<4x2x!HLFHE.eint<2>> - return %1 : tensor<4x2x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.matmul_int_eint -///////////////////////////////////////////////// - -func @matmul_int_eint(%arg0: tensor<2x3x4xi3>, %arg1: tensor<4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_int_eint' op should have 2D tensors as operands}} - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<2x3x4xi3>, tensor<4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<2x4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_int_eint' op should have 2D tensors as operands}} - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<2x4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<5x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_int_eint' op should have the dimension #0 of operand #1equals to the dimension #1 of operand #0, expect 4 got 5}} - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<5x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -// ----- - -func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<4x2x!HLFHE.eint<2>>) -> tensor<4x2x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.matmul_int_eint' op should have the result shape compatible with operands shape, expect 3x2 as the shape of the result}} - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<4x2x!HLFHE.eint<2>>) -> tensor<4x2x!HLFHE.eint<2>> - return %1 : tensor<4x2x!HLFHE.eint<2>> -} - -// ----- - -///////////////////////////////////////////////// -// HLFHELinalg.zero -///////////////////////////////////////////////// - -func @zero_1D_scalar() -> tensor<4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.zero' op}} - %0 = "HLFHELinalg.zero"() : () -> !HLFHE.eint<2> - return %0 : !HLFHE.eint<2> -} - -// ----- - -func @zero_plaintext() -> tensor<4x9xi32> { - // expected-error @+1 {{'HLFHELinalg.zero' op}} - %0 = "HLFHELinalg.zero"() : () -> tensor<4x9xi32> - return %0 : tensor<4x9xi32> -} diff --git a/compiler/tests/Dialect/HLFHELinalg/ops.mlir b/compiler/tests/Dialect/HLFHELinalg/ops.mlir deleted file mode 100644 index aa199fd61..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/ops.mlir +++ /dev/null @@ -1,369 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -///////////////////////////////////////////////// -// HLFHELinalg.add_eint_int -///////////////////////////////////////////////// - -// 1D tensor -// CHECK: func @add_eint_int_1D(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_int_1D(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> - return %1: tensor<4x!HLFHE.eint<2>> -} - -// 2D tensor -// CHECK: func @add_eint_int_2D(%[[a0:.*]]: tensor<2x4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_int_2D(%a0: tensor<2x4x!HLFHE.eint<2>>, %a1: tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> - return %1: tensor<2x4x!HLFHE.eint<2>> -} - -// 10D tensor -// CHECK: func @add_eint_int_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_int_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, %a1: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> - return %1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -} - -// Broadcasting with tensor with dimensions equals to one -// CHECK: func @add_eint_int_broadcast_1(%[[a0:.*]]: tensor<1x4x5x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x4x5x!HLFHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_int_broadcast_1(%a0: tensor<1x4x5x!HLFHE.eint<2>>, %a1: tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<1x4x5x!HLFHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> - return %1: tensor<3x4x5x!HLFHE.eint<2>> -} - -// Broadcasting with a tensor less dimensions of another -// CHECK: func @add_eint_int_broadcast_2(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!HLFHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_int_broadcast_2(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> { - %1 ="HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> - return %1: tensor<3x4x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.add_eint -///////////////////////////////////////////////// - -// 1D tensor -// CHECK: func @add_eint_1D(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<4x!HLFHE.eint<2>>, tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_1D(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> - return %1: tensor<4x!HLFHE.eint<2>> -} - -// 2D tensor -// CHECK: func @add_eint_2D(%[[a0:.*]]: tensor<2x4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_2D(%a0: tensor<2x4x!HLFHE.eint<2>>, %a1: tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> - return %1: tensor<2x4x!HLFHE.eint<2>> -} - -// 10D tensor -// CHECK: func @add_eint_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, %a1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> - return %1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -} - -// Broadcasting with tensor with dimensions equals to one -// CHECK: func @add_eint_broadcast_1(%[[a0:.*]]: tensor<1x4x5x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<3x4x1x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<1x4x5x!HLFHE.eint<2>>, tensor<3x4x1x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_broadcast_1(%a0: tensor<1x4x5x!HLFHE.eint<2>>, %a1: tensor<3x4x1x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<1x4x5x!HLFHE.eint<2>>, tensor<3x4x1x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> - return %1: tensor<3x4x5x!HLFHE.eint<2>> -} - -// Broadcasting with a tensor less dimensions of another -// CHECK: func @add_eint_broadcast_2(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<3x4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.add_eint"(%[[a0]], %[[a1]]) : (tensor<4x!HLFHE.eint<2>>, tensor<3x4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @add_eint_broadcast_2(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<3x4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> { - %1 ="HLFHELinalg.add_eint"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<3x4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> - return %1: tensor<3x4x!HLFHE.eint<2>> -} - - -///////////////////////////////////////////////// -// HLFHELinalg.sub_eint_int -///////////////////////////////////////////////// - -// 1D tensor -// CHECK: func @sub_int_eint_1D(%[[a0:.*]]: tensor<4xi3>, %[[a1:.*]]: tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<4xi3>, tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @sub_int_eint_1D(%a0: tensor<4xi3>, %a1: tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4xi3>, tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> - return %1: tensor<4x!HLFHE.eint<2>> -} - -// 2D tensor -// CHECK: func @sub_int_eint_2D(%[[a0:.*]]: tensor<2x4xi3>, %[[a1:.*]]: tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<2x4xi3>, tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @sub_int_eint_2D(%a0: tensor<2x4xi3>, %a1: tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<2x4xi3>, tensor<2x4x!HLFHE.eint<2>>) -> tensor<2x4x!HLFHE.eint<2>> - return %1: tensor<2x4x!HLFHE.eint<2>> -} - -// 10D tensor -// CHECK: func @sub_int_eint_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10xi3>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10xi3>, tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @sub_int_eint_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10xi3>, %a1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10xi3>, tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> - return %1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -} - -// Broadcasting with tensor with dimensions equals to one -// CHECK: func @sub_int_eint_broadcast_1(%[[a0:.*]]: tensor<3x4x1xi3>, %[[a1:.*]]: tensor<1x4x5x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<3x4x1xi3>, tensor<1x4x5x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @sub_int_eint_broadcast_1(%a0: tensor<3x4x1xi3>, %a1: tensor<1x4x5x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x4x1xi3>, tensor<1x4x5x!HLFHE.eint<2>>) -> tensor<3x4x5x!HLFHE.eint<2>> - return %1: tensor<3x4x5x!HLFHE.eint<2>> -} - -// Broadcasting with a tensor less dimensions of another -// CHECK: func @sub_int_eint_broadcast_2(%[[a0:.*]]: tensor<3x4xi3>, %[[a1:.*]]: tensor<4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.sub_int_eint"(%[[a0]], %[[a1]]) : (tensor<3x4xi3>, tensor<4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @sub_int_eint_broadcast_2(%a0: tensor<3x4xi3>, %a1: tensor<4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> { - %1 ="HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x4xi3>, tensor<4x!HLFHE.eint<2>>) -> tensor<3x4x!HLFHE.eint<2>> - return %1: tensor<3x4x!HLFHE.eint<2>> -} - - -///////////////////////////////////////////////// -// HLFHELinalg.neg_eint -///////////////////////////////////////////////// - -// 1D tensor -// CHECK: func @neg_eint_1D(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.neg_eint"(%[[a0]]) : (tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @neg_eint_1D(%a0: tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.neg_eint"(%a0) : (tensor<4x!HLFHE.eint<2>>) -> tensor<4x!HLFHE.eint<2>> - return %1: tensor<4x!HLFHE.eint<2>> -} - -// 1D tensor -// CHECK: func @neg_eint_2D(%[[a0:.*]]: tensor<4x4x!HLFHE.eint<2>>) -> tensor<4x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.neg_eint"(%[[a0]]) : (tensor<4x4x!HLFHE.eint<2>>) -> tensor<4x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<4x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @neg_eint_2D(%a0: tensor<4x4x!HLFHE.eint<2>>) -> tensor<4x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.neg_eint"(%a0) : (tensor<4x4x!HLFHE.eint<2>>) -> tensor<4x4x!HLFHE.eint<2>> - return %1: tensor<4x4x!HLFHE.eint<2>> -} - -// 10D tensor -// CHECK: func @neg_eint_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.neg_eint"(%[[a0]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @neg_eint_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.neg_eint"(%a0) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> - return %1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -} - - -///////////////////////////////////////////////// -// HLFHELinalg.mul_eint_int -///////////////////////////////////////////////// - -// 1D tensor -// CHECK: func @mul_eint_int_1D(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @mul_eint_int_1D(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> - return %1: tensor<4x!HLFHE.eint<2>> -} - -// 2D tensor -// CHECK: func @mul_eint_int_2D(%[[a0:.*]]: tensor<2x4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<2x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @mul_eint_int_2D(%a0: tensor<2x4x!HLFHE.eint<2>>, %a1: tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<2x4x!HLFHE.eint<2>>, tensor<2x4xi3>) -> tensor<2x4x!HLFHE.eint<2>> - return %1: tensor<2x4x!HLFHE.eint<2>> -} - -// 10D tensor -// CHECK: func @mul_eint_int_10D(%[[a0:.*]]: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @mul_eint_int_10D(%a0: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, %a1: tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>>, tensor<1x2x3x4x5x6x7x8x9x10xi3>) -> tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> - return %1: tensor<1x2x3x4x5x6x7x8x9x10x!HLFHE.eint<2>> -} - -// Broadcasting with tensor with dimensions equals to one -// CHECK: func @mul_eint_int_broadcast_1(%[[a0:.*]]: tensor<1x4x5x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<1x4x5x!HLFHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x5x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @mul_eint_int_broadcast_1(%a0: tensor<1x4x5x!HLFHE.eint<2>>, %a1: tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<1x4x5x!HLFHE.eint<2>>, tensor<3x4x1xi3>) -> tensor<3x4x5x!HLFHE.eint<2>> - return %1: tensor<3x4x5x!HLFHE.eint<2>> -} - -// Broadcasting with a tensor less dimensions of another -// CHECK: func @mul_eint_int_broadcast_2(%[[a0:.*]]: tensor<4x!HLFHE.eint<2>>, %[[a1:.*]]: tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.mul_eint_int"(%[[a0]], %[[a1]]) : (tensor<4x!HLFHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[V0]] : tensor<3x4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @mul_eint_int_broadcast_2(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> { - %1 ="HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<3x4xi3>) -> tensor<3x4x!HLFHE.eint<2>> - return %1: tensor<3x4x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.apply_lookup_table -///////////////////////////////////////////////// - -// CHECK-LABEL: func @apply_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> -func @apply_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHELinalg.apply_lookup_table"(%arg0, %arg1) : (tensor<2x3x4x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> - // CHECK-NEXT: return %[[V1]] : tensor<2x3x4x!HLFHE.eint<2>> - - %1 = "HLFHELinalg.apply_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<4xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.apply_multi_lookup_table -///////////////////////////////////////////////// - -// CHECK-LABEL: func @apply_multi_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<2x3x4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> -func @apply_multi_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<2x3x4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1) : (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x3x4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> - // CHECK-NEXT: return %[[V1]] : tensor<2x3x4x!HLFHE.eint<2>> - - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x3x4xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -// CHECK-LABEL: func @apply_multi_lookup_table_broadcast(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<2x4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> -func @apply_multi_lookup_table_broadcast(%arg0: tensor<2x3x4x!HLFHE.eint<2>>, %arg1: tensor<2x4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1) : (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x4xi64>) -> tensor<2x3x4x!HLFHE.eint<2>> - // CHECK-NEXT: return %[[V1]] : tensor<2x3x4x!HLFHE.eint<2>> - - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<2x3x4x!HLFHE.eint<2>>, tensor<2x4xi64>) -> (tensor<2x3x4x!HLFHE.eint<2>>) - return %1: tensor<2x3x4x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.apply_mapped_lookup_table -///////////////////////////////////////////////// - -// CHECK-LABEL: func @apply_mapped_lookup_table(%arg0: tensor<2x3x4x!HLFHE.eint<7>>, %arg1: tensor<10x128xi64>, %arg2: tensor<2x3x4xindex>) -> tensor<2x3x4x!HLFHE.eint<7>> { -func @apply_mapped_lookup_table( - %input: tensor<2x3x4x!HLFHE.eint<7>>, - %luts: tensor<10x128xi64>, - %map: tensor<2x3x4xindex> -) -> tensor<2x3x4x!HLFHE.eint<7>> { - // CHECK-NEXT: %0 = "HLFHELinalg.apply_mapped_lookup_table"(%arg0, %arg1, %arg2) : (tensor<2x3x4x!HLFHE.eint<7>>, tensor<10x128xi64>, tensor<2x3x4xindex>) -> tensor<2x3x4x!HLFHE.eint<7>> - // CHECK-NEXT: return %0 : tensor<2x3x4x!HLFHE.eint<7>> - %0 = "HLFHELinalg.apply_mapped_lookup_table"(%input, %luts, %map): (tensor<2x3x4x!HLFHE.eint<7>>, tensor<10x128xi64>, tensor<2x3x4xindex>) -> (tensor<2x3x4x!HLFHE.eint<7>>) - return %0: tensor<2x3x4x!HLFHE.eint<7>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.dot_eint_int -///////////////////////////////////////////////// - -// CHECK-LABEL: func @dot_eint_int(%arg0: tensor<2x!HLFHE.eint<2>>, %arg1: tensor<2xi3>) -> !HLFHE.eint<2> -func @dot_eint_int(%arg0: tensor<2x!HLFHE.eint<2>>, - %arg1: tensor<2xi3>) -> !HLFHE.eint<2> -{ - // CHECK-NEXT: %[[RET:.*]] = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : (tensor<2x!HLFHE.eint<2>>, tensor<2xi3>) -> !HLFHE.eint<2> - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<2x!HLFHE.eint<2>>, tensor<2xi3>) -> !HLFHE.eint<2> - - //CHECK-NEXT: return %[[RET]] : !HLFHE.eint<2> - return %ret : !HLFHE.eint<2> -} - -///////////////////////////////////////////////// -// HLFHELinalg.matmul_eint_int -///////////////////////////////////////////////// - -// CHECK-LABEL: @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> -func @matmul_eint_int(%arg0: tensor<3x4x!HLFHE.eint<2>>, %arg1: tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1) : (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - // CHECK-NEXT: return %[[V1]] : tensor<3x2x!HLFHE.eint<2>> - - %1 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1): (tensor<3x4x!HLFHE.eint<2>>, tensor<4x2xi3>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.matmul_int_eint -///////////////////////////////////////////////// - -// CHECK-LABEL: @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> -func @matmul_int_eint(%arg0: tensor<3x4xi3>, %arg1: tensor<4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> { - // CHECK-NEXT: %[[V1:.*]] = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1) : (tensor<3x4xi3>, tensor<4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - // CHECK-NEXT: return %[[V1]] : tensor<3x2x!HLFHE.eint<2>> - - %1 = "HLFHELinalg.matmul_int_eint"(%arg0, %arg1): (tensor<3x4xi3>, tensor<4x2x!HLFHE.eint<2>>) -> tensor<3x2x!HLFHE.eint<2>> - return %1 : tensor<3x2x!HLFHE.eint<2>> -} - -///////////////////////////////////////////////// -// HLFHELinalg.zero -///////////////////////////////////////////////// - -// CHECK: func @zero_1D() -> tensor<4x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[v0:.*]] = "HLFHELinalg.zero"() : () -> tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[v0]] : tensor<4x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @zero_1D() -> tensor<4x!HLFHE.eint<2>> { - %0 = "HLFHELinalg.zero"() : () -> tensor<4x!HLFHE.eint<2>> - return %0 : tensor<4x!HLFHE.eint<2>> -} - -// CHECK: func @zero_2D() -> tensor<4x9x!HLFHE.eint<2>> { -// CHECK-NEXT: %[[v0:.*]] = "HLFHELinalg.zero"() : () -> tensor<4x9x!HLFHE.eint<2>> -// CHECK-NEXT: return %[[v0]] : tensor<4x9x!HLFHE.eint<2>> -// CHECK-NEXT: } -func @zero_2D() -> tensor<4x9x!HLFHE.eint<2>> { - %0 = "HLFHELinalg.zero"() : () -> tensor<4x9x!HLFHE.eint<2>> - return %0 : tensor<4x9x!HLFHE.eint<2>> -} diff --git a/compiler/tests/Dialect/HLFHELinalg/tensor-ops-to-linalg.mlir b/compiler/tests/Dialect/HLFHELinalg/tensor-ops-to-linalg.mlir deleted file mode 100644 index cea2ee9b5..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/tensor-ops-to-linalg.mlir +++ /dev/null @@ -1,26 +0,0 @@ -// RUN: concretecompiler %s --action=dump-midlfhe 2>&1 | FileCheck %s - -//CHECK: #map0 = affine_map<(d0) -> (d0)> -//CHECK-NEXT: #map1 = affine_map<(d0) -> (0)> -//CHECK-NEXT: module { -//CHECK-NEXT: func @dot_eint_int(%arg0: tensor<2x!MidLFHE.glwe<{_,_,_}{2}>>, %arg1: tensor<2xi3>) -> !MidLFHE.glwe<{_,_,_}{2}> { -//CHECK-NEXT: %0 = "MidLFHE.zero"() : () -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: %1 = tensor.from_elements %0 : tensor<1x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!MidLFHE.glwe<{_,_,_}{2}>>, tensor<2xi3>) outs(%1 : tensor<1x!MidLFHE.glwe<{_,_,_}{2}>>) { -//CHECK-NEXT: ^bb0(%arg2: !MidLFHE.glwe<{_,_,_}{2}>, %arg3: i3, %arg4: !MidLFHE.glwe<{_,_,_}{2}>): // no predecessors -//CHECK-NEXT: %4 = "MidLFHE.mul_glwe_int"(%arg2, %arg3) : (!MidLFHE.glwe<{_,_,_}{2}>, i3) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: %5 = "MidLFHE.add_glwe"(%4, %arg4) : (!MidLFHE.glwe<{_,_,_}{2}>, !MidLFHE.glwe<{_,_,_}{2}>) -> !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: linalg.yield %5 : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -> tensor<1x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: %c0 = arith.constant 0 : index -//CHECK-NEXT: %3 = tensor.extract %2[%c0] : tensor<1x!MidLFHE.glwe<{_,_,_}{2}>> -//CHECK-NEXT: return %3 : !MidLFHE.glwe<{_,_,_}{2}> -//CHECK-NEXT: } -//CHECK-NEXT: } -func @dot_eint_int(%arg0: tensor<2x!HLFHE.eint<2>>, - %arg1: tensor<2xi3>) -> !HLFHE.eint<2> -{ - %o = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<2x!HLFHE.eint<2>>, tensor<2xi3>) -> !HLFHE.eint<2> - return %o : !HLFHE.eint<2> -} diff --git a/compiler/tests/Dialect/HLFHELinalg/tiling.mlir b/compiler/tests/Dialect/HLFHELinalg/tiling.mlir deleted file mode 100644 index 2e6a4347a..000000000 --- a/compiler/tests/Dialect/HLFHELinalg/tiling.mlir +++ /dev/null @@ -1,60 +0,0 @@ -// RUN: concretecompiler --action=dump-hlfhe %s 2>&1 --split-input-file | FileCheck %s - -// CHECK: func @tiled_2x2(%[[Varg0:.*]]: tensor<8x4x!HLFHE.eint<6>>, %[[Varg1:.*]]: tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> { -// CHECK-NEXT: %[[Vc2:.*]] = arith.constant 2 : index -// CHECK-NEXT: %[[Vc0:.*]] = arith.constant 0 : index -// CHECK-NEXT: %[[Vc8:.*]] = arith.constant 8 : index -// CHECK-NEXT: %[[Vc4:.*]] = arith.constant 4 : index -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.zero"() : () -> tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V1:.*]] = scf.for %[[Varg2:.*]] = %[[Vc0]] to %[[Vc8]] step %[[Vc2]] iter_args(%[[Varg3:.*]] = %[[V0]]) -> (tensor<8x2x!HLFHE.eint<6>>) { -// CHECK-NEXT: %[[V2:.*]] = scf.for %[[Varg4:.*]] = %[[Vc0]] to %[[Vc4]] step %[[Vc2]] iter_args(%[[Varg5:.*]] = %[[Varg3]]) -> (tensor<8x2x!HLFHE.eint<6>>) { -// CHECK-NEXT: %[[V3:.*]] = scf.for %[[Varg6:.*]] = %[[Vc0]] to %[[Vc2]] step %[[Vc2]] iter_args(%[[Varg7:.*]] = %[[Varg5]]) -> (tensor<8x2x!HLFHE.eint<6>>) { -// CHECK-NEXT: %[[V4:.*]] = tensor.extract_slice %[[Varg0]][%[[Varg2]], %[[Varg4]]] [2, 2] [1, 1] : tensor<8x4x!HLFHE.eint<6>> to tensor<2x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V5:.*]] = tensor.extract_slice %[[Varg1]][%[[Varg4]], %[[Varg6]]] [2, 2] [1, 1] : tensor<4x2xi7> to tensor<2x2xi7> -// CHECK-NEXT: %[[V6:.*]] = tensor.extract_slice %[[Varg7]][%[[Varg2]], %[[Varg6]]] [2, 2] [1, 1] : tensor<8x2x!HLFHE.eint<6>> to tensor<2x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V7:.*]] = "HLFHELinalg.matmul_eint_int"(%[[V4]], %[[V5]]) : (tensor<2x2x!HLFHE.eint<6>>, tensor<2x2xi7>) -> tensor<2x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V8:.*]] = "HLFHELinalg.add_eint"(%[[V6]], %[[V7]]) : (tensor<2x2x!HLFHE.eint<6>>, tensor<2x2x!HLFHE.eint<6>>) -> tensor<2x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V9:.*]] = tensor.insert_slice %[[V8]] into %[[Varg7]][%[[Varg2]], %[[Varg6]]] [2, 2] [1, 1] : tensor<2x2x!HLFHE.eint<6>> into tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: scf.yield %[[V9]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -// CHECK-NEXT: scf.yield %[[V3]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -// CHECK-NEXT: scf.yield %[[V2]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -// CHECK-NEXT: return %[[V1]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -func @tiled_2x2(%a: tensor<8x4x!HLFHE.eint<6>>, %b: tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> { - %0 = "HLFHELinalg.matmul_eint_int"(%a, %b) { "tile-sizes" = [2,2,2] } : (tensor<8x4x!HLFHE.eint<6>>, tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> - return %0 : tensor<8x2x!HLFHE.eint<6>> -} - -// ----- - -// CHECK: func @tiled_one_big_tile(%[[Varg0:.*]]: tensor<8x4x!HLFHE.eint<6>>, %[[Varg1:.*]]: tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> { -// CHECK-NEXT: %[[Vc8:.*]] = arith.constant 8 : index -// CHECK-NEXT: %[[Vc4:.*]] = arith.constant 4 : index -// CHECK-NEXT: %[[Vc2:.*]] = arith.constant 2 : index -// CHECK-NEXT: %[[Vc0:.*]] = arith.constant 0 : index -// CHECK-NEXT: %[[V0:.*]] = "HLFHELinalg.zero"() : () -> tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V1:.*]] = scf.for %[[Varg2:.*]] = %[[Vc0]] to %[[Vc8]] step %[[Vc8]] iter_args(%[[Varg3:.*]] = %[[V0]]) -> (tensor<8x2x!HLFHE.eint<6>>) { -// CHECK-NEXT: %[[V2:.*]] = scf.for %[[Varg4:.*]] = %[[Vc0]] to %[[Vc4]] step %[[Vc4]] iter_args(%[[Varg5:.*]] = %[[Varg3]]) -> (tensor<8x2x!HLFHE.eint<6>>) { -// CHECK-NEXT: %[[V3:.*]] = scf.for %[[Varg6:.*]] = %[[Vc0]] to %[[Vc2]] step %[[Vc2]] iter_args(%[[Varg7:.*]] = %[[Varg5]]) -> (tensor<8x2x!HLFHE.eint<6>>) { -// CHECK-NEXT: %[[V4:.*]] = tensor.extract_slice %[[Varg0]][%[[Varg2]], %[[Varg4]]] [8, 4] [1, 1] : tensor<8x4x!HLFHE.eint<6>> to tensor<8x4x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V5:.*]] = tensor.extract_slice %[[Varg1]][%[[Varg4]], %[[Varg6]]] [4, 2] [1, 1] : tensor<4x2xi7> to tensor<4x2xi7> -// CHECK-NEXT: %[[V6:.*]] = tensor.extract_slice %[[Varg7]][%[[Varg2]], %[[Varg6]]] [8, 2] [1, 1] : tensor<8x2x!HLFHE.eint<6>> to tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V7:.*]] = "HLFHELinalg.matmul_eint_int"(%[[V4]], %[[V5]]) : (tensor<8x4x!HLFHE.eint<6>>, tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V8:.*]] = "HLFHELinalg.add_eint"(%[[V6]], %[[V7]]) : (tensor<8x2x!HLFHE.eint<6>>, tensor<8x2x!HLFHE.eint<6>>) -> tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: %[[V9:.*]] = tensor.insert_slice %[[V8]] into %[[Varg7]][%[[Varg2]], %[[Varg6]]] [8, 2] [1, 1] : tensor<8x2x!HLFHE.eint<6>> into tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: scf.yield %[[V9]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -// CHECK-NEXT: scf.yield %[[V3]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -// CHECK-NEXT: scf.yield %[[V2]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -// CHECK-NEXT: return %[[V1]] : tensor<8x2x!HLFHE.eint<6>> -// CHECK-NEXT: } -func @tiled_one_big_tile(%a: tensor<8x4x!HLFHE.eint<6>>, %b: tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> { - %0 = "HLFHELinalg.matmul_eint_int"(%a, %b) { "tile-sizes" = [8,4,2] } : (tensor<8x4x!HLFHE.eint<6>>, tensor<4x2xi7>) -> tensor<8x2x!HLFHE.eint<6>> - return %0 : tensor<8x2x!HLFHE.eint<6>> -} - diff --git a/compiler/tests/Dialect/LowLFHE/ops.mlir b/compiler/tests/Dialect/LowLFHE/ops.mlir deleted file mode 100644 index 647a4648b..000000000 --- a/compiler/tests/Dialect/LowLFHE/ops.mlir +++ /dev/null @@ -1,74 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_lwe_ciphertexts(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @add_lwe_ciphertexts(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.add_lwe_ciphertexts"(%arg0, %arg1) : (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %1 = "LowLFHE.add_lwe_ciphertexts"(%arg0, %arg1): (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.lwe_ciphertext<2048,7>) -> (!LowLFHE.lwe_ciphertext<2048,7>) - return %1: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @add_plaintext_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.plaintext<5>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @add_plaintext_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.plaintext<5>) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.add_plaintext_lwe_ciphertext"(%arg0, %arg1) : (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.plaintext<5>) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %1 = "LowLFHE.add_plaintext_lwe_ciphertext"(%arg0, %arg1): (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.plaintext<5>) -> (!LowLFHE.lwe_ciphertext<2048,7>) - return %1: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @mul_cleartext_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.cleartext<7>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @mul_cleartext_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.cleartext<7>) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.mul_cleartext_lwe_ciphertext"(%arg0, %arg1) : (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.cleartext<7>) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %1 = "LowLFHE.mul_cleartext_lwe_ciphertext"(%arg0, %arg1): (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.cleartext<7>) -> (!LowLFHE.lwe_ciphertext<2048,7>) - return %1: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @negate_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @negate_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.negate_lwe_ciphertext"(%arg0) : (!LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %1 = "LowLFHE.negate_lwe_ciphertext"(%arg0): (!LowLFHE.lwe_ciphertext<2048,7>) -> (!LowLFHE.lwe_ciphertext<2048,7>) - return %1: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @bootstrap_lwe(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<2048,7> -func @bootstrap_lwe(%arg0: !LowLFHE.lwe_ciphertext<2048,7>, %arg1: !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.bootstrap_lwe"(%arg0, %arg1) {baseLog = -1 : i32, glweDimension = 1 : i32, level = -1 : i32, polynomialSize = 1024 : i32} : (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.glwe_ciphertext) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %1 = "LowLFHE.bootstrap_lwe"(%arg0, %arg1) {baseLog = -1 : i32, glweDimension = 1 : i32, level = -1 : i32, polynomialSize = 1024 : i32} : (!LowLFHE.lwe_ciphertext<2048,7>, !LowLFHE.glwe_ciphertext) -> (!LowLFHE.lwe_ciphertext<2048,7>) - return %1: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @keyswitch_lwe(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @keyswitch_lwe(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.keyswitch_lwe"(%arg0) {baseLog = 2 : i32, level = 3 : i32} : (!LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.lwe_ciphertext<2048,7> - - %1 = "LowLFHE.keyswitch_lwe"(%arg0){baseLog = 2 : i32, level = 3 : i32}: (!LowLFHE.lwe_ciphertext<2048,7>) -> (!LowLFHE.lwe_ciphertext<2048,7>) - return %1: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @encode_int(%arg0: i6) -> !LowLFHE.plaintext<6> -func @encode_int(%arg0: i6) -> (!LowLFHE.plaintext<6>) { - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.encode_int"(%arg0) : (i6) -> !LowLFHE.plaintext<6> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.plaintext<6> - - %0 = "LowLFHE.encode_int"(%arg0): (i6) -> !LowLFHE.plaintext<6> - return %0: !LowLFHE.plaintext<6> -} - -// CHECK-LABEL: func @int_to_cleartext() -> !LowLFHE.cleartext<6> -func @int_to_cleartext() -> !LowLFHE.cleartext<6> { - // CHECK-NEXT: %[[V0:.*]] = arith.constant 5 : i6 - // CHECK-NEXT: %[[V1:.*]] = "LowLFHE.int_to_cleartext"(%[[V0]]) : (i6) -> !LowLFHE.cleartext<6> - // CHECK-NEXT: return %[[V1]] : !LowLFHE.cleartext<6> - %0 = arith.constant 5 : i6 - %1 = "LowLFHE.int_to_cleartext"(%0) : (i6) -> !LowLFHE.cleartext<6> - return %1 : !LowLFHE.cleartext<6> -} diff --git a/compiler/tests/Dialect/LowLFHE/types.mlir b/compiler/tests/Dialect/LowLFHE/types.mlir deleted file mode 100644 index 6fbd07320..000000000 --- a/compiler/tests/Dialect/LowLFHE/types.mlir +++ /dev/null @@ -1,44 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - - -// CHECK-LABEL: func @type_plaintext(%arg0: !LowLFHE.plaintext<7>) -> !LowLFHE.plaintext<7> -func @type_plaintext(%arg0: !LowLFHE.plaintext<7>) -> !LowLFHE.plaintext<7> { - // CHECK-NEXT: return %arg0 : !LowLFHE.plaintext<7> - return %arg0: !LowLFHE.plaintext<7> -} - -// CHECK-LABEL: func @type_plaintext_list(%arg0: !LowLFHE.plaintext_list) -> !LowLFHE.plaintext_list -func @type_plaintext_list(%arg0: !LowLFHE.plaintext_list) -> !LowLFHE.plaintext_list { - // CHECK-NEXT: return %arg0 : !LowLFHE.plaintext_list - return %arg0: !LowLFHE.plaintext_list -} - -// CHECK-LABEL: func @type_foreign_plaintext_list(%arg0: !LowLFHE.foreign_plaintext_list) -> !LowLFHE.foreign_plaintext_list -func @type_foreign_plaintext_list(%arg0: !LowLFHE.foreign_plaintext_list) -> !LowLFHE.foreign_plaintext_list { - // CHECK-NEXT: return %arg0 : !LowLFHE.foreign_plaintext_list - return %arg0: !LowLFHE.foreign_plaintext_list -} - -// CHECK-LABEL: func @type_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> -func @type_lwe_ciphertext(%arg0: !LowLFHE.lwe_ciphertext<2048,7>) -> !LowLFHE.lwe_ciphertext<2048,7> { - // CHECK-NEXT: return %arg0 : !LowLFHE.lwe_ciphertext<2048,7> - return %arg0: !LowLFHE.lwe_ciphertext<2048,7> -} - -// CHECK-LABEL: func @type_lwe_key_switch_key(%arg0: !LowLFHE.lwe_key_switch_key) -> !LowLFHE.lwe_key_switch_key -func @type_lwe_key_switch_key(%arg0: !LowLFHE.lwe_key_switch_key) -> !LowLFHE.lwe_key_switch_key { - // CHECK-NEXT: return %arg0 : !LowLFHE.lwe_key_switch_key - return %arg0: !LowLFHE.lwe_key_switch_key -} - -// CHECK-LABEL: func @type_lwe_bootstrap_key(%arg0: !LowLFHE.lwe_bootstrap_key) -> !LowLFHE.lwe_bootstrap_key -func @type_lwe_bootstrap_key(%arg0: !LowLFHE.lwe_bootstrap_key) -> !LowLFHE.lwe_bootstrap_key { - // CHECK-NEXT: return %arg0 : !LowLFHE.lwe_bootstrap_key - return %arg0: !LowLFHE.lwe_bootstrap_key -} - -// CHECK-LABEL: func @type_cleartext(%arg0: !LowLFHE.cleartext<5>) -> !LowLFHE.cleartext<5> -func @type_cleartext(%arg0: !LowLFHE.cleartext<5>) -> !LowLFHE.cleartext<5> { - // CHECK-NEXT: return %arg0 : !LowLFHE.cleartext<5> - return %arg0: !LowLFHE.cleartext<5> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_add_glwe.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_add_glwe.invalid.mlir deleted file mode 100644 index 8fcf6c926..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_add_glwe.invalid.mlir +++ /dev/null @@ -1,54 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// GLWE p parameter result -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{6}> { - // expected-error @+1 {{'MidLFHE.add_glwe' op should have the same GLWE 'p' parameter}} - %1 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{6}>) - return %1: !MidLFHE.glwe<{1024,12,64}{6}> -} - -// ----- - -// GLWE p parameter inputs -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,12,64}{6}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // expected-error @+1 {{'MidLFHE.add_glwe' op should have the same GLWE 'p' parameter}} - %1 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,12,64}{6}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} - -// ----- - -// GLWE dimension parameter result -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{512,12,64}{7}> { - // expected-error @+1 {{'MidLFHE.add_glwe' op should have the same GLWE 'dimension' parameter}} - %1 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{512,12,64}{7}>) - return %1: !MidLFHE.glwe<{512,12,64}{7}> -} - -// ----- - -// GLWE dimension parameter inputs -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{512,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // expected-error @+1 {{'MidLFHE.add_glwe' op should have the same GLWE 'dimension' parameter}} - %1 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{512,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} - -// ----- - -// GLWE polynomialSize parameter result -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - // expected-error @+1 {{'MidLFHE.add_glwe' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - -// ----- - -// GLWE polynomialSize parameter inputs -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,11,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // expected-error @+1 {{'MidLFHE.add_glwe' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,11,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} - diff --git a/compiler/tests/Dialect/MidLFHE/op_add_glwe.mlir b/compiler/tests/Dialect/MidLFHE/op_add_glwe.mlir deleted file mode 100644 index 5613adeb7..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_add_glwe.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> -func @add_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.add_glwe"(%arg0, %arg1) : (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> - // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{1024,12,64}{7}> - - %0 = "MidLFHE.add_glwe"(%arg0, %arg1): (!MidLFHE.glwe<{1024,12,64}{7}>, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %0: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_add_glwe_int.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_add_glwe_int.invalid.mlir deleted file mode 100644 index 9af0e7d4c..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_add_glwe_int.invalid.mlir +++ /dev/null @@ -1,39 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// GLWE p parameter -func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{6}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.add_glwe_int' op should have the same GLWE 'p' parameter}} - %1 = "MidLFHE.add_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,12,64}{6}>) - return %1: !MidLFHE.glwe<{1024,12,64}{6}> -} - -// ----- - -// GLWE dimension parameter -func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{512,12,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.add_glwe_int' op should have the same GLWE 'dimension' parameter}} - %1 = "MidLFHE.add_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{512,12,64}{7}>) - return %1: !MidLFHE.glwe<{512,12,64}{7}> -} - -// ----- - -// GLWE polynomialSize parameter -func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.add_glwe_int' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.add_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - -// ----- - -// integer width doesn't match GLWE parameter -func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - %0 = arith.constant 1 : i9 - // expected-error @+1 {{'MidLFHE.add_glwe_int' op should have the width of `b` equals or less than 'p'+1}} - %1 = "MidLFHE.add_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i9) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_add_glwe_int.mlir b/compiler/tests/Dialect/MidLFHE/op_add_glwe_int.mlir deleted file mode 100644 index a94087b16..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_add_glwe_int.mlir +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> -func @add_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "MidLFHE.add_glwe_int"(%arg0, %[[V1]]) : (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> !MidLFHE.glwe<{1024,12,64}{7}> - // CHECK-NEXT: return %[[V2]] : !MidLFHE.glwe<{1024,12,64}{7}> - - %0 = arith.constant 1 : i8 - %1 = "MidLFHE.add_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir deleted file mode 100644 index cccfaa849..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.invalid.mlir +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// Bad dimension of the lookup table -func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<4xi2>) -> !MidLFHE.glwe<{512,10,64}{2}> { - // expected-error @+1 {{'MidLFHE.apply_lookup_table' op : `l_cst` (operand #2) inner dimension should have size 128(=2^7) to match `ct` (operand #1) elements bitwidth (7)}} - %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {glweDimension = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32, outputSizeKS = 600 : i32}: (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<4xi2>) -> (!MidLFHE.glwe<{512,10,64}{2}>) - return %1: !MidLFHE.glwe<{512,10,64}{2}> -} - diff --git a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir b/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir deleted file mode 100644 index 5fb888a52..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_apply_lookup_table.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<128xi64>) -> !MidLFHE.glwe<{512,10,64}{2}> -func @apply_lookup_table(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<128xi64>) -> !MidLFHE.glwe<{512,10,64}{2}> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -83 : i32, baseLogKS = -82 : i32, glweDimension = 1 : i32, levelBS = 3 : i32, levelKS = 2 : i32, outputSizeKS = 600 : i32, polynomialSize = 1024 : i32} : (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<128xi64>) -> !MidLFHE.glwe<{512,10,64}{2}> - // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{512,10,64}{2}> - - %1 = "MidLFHE.apply_lookup_table"(%arg0, %arg1) {glweDimension = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32, outputSizeKS = 600 : i32} : (!MidLFHE.glwe<{1024,12,64}{7}>, tensor<128xi64>) -> (!MidLFHE.glwe<{512,10,64}{2}>) - return %1: !MidLFHE.glwe<{512,10,64}{2}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_mul_glwe_int.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_mul_glwe_int.invalid.mlir deleted file mode 100644 index aacf4e35e..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_mul_glwe_int.invalid.mlir +++ /dev/null @@ -1,39 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// GLWE p parameter -func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{6}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.mul_glwe_int' op should have the same GLWE 'p' parameter}} - %1 = "MidLFHE.mul_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,12,64}{6}>) - return %1: !MidLFHE.glwe<{1024,12,64}{6}> -} - -// ----- - -// GLWE dimension parameter -func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{512,12,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.mul_glwe_int' op should have the same GLWE 'dimension' parameter}} - %1 = "MidLFHE.mul_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{512,12,64}{7}>) - return %1: !MidLFHE.glwe<{512,12,64}{7}> -} - -// ----- - -// GLWE polynomialSize parameter -func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.mul_glwe_int' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.mul_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - -// ----- - -// integer width doesn't match GLWE parameter -func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - %0 = arith.constant 1 : i9 - // expected-error @+1 {{'MidLFHE.mul_glwe_int' op should have the width of `b` equals or less than 'p'+1}} - %1 = "MidLFHE.mul_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i9) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_mul_glwe_int.mlir b/compiler/tests/Dialect/MidLFHE/op_mul_glwe_int.mlir deleted file mode 100644 index 78b7494e1..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_mul_glwe_int.mlir +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> -func @mul_glwe_int(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "MidLFHE.mul_glwe_int"(%arg0, %[[V1]]) : (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> !MidLFHE.glwe<{1024,12,64}{7}> - // CHECK-NEXT: return %[[V2]] : !MidLFHE.glwe<{1024,12,64}{7}> - - %0 = arith.constant 1 : i8 - %1 = "MidLFHE.mul_glwe_int"(%arg0, %0): (!MidLFHE.glwe<{1024,12,64}{7}>, i8) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_neg_glwe.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_neg_glwe.invalid.mlir deleted file mode 100644 index e9339ada2..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_neg_glwe.invalid.mlir +++ /dev/null @@ -1,36 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// GLWE p parameter -func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{6}> { - // expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'p' parameter}} - %1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{6}>) - return %1: !MidLFHE.glwe<{1024,12,64}{6}> -} - -// ----- - -// GLWE dimension parameter -func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{512,12,64}{7}> { - // expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'dimension' parameter}} - %1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{512,12,64}{7}>) - return %1: !MidLFHE.glwe<{512,12,64}{7}> -} - -// ----- - -// GLWE polynomialSize parameter -func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - // expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - -// ----- - -// integer width doesn't match GLWE parameter -func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - // expected-error @+1 {{'MidLFHE.neg_glwe' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - diff --git a/compiler/tests/Dialect/MidLFHE/op_neg_glwe.mlir b/compiler/tests/Dialect/MidLFHE/op_neg_glwe.mlir deleted file mode 100644 index f8b5c0f86..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_neg_glwe.mlir +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> -func @neg_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = "MidLFHE.neg_glwe"(%arg0) : (!MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> - // CHECK-NEXT: return %[[V1]] : !MidLFHE.glwe<{1024,12,64}{7}> - - %1 = "MidLFHE.neg_glwe"(%arg0): (!MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/op_sub_int_glwe.invalid.mlir b/compiler/tests/Dialect/MidLFHE/op_sub_int_glwe.invalid.mlir deleted file mode 100644 index 003f3dfcd..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_sub_int_glwe.invalid.mlir +++ /dev/null @@ -1,40 +0,0 @@ -// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s - -// GLWE p parameter -func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{6}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.sub_int_glwe' op should have the same GLWE 'p' parameter}} - %1 = "MidLFHE.sub_int_glwe"(%0, %arg0): (i8, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{6}>) - return %1: !MidLFHE.glwe<{1024,12,64}{6}> -} - -// ----- - -// GLWE dimension parameter -func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{512,12,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.sub_int_glwe' op should have the same GLWE 'dimension' parameter}} - %1 = "MidLFHE.sub_int_glwe"(%0, %arg0): (i8, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{512,12,64}{7}>) - return %1: !MidLFHE.glwe<{512,12,64}{7}> -} - -// ----- - -// GLWE polynomialSize parameter -func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.sub_int_glwe' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.sub_int_glwe"(%0, %arg0): (i8, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - -// ----- - -// integer width doesn't match GLWE parameter -func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,11,64}{7}> { - %0 = arith.constant 1 : i8 - // expected-error @+1 {{'MidLFHE.sub_int_glwe' op should have the same GLWE 'polynomialSize' parameter}} - %1 = "MidLFHE.sub_int_glwe"(%0, %arg0): (i8, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,11,64}{7}>) - return %1: !MidLFHE.glwe<{1024,11,64}{7}> -} - diff --git a/compiler/tests/Dialect/MidLFHE/op_sub_int_glwe.mlir b/compiler/tests/Dialect/MidLFHE/op_sub_int_glwe.mlir deleted file mode 100644 index 068da9c23..000000000 --- a/compiler/tests/Dialect/MidLFHE/op_sub_int_glwe.mlir +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s - -// CHECK-LABEL: func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> -func @sub_int_glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 - // CHECK-NEXT: %[[V2:.*]] = "MidLFHE.sub_int_glwe"(%[[V1]], %arg0) : (i8, !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> - // CHECK-NEXT: return %[[V2]] : !MidLFHE.glwe<{1024,12,64}{7}> - - %0 = arith.constant 1 : i8 - %1 = "MidLFHE.sub_int_glwe"(%0, %arg0): (i8, !MidLFHE.glwe<{1024,12,64}{7}>) -> (!MidLFHE.glwe<{1024,12,64}{7}>) - return %1: !MidLFHE.glwe<{1024,12,64}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/types_glwe.mlir b/compiler/tests/Dialect/MidLFHE/types_glwe.mlir deleted file mode 100644 index 5d64f23e7..000000000 --- a/compiler/tests/Dialect/MidLFHE/types_glwe.mlir +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: concretecompiler %s --action=roundtrip 2>&1| FileCheck %s - -// CHECK-LABEL: func @glwe_0(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> -func @glwe_0(%arg0: !MidLFHE.glwe<{1024,12,64}{7}>) -> !MidLFHE.glwe<{1024,12,64}{7}> { - // CHECK-LABEL: return %arg0 : !MidLFHE.glwe<{1024,12,64}{7}> - return %arg0: !MidLFHE.glwe<{1024,12,64}{7}> -} - -// CHECK-LABEL: func @glwe_1(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> -func @glwe_1(%arg0: !MidLFHE.glwe<{_,_,_}{7}>) -> !MidLFHE.glwe<{_,_,_}{7}> { - // CHECK-LABEL: return %arg0 : !MidLFHE.glwe<{_,_,_}{7}> - return %arg0: !MidLFHE.glwe<{_,_,_}{7}> -} diff --git a/compiler/tests/Dialect/MidLFHE/Output/ops.mlir.script b/compiler/tests/Dialect/TFHE/TFHE/Output/ops.mlir.script similarity index 100% rename from compiler/tests/Dialect/MidLFHE/Output/ops.mlir.script rename to compiler/tests/Dialect/TFHE/TFHE/Output/ops.mlir.script diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe.invalid.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe.invalid.mlir new file mode 100644 index 000000000..3b249a640 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe.invalid.mlir @@ -0,0 +1,54 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// GLWE p parameter result +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{6}> { + // expected-error @+1 {{'TFHE.add_glwe' op should have the same GLWE 'p' parameter}} + %1 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{6}>) + return %1: !TFHE.glwe<{1024,12,64}{6}> +} + +// ----- + +// GLWE p parameter inputs +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,12,64}{6}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // expected-error @+1 {{'TFHE.add_glwe' op should have the same GLWE 'p' parameter}} + %1 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,12,64}{6}>) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} + +// ----- + +// GLWE dimension parameter result +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{512,12,64}{7}> { + // expected-error @+1 {{'TFHE.add_glwe' op should have the same GLWE 'dimension' parameter}} + %1 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{512,12,64}{7}>) + return %1: !TFHE.glwe<{512,12,64}{7}> +} + +// ----- + +// GLWE dimension parameter inputs +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{512,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // expected-error @+1 {{'TFHE.add_glwe' op should have the same GLWE 'dimension' parameter}} + %1 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{512,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} + +// ----- + +// GLWE polynomialSize parameter result +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + // expected-error @+1 {{'TFHE.add_glwe' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + +// ----- + +// GLWE polynomialSize parameter inputs +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,11,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // expected-error @+1 {{'TFHE.add_glwe' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,11,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} + diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe.mlir new file mode 100644 index 000000000..77c6b398a --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> +func @add_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = "TFHE.add_glwe"(%arg0, %arg1) : (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> + // CHECK-NEXT: return %[[V1]] : !TFHE.glwe<{1024,12,64}{7}> + + %0 = "TFHE.add_glwe"(%arg0, %arg1): (!TFHE.glwe<{1024,12,64}{7}>, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %0: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe_int.invalid.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe_int.invalid.mlir new file mode 100644 index 000000000..ebf85fdeb --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe_int.invalid.mlir @@ -0,0 +1,39 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// GLWE p parameter +func @add_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{6}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.add_glwe_int' op should have the same GLWE 'p' parameter}} + %1 = "TFHE.add_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{1024,12,64}{6}>) + return %1: !TFHE.glwe<{1024,12,64}{6}> +} + +// ----- + +// GLWE dimension parameter +func @add_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{512,12,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.add_glwe_int' op should have the same GLWE 'dimension' parameter}} + %1 = "TFHE.add_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{512,12,64}{7}>) + return %1: !TFHE.glwe<{512,12,64}{7}> +} + +// ----- + +// GLWE polynomialSize parameter +func @add_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.add_glwe_int' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.add_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + +// ----- + +// integer width doesn't match GLWE parameter +func @add_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + %0 = arith.constant 1 : i9 + // expected-error @+1 {{'TFHE.add_glwe_int' op should have the width of `b` equals or less than 'p'+1}} + %1 = "TFHE.add_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i9) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe_int.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe_int.mlir new file mode 100644 index 000000000..b73a51d7a --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_add_glwe_int.mlir @@ -0,0 +1,12 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @add_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> +func @add_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "TFHE.add_glwe_int"(%arg0, %[[V1]]) : (!TFHE.glwe<{1024,12,64}{7}>, i8) -> !TFHE.glwe<{1024,12,64}{7}> + // CHECK-NEXT: return %[[V2]] : !TFHE.glwe<{1024,12,64}{7}> + + %0 = arith.constant 1 : i8 + %1 = "TFHE.add_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_apply_lookup_table.invalid.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_apply_lookup_table.invalid.mlir new file mode 100644 index 000000000..99ffc022b --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_apply_lookup_table.invalid.mlir @@ -0,0 +1,9 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// Bad dimension of the lookup table +func @apply_lookup_table(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<4xi2>) -> !TFHE.glwe<{512,10,64}{2}> { + // expected-error @+1 {{'TFHE.apply_lookup_table' op : `l_cst` (operand #2) inner dimension should have size 128(=2^7) to match `ct` (operand #1) elements bitwidth (7)}} + %1 = "TFHE.apply_lookup_table"(%arg0, %arg1) {glweDimension = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32, outputSizeKS = 600 : i32}: (!TFHE.glwe<{1024,12,64}{7}>, tensor<4xi2>) -> (!TFHE.glwe<{512,10,64}{2}>) + return %1: !TFHE.glwe<{512,10,64}{2}> +} + diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_apply_lookup_table.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_apply_lookup_table.mlir new file mode 100644 index 000000000..46fba3264 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_apply_lookup_table.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @apply_lookup_table(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<128xi64>) -> !TFHE.glwe<{512,10,64}{2}> +func @apply_lookup_table(%arg0: !TFHE.glwe<{1024,12,64}{7}>, %arg1: tensor<128xi64>) -> !TFHE.glwe<{512,10,64}{2}> { + // CHECK-NEXT: %[[V1:.*]] = "TFHE.apply_lookup_table"(%arg0, %arg1) {baseLogBS = -83 : i32, baseLogKS = -82 : i32, glweDimension = 1 : i32, levelBS = 3 : i32, levelKS = 2 : i32, outputSizeKS = 600 : i32, polynomialSize = 1024 : i32} : (!TFHE.glwe<{1024,12,64}{7}>, tensor<128xi64>) -> !TFHE.glwe<{512,10,64}{2}> + // CHECK-NEXT: return %[[V1]] : !TFHE.glwe<{512,10,64}{2}> + + %1 = "TFHE.apply_lookup_table"(%arg0, %arg1) {glweDimension = 1 : i32, polynomialSize = 1024 : i32, levelKS = 2 : i32, baseLogKS = -82 : i32, levelBS = 3 : i32, baseLogBS = -83 : i32, outputSizeKS = 600 : i32} : (!TFHE.glwe<{1024,12,64}{7}>, tensor<128xi64>) -> (!TFHE.glwe<{512,10,64}{2}>) + return %1: !TFHE.glwe<{512,10,64}{2}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_mul_glwe_int.invalid.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_mul_glwe_int.invalid.mlir new file mode 100644 index 000000000..bfcd29f71 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_mul_glwe_int.invalid.mlir @@ -0,0 +1,39 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// GLWE p parameter +func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{6}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.mul_glwe_int' op should have the same GLWE 'p' parameter}} + %1 = "TFHE.mul_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{1024,12,64}{6}>) + return %1: !TFHE.glwe<{1024,12,64}{6}> +} + +// ----- + +// GLWE dimension parameter +func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{512,12,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.mul_glwe_int' op should have the same GLWE 'dimension' parameter}} + %1 = "TFHE.mul_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{512,12,64}{7}>) + return %1: !TFHE.glwe<{512,12,64}{7}> +} + +// ----- + +// GLWE polynomialSize parameter +func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.mul_glwe_int' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.mul_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + +// ----- + +// integer width doesn't match GLWE parameter +func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + %0 = arith.constant 1 : i9 + // expected-error @+1 {{'TFHE.mul_glwe_int' op should have the width of `b` equals or less than 'p'+1}} + %1 = "TFHE.mul_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i9) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_mul_glwe_int.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_mul_glwe_int.mlir new file mode 100644 index 000000000..70af889de --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_mul_glwe_int.mlir @@ -0,0 +1,12 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> +func @mul_glwe_int(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "TFHE.mul_glwe_int"(%arg0, %[[V1]]) : (!TFHE.glwe<{1024,12,64}{7}>, i8) -> !TFHE.glwe<{1024,12,64}{7}> + // CHECK-NEXT: return %[[V2]] : !TFHE.glwe<{1024,12,64}{7}> + + %0 = arith.constant 1 : i8 + %1 = "TFHE.mul_glwe_int"(%arg0, %0): (!TFHE.glwe<{1024,12,64}{7}>, i8) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_neg_glwe.invalid.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_neg_glwe.invalid.mlir new file mode 100644 index 000000000..d04a9d159 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_neg_glwe.invalid.mlir @@ -0,0 +1,36 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// GLWE p parameter +func @neg_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{6}> { + // expected-error @+1 {{'TFHE.neg_glwe' op should have the same GLWE 'p' parameter}} + %1 = "TFHE.neg_glwe"(%arg0): (!TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{6}>) + return %1: !TFHE.glwe<{1024,12,64}{6}> +} + +// ----- + +// GLWE dimension parameter +func @neg_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{512,12,64}{7}> { + // expected-error @+1 {{'TFHE.neg_glwe' op should have the same GLWE 'dimension' parameter}} + %1 = "TFHE.neg_glwe"(%arg0): (!TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{512,12,64}{7}>) + return %1: !TFHE.glwe<{512,12,64}{7}> +} + +// ----- + +// GLWE polynomialSize parameter +func @neg_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + // expected-error @+1 {{'TFHE.neg_glwe' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.neg_glwe"(%arg0): (!TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + +// ----- + +// integer width doesn't match GLWE parameter +func @neg_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + // expected-error @+1 {{'TFHE.neg_glwe' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.neg_glwe"(%arg0): (!TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_neg_glwe.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_neg_glwe.mlir new file mode 100644 index 000000000..2c43da700 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_neg_glwe.mlir @@ -0,0 +1,10 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @neg_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> +func @neg_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = "TFHE.neg_glwe"(%arg0) : (!TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> + // CHECK-NEXT: return %[[V1]] : !TFHE.glwe<{1024,12,64}{7}> + + %1 = "TFHE.neg_glwe"(%arg0): (!TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_sub_int_glwe.invalid.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_sub_int_glwe.invalid.mlir new file mode 100644 index 000000000..2f671bc3a --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_sub_int_glwe.invalid.mlir @@ -0,0 +1,40 @@ +// RUN: concretecompiler --split-input-file --verify-diagnostics --action=roundtrip %s + +// GLWE p parameter +func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{6}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.sub_int_glwe' op should have the same GLWE 'p' parameter}} + %1 = "TFHE.sub_int_glwe"(%0, %arg0): (i8, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{6}>) + return %1: !TFHE.glwe<{1024,12,64}{6}> +} + +// ----- + +// GLWE dimension parameter +func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{512,12,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.sub_int_glwe' op should have the same GLWE 'dimension' parameter}} + %1 = "TFHE.sub_int_glwe"(%0, %arg0): (i8, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{512,12,64}{7}>) + return %1: !TFHE.glwe<{512,12,64}{7}> +} + +// ----- + +// GLWE polynomialSize parameter +func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.sub_int_glwe' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.sub_int_glwe"(%0, %arg0): (i8, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + +// ----- + +// integer width doesn't match GLWE parameter +func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,11,64}{7}> { + %0 = arith.constant 1 : i8 + // expected-error @+1 {{'TFHE.sub_int_glwe' op should have the same GLWE 'polynomialSize' parameter}} + %1 = "TFHE.sub_int_glwe"(%0, %arg0): (i8, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,11,64}{7}>) + return %1: !TFHE.glwe<{1024,11,64}{7}> +} + diff --git a/compiler/tests/Dialect/TFHE/TFHE/op_sub_int_glwe.mlir b/compiler/tests/Dialect/TFHE/TFHE/op_sub_int_glwe.mlir new file mode 100644 index 000000000..1a1ba1b56 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/op_sub_int_glwe.mlir @@ -0,0 +1,12 @@ +// RUN: concretecompiler --action=roundtrip %s 2>&1| FileCheck %s + +// CHECK-LABEL: func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> +func @sub_int_glwe(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // CHECK-NEXT: %[[V1:.*]] = arith.constant 1 : i8 + // CHECK-NEXT: %[[V2:.*]] = "TFHE.sub_int_glwe"(%[[V1]], %arg0) : (i8, !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> + // CHECK-NEXT: return %[[V2]] : !TFHE.glwe<{1024,12,64}{7}> + + %0 = arith.constant 1 : i8 + %1 = "TFHE.sub_int_glwe"(%0, %arg0): (i8, !TFHE.glwe<{1024,12,64}{7}>) -> (!TFHE.glwe<{1024,12,64}{7}>) + return %1: !TFHE.glwe<{1024,12,64}{7}> +} diff --git a/compiler/tests/Dialect/TFHE/TFHE/types_glwe.mlir b/compiler/tests/Dialect/TFHE/TFHE/types_glwe.mlir new file mode 100644 index 000000000..7c0e540c0 --- /dev/null +++ b/compiler/tests/Dialect/TFHE/TFHE/types_glwe.mlir @@ -0,0 +1,13 @@ +// RUN: concretecompiler %s --action=roundtrip 2>&1| FileCheck %s + +// CHECK-LABEL: func @glwe_0(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> +func @glwe_0(%arg0: !TFHE.glwe<{1024,12,64}{7}>) -> !TFHE.glwe<{1024,12,64}{7}> { + // CHECK-LABEL: return %arg0 : !TFHE.glwe<{1024,12,64}{7}> + return %arg0: !TFHE.glwe<{1024,12,64}{7}> +} + +// CHECK-LABEL: func @glwe_1(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> +func @glwe_1(%arg0: !TFHE.glwe<{_,_,_}{7}>) -> !TFHE.glwe<{_,_,_}{7}> { + // CHECK-LABEL: return %arg0 : !TFHE.glwe<{_,_,_}{7}> + return %arg0: !TFHE.glwe<{_,_,_}{7}> +} diff --git a/compiler/tests/python/test_compiler_engine.py b/compiler/tests/python/test_compiler_engine.py index 869579619..530d331e7 100644 --- a/compiler/tests/python/test_compiler_engine.py +++ b/compiler/tests/python/test_compiler_engine.py @@ -12,9 +12,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') [ pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (5, 7), @@ -23,9 +23,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (np.array(4, dtype=np.uint8), np.array(5, dtype=np.uint8)), @@ -34,9 +34,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (np.uint8(3), np.uint8(5)), @@ -45,9 +45,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (np.uint16(3), np.uint16(5)), @@ -56,9 +56,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (np.uint32(3), np.uint32(5)), @@ -67,9 +67,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (np.uint64(3), np.uint64(5)), @@ -78,11 +78,11 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: tensor<4x!HLFHE.eint<7>>, %arg1: tensor<4xi8>) -> !HLFHE.eint<7> + func @main(%arg0: tensor<4x!FHE.eint<7>>, %arg1: tensor<4xi8>) -> !FHE.eint<7> { - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7> - return %ret : !HLFHE.eint<7> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<7>>, tensor<4xi8>) -> !FHE.eint<7> + return %ret : !FHE.eint<7> } """, ( @@ -94,11 +94,11 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: tensor<4x!HLFHE.eint<7>>, %arg1: tensor<4xi8>) -> !HLFHE.eint<7> + func @main(%arg0: tensor<4x!FHE.eint<7>>, %arg1: tensor<4xi8>) -> !FHE.eint<7> { - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7> - return %ret : !HLFHE.eint<7> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<7>>, tensor<4xi8>) -> !FHE.eint<7> + return %ret : !FHE.eint<7> } """, ( @@ -110,11 +110,11 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: tensor<4x!HLFHE.eint<7>>, %arg1: tensor<4xi8>) -> !HLFHE.eint<7> + func @main(%arg0: tensor<4x!FHE.eint<7>>, %arg1: tensor<4xi8>) -> !FHE.eint<7> { - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7> - return %ret : !HLFHE.eint<7> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<7>>, tensor<4xi8>) -> !FHE.eint<7> + return %ret : !FHE.eint<7> } """, ( @@ -126,11 +126,11 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%arg0: tensor<4x!HLFHE.eint<7>>, %arg1: tensor<4xi8>) -> !HLFHE.eint<7> + func @main(%arg0: tensor<4x!FHE.eint<7>>, %arg1: tensor<4xi8>) -> !FHE.eint<7> { - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7> - return %ret : !HLFHE.eint<7> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<7>>, tensor<4xi8>) -> !FHE.eint<7> + return %ret : !FHE.eint<7> } """, ( @@ -142,9 +142,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%a0: tensor<4x!HLFHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<6>>, tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> - return %res : tensor<4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x!FHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!FHE.eint<6>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<6>>, tensor<4xi7>) -> tensor<4x!FHE.eint<6>> + return %res : tensor<4x!FHE.eint<6>> } """, ( @@ -156,9 +156,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%a0: tensor<4x4x!HLFHE.eint<6>>, %a1: tensor<4x4xi7>) -> tensor<4x4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x4x!HLFHE.eint<6>>, tensor<4x4xi7>) -> tensor<4x4x!HLFHE.eint<6>> - return %res : tensor<4x4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x4x!FHE.eint<6>>, %a1: tensor<4x4xi7>) -> tensor<4x4x!FHE.eint<6>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x4x!FHE.eint<6>>, tensor<4x4xi7>) -> tensor<4x4x!FHE.eint<6>> + return %res : tensor<4x4x!FHE.eint<6>> } """, ( @@ -184,9 +184,9 @@ KEY_SET_CACHE_PATH = os.path.join(tempfile.gettempdir(), 'KeySetCache') ), pytest.param( """ - func @main(%a0: tensor<2x2x2x!HLFHE.eint<6>>, %a1: tensor<2x2x2xi7>) -> tensor<2x2x2x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x2x!HLFHE.eint<6>>, tensor<2x2x2xi7>) -> tensor<2x2x2x!HLFHE.eint<6>> - return %res : tensor<2x2x2x!HLFHE.eint<6>> + func @main(%a0: tensor<2x2x2x!FHE.eint<6>>, %a1: tensor<2x2x2xi7>) -> tensor<2x2x2x!FHE.eint<6>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x2x!FHE.eint<6>>, tensor<2x2x2xi7>) -> tensor<2x2x2x!FHE.eint<6>> + return %res : tensor<2x2x2x!FHE.eint<6>> } """, ( @@ -222,9 +222,9 @@ def test_compile_and_run(mlir_input, args, expected_result): [ pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>, %arg1: i8) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint_int"(%arg0, %arg1): (!HLFHE.eint<7>, i8) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + func @main(%arg0: !FHE.eint<7>, %arg1: i8) -> !FHE.eint<7> { + %1 = "FHE.add_eint_int"(%arg0, %arg1): (!FHE.eint<7>, i8) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (5, 7, 8), @@ -244,10 +244,10 @@ def test_compile_and_run_invalid_arg_number(mlir_input, args): [ pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { + func @main(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { %tlu = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]> : tensor<128xi64> - %1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<7>, tensor<128xi64>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + %1 = "FHE.apply_lookup_table"(%arg0, %tlu): (!FHE.eint<7>, tensor<128xi64>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, (73,), @@ -268,11 +268,11 @@ def test_compile_and_run_tlu(mlir_input, args, expected_result, tab_size): [ pytest.param( """ - func @test(%arg0: tensor<4x!HLFHE.eint<7>>, %arg1: tensor<4xi8>) -> !HLFHE.eint<7> + func @test(%arg0: tensor<4x!FHE.eint<7>>, %arg1: tensor<4xi8>) -> !FHE.eint<7> { - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7> - return %ret : !HLFHE.eint<7> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<7>>, tensor<4xi8>) -> !FHE.eint<7> + return %ret : !FHE.eint<7> } """, id="not @main", diff --git a/compiler/tests/python/test_hlfhe_dialect.py b/compiler/tests/python/test_fhe_dialect.py similarity index 73% rename from compiler/tests/python/test_hlfhe_dialect.py rename to compiler/tests/python/test_fhe_dialect.py index 86bdc5bfa..ab7c21d48 100644 --- a/compiler/tests/python/test_hlfhe_dialect.py +++ b/compiler/tests/python/test_fhe_dialect.py @@ -1,25 +1,25 @@ import pytest from mlir.ir import Context, RankedTensorType, Location from concrete.lang import register_dialects -from concrete.lang.dialects import hlfhe +from concrete.lang.dialects import fhe @pytest.mark.parametrize("width", list(range(1, 8))) def test_eint(width): ctx = Context() register_dialects(ctx) - eint = hlfhe.EncryptedIntegerType.get(ctx, width) - assert eint.__str__() == f"!HLFHE.eint<{width}>" + eint = fhe.EncryptedIntegerType.get(ctx, width) + assert eint.__str__() == f"!FHE.eint<{width}>" @pytest.mark.parametrize("shape", [(1,), (2,), (1, 1), (1, 2), (2, 1), (3, 3, 3)]) def test_eint_tensor(shape): with Context() as ctx, Location.unknown(context=ctx): register_dialects(ctx) - eint = hlfhe.EncryptedIntegerType.get(ctx, 3) + eint = fhe.EncryptedIntegerType.get(ctx, 3) tensor = RankedTensorType.get(shape, eint) assert ( - tensor.__str__() == f"tensor<{'x'.join(map(str, shape))}x!HLFHE.eint<{3}>>" + tensor.__str__() == f"tensor<{'x'.join(map(str, shape))}x!FHE.eint<{3}>>" ) @@ -28,4 +28,4 @@ def test_invalid_eint(width): ctx = Context() register_dialects(ctx) with pytest.raises(ValueError, match=r"can't create eint with the given width"): - eint = hlfhe.EncryptedIntegerType.get(ctx, width) + eint = fhe.EncryptedIntegerType.get(ctx, width) diff --git a/compiler/tests/python/test_round_trip.py b/compiler/tests/python/test_round_trip.py index 761b7b8ff..d9e534006 100644 --- a/compiler/tests/python/test_round_trip.py +++ b/compiler/tests/python/test_round_trip.py @@ -5,50 +5,50 @@ from concrete import compiler VALID_INPUTS = [ pytest.param( """ - func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> { + func @add_eint_int(%arg0: !FHE.eint<2>) -> !FHE.eint<2> { %0 = arith.constant 1 : i3 - %1 = "HLFHE.add_eint_int"(%arg0, %0): (!HLFHE.eint<2>, i3) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> + %1 = "FHE.add_eint_int"(%arg0, %0): (!FHE.eint<2>, i3) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> } """, id="add_eint_int_cst", ), pytest.param( """ - func @apply_lookup_table(%arg0: !HLFHE.eint<2>, %arg1: tensor<4xi64>) -> !HLFHE.eint<2> { - %1 = "HLFHE.apply_lookup_table"(%arg0, %arg1): (!HLFHE.eint<2>, tensor<4xi64>) -> (!HLFHE.eint<2>) - return %1: !HLFHE.eint<2> + func @apply_lookup_table(%arg0: !FHE.eint<2>, %arg1: tensor<4xi64>) -> !FHE.eint<2> { + %1 = "FHE.apply_lookup_table"(%arg0, %arg1): (!FHE.eint<2>, tensor<4xi64>) -> (!FHE.eint<2>) + return %1: !FHE.eint<2> } """, id="add_eint_int_cst", ), pytest.param( """ - func @dot_eint_int(%arg0: tensor<2x!HLFHE.eint<2>>, - %arg1: tensor<2xi3>) -> !HLFHE.eint<2> + func @dot_eint_int(%arg0: tensor<2x!FHE.eint<2>>, + %arg1: tensor<2xi3>) -> !FHE.eint<2> { - %1 = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<2x!HLFHE.eint<2>>, tensor<2xi3>) -> !HLFHE.eint<2> - return %1 : !HLFHE.eint<2> + %1 = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<2x!FHE.eint<2>>, tensor<2xi3>) -> !FHE.eint<2> + return %1 : !FHE.eint<2> } """, id="add_eint_int_cst", ), pytest.param( """ - func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { + func @main(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { %tlu = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]> : tensor<128xi64> - %1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<7>, tensor<128xi64>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> + %1 = "FHE.apply_lookup_table"(%arg0, %tlu): (!FHE.eint<7>, tensor<128xi64>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } """, id="add_eint_int_cst", ), pytest.param( """ - func @main(%a0: tensor<4x!HLFHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<2>>, tensor<4xi3>) -> tensor<4x!HLFHE.eint<2>> - return %1: tensor<4x!HLFHE.eint<2>> + func @main(%a0: tensor<4x!FHE.eint<2>>, %a1: tensor<4xi3>) -> tensor<4x!FHE.eint<2>> { + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<2>>, tensor<4xi3>) -> tensor<4x!FHE.eint<2>> + return %1: tensor<4x!FHE.eint<2>> } """, id="add_eint_int_1D", @@ -59,7 +59,7 @@ INVALID_INPUTS = [ pytest.param("nothing really mlir", id="english sentence"), pytest.param( """ - func @test(%arg0: !HLFHE.eint<0>) { + func @test(%arg0: !FHE.eint<0>) { return } """, @@ -67,10 +67,10 @@ INVALID_INPUTS = [ ), pytest.param( """ - func @main(%a0: tensor<2x2x3x4x!HLFHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> { - // expected-error @+1 {{'HLFHELinalg.add_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} - %1 = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!HLFHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!HLFHE.eint<2>> - return %1 : tensor<2x2x3x4x!HLFHE.eint<2>> + func @main(%a0: tensor<2x2x3x4x!FHE.eint<2>>, %a1: tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!FHE.eint<2>> { + // expected-error @+1 {{'FHELinalg.add_eint_int' op has the dimension #2 of the operand #1 incompatible with other operands, got 2 expect 1 or 3}} + %1 = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<2x2x3x4x!FHE.eint<2>>, tensor<2x2x2x4xi3>) -> tensor<2x2x3x4x!FHE.eint<2>> + return %1 : tensor<2x2x3x4x!FHE.eint<2>> } """, id="incompatible dimensions", diff --git a/compiler/tests/stress_tests/read_mlir.py b/compiler/tests/stress_tests/read_mlir.py index c29bafa64..196ded188 100644 --- a/compiler/tests/stress_tests/read_mlir.py +++ b/compiler/tests/stress_tests/read_mlir.py @@ -4,8 +4,8 @@ import re from stress_tests.utils import CONCRETECOMPILER, log2, ceil_log2, run -DUMP_HLFHE = '--action=dump-hlfhe' -DUMP_LOWLFHE = '--action=dump-lowlfhe' +DUMP_FHE = '--action=dump-fhe' +DUMP_CONCRETE = '--action=dump-concrete' def read_max_mlir_attribute(name, content): regexp = re.compile(f'{name} = (?P[0-9]+)') @@ -15,8 +15,8 @@ def read_max_mlir_attribute(name, content): ) def log_manp_max(path): - hlfhe = run(CONCRETECOMPILER, path, DUMP_HLFHE) - return ceil_log2(read_max_mlir_attribute('MANP', hlfhe)) + fhe = run(CONCRETECOMPILER, path, DUMP_FHE) + return ceil_log2(read_max_mlir_attribute('MANP', fhe)) @dataclass class FHEParams: @@ -24,8 +24,8 @@ class FHEParams: glwe_dim: int def v0_param(path): - lowlfhe = run(CONCRETECOMPILER, path, DUMP_LOWLFHE) + concrete = run(CONCRETECOMPILER, path, DUMP_CONCRETE) return FHEParams( - log_poly_size=log2(read_max_mlir_attribute('polynomialSize', lowlfhe)), - glwe_dim=read_max_mlir_attribute('glweDimension', lowlfhe), + log_poly_size=log2(read_max_mlir_attribute('polynomialSize', concrete)), + glwe_dim=read_max_mlir_attribute('glweDimension', concrete), ) diff --git a/compiler/tests/stress_tests/test_stress.py b/compiler/tests/stress_tests/test_stress.py index f99478135..011364fc2 100644 --- a/compiler/tests/stress_tests/test_stress.py +++ b/compiler/tests/stress_tests/test_stress.py @@ -74,7 +74,7 @@ def basic_multisum_identity(bitwidth, size): return ', '.join(f'%{name}{i}{ty_annot}' for i in range(size)) def tensor(size, ty): return f'tensor<{size}x{ty}>' - v_ty = f"!HLFHE.eint<{bitwidth}>" + v_ty = f"!FHE.eint<{bitwidth}>" tv_ty = tensor(size, v_ty) w_ty = f"i{bitwidth+1}" w_modulo = 2 ** bitwidth # to match v bitwidth @@ -102,8 +102,8 @@ func @main({components('v', size, v_ty)}) -> {v_ty} {{ )} %lut = tensor.from_elements {components('lut', lut_size)} : {tlut_ty} - %dot_product = "HLFHELinalg.dot_eint_int"(%v, %w) : ({tv_ty}, {tw_ty}) -> {v_ty} - %pbs_result = "HLFHE.apply_lookup_table"(%dot_product, %lut): ({v_ty}, {tlut_ty}) -> {v_ty} + %dot_product = "FHELinalg.dot_eint_int"(%v, %w) : ({tv_ty}, {tw_ty}) -> {v_ty} + %pbs_result = "FHE.apply_lookup_table"(%dot_product, %lut): ({v_ty}, {tlut_ty}) -> {v_ty} return %pbs_result: {v_ty} }} """ diff --git a/compiler/tests/unittest/CMakeLists.txt b/compiler/tests/unittest/CMakeLists.txt index 7f884a030..b592af8f1 100644 --- a/compiler/tests/unittest/CMakeLists.txt +++ b/compiler/tests/unittest/CMakeLists.txt @@ -33,8 +33,8 @@ add_executable( ) add_executable( - end_to_end_jit_hlfhelinalg - end_to_end_jit_hlfhelinalg.cc + end_to_end_jit_fhelinalg + end_to_end_jit_fhelinalg.cc globals.cc ) @@ -48,7 +48,7 @@ set_source_files_properties( end_to_end_jit_test.cc end_to_end_jit_clear_tensor.cc end_to_end_jit_encrypted_tensor.cc - end_to_end_jit_hlfhelinalg.cc + end_to_end_jit_fhelinalg.cc end_to_end_jit_lambda.cc PROPERTIES COMPILE_FLAGS "-fno-rtti" @@ -73,7 +73,7 @@ target_link_libraries( ) target_link_libraries( - end_to_end_jit_hlfhelinalg + end_to_end_jit_fhelinalg gtest_main ConcretelangSupport ) @@ -88,7 +88,7 @@ include(GoogleTest) gtest_discover_tests(end_to_end_jit_test) gtest_discover_tests(end_to_end_jit_clear_tensor) gtest_discover_tests(end_to_end_jit_encrypted_tensor) -gtest_discover_tests(end_to_end_jit_hlfhelinalg) +gtest_discover_tests(end_to_end_jit_fhelinalg) gtest_discover_tests(end_to_end_jit_lambda) if(CONCRETELANG_PARALLEL_EXECUTION_ENABLED) diff --git a/compiler/tests/unittest/end_to_end_jit_auto_parallelization.cc b/compiler/tests/unittest/end_to_end_jit_auto_parallelization.cc index cb4b75e4f..c471176e2 100644 --- a/compiler/tests/unittest/end_to_end_jit_auto_parallelization.cc +++ b/compiler/tests/unittest/end_to_end_jit_auto_parallelization.cc @@ -6,53 +6,53 @@ #include "end_to_end_jit_test.h" /////////////////////////////////////////////////////////////////////////////// -// Auto-parallelize independent HLFHE ops ///////////////////////////////////// +// Auto-parallelize independent FHE ops ///////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(ParallelizeAndRunHLFHE, add_eint_tree) { +TEST(ParallelizeAndRunFHE, add_eint_tree) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>, %arg2: !HLFHE.eint<7>, %arg3: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %2 = "HLFHE.add_eint"(%arg0, %arg2): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %3 = "HLFHE.add_eint"(%arg0, %arg3): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %4 = "HLFHE.add_eint"(%arg1, %arg2): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %5 = "HLFHE.add_eint"(%arg1, %arg3): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %6 = "HLFHE.add_eint"(%arg2, %arg3): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) +func @main(%arg0: !FHE.eint<7>, %arg1: !FHE.eint<7>, %arg2: !FHE.eint<7>, %arg3: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %2 = "FHE.add_eint"(%arg0, %arg2): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %3 = "FHE.add_eint"(%arg0, %arg3): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %4 = "FHE.add_eint"(%arg1, %arg2): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %5 = "FHE.add_eint"(%arg1, %arg3): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %6 = "FHE.add_eint"(%arg2, %arg3): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) - %7 = "HLFHE.add_eint"(%1, %2): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %8 = "HLFHE.add_eint"(%1, %3): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %9 = "HLFHE.add_eint"(%1, %4): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %10 = "HLFHE.add_eint"(%1, %5): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %11 = "HLFHE.add_eint"(%1, %6): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %12 = "HLFHE.add_eint"(%2, %3): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %13 = "HLFHE.add_eint"(%2, %4): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %14 = "HLFHE.add_eint"(%2, %5): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %15 = "HLFHE.add_eint"(%2, %6): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %16 = "HLFHE.add_eint"(%3, %4): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %17 = "HLFHE.add_eint"(%3, %5): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %18 = "HLFHE.add_eint"(%3, %6): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %19 = "HLFHE.add_eint"(%4, %5): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %20 = "HLFHE.add_eint"(%4, %6): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %21 = "HLFHE.add_eint"(%5, %6): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) + %7 = "FHE.add_eint"(%1, %2): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %8 = "FHE.add_eint"(%1, %3): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %9 = "FHE.add_eint"(%1, %4): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %10 = "FHE.add_eint"(%1, %5): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %11 = "FHE.add_eint"(%1, %6): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %12 = "FHE.add_eint"(%2, %3): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %13 = "FHE.add_eint"(%2, %4): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %14 = "FHE.add_eint"(%2, %5): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %15 = "FHE.add_eint"(%2, %6): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %16 = "FHE.add_eint"(%3, %4): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %17 = "FHE.add_eint"(%3, %5): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %18 = "FHE.add_eint"(%3, %6): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %19 = "FHE.add_eint"(%4, %5): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %20 = "FHE.add_eint"(%4, %6): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %21 = "FHE.add_eint"(%5, %6): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) - %22 = "HLFHE.add_eint"(%7, %8): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %23 = "HLFHE.add_eint"(%9, %10): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %24 = "HLFHE.add_eint"(%11, %12): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %25 = "HLFHE.add_eint"(%13, %14): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %26 = "HLFHE.add_eint"(%15, %16): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %27 = "HLFHE.add_eint"(%17, %18): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %28 = "HLFHE.add_eint"(%19, %20): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) + %22 = "FHE.add_eint"(%7, %8): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %23 = "FHE.add_eint"(%9, %10): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %24 = "FHE.add_eint"(%11, %12): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %25 = "FHE.add_eint"(%13, %14): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %26 = "FHE.add_eint"(%15, %16): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %27 = "FHE.add_eint"(%17, %18): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %28 = "FHE.add_eint"(%19, %20): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) - %29 = "HLFHE.add_eint"(%22, %23): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %30 = "HLFHE.add_eint"(%24, %25): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %31 = "HLFHE.add_eint"(%26, %27): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %32 = "HLFHE.add_eint"(%21, %28): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) + %29 = "FHE.add_eint"(%22, %23): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %30 = "FHE.add_eint"(%24, %25): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %31 = "FHE.add_eint"(%26, %27): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %32 = "FHE.add_eint"(%21, %28): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) - %33 = "HLFHE.add_eint"(%29, %30): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - %34 = "HLFHE.add_eint"(%31, %32): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) + %33 = "FHE.add_eint"(%29, %30): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + %34 = "FHE.add_eint"(%31, %32): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) - %35 = "HLFHE.add_eint"(%33, %34): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %35: !HLFHE.eint<7> + %35 = "FHE.add_eint"(%33, %34): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + return %35: !FHE.eint<7> } )XXX", "main", false, true); diff --git a/compiler/tests/unittest/end_to_end_jit_encrypted_tensor.cc b/compiler/tests/unittest/end_to_end_jit_encrypted_tensor.cc index 631a14199..a4f1eb1ba 100644 --- a/compiler/tests/unittest/end_to_end_jit_encrypted_tensor.cc +++ b/compiler/tests/unittest/end_to_end_jit_encrypted_tensor.cc @@ -19,8 +19,8 @@ const llvm::ArrayRef shape2D(dims, numDim); TEST(End2EndJit_EncryptedTensor_2D, identity) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<2x10x!HLFHE.eint<6>>) -> tensor<2x10x!HLFHE.eint<6>> { - return %t : tensor<2x10x!HLFHE.eint<6>> +func @main(%t: tensor<2x10x!FHE.eint<6>>) -> tensor<2x10x!FHE.eint<6>> { + return %t : tensor<2x10x!FHE.eint<6>> } )XXX"); @@ -42,10 +42,10 @@ func @main(%t: tensor<2x10x!HLFHE.eint<6>>) -> tensor<2x10x!HLFHE.eint<6>> { TEST(End2EndJit_EncryptedTensor_2D, extract) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<2x10x!HLFHE.eint<6>>, %i: index, %j: index) -> -!HLFHE.eint<6> { - %c = tensor.extract %t[%i, %j] : tensor<2x10x!HLFHE.eint<6>> - return %c : !HLFHE.eint<6> +func @main(%t: tensor<2x10x!FHE.eint<6>>, %i: index, %j: index) -> +!FHE.eint<6> { + %c = tensor.extract %t[%i, %j] : tensor<2x10x!FHE.eint<6>> + return %c : !FHE.eint<6> } )XXX"); @@ -64,9 +64,9 @@ func @main(%t: tensor<2x10x!HLFHE.eint<6>>, %i: index, %j: index) -> TEST(End2EndJit_EncryptedTensor_2D, extract_slice) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<2x10x!HLFHE.eint<6>>) -> tensor<1x5x!HLFHE.eint<6>> { - %r = tensor.extract_slice %t[1, 5][1, 5][1, 1] : tensor<2x10x!HLFHE.eint<6>> to tensor<1x5x!HLFHE.eint<6>> - return %r : tensor<1x5x!HLFHE.eint<6>> +func @main(%t: tensor<2x10x!FHE.eint<6>>) -> tensor<1x5x!FHE.eint<6>> { + %r = tensor.extract_slice %t[1, 5][1, 5][1, 1] : tensor<2x10x!FHE.eint<6>> to tensor<1x5x!FHE.eint<6>> + return %r : tensor<1x5x!FHE.eint<6>> } )XXX"); @@ -90,9 +90,9 @@ func @main(%t: tensor<2x10x!HLFHE.eint<6>>) -> tensor<1x5x!HLFHE.eint<6>> { TEST(End2EndJit_EncryptedTensor_2D, extract_slice_parametric_2x2) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<8x4x!HLFHE.eint<6>>, %y: index, %x: index) -> tensor<2x2x!HLFHE.eint<6>> { - %r = tensor.extract_slice %t[%y, %x][2, 2][1, 1] : tensor<8x4x!HLFHE.eint<6>> to tensor<2x2x!HLFHE.eint<6>> - return %r : tensor<2x2x!HLFHE.eint<6>> +func @main(%t: tensor<8x4x!FHE.eint<6>>, %y: index, %x: index) -> tensor<2x2x!FHE.eint<6>> { + %r = tensor.extract_slice %t[%y, %x][2, 2][1, 1] : tensor<8x4x!FHE.eint<6>> to tensor<2x2x!FHE.eint<6>> + return %r : tensor<2x2x!FHE.eint<6>> } )XXX"); const size_t rows = 8; @@ -130,9 +130,9 @@ TEST(End2EndJit_EncryptedTensor_4D, extract_slice_parametric_2x2x2x2) { constexpr int64_t dimSizes[4] = {8, 4, 5, 3}; mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<8x4x5x3x!HLFHE.eint<6>>, %d0: index, %d1: index, %d2: index, %d3: index) -> tensor<2x2x2x2x!HLFHE.eint<6>> { - %r = tensor.extract_slice %t[%d0, %d1, %d2, %d3][2, 2, 2, 2][1, 1, 1, 1] : tensor<8x4x5x3x!HLFHE.eint<6>> to tensor<2x2x2x2x!HLFHE.eint<6>> - return %r : tensor<2x2x2x2x!HLFHE.eint<6>> +func @main(%t: tensor<8x4x5x3x!FHE.eint<6>>, %d0: index, %d1: index, %d2: index, %d3: index) -> tensor<2x2x2x2x!FHE.eint<6>> { + %r = tensor.extract_slice %t[%d0, %d1, %d2, %d3][2, 2, 2, 2][1, 1, 1, 1] : tensor<8x4x5x3x!FHE.eint<6>> to tensor<2x2x2x2x!FHE.eint<6>> + return %r : tensor<2x2x2x2x!FHE.eint<6>> } )XXX"); uint8_t A[dimSizes[0]][dimSizes[1]][dimSizes[2]][dimSizes[3]]; @@ -193,9 +193,9 @@ func @main(%t: tensor<8x4x5x3x!HLFHE.eint<6>>, %d0: index, %d1: index, %d2: inde TEST(End2EndJit_EncryptedTensor_2D, extract_slice_stride) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<2x10x!HLFHE.eint<6>>) -> tensor<1x5x!HLFHE.eint<6>> { - %r = tensor.extract_slice %t[1, 0][1, 5][1, 2] : tensor<2x10x!HLFHE.eint<6>> to tensor<1x5x!HLFHE.eint<6>> - return %r : tensor<1x5x!HLFHE.eint<6>> +func @main(%t: tensor<2x10x!FHE.eint<6>>) -> tensor<1x5x!FHE.eint<6>> { + %r = tensor.extract_slice %t[1, 0][1, 5][1, 2] : tensor<2x10x!FHE.eint<6>> to tensor<1x5x!FHE.eint<6>> + return %r : tensor<1x5x!FHE.eint<6>> } )XXX"); @@ -220,10 +220,10 @@ func @main(%t: tensor<2x10x!HLFHE.eint<6>>) -> tensor<1x5x!HLFHE.eint<6>> { TEST(End2EndJit_EncryptedTensor_2D, insert_slice) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t0: tensor<2x10x!HLFHE.eint<6>>, %t1: tensor<2x2x!HLFHE.eint<6>>) --> tensor<2x10x!HLFHE.eint<6>> { - %r = tensor.insert_slice %t1 into %t0[0, 5][2, 2][1, 1] : tensor<2x2x!HLFHE.eint<6>> into tensor<2x10x!HLFHE.eint<6>> - return %r : tensor<2x10x!HLFHE.eint<6>> +func @main(%t0: tensor<2x10x!FHE.eint<6>>, %t1: tensor<2x2x!FHE.eint<6>>) +-> tensor<2x10x!FHE.eint<6>> { + %r = tensor.insert_slice %t1 into %t0[0, 5][2, 2][1, 1] : tensor<2x2x!FHE.eint<6>> into tensor<2x10x!FHE.eint<6>> + return %r : tensor<2x10x!FHE.eint<6>> } )XXX"); diff --git a/compiler/tests/unittest/end_to_end_jit_hlfhelinalg.cc b/compiler/tests/unittest/end_to_end_jit_fhelinalg.cc similarity index 78% rename from compiler/tests/unittest/end_to_end_jit_hlfhelinalg.cc rename to compiler/tests/unittest/end_to_end_jit_fhelinalg.cc index 5096b61f1..823ad047f 100644 --- a/compiler/tests/unittest/end_to_end_jit_hlfhelinalg.cc +++ b/compiler/tests/unittest/end_to_end_jit_fhelinalg.cc @@ -8,16 +8,16 @@ using tensorArgTy = Z::TensorLambdaArgument>; #define GET_2D(tensor, i, j, di, dj) (tensor)[i * dj + j] /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg add_eint_int//////////////////////////////////////////////////// +// FHELinalg add_eint_int//////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, add_eint_int_term_to_term) { +TEST(End2EndJit_FHELinalg, add_eint_int_term_to_term) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term addition of `%a0` with `%a1` - func @main(%a0: tensor<4x!HLFHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<6>>, tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> - return %res : tensor<4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x!FHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!FHE.eint<6>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<6>>, tensor<4xi7>) -> tensor<4x!FHE.eint<6>> + return %res : tensor<4x!FHE.eint<6>> } )XXX"); std::vector a0{31, 6, 12, 9}; @@ -43,13 +43,13 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_term_to_term) { } // Same as add_eint_int_term_to_term test above, but returning a lambda argument -TEST(End2EndJit_HLFHELinalg, add_eint_int_term_to_term_ret_lambda_argument) { +TEST(End2EndJit_FHELinalg, add_eint_int_term_to_term_ret_lambda_argument) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term addition of `%a0` with `%a1` - func @main(%a0: tensor<4x!HLFHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<6>>, tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> - return %res : tensor<4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x!FHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!FHE.eint<6>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<6>>, tensor<4xi7>) -> tensor<4x!FHE.eint<6>> + return %res : tensor<4x!FHE.eint<6>> } )XXX"); std::vector a0{31, 6, 12, 9}; @@ -84,14 +84,14 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_term_to_term_ret_lambda_argument) { // Same as add_eint_int_term_to_term_ret_lambda_argument, but returning a // multi-dimensional tensor -TEST(End2EndJit_HLFHELinalg, +TEST(End2EndJit_FHELinalg, add_eint_int_term_to_term_ret_lambda_argument_multi_dim) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term addition of `%a0` with `%a1` - func @main(%a0: tensor<4x2x3x!HLFHE.eint<6>>, %a1: tensor<4x2x3xi7>) -> tensor<4x2x3x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x2x3x!HLFHE.eint<6>>, tensor<4x2x3xi7>) -> tensor<4x2x3x!HLFHE.eint<6>> - return %res : tensor<4x2x3x!HLFHE.eint<6>> + func @main(%a0: tensor<4x2x3x!FHE.eint<6>>, %a1: tensor<4x2x3xi7>) -> tensor<4x2x3x!FHE.eint<6>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x2x3x!FHE.eint<6>>, tensor<4x2x3xi7>) -> tensor<4x2x3x!FHE.eint<6>> + return %res : tensor<4x2x3x!FHE.eint<6>> } )XXX"); std::vector a0{31, 6, 12, 9, 1, 2, 3, 4, 9, 0, 3, 2, @@ -128,13 +128,13 @@ TEST(End2EndJit_HLFHELinalg, } } -TEST(End2EndJit_HLFHELinalg, add_eint_int_term_to_term_broadcast) { +TEST(End2EndJit_FHELinalg, add_eint_int_term_to_term_broadcast) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term addition of `%a0` with `%a1` - func @main(%a0: tensor<4x1x4x!HLFHE.eint<5>>, %a1: tensor<1x4x4xi6>) -> tensor<4x4x4x!HLFHE.eint<5>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x1x4x!HLFHE.eint<5>>, tensor<1x4x4xi6>) -> tensor<4x4x4x!HLFHE.eint<5>> - return %res : tensor<4x4x4x!HLFHE.eint<5>> + func @main(%a0: tensor<4x1x4x!FHE.eint<5>>, %a1: tensor<1x4x4xi6>) -> tensor<4x4x4x!FHE.eint<5>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<4x1x4x!FHE.eint<5>>, tensor<1x4x4xi6>) -> tensor<4x4x4x!FHE.eint<5>> + return %res : tensor<4x4x4x!FHE.eint<5>> } )XXX"); uint8_t a0[4][1][4]{ @@ -177,7 +177,7 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_term_to_term_broadcast) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_column) { +TEST(End2EndJit_FHELinalg, add_eint_int_matrix_column) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the addition of a 3x3 matrix of encrypted integers and a 3x1 matrix (a column) of encrypted integers. @@ -187,9 +187,9 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_column) { // [7,8,9] [3] [10,11,12] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<3x1xi5>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<3x1xi5>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); uint8_t a0[3][3]{ @@ -224,7 +224,7 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_column) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_line) { +TEST(End2EndJit_FHELinalg, add_eint_int_matrix_line) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the addition of a 3x3 matrix of encrypted integers and a 1x3 matrix (a line) of encrypted integers. // @@ -233,9 +233,9 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_line) { // [7,8,9] [8,10,12] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<1x3xi5>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<1x3xi5>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -268,12 +268,12 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_line) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_line_missing_dim) { +TEST(End2EndJit_FHELinalg, add_eint_int_matrix_line_missing_dim) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Same behavior than the previous one, but as the dimension #2 of operand #2 is missing. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<3xi5>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3xi5>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<3xi5>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.add_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3xi5>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -307,16 +307,16 @@ TEST(End2EndJit_HLFHELinalg, add_eint_int_matrix_line_missing_dim) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg add_eint /////////////////////////////////////////////////////// +// FHELinalg add_eint /////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, add_eint_term_to_term) { +TEST(End2EndJit_FHELinalg, add_eint_term_to_term) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term addition of `%a0` with `%a1` - func @main(%a0: tensor<4x!HLFHE.eint<6>>, %a1: tensor<4x!HLFHE.eint<6>>) -> tensor<4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<4x!HLFHE.eint<6>>, tensor<4x!HLFHE.eint<6>>) -> tensor<4x!HLFHE.eint<6>> - return %res : tensor<4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x!FHE.eint<6>>, %a1: tensor<4x!FHE.eint<6>>) -> tensor<4x!FHE.eint<6>> { + %res = "FHELinalg.add_eint"(%a0, %a1) : (tensor<4x!FHE.eint<6>>, tensor<4x!FHE.eint<6>>) -> tensor<4x!FHE.eint<6>> + return %res : tensor<4x!FHE.eint<6>> } )XXX"); @@ -344,15 +344,15 @@ TEST(End2EndJit_HLFHELinalg, add_eint_term_to_term) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_term_to_term_broadcast) { +TEST(End2EndJit_FHELinalg, add_eint_term_to_term_broadcast) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term addition of `%a0` with `%a1` - func @main(%a0: tensor<4x1x4x!HLFHE.eint<5>>, %a1: - tensor<1x4x4x!HLFHE.eint<5>>) -> tensor<4x4x4x!HLFHE.eint<5>> { - %res = "HLFHELinalg.add_eint"(%a0, %a1) : - (tensor<4x1x4x!HLFHE.eint<5>>, tensor<1x4x4x!HLFHE.eint<5>>) -> - tensor<4x4x4x!HLFHE.eint<5>> return %res : tensor<4x4x4x!HLFHE.eint<5>> + func @main(%a0: tensor<4x1x4x!FHE.eint<5>>, %a1: + tensor<1x4x4x!FHE.eint<5>>) -> tensor<4x4x4x!FHE.eint<5>> { + %res = "FHELinalg.add_eint"(%a0, %a1) : + (tensor<4x1x4x!FHE.eint<5>>, tensor<1x4x4x!FHE.eint<5>>) -> + tensor<4x4x4x!FHE.eint<5>> return %res : tensor<4x4x4x!FHE.eint<5>> } )XXX"); uint8_t a0[4][1][4]{ @@ -395,7 +395,7 @@ TEST(End2EndJit_HLFHELinalg, add_eint_term_to_term_broadcast) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_matrix_column) { +TEST(End2EndJit_FHELinalg, add_eint_matrix_column) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the addition of a 3x3 matrix of encrypted integers and a 3x1 matrix (a column) of encrypted integers. @@ -405,10 +405,10 @@ TEST(End2EndJit_HLFHELinalg, add_eint_matrix_column) { // [7,8,9] [3] [10,11,12] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: - tensor<3x1x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x1x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: + tensor<3x1x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x1x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -443,7 +443,7 @@ TEST(End2EndJit_HLFHELinalg, add_eint_matrix_column) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_matrix_line) { +TEST(End2EndJit_FHELinalg, add_eint_matrix_line) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the addition of a 3x3 matrix of encrypted integers and a 1x3 matrix (a line) of encrypted integers. @@ -453,11 +453,11 @@ TEST(End2EndJit_HLFHELinalg, add_eint_matrix_line) { // [7,8,9] [8,10,12] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: - tensor<1x3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, - tensor<1x3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> return %res : - tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: + tensor<1x3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, + tensor<1x3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> return %res : + tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -490,13 +490,13 @@ TEST(End2EndJit_HLFHELinalg, add_eint_matrix_line) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_matrix_line_missing_dim) { +TEST(End2EndJit_FHELinalg, add_eint_matrix_line_missing_dim) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Same behavior than the previous one, but as the dimension #2 of operand #2 is missing. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.add_eint"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -529,13 +529,13 @@ TEST(End2EndJit_HLFHELinalg, add_eint_matrix_line_missing_dim) { } } -TEST(End2EndJit_HLFHELinalg, add_eint_tensor_dim_equals_1) { +TEST(End2EndJit_FHELinalg, add_eint_tensor_dim_equals_1) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Broadcasting shouldn't happen when some dimensions are equals to 1 - func @main(%arg0: tensor<3x1x2x!HLFHE.eint<5>>, %arg1: tensor<3x1x2x!HLFHE.eint<5>>) -> tensor<3x1x2x!HLFHE.eint<5>> { - %1 = "HLFHELinalg.add_eint"(%arg0, %arg1) : (tensor<3x1x2x!HLFHE.eint<5>>, tensor<3x1x2x!HLFHE.eint<5>>) -> tensor<3x1x2x!HLFHE.eint<5>> - return %1 : tensor<3x1x2x!HLFHE.eint<5>> + func @main(%arg0: tensor<3x1x2x!FHE.eint<5>>, %arg1: tensor<3x1x2x!FHE.eint<5>>) -> tensor<3x1x2x!FHE.eint<5>> { + %1 = "FHELinalg.add_eint"(%arg0, %arg1) : (tensor<3x1x2x!FHE.eint<5>>, tensor<3x1x2x!FHE.eint<5>>) -> tensor<3x1x2x!FHE.eint<5>> + return %1 : tensor<3x1x2x!FHE.eint<5>> } )XXX"); const uint8_t a0[3][1][2]{ @@ -573,16 +573,16 @@ TEST(End2EndJit_HLFHELinalg, add_eint_tensor_dim_equals_1) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg sub_int_eint /////////////////////////////////////////////////// +// FHELinalg sub_int_eint /////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, sub_int_eint_term_to_term) { +TEST(End2EndJit_FHELinalg, sub_int_eint_term_to_term) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term substraction of `%a0` with `%a1` - func @main(%a0: tensor<4xi5>, %a1: tensor<4x!HLFHE.eint<4>>) -> tensor<4x!HLFHE.eint<4>> { - %res = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4xi5>, tensor<4x!HLFHE.eint<4>>) -> tensor<4x!HLFHE.eint<4>> - return %res : tensor<4x!HLFHE.eint<4>> + func @main(%a0: tensor<4xi5>, %a1: tensor<4x!FHE.eint<4>>) -> tensor<4x!FHE.eint<4>> { + %res = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4xi5>, tensor<4x!FHE.eint<4>>) -> tensor<4x!FHE.eint<4>> + return %res : tensor<4x!FHE.eint<4>> } )XXX"); std::vector a0{32, 9, 12, 9}; @@ -607,13 +607,13 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_term_to_term) { } } -TEST(End2EndJit_HLFHELinalg, sub_int_eint_term_to_term_broadcast) { +TEST(End2EndJit_FHELinalg, sub_int_eint_term_to_term_broadcast) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term substraction of `%a0` with `%a1`, where dimensions equals to one are stretched. - func @main(%a0: tensor<4x1x4xi8>, %a1: tensor<1x4x4x!HLFHE.eint<7>>) -> tensor<4x4x4x!HLFHE.eint<7>> { - %res = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4x1x4xi8>, tensor<1x4x4x!HLFHE.eint<7>>) -> tensor<4x4x4x!HLFHE.eint<7>> - return %res : tensor<4x4x4x!HLFHE.eint<7>> + func @main(%a0: tensor<4x1x4xi8>, %a1: tensor<1x4x4x!FHE.eint<7>>) -> tensor<4x4x4x!FHE.eint<7>> { + %res = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<4x1x4xi8>, tensor<1x4x4x!FHE.eint<7>>) -> tensor<4x4x4x!FHE.eint<7>> + return %res : tensor<4x4x4x!FHE.eint<7>> } )XXX"); const uint8_t a0[4][1][4]{ @@ -654,7 +654,7 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_term_to_term_broadcast) { } } -TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_column) { +TEST(End2EndJit_FHELinalg, sub_int_eint_matrix_column) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the substraction of a 3x3 matrix of integers and a 3x1 matrix (a column) of encrypted integers. @@ -664,11 +664,11 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_column) { // [7,8,9] [3] [4,5,6] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3xi5>, %a1: tensor<3x1x!HLFHE.eint<4>>) -> - tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, - tensor<3x1x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> return %res : - tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3xi5>, %a1: tensor<3x1x!FHE.eint<4>>) -> + tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, + tensor<3x1x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> return %res : + tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -703,7 +703,7 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_column) { } } -TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_line) { +TEST(End2EndJit_FHELinalg, sub_int_eint_matrix_line) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the substraction of a 3x3 matrix of integers and a 1x3 matrix (a line) of encrypted integers. @@ -713,11 +713,11 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_line) { // [7,8,9] [6,6,6] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3xi5>, %a1: tensor<1x3x!HLFHE.eint<4>>) -> - tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, - tensor<1x3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> return %res : - tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3xi5>, %a1: tensor<1x3x!FHE.eint<4>>) -> + tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, + tensor<1x3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> return %res : + tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -750,13 +750,13 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_line) { } } -TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_line_missing_dim) { +TEST(End2EndJit_FHELinalg, sub_int_eint_matrix_line_missing_dim) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Same behavior than the previous one, but as the dimension #2 of operand #2 is missing. - func @main(%a0: tensor<3x3xi5>, %a1: tensor<3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<3x!HLFHE.eint<4>>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3xi5>, %a1: tensor<3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.sub_int_eint"(%a0, %a1) : (tensor<3x3xi5>, tensor<3x!FHE.eint<4>>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -790,16 +790,16 @@ TEST(End2EndJit_HLFHELinalg, sub_int_eint_matrix_line_missing_dim) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg mul_eint_int /////////////////////////////////////////////////// +// FHELinalg mul_eint_int /////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, mul_eint_int_term_to_term) { +TEST(End2EndJit_FHELinalg, mul_eint_int_term_to_term) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term multiplication of `%a0` with `%a1` - func @main(%a0: tensor<4x!HLFHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!HLFHE.eint<6>>, tensor<4xi7>) -> tensor<4x!HLFHE.eint<6>> - return %res : tensor<4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x!FHE.eint<6>>, %a1: tensor<4xi7>) -> tensor<4x!FHE.eint<6>> { + %res = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x!FHE.eint<6>>, tensor<4xi7>) -> tensor<4x!FHE.eint<6>> + return %res : tensor<4x!FHE.eint<6>> } )XXX"); std::vector a0{31, 6, 12, 9}; @@ -824,13 +824,13 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_term_to_term) { } } -TEST(End2EndJit_HLFHELinalg, mul_eint_int_term_to_term_broadcast) { +TEST(End2EndJit_FHELinalg, mul_eint_int_term_to_term_broadcast) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the term to term multiplication of `%a0` with `%a1`, where dimensions equals to one are stretched. - func @main(%a0: tensor<4x1x4x!HLFHE.eint<6>>, %a1: tensor<1x4x4xi7>) -> tensor<4x4x4x!HLFHE.eint<6>> { - %res = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x1x4x!HLFHE.eint<6>>, tensor<1x4x4xi7>) -> tensor<4x4x4x!HLFHE.eint<6>> - return %res : tensor<4x4x4x!HLFHE.eint<6>> + func @main(%a0: tensor<4x1x4x!FHE.eint<6>>, %a1: tensor<1x4x4xi7>) -> tensor<4x4x4x!FHE.eint<6>> { + %res = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<4x1x4x!FHE.eint<6>>, tensor<1x4x4xi7>) -> tensor<4x4x4x!FHE.eint<6>> + return %res : tensor<4x4x4x!FHE.eint<6>> } )XXX"); const uint8_t a0[4][1][4]{ @@ -872,7 +872,7 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_term_to_term_broadcast) { } } -TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_column) { +TEST(End2EndJit_FHELinalg, mul_eint_int_matrix_column) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the multiplication of a 3x3 matrix of encrypted integers and a 3x1 matrix (a column) of integers. @@ -882,9 +882,9 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_column) { // [7,8,9] [3] [21,24,27] // // The dimension #1 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<3x1xi5>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<3x1xi5>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3x1xi5>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -919,7 +919,7 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_column) { } } -TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_line) { +TEST(End2EndJit_FHELinalg, mul_eint_int_matrix_line) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the multiplication of a 3x3 matrix of encrypted integers and a 1x3 matrix (a line) of integers. @@ -929,9 +929,9 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_line) { // [7,8,9] [8,10,12] // // The dimension #2 of operand #2 is stretched as it is equals to 1. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<1x3xi5>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<1x3xi5>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<1x3xi5>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -964,13 +964,13 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_line) { } } -TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_line_missing_dim) { +TEST(End2EndJit_FHELinalg, mul_eint_int_matrix_line_missing_dim) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Same behavior than the previous one, but as the dimension #2 of operand #2 is missing. - func @main(%a0: tensor<3x3x!HLFHE.eint<4>>, %a1: tensor<3xi5>) -> tensor<3x3x!HLFHE.eint<4>> { - %res = "HLFHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!HLFHE.eint<4>>, tensor<3xi5>) -> tensor<3x3x!HLFHE.eint<4>> - return %res : tensor<3x3x!HLFHE.eint<4>> + func @main(%a0: tensor<3x3x!FHE.eint<4>>, %a1: tensor<3xi5>) -> tensor<3x3x!FHE.eint<4>> { + %res = "FHELinalg.mul_eint_int"(%a0, %a1) : (tensor<3x3x!FHE.eint<4>>, tensor<3xi5>) -> tensor<3x3x!FHE.eint<4>> + return %res : tensor<3x3x!FHE.eint<4>> } )XXX"); const uint8_t a0[3][3]{ @@ -1004,10 +1004,10 @@ TEST(End2EndJit_HLFHELinalg, mul_eint_int_matrix_line_missing_dim) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg apply_lookup_table ///////////////////////////////////////////// +// FHELinalg apply_lookup_table ///////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, apply_lookup_table) { +TEST(End2EndJit_FHELinalg, apply_lookup_table) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the lookup of 3x3 matrix of encrypted indices of with 2 on a table of size 4=2² of clear integers. @@ -1015,10 +1015,10 @@ TEST(End2EndJit_HLFHELinalg, apply_lookup_table) { // [0,1,2] [1,3,5] // [3,0,1] lut [1,3,5,7] = [7,1,3] // [2,3,0] [5,7,1] - func @main(%t: tensor<3x3x!HLFHE.eint<2>>) -> tensor<3x3x!HLFHE.eint<3>> { + func @main(%t: tensor<3x3x!FHE.eint<2>>) -> tensor<3x3x!FHE.eint<3>> { %lut = arith.constant dense<[1,3,5,7]> : tensor<4xi64> - %res = "HLFHELinalg.apply_lookup_table"(%t, %lut) : (tensor<3x3x!HLFHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!HLFHE.eint<3>> - return %res : tensor<3x3x!HLFHE.eint<3>> + %res = "FHELinalg.apply_lookup_table"(%t, %lut) : (tensor<3x3x!FHE.eint<2>>, tensor<4xi64>) -> tensor<3x3x!FHE.eint<3>> + return %res : tensor<3x3x!FHE.eint<3>> } )XXX"); const uint8_t t[3][3]{ @@ -1052,17 +1052,17 @@ TEST(End2EndJit_HLFHELinalg, apply_lookup_table) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg apply_multi_lookup_table +// FHELinalg apply_multi_lookup_table // ///////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, apply_multi_lookup_table) { +TEST(End2EndJit_FHELinalg, apply_multi_lookup_table) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the lookup of 3x3 matrix of encrypted indices of width 2 on a 3x3 matrix of tables of size 4=2² of clear integers. - func @main(%arg0: tensor<3x3x!HLFHE.eint<2>>, %arg1: tensor<3x3x4xi64>) -> tensor<3x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<3x3x!HLFHE.eint<2>>, tensor<3x3x4xi64>) -> tensor<3x3x!HLFHE.eint<2>> - return %1: tensor<3x3x!HLFHE.eint<2>> + func @main(%arg0: tensor<3x3x!FHE.eint<2>>, %arg1: tensor<3x3x4xi64>) -> tensor<3x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<3x3x!FHE.eint<2>>, tensor<3x3x4xi64>) -> tensor<3x3x!FHE.eint<2>> + return %1: tensor<3x3x!FHE.eint<2>> } )XXX"); const uint8_t t[3][3]{ @@ -1105,13 +1105,13 @@ TEST(End2EndJit_HLFHELinalg, apply_multi_lookup_table) { } } -TEST(End2EndJit_HLFHELinalg, apply_multi_lookup_table_with_boradcast) { +TEST(End2EndJit_FHELinalg, apply_multi_lookup_table_with_boradcast) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the lookup of 3x3 matrix of encrypted indices of width 2 on a vector of 3 tables of size 4=2² of clear integers. - func @main(%arg0: tensor<3x3x!HLFHE.eint<2>>, %arg1: tensor<3x4xi64>) -> tensor<3x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<3x3x!HLFHE.eint<2>>, tensor<3x4xi64>) -> tensor<3x3x!HLFHE.eint<2>> - return %1: tensor<3x3x!HLFHE.eint<2>> + func @main(%arg0: tensor<3x3x!FHE.eint<2>>, %arg1: tensor<3x4xi64>) -> tensor<3x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_multi_lookup_table"(%arg0, %arg1): (tensor<3x3x!FHE.eint<2>>, tensor<3x4xi64>) -> tensor<3x3x!FHE.eint<2>> + return %1: tensor<3x3x!FHE.eint<2>> } )XXX"); const uint8_t t[3][3]{ @@ -1154,17 +1154,17 @@ TEST(End2EndJit_HLFHELinalg, apply_multi_lookup_table_with_boradcast) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg apply_mapped_lookup_table ///////////////////////////////////////////// +// FHELinalg apply_mapped_lookup_table ///////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, apply_mapped_lookup_table_sequential) { +TEST(End2EndJit_FHELinalg, apply_mapped_lookup_table_sequential) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the lookup of 3x3 matrix of encrypted indices of width 2 of a 3x3 matrix of tables of size 4=2² of clear integers. - func @main(%t: tensor<3x3x!HLFHE.eint<2>>, %luts: tensor<9x4xi64>, %map: tensor<3x3xindex>) -> tensor<3x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) : - (tensor<3x3x!HLFHE.eint<2>>, tensor<9x4xi64>, tensor<3x3xindex>) -> tensor<3x3x!HLFHE.eint<2>> - return %1: tensor<3x3x!HLFHE.eint<2>> + func @main(%t: tensor<3x3x!FHE.eint<2>>, %luts: tensor<9x4xi64>, %map: tensor<3x3xindex>) -> tensor<3x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) : + (tensor<3x3x!FHE.eint<2>>, tensor<9x4xi64>, tensor<3x3xindex>) -> tensor<3x3x!FHE.eint<2>> + return %1: tensor<3x3x!FHE.eint<2>> } )XXX"); uint8_t t[3][3]{ @@ -1207,14 +1207,14 @@ TEST(End2EndJit_HLFHELinalg, apply_mapped_lookup_table_sequential) { } } -TEST(End2EndJit_HLFHELinalg, apply_mapped_lookup_table_same_lut) { +TEST(End2EndJit_FHELinalg, apply_mapped_lookup_table_same_lut) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the lookup of 3x3 matrix of encrypted indices of width 2 of a 3x3 matrix of tables of size 4=2² of clear integers. - func @main(%t: tensor<3x3x!HLFHE.eint<2>>, %luts: tensor<9x4xi64>, %map: tensor<3x3xindex>) -> tensor<3x3x!HLFHE.eint<2>> { - %1 = "HLFHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) : - (tensor<3x3x!HLFHE.eint<2>>, tensor<9x4xi64>, tensor<3x3xindex>) -> tensor<3x3x!HLFHE.eint<2>> - return %1: tensor<3x3x!HLFHE.eint<2>> + func @main(%t: tensor<3x3x!FHE.eint<2>>, %luts: tensor<9x4xi64>, %map: tensor<3x3xindex>) -> tensor<3x3x!FHE.eint<2>> { + %1 = "FHELinalg.apply_mapped_lookup_table"(%t, %luts, %map) : + (tensor<3x3x!FHE.eint<2>>, tensor<9x4xi64>, tensor<3x3xindex>) -> tensor<3x3x!FHE.eint<2>> + return %1: tensor<3x3x!FHE.eint<2>> } )XXX"); uint8_t t[3][3]{ @@ -1258,17 +1258,17 @@ TEST(End2EndJit_HLFHELinalg, apply_mapped_lookup_table_same_lut) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg dot_eint_int /////////////////////////////////////////////////// +// FHELinalg dot_eint_int /////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// TEST(CompileAndRunTensorEncrypted, dot_eint_int_7) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: tensor<4x!HLFHE.eint<7>>, - %arg1: tensor<4xi8>) -> !HLFHE.eint<7> +func @main(%arg0: tensor<4x!FHE.eint<7>>, + %arg1: tensor<4xi8>) -> !FHE.eint<7> { - %ret = "HLFHELinalg.dot_eint_int"(%arg0, %arg1) : - (tensor<4x!HLFHE.eint<7>>, tensor<4xi8>) -> !HLFHE.eint<7> - return %ret : !HLFHE.eint<7> + %ret = "FHELinalg.dot_eint_int"(%arg0, %arg1) : + (tensor<4x!FHE.eint<7>>, tensor<4xi8>) -> !FHE.eint<7> + return %ret : !FHE.eint<7> } )XXX"); static uint8_t arg0[] = {0, 1, 2, 3}; @@ -1281,10 +1281,10 @@ func @main(%arg0: tensor<4x!HLFHE.eint<7>>, } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg neg_eint ///////////////////////////////////////////// +// FHELinalg neg_eint ///////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, neg_eint) { +TEST(End2EndJit_FHELinalg, neg_eint) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the negation of a 3x3 matrix of encrypted integers of width 2. @@ -1292,9 +1292,9 @@ TEST(End2EndJit_HLFHELinalg, neg_eint) { // ([0,1,2]) [0,7,6] // negate ([3,4,5]) = [5,4,3] // ([6,7,0]) [2,1,0] - func @main(%t: tensor<3x3x!HLFHE.eint<2>>) -> tensor<3x3x!HLFHE.eint<2>> { - %res = "HLFHELinalg.neg_eint"(%t) : (tensor<3x3x!HLFHE.eint<2>>) -> tensor<3x3x!HLFHE.eint<2>> - return %res : tensor<3x3x!HLFHE.eint<2>> + func @main(%t: tensor<3x3x!FHE.eint<2>>) -> tensor<3x3x!FHE.eint<2>> { + %res = "FHELinalg.neg_eint"(%t) : (tensor<3x3x!FHE.eint<2>>) -> tensor<3x3x!FHE.eint<2>> + return %res : tensor<3x3x!FHE.eint<2>> } )XXX"); const uint8_t t[3][3]{ @@ -1328,10 +1328,10 @@ TEST(End2EndJit_HLFHELinalg, neg_eint) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg matmul_eint_int //////////////////////////////////////////////// +// FHELinalg matmul_eint_int //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, matmul_eint_int) { +TEST(End2EndJit_FHELinalg, matmul_eint_int) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the matrix multiplication of a 3x2 matrix of encrypted integers and a 2x3 matrix of integers. @@ -1341,9 +1341,9 @@ TEST(End2EndJit_HLFHELinalg, matmul_eint_int) { // [1,2] [ 5, 8,11] // [3,4] = [11,18,25] // [5,6] [17,28,39] - func @main(%a: tensor<3x2x!HLFHE.eint<6>>, %b: tensor<2x3xi7>) -> tensor<3x3x!HLFHE.eint<6>> { - %0 = "HLFHELinalg.matmul_eint_int"(%a, %b) : (tensor<3x2x!HLFHE.eint<6>>, tensor<2x3xi7>) -> tensor<3x3x!HLFHE.eint<6>> - return %0 : tensor<3x3x!HLFHE.eint<6>> + func @main(%a: tensor<3x2x!FHE.eint<6>>, %b: tensor<2x3xi7>) -> tensor<3x3x!FHE.eint<6>> { + %0 = "FHELinalg.matmul_eint_int"(%a, %b) : (tensor<3x2x!FHE.eint<6>>, tensor<2x3xi7>) -> tensor<3x3x!FHE.eint<6>> + return %0 : tensor<3x3x!FHE.eint<6>> } )XXX"); const uint8_t A[3][2]{ @@ -1384,10 +1384,10 @@ TEST(End2EndJit_HLFHELinalg, matmul_eint_int) { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg matmul_eint_int //////////////////////////////////////////////// +// FHELinalg matmul_eint_int //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -TEST(End2EndJit_HLFHELinalg, matmul_int_eint) { +TEST(End2EndJit_FHELinalg, matmul_int_eint) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( // Returns the matrix multiplication of a 3x2 matrix of encrypted integers and a 2x3 matrix of integers. @@ -1397,9 +1397,9 @@ TEST(End2EndJit_HLFHELinalg, matmul_int_eint) { // [1,2] [ 5, 8,11] // [3,4] = [11,18,25] // [5,6] [17,28,39] - func @main(%a: tensor<3x2xi7>, %b: tensor<2x3x!HLFHE.eint<6>>) -> tensor<3x3x!HLFHE.eint<6>> { - %0 = "HLFHELinalg.matmul_int_eint"(%a, %b) : (tensor<3x2xi7>, tensor<2x3x!HLFHE.eint<6>>) -> tensor<3x3x!HLFHE.eint<6>> - return %0 : tensor<3x3x!HLFHE.eint<6>> + func @main(%a: tensor<3x2xi7>, %b: tensor<2x3x!FHE.eint<6>>) -> tensor<3x3x!FHE.eint<6>> { + %0 = "FHELinalg.matmul_int_eint"(%a, %b) : (tensor<3x2xi7>, tensor<2x3x!FHE.eint<6>>) -> tensor<3x3x!FHE.eint<6>> + return %0 : tensor<3x3x!FHE.eint<6>> } )XXX"); const uint8_t A[3][2]{ @@ -1446,9 +1446,9 @@ TEST(End2EndJit_HLFHELinalg, matmul_int_eint) { TEST(End2EndJit_Linalg, tensor_collapse_shape) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%a: tensor<2x2x4x!HLFHE.eint<6>>) -> tensor<2x8x!HLFHE.eint<6>> { - %0 = linalg.tensor_collapse_shape %a [[0],[1,2]] : tensor<2x2x4x!HLFHE.eint<6>> into tensor<2x8x!HLFHE.eint<6>> - return %0 : tensor<2x8x!HLFHE.eint<6>> +func @main(%a: tensor<2x2x4x!FHE.eint<6>>) -> tensor<2x8x!FHE.eint<6>> { + %0 = linalg.tensor_collapse_shape %a [[0],[1,2]] : tensor<2x2x4x!FHE.eint<6>> into tensor<2x8x!FHE.eint<6>> + return %0 : tensor<2x8x!FHE.eint<6>> } )XXX"); static uint8_t A[2][2][4]{ @@ -1495,9 +1495,9 @@ func @main(%a: tensor<2x2x4x!HLFHE.eint<6>>) -> tensor<2x8x!HLFHE.eint<6>> { TEST(End2EndJit_Linalg, tensor_expand_shape) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%a: tensor<2x8x!HLFHE.eint<6>>) -> tensor<2x2x4x!HLFHE.eint<6>> { - %0 = linalg.tensor_expand_shape %a [[0],[1,2]] : tensor<2x8x!HLFHE.eint<6>> into tensor<2x2x4x!HLFHE.eint<6>> - return %0 : tensor<2x2x4x!HLFHE.eint<6>> +func @main(%a: tensor<2x8x!FHE.eint<6>>) -> tensor<2x2x4x!FHE.eint<6>> { + %0 = linalg.tensor_expand_shape %a [[0],[1,2]] : tensor<2x8x!FHE.eint<6>> into tensor<2x2x4x!FHE.eint<6>> + return %0 : tensor<2x2x4x!FHE.eint<6>> } )XXX"); @@ -1542,14 +1542,14 @@ func @main(%a: tensor<2x8x!HLFHE.eint<6>>) -> tensor<2x2x4x!HLFHE.eint<6>> { } /////////////////////////////////////////////////////////////////////////////// -// HLFHELinalg.zero /////////////////////////////////////////////// +// FHELinalg.zero /////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// TEST(End2EndJit_Linalg, zero) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main() -> tensor<2x2x4x!HLFHE.eint<6>> { - %0 = "HLFHELinalg.zero"() : () -> tensor<2x2x4x!HLFHE.eint<6>> - return %0 : tensor<2x2x4x!HLFHE.eint<6>> +func @main() -> tensor<2x2x4x!FHE.eint<6>> { + %0 = "FHELinalg.zero"() : () -> tensor<2x2x4x!FHE.eint<6>> + return %0 : tensor<2x2x4x!FHE.eint<6>> } )XXX"); @@ -1587,14 +1587,14 @@ TEST_P(TiledMatMulParametric, tiled_matmul_eint_int) { std::ostringstream mlirProgram; mlirProgram - << "func @main(%a: tensor<8x4x!HLFHE.eint<6>>, %b: tensor<4x2xi7>) ->\n" - << " tensor<8x2x!HLFHE.eint<6>> {\n" - << " %0 = \"HLFHELinalg.matmul_eint_int\"(%a, %b) { \"tile-sizes\" = " + << "func @main(%a: tensor<8x4x!FHE.eint<6>>, %b: tensor<4x2xi7>) ->\n" + << " tensor<8x2x!FHE.eint<6>> {\n" + << " %0 = \"FHELinalg.matmul_eint_int\"(%a, %b) { \"tile-sizes\" = " << "[" << tiling[0] << ", " << tiling[1] << ", " << tiling[2] << "]" << "} :\n" - << " (tensor<8x4x!HLFHE.eint<6>>, tensor<4x2xi7>) ->\n" - << " tensor<8x2x!HLFHE.eint<6>>\n" - << " return %0 : tensor<8x2x!HLFHE.eint<6>>\n" + << " (tensor<8x4x!FHE.eint<6>>, tensor<4x2xi7>) ->\n" + << " tensor<8x2x!FHE.eint<6>>\n" + << " return %0 : tensor<8x2x!FHE.eint<6>>\n" << " }"; mlir::concretelang::JitCompilerEngine::Lambda lambda = diff --git a/compiler/tests/unittest/end_to_end_jit_lambda.cc b/compiler/tests/unittest/end_to_end_jit_lambda.cc index 981e18f47..91b2e86bc 100644 --- a/compiler/tests/unittest/end_to_end_jit_lambda.cc +++ b/compiler/tests/unittest/end_to_end_jit_lambda.cc @@ -9,7 +9,7 @@ using Lambda = mlir::concretelang::JitCompilerEngine::Lambda; TEST(Lambda_check_param, int_to_void_missing_param) { Lambda lambda = checkedJit(R"XXX( - func @main(%arg0: !HLFHE.eint<1>) { + func @main(%arg0: !FHE.eint<1>) { return } )XXX"); @@ -19,7 +19,7 @@ TEST(Lambda_check_param, int_to_void_missing_param) { TEST(Lambda_check_param, DISABLED_int_to_void_good) { // DISABLED Note: it segfaults Lambda lambda = checkedJit(R"XXX( - func @main(%arg0: !HLFHE.eint<1>) { + func @main(%arg0: !FHE.eint<1>) { return } )XXX"); @@ -28,7 +28,7 @@ TEST(Lambda_check_param, DISABLED_int_to_void_good) { TEST(Lambda_check_param, int_to_void_superfluous_param) { Lambda lambda = checkedJit(R"XXX( - func @main(%arg0: !HLFHE.eint<1>) { + func @main(%arg0: !FHE.eint<1>) { return } )XXX"); @@ -38,10 +38,10 @@ TEST(Lambda_check_param, int_to_void_superfluous_param) { TEST(Lambda_check_param, scalar_parameters_number) { Lambda lambda = checkedJit(R"XXX( func @main( - %arg0: !HLFHE.eint<1>, %arg1: !HLFHE.eint<1>, - %arg2: !HLFHE.eint<1>) -> !HLFHE.eint<1> + %arg0: !FHE.eint<1>, %arg1: !FHE.eint<1>, + %arg2: !FHE.eint<1>) -> !FHE.eint<1> { - return %arg0: !HLFHE.eint<1> + return %arg0: !FHE.eint<1> } )XXX"); ASSERT_EXPECTED_FAILURE(lambda()); @@ -54,9 +54,9 @@ TEST(Lambda_check_param, scalar_parameters_number) { TEST(Lambda_check_param, scalar_tensor_to_scalar_missing_param) { Lambda lambda = checkedJit(R"XXX( func @main( - %arg0: !HLFHE.eint<1>, %arg1: tensor<2x!HLFHE.eint<1>>) -> !HLFHE.eint<1> + %arg0: !FHE.eint<1>, %arg1: tensor<2x!FHE.eint<1>>) -> !FHE.eint<1> { - return %arg0: !HLFHE.eint<1> + return %arg0: !FHE.eint<1> } )XXX"); ASSERT_EXPECTED_FAILURE(lambda(1_u64)); @@ -65,9 +65,9 @@ TEST(Lambda_check_param, scalar_tensor_to_scalar_missing_param) { TEST(Lambda_check_param, scalar_tensor_to_scalar) { Lambda lambda = checkedJit(R"XXX( func @main( - %arg0: !HLFHE.eint<1>, %arg1: tensor<2x!HLFHE.eint<1>>) -> !HLFHE.eint<1> + %arg0: !FHE.eint<1>, %arg1: tensor<2x!FHE.eint<1>>) -> !FHE.eint<1> { - return %arg0: !HLFHE.eint<1> + return %arg0: !FHE.eint<1> } )XXX"); uint8_t arg[2] = {1 ,2}; @@ -77,9 +77,9 @@ TEST(Lambda_check_param, scalar_tensor_to_scalar) { TEST(Lambda_check_param, scalar_tensor_to_scalar_superfluous_param) { Lambda lambda = checkedJit(R"XXX( func @main( - %arg0: !HLFHE.eint<1>, %arg1: tensor<2x!HLFHE.eint<1>>) -> !HLFHE.eint<1> + %arg0: !FHE.eint<1>, %arg1: tensor<2x!FHE.eint<1>>) -> !FHE.eint<1> { - return %arg0: !HLFHE.eint<1> + return %arg0: !FHE.eint<1> } )XXX"); uint8_t arg[2] = {1 ,2}; @@ -89,9 +89,9 @@ TEST(Lambda_check_param, scalar_tensor_to_scalar_superfluous_param) { TEST(Lambda_check_param, scalar_tensor_to_tensor_good_number_param) { Lambda lambda = checkedJit(R"XXX( func @main( - %arg0: !HLFHE.eint<1>, %arg1: tensor<2x!HLFHE.eint<1>>) -> tensor<2x!HLFHE.eint<1>> + %arg0: !FHE.eint<1>, %arg1: tensor<2x!FHE.eint<1>>) -> tensor<2x!FHE.eint<1>> { - return %arg1: tensor<2x!HLFHE.eint<1>> + return %arg1: tensor<2x!FHE.eint<1>> } )XXX"); uint8_t arg[2] = {1 ,2}; @@ -103,9 +103,9 @@ TEST(Lambda_check_param, scalar_tensor_to_tensor_good_number_param) { TEST(Lambda_check_param, DISABLED_check_parameters_scalar_too_big) { // DISABLED Note: loss of precision without any warning or error. Lambda lambda = checkedJit(R"XXX( - func @main(%arg0: !HLFHE.eint<1>) -> !HLFHE.eint<1> + func @main(%arg0: !FHE.eint<1>) -> !FHE.eint<1> { - return %arg0: !HLFHE.eint<1> + return %arg0: !FHE.eint<1> } )XXX"); uint16_t arg = 3; diff --git a/compiler/tests/unittest/end_to_end_jit_test.cc b/compiler/tests/unittest/end_to_end_jit_test.cc index d4ab54bc6..b3a1662b8 100644 --- a/compiler/tests/unittest/end_to_end_jit_test.cc +++ b/compiler/tests/unittest/end_to_end_jit_test.cc @@ -5,11 +5,11 @@ #include "end_to_end_jit_test.h" -TEST(CompileAndRunHLFHE, add_eint) { +TEST(CompileAndRunFHE, add_eint) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> +func @main(%arg0: !FHE.eint<7>, %arg1: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } )XXX"); @@ -18,13 +18,13 @@ func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { ASSERT_EXPECTED_VALUE(lambda(1_u64, 1_u64), 2); } -// Same as CompileAndRunHLFHE::add_eint above, but using +// Same as CompileAndRunFHE::add_eint above, but using // `LambdaArgument` instances as arguments -TEST(CompileAndRunHLFHE, add_eint_lambda_argument) { +TEST(CompileAndRunFHE, add_eint_lambda_argument) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> +func @main(%arg0: !FHE.eint<7>, %arg1: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } )XXX"); @@ -40,13 +40,13 @@ func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { ASSERT_EXPECTED_VALUE(lambda({&ila2, &ila7}), 9); } -// Same as CompileAndRunHLFHE::add_eint above, but using +// Same as CompileAndRunFHE::add_eint above, but using // `LambdaArgument` instances as arguments and as a result type -TEST(CompileAndRunHLFHE, add_eint_lambda_argument_res) { +TEST(CompileAndRunFHE, add_eint_lambda_argument_res) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.add_eint"(%arg0, %arg1): (!HLFHE.eint<7>, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> +func @main(%arg0: !FHE.eint<7>, %arg1: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.add_eint"(%arg0, %arg1): (!FHE.eint<7>, !FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } )XXX"); @@ -75,11 +75,11 @@ func @main(%arg0: !HLFHE.eint<7>, %arg1: !HLFHE.eint<7>) -> !HLFHE.eint<7> { eval(ila2, ila7, 9); } -TEST(CompileAndRunHLFHE, neg_eint) { +TEST(CompileAndRunFHE, neg_eint) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> +func @main(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } )XXX"); @@ -89,12 +89,12 @@ func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { ASSERT_EXPECTED_VALUE(lambda(250_u64), 6); } -// Same as CompileAndRunHLFHE::neg_eint above, but using 3 bits -TEST(CompileAndRunHLFHE, neg_eint_3bits) { +// Same as CompileAndRunFHE::neg_eint above, but using 3 bits +TEST(CompileAndRunFHE, neg_eint_3bits) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<3>) -> !HLFHE.eint<3> { - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<3>) -> (!HLFHE.eint<3>) - return %1: !HLFHE.eint<3> +func @main(%arg0: !FHE.eint<3>) -> !FHE.eint<3> { + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<3>) -> (!FHE.eint<3>) + return %1: !FHE.eint<3> } )XXX"); @@ -104,13 +104,13 @@ func @main(%arg0: !HLFHE.eint<3>) -> !HLFHE.eint<3> { ASSERT_EXPECTED_VALUE(lambda(13_u64), 3); } -// Same as CompileAndRunHLFHE::neg_eint above, but using +// Same as CompileAndRunFHE::neg_eint above, but using // `LambdaArgument` instances as arguments -TEST(CompileAndRunHLFHE, neg_eint_lambda_argument) { +TEST(CompileAndRunFHE, neg_eint_lambda_argument) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> +func @main(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } )XXX"); @@ -127,13 +127,13 @@ func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { ASSERT_EXPECTED_VALUE(lambda({&ila249}), 7); } -// Same as CompileAndRunHLFHE::neg_eint above, but using +// Same as CompileAndRunFHE::neg_eint above, but using // `LambdaArgument` instances as arguments and as a result type -TEST(CompileAndRunHLFHE, neg_eint_lambda_argument_res) { +TEST(CompileAndRunFHE, neg_eint_lambda_argument_res) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<7>) -> (!HLFHE.eint<7>) - return %1: !HLFHE.eint<7> +func @main(%arg0: !FHE.eint<7>) -> !FHE.eint<7> { + %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<7>) -> (!FHE.eint<7>) + return %1: !FHE.eint<7> } )XXX"); @@ -160,7 +160,7 @@ func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { eval(ila9, 247); } -TEST(CompileAndRunHLFHE, add_u64) { +TEST(CompileAndRunFHE, add_u64) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( func @main(%arg0: i64, %arg1: i64) -> i64 { %1 = arith.addi %arg0, %arg1 : i64 @@ -299,9 +299,9 @@ func @main(%t: tensor<10xi1>, %i: index) -> i1{ TEST(CompileAndRunTensorEncrypted, extract_5) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<10x!HLFHE.eint<5>>, %i: index) -> !HLFHE.eint<5>{ - %c = tensor.extract %t[%i] : tensor<10x!HLFHE.eint<5>> - return %c : !HLFHE.eint<5> +func @main(%t: tensor<10x!FHE.eint<5>>, %i: index) -> !FHE.eint<5>{ + %c = tensor.extract %t[%i] : tensor<10x!FHE.eint<5>> + return %c : !FHE.eint<5> } )XXX"); @@ -313,12 +313,12 @@ func @main(%t: tensor<10x!HLFHE.eint<5>>, %i: index) -> !HLFHE.eint<5>{ TEST(CompileAndRunTensorEncrypted, extract_twice_and_add_5) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<10x!HLFHE.eint<5>>, %i: index, %j: index) -> -!HLFHE.eint<5>{ - %ti = tensor.extract %t[%i] : tensor<10x!HLFHE.eint<5>> - %tj = tensor.extract %t[%j] : tensor<10x!HLFHE.eint<5>> - %c = "HLFHE.add_eint"(%ti, %tj) : (!HLFHE.eint<5>, !HLFHE.eint<5>) -> - !HLFHE.eint<5> return %c : !HLFHE.eint<5> +func @main(%t: tensor<10x!FHE.eint<5>>, %i: index, %j: index) -> +!FHE.eint<5>{ + %ti = tensor.extract %t[%i] : tensor<10x!FHE.eint<5>> + %tj = tensor.extract %t[%j] : tensor<10x!FHE.eint<5>> + %c = "FHE.add_eint"(%ti, %tj) : (!FHE.eint<5>, !FHE.eint<5>) -> + !FHE.eint<5> return %c : !FHE.eint<5> } )XXX"); @@ -332,9 +332,9 @@ func @main(%t: tensor<10x!HLFHE.eint<5>>, %i: index, %j: index) -> TEST(CompileAndRunTensorEncrypted, dim_5) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%t: tensor<10x!HLFHE.eint<5>>) -> index{ +func @main(%t: tensor<10x!FHE.eint<5>>) -> index{ %c0 = arith.constant 0 : index - %c = tensor.dim %t, %c0 : tensor<10x!HLFHE.eint<5>> + %c = tensor.dim %t, %c0 : tensor<10x!FHE.eint<5>> return %c : index } )XXX"); @@ -345,9 +345,9 @@ func @main(%t: tensor<10x!HLFHE.eint<5>>) -> index{ TEST(CompileAndRunTensorEncrypted, from_elements_5) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%0: !HLFHE.eint<5>) -> tensor<1x!HLFHE.eint<5>> { - %t = tensor.from_elements %0 : tensor<1x!HLFHE.eint<5>> - return %t: tensor<1x!HLFHE.eint<5>> +func @main(%0: !FHE.eint<5>) -> tensor<1x!FHE.eint<5>> { + %t = tensor.from_elements %0 : tensor<1x!FHE.eint<5>> + return %t: tensor<1x!FHE.eint<5>> } )XXX"); @@ -363,9 +363,9 @@ func @main(%0: !HLFHE.eint<5>) -> tensor<1x!HLFHE.eint<5>> { // `LambdaArgument` instances as arguments and as a result type TEST(CompileAndRunTensorEncrypted, from_elements_5_lambda_argument_res) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%0: !HLFHE.eint<5>) -> tensor<1x!HLFHE.eint<5>> { - %t = tensor.from_elements %0 : tensor<1x!HLFHE.eint<5>> - return %t: tensor<1x!HLFHE.eint<5>> +func @main(%0: !FHE.eint<5>) -> tensor<1x!FHE.eint<5>> { + %t = tensor.from_elements %0 : tensor<1x!FHE.eint<5>> + return %t: tensor<1x!FHE.eint<5>> } )XXX"); @@ -393,17 +393,17 @@ func @main(%0: !HLFHE.eint<5>) -> tensor<1x!HLFHE.eint<5>> { TEST(CompileAndRunTensorEncrypted, in_out_tensor_with_op_5) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%in: tensor<2x!HLFHE.eint<5>>) -> tensor<3x!HLFHE.eint<5>> { +func @main(%in: tensor<2x!FHE.eint<5>>) -> tensor<3x!FHE.eint<5>> { %c_0 = arith.constant 0 : index %c_1 = arith.constant 1 : index - %a = tensor.extract %in[%c_0] : tensor<2x!HLFHE.eint<5>> - %b = tensor.extract %in[%c_1] : tensor<2x!HLFHE.eint<5>> - %aplusa = "HLFHE.add_eint"(%a, %a): (!HLFHE.eint<5>, !HLFHE.eint<5>) -> - (!HLFHE.eint<5>) %aplusb = "HLFHE.add_eint"(%a, %b): (!HLFHE.eint<5>, - !HLFHE.eint<5>) -> (!HLFHE.eint<5>) %bplusb = "HLFHE.add_eint"(%b, %b): - (!HLFHE.eint<5>, !HLFHE.eint<5>) -> (!HLFHE.eint<5>) %out = - tensor.from_elements %aplusa, %aplusb, %bplusb : tensor<3x!HLFHE.eint<5>> - return %out: tensor<3x!HLFHE.eint<5>> + %a = tensor.extract %in[%c_0] : tensor<2x!FHE.eint<5>> + %b = tensor.extract %in[%c_1] : tensor<2x!FHE.eint<5>> + %aplusa = "FHE.add_eint"(%a, %a): (!FHE.eint<5>, !FHE.eint<5>) -> + (!FHE.eint<5>) %aplusb = "FHE.add_eint"(%a, %b): (!FHE.eint<5>, + !FHE.eint<5>) -> (!FHE.eint<5>) %bplusb = "FHE.add_eint"(%b, %b): + (!FHE.eint<5>, !FHE.eint<5>) -> (!FHE.eint<5>) %out = + tensor.from_elements %aplusa, %aplusb, %bplusb : tensor<3x!FHE.eint<5>> + return %out: tensor<3x!FHE.eint<5>> } )XXX"); @@ -424,20 +424,20 @@ TEST(CompileAndRunTensorEncrypted, linalg_generic) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( #map0 = affine_map<(d0) -> (d0)> #map1 = affine_map<(d0) -> (0)> -func @main(%arg0: tensor<2x!HLFHE.eint<7>>, %arg1: tensor<2xi8>, %acc: -!HLFHE.eint<7>) -> !HLFHE.eint<7> { - %tacc = tensor.from_elements %acc : tensor<1x!HLFHE.eint<7>> +func @main(%arg0: tensor<2x!FHE.eint<7>>, %arg1: tensor<2xi8>, %acc: +!FHE.eint<7>) -> !FHE.eint<7> { + %tacc = tensor.from_elements %acc : tensor<1x!FHE.eint<7>> %2 = linalg.generic {indexing_maps = [#map0, #map0, #map1], iterator_types - = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!HLFHE.eint<7>>, tensor<2xi8>) - outs(%tacc : tensor<1x!HLFHE.eint<7>>) { ^bb0(%arg2: !HLFHE.eint<7>, %arg3: - i8, %arg4: !HLFHE.eint<7>): // no predecessors - %4 = "HLFHE.mul_eint_int"(%arg2, %arg3) : (!HLFHE.eint<7>, i8) -> - !HLFHE.eint<7> %5 = "HLFHE.add_eint"(%4, %arg4) : (!HLFHE.eint<7>, - !HLFHE.eint<7>) -> !HLFHE.eint<7> linalg.yield %5 : !HLFHE.eint<7> - } -> tensor<1x!HLFHE.eint<7>> + = ["reduction"]} ins(%arg0, %arg1 : tensor<2x!FHE.eint<7>>, tensor<2xi8>) + outs(%tacc : tensor<1x!FHE.eint<7>>) { ^bb0(%arg2: !FHE.eint<7>, %arg3: + i8, %arg4: !FHE.eint<7>): // no predecessors + %4 = "FHE.mul_eint_int"(%arg2, %arg3) : (!FHE.eint<7>, i8) -> + !FHE.eint<7> %5 = "FHE.add_eint"(%4, %arg4) : (!FHE.eint<7>, + !FHE.eint<7>) -> !FHE.eint<7> linalg.yield %5 : !FHE.eint<7> + } -> tensor<1x!FHE.eint<7>> %c0 = arith.constant 0 : index - %ret = tensor.extract %2[%c0] : tensor<1x!HLFHE.eint<7>> - return %ret : !HLFHE.eint<7> + %ret = tensor.extract %2[%c0] : tensor<1x!FHE.eint<7>> + return %ret : !FHE.eint<7> } )XXX", "main", true); @@ -458,18 +458,18 @@ TEST_P(CompileAndRunWithPrecision, identity_func) { std::ostringstream mlirProgram; uint64_t sizeOfTLU = 1 << precision; - mlirProgram << "func @main(%arg0: !HLFHE.eint<" << precision - << ">) -> !HLFHE.eint<" << precision << "> { \n" + mlirProgram << "func @main(%arg0: !FHE.eint<" << precision + << ">) -> !FHE.eint<" << precision << "> { \n" << " %tlu = arith.constant dense<[0"; for (uint64_t i = 1; i < sizeOfTLU; i++) mlirProgram << ", " << i; mlirProgram << "]> : tensor<" << sizeOfTLU << "xi64>\n" - << " %1 = \"HLFHE.apply_lookup_table\"(%arg0, %tlu): " - << "(!HLFHE.eint<" << precision << ">, tensor<" << sizeOfTLU - << "xi64>) -> (!HLFHE.eint<" << precision << ">)\n " - << "return %1: !HLFHE.eint<" << precision << ">\n" + << " %1 = \"FHE.apply_lookup_table\"(%arg0, %tlu): " + << "(!FHE.eint<" << precision << ">, tensor<" << sizeOfTLU + << "xi64>) -> (!FHE.eint<" << precision << ">)\n " + << "return %1: !FHE.eint<" << precision << ">\n" << "}\n"; mlir::concretelang::JitCompilerEngine::Lambda lambda = @@ -499,18 +499,18 @@ TEST_P(CompileAndRunWithPrecision, identity_func) { } } -INSTANTIATE_TEST_SUITE_P(TestHLFHEApplyLookupTable, CompileAndRunWithPrecision, +INSTANTIATE_TEST_SUITE_P(TestFHEApplyLookupTable, CompileAndRunWithPrecision, ::testing::Values(1, 2, 3, 4, 5, 6, 7)); -TEST(TestHLFHEApplyLookupTable, multiple_precision) { +TEST(TestFHEApplyLookupTable, multiple_precision) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<6>, %arg1: !HLFHE.eint<3>) -> !HLFHE.eint<6> { +func @main(%arg0: !FHE.eint<6>, %arg1: !FHE.eint<3>) -> !FHE.eint<6> { %tlu_7 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]> : tensor<64xi64> %tlu_3 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7]> : tensor<8xi64> - %a = "HLFHE.apply_lookup_table"(%arg0, %tlu_7): (!HLFHE.eint<6>, tensor<64xi64>) -> (!HLFHE.eint<6>) - %b = "HLFHE.apply_lookup_table"(%arg1, %tlu_3): (!HLFHE.eint<3>, tensor<8xi64>) -> (!HLFHE.eint<6>) - %a_plus_b = "HLFHE.add_eint"(%a, %b): (!HLFHE.eint<6>, !HLFHE.eint<6>) -> (!HLFHE.eint<6>) - return %a_plus_b: !HLFHE.eint<6> + %a = "FHE.apply_lookup_table"(%arg0, %tlu_7): (!FHE.eint<6>, tensor<64xi64>) -> (!FHE.eint<6>) + %b = "FHE.apply_lookup_table"(%arg1, %tlu_3): (!FHE.eint<3>, tensor<8xi64>) -> (!FHE.eint<6>) + %a_plus_b = "FHE.add_eint"(%a, %b): (!FHE.eint<6>, !FHE.eint<6>) -> (!FHE.eint<6>) + return %a_plus_b: !FHE.eint<6> } )XXX"); @@ -519,10 +519,10 @@ func @main(%arg0: !HLFHE.eint<6>, %arg1: !HLFHE.eint<3>) -> !HLFHE.eint<6> { TEST(CompileAndRunTLU, random_func) { mlir::concretelang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( -func @main(%arg0: !HLFHE.eint<6>) -> !HLFHE.eint<6> { +func @main(%arg0: !FHE.eint<6>) -> !FHE.eint<6> { %tlu = arith.constant dense<[16, 91, 16, 83, 80, 74, 21, 96, 1, 63, 49, 122, 76, 89, 74, 55, 109, 110, 103, 54, 105, 14, 66, 47, 52, 89, 7, 10, 73, 44, 119, 92, 25, 104, 123, 100, 108, 86, 29, 121, 118, 52, 107, 48, 34, 37, 13, 122, 107, 48, 74, 59, 96, 36, 50, 55, 120, 72, 27, 45, 12, 5, 96, 12]> : tensor<64xi64> - %1 = "HLFHE.apply_lookup_table"(%arg0, %tlu): (!HLFHE.eint<6>, tensor<64xi64>) -> (!HLFHE.eint<6>) - return %1: !HLFHE.eint<6> + %1 = "FHE.apply_lookup_table"(%arg0, %tlu): (!FHE.eint<6>, tensor<64xi64>) -> (!FHE.eint<6>) + return %1: !FHE.eint<6> } )XXX");