Commit Graph

249 Commits

Author SHA1 Message Date
youben11
efacd7d8a1 feat(compiler): support HLFHE.neg_eint in MANP 2021-11-10 15:24:31 +01:00
youben11
08869bc998 chore: separate unittests into different executables
it's easier to run a specific set of tests if they are into separate
executable. We shouldn't have to run them all for testing a specific set
of tests
2021-11-10 15:24:21 +01:00
youben11
aee493392b feat(compiler): lower neg_eint from HLFHE to LowLFHE 2021-11-10 15:24:21 +01:00
youben11
c1cd6bb380 feat(compiler): add MidLFHE.neg_glwe op 2021-11-10 15:24:06 +01:00
youben11
cc4e403e7a feat(compiler): add HLFHE.neg_eint op 2021-11-10 14:52:35 +01:00
Andi Drebes
47cb4b0e70 fix(compiler): HLFHELinalg JIT tests: Use immutable ArrayRefs for tensor arguments
Fix compiler warnings related to the conversion from const pointers to
mutable pointers in `tests/unittest/end_to_end_jit_hlfhelinalg.cc`.
2021-11-10 11:25:35 +01:00
Andi Drebes
8cd893a7fd fix(compiler): JIT unit tests: Remove unused variables
Remove unused variable `pos` in `End2EndJit_ClearTensor_2D::extract`
and `End2EndJit_EncryptedTensor_2D::extract` to avoid warnings on
compilation.
2021-11-10 11:25:35 +01:00
Andi Drebes
5cc551dd4f fix(compiler): JIT unit tests: Don't compare expressions of different signedness
Fix compiler warnings in `end_to_end_jit_clear_tensor.cc` and
`end_to_end_jit_encrypted_tensor.cc` due to the comparison of integer
expressions of different signedness.
2021-11-10 11:25:35 +01:00
rudy
97389a3b06 Move HLFHE.dot_eint_int to HLFHELinalg.
Resolves #183
2021-11-09 11:39:08 +01:00
youben11
0670d4efc1 fix(python): add mlir[.dialects] as namespace packages
I initially thought there were missing init files, but it was intended
that mlir and mlir.dialects are namespace packages
2021-11-08 15:29:57 +01:00
Andi Drebes
c401b5ae44 test(compiler): Add JIT test returning multi-dimensional TensorLambdaArgument 2021-11-08 12:00:20 +01:00
youben11
59e859177c refactor: replace ExecutionArg by TensorLambdaArg
This add support for tensor inputs from the python bindings
2021-11-08 11:55:02 +01:00
youben11
56e261d140 fix(compiler): pass dimensions at TensorLambdaArg creation 2021-11-08 11:55:02 +01:00
youben11
b501e3d6c0 feat(python): support functions returning tensors 2021-11-08 11:55:02 +01:00
youben11
badc8e44bf test(comiler): add tests for result tensor when calling Lambda::operator()
Lambda::operator()<unique_ptr<LambdaArgument>> was giving bad results
when using tensors due to bad references. Now it's fixed and we want to
spot that in the future.
2021-11-04 19:07:54 +01:00
Andi Drebes
c92f047721 fix(compiler): TensorLambdaArgument: Copy input data instead of using a reference
`TensorLambdaArgument` uses an `llvm::MutableArrayRef` to reference
the tensor values. This prevents temporary tensors from being used as
an argument, due to the data of the `TensorLambdaArgument` being
accessed after the destruction of the temporary.

This patch changes the type of the data field of
`TensorLambdaArgument` from `llvm::MutableArrayRef` to `std::vector`
and causes input data to be copied in order to guarantee that all data
remains available until invocation of the destructor.
2021-11-04 19:07:54 +01:00
Andi Drebes
a670ee3f85 enhance(compiler): Use const pointers in JITLambda::Arguments::setArg
All results in code compiled by zamacompiler are passed as return
values, which means that all tensors passed as function arguments are
constant inputs that are never written.

This patch changes the arguments used as data pointers for input
tensors in `JITLambda::Arguments::setArg()` from `void*` to `const
void*` to emphasize their use as inputs and to allow for constant
arrays to be passed as function inputs.
2021-11-04 19:07:54 +01:00
Andi Drebes
2033a70ad2 ci: Use ccache when building the project
In some cases, even small changes in zamacompiler lead to the
recompilation of the LLVM / MLIR sources, causing significant delay in
the CI. This change forces the use of ccache to speed up recompilation
after the project has been built at least once.
2021-11-04 16:01:27 +01:00
Andi Drebes
d6dc9874d9 enhance(compiler): Add support for ccache in Makefile
This adds a new variable `CCACHE` to `Makefile` that specifies whether
CMake is instructed upon configuration of the project to use the
default, plain C++ compiler or ccache as a wrapper.

By default, ccache is not used. To override the default value and
force the use of ccache, the variable `CCACHE` must be set to `ON`,
e.g., using `make CCACHE=ON`.
2021-11-04 16:01:27 +01:00
Andi Drebes
3d6ad06f46 test(compiler): Add tests for JitCompilerEngine::Lambda with a generic result 2021-11-03 18:32:06 +01:00
Andi Drebes
9040e5ab00 feat(compiler): Add generic overload for result of JitCompilerEngine::Lambda
This adds a new overload for `JitCompilerEngine::Lambda::operator()`,
returning a result wrapped in a `std::unique_ptr<LambdaArgument>` with
meta information about the result. This allows for generic invocations
of JitCompilerEngine::Lambda::operator(), where the result type is
unknown before the invocation.
2021-11-03 18:32:06 +01:00
Andi Drebes
1ad3d57f66 feat(compiler): Add method JITLambda::Argument::getResultType(size_t)
Add a method `JITLambda::Argument::getResultType(size_t pos)` that
returns the type of the result with the index `pos` of a
`JITLambda::Argument`.
2021-11-03 18:32:06 +01:00
youben11
97ee8134ed fix(python): register hlfhelinalg dialect 2021-11-03 15:37:43 +01:00
Andi Drebes
5999d402ec enhance(compiler): CompilerEngine: Forward parse errors instead of printing them
By default, `mlir::SourceMgrDiagnosticVerifierHandler` used by
`CompilerEngine::compile()` prints parse errors to
`llvm::errs()`. This makes it impossible for a caller of
`CompilerEngine::compile()` to process parse errors or to suppress the
emission of error messages to the standard error stream altogether.

This change captures parse errors in a string via a string-backed
output stream and forwards the error message in the `llvm::Error`
instance of the return value.
2021-11-03 12:05:12 +01:00
Andi Drebes
0cb5007c3c enhance(compiler): Python bindings: Forward llvm::Expected error messages in exceptions
The code in `lib/CAPI/Support/CompilerEngine.cpp` invokes several
functions returning an `llvm::Expected<T>`. When those fail, the error
message retrieved from the error object the `llvm::Expected<T>`
instance is written to the standard error stream via
`mlir::zamalang::log_error()` and an exception with a more generic
error message is thrown.

This causes errors to show up on the standard error stream in tests
generating errors on purpose and checking them, e.g.:

  ```
  tests/python/test_compiler_engine.py::test_compile_invalid[not
  @main] Compilation failed: cannot find the function for generate
  client parameters PASSED
  ```

This patch forwards the error message from an `llvm::Expected<T>`
instance in a runtime exception rather than writing it to the standard
error stream. Since exceptions are properly caught by the tests, no
errors show up during testing.
2021-11-02 16:34:42 +01:00
youben11
766b42fb49 feat(python): generate the hlfhelinalg dialect module 2021-11-02 11:45:18 +01:00
youben11
03c1588db4 chore: update to LLVM 8b7cc93e
major changes:
- https://llvm.discourse.group/t/psa-removed-arithmetic-ops-from-standard/4455
- use add_mlir_public_c_api_library helper to correctly add a CAPI library
2021-10-29 16:08:41 +01:00
Quentin Bourgerie
5bb58453aa feat(compiler): MANP Analysis of HLFHELinalg.apply_lookup_table (close #175) 2021-10-29 13:47:38 +02:00
Quentin Bourgerie
ccaf1bff15 feat(compiler): Lower HLFHELinalg.apply_lookup_table (close #174) 2021-10-29 13:47:38 +02:00
Quentin Bourgerie
2900c9a2a1 feat(compiler): Add support of HLFHELinalg binary operators in MANP pass (close #172) 2021-10-29 13:47:38 +02:00
Quentin Bourgerie
be92b4580d Merge branch 'master' into hlfhelinalg-binary-op-lowering 2021-10-29 13:47:35 +02:00
Quentin Bourgerie
e66fb20c4f test(compiler): Re introduce tests that was removed by a prior refacto 2021-10-29 13:44:34 +02:00
Quentin Bourgerie
85d102c9b2 refactor(compiler): Simplify the compiler flow and re enable --passes compiler option
No more need to compute the fhe context at high level
2021-10-29 13:44:34 +02:00
Quentin Bourgerie
41cba63113 refactor(compiler): Move the keyset generation from CompilerEngine to JitCompilerEngine 2021-10-29 13:44:34 +02:00
Andi Drebes
1187cfbd62 refactor(compiler): Refactor CompilerEngine and related classes
This commit contains several incremental improvements towards a clear
interface for lambdas:

  - Unification of static and JIT compilation by using the static
    compilation path of `CompilerEngine` within a new subclass
    `JitCompilerEngine`.

  - Clear ownership for compilation artefacts through
    `CompilationContext`, making it impossible to destroy objects used
    directly or indirectly before destruction of their users.

  - Clear interface for lambdas generated by the compiler through
    `JitCompilerEngine::Lambda` with a templated call operator,
    encapsulating otherwise manual orchestration of `CompilerEngine`,
    `JITLambda`, and `CompilerEngine::Argument`.

  - Improved error handling through `llvm::Expected<T>` and proper
    error checking following the conventions for `llvm::Expected<T>`
    and `llvm::Error`.

Co-authored-by: youben11 <ayoub.benaissa@zama.ai>
2021-10-29 13:44:34 +02:00
youben11
d738104c4b fix: use std::string for JIT entrypoint funcname
As we store the funcname for the entrypoint for later use, a pointer
might point to some random memory when used as there is no special
management for that name at the higher levels.
2021-10-29 13:44:34 +02:00
Andi Drebes
3ae924e174 enhance(compiler): Disable RTTI for unit tests
LLVM and MLIR are compiled without runtime type information
(RTTI). Use the same restrictions for unit tests to avoid linker
errors related to typeinfo when building the test executable.
2021-10-29 13:44:34 +02:00
Andi Drebes
e76aee7e10 feat(compiler): Add class StreamStringError with a stream interface for llvm::Error
Composing error messages for `llvm::Error` is either done by using
`llvm::createStringError()` with an appropriate format string and
arguments or by writing to a `std::string`-backed
`llvm::raw_string_ostream` and passing the result to
`llvm::make_error<llvm::StringError>()` verbatim.

The new class `StreamStringError` encapsulates the latter solution
into a class with an appropriate stream operator and implicit cast
operators to `llvm::Error` and `llvm::Expected`.

Example usage:

   llvm::Error foo(int i, size_t s, ...) {
      ...
      if(...) {
        return StreamStringError()
               << "Some error message with an integer: "
               << i << " and a size_t: " << s;
      }
      ...
   }
2021-10-29 13:44:34 +02:00
Andi Drebes
b12be45143 feat(compiler): Add method getResultVectorSize to JITLambda::Argument
Add method `JITLambda::Argument::getResultVectorSize` that returns the
number of elements of the result if the result is a vector.
2021-10-29 13:44:34 +02:00
Andi Drebes
d4b4839d6e fix(compiler): Take into account function parameters in MaxMANPPass
When determining the maximum MANP and precision, the `MaxMANPPass`
only takes into account results generated by an operation, but ignores
function parameters. However, encrypted function parameters are
assumed to have a MANP value of 1 and can have an arbitrary
precision. This patch takes into account function arguments by using
their default MANP values and the extracting their precision.
2021-10-29 13:44:34 +02:00
Andi Drebes
0423a05db8 feat(compiler): Add support for tensor.extract operations in MANP pass
Add support for `tensor.extract` operations in the MANP pass. This
currently only supports extract operations on tensors of encrypted
integers, which are passed as function arguments, e.g.:

 func @extract_ith(%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>
 }
2021-10-29 13:44:34 +02:00
Quentin Bourgerie
31d9f568fa refactor(test): Move HLFHELinalg e2e test 2021-10-29 12:18:30 +02:00
Quentin Bourgerie
a135d05e4d feat(compiler): Lowering of HLFHELinalg.mul_eint_int 2021-10-29 12:18:30 +02:00
Quentin Bourgerie
0b5ee3497a feat(compiler): Lowering of HLFHELinalg.sub_int_eint 2021-10-29 12:18:22 +02:00
Quentin Bourgerie
b81cb978d0 feat(compiler): Lowering of HLFHELinalg.add_eint_int 2021-10-29 12:17:38 +02:00
Quentin Bourgerie
a804e90291 fix(compiler): Fix lowering MidLFHE.add_glwe_int, the operand type can be already lowered 2021-10-29 12:17:38 +02:00
Quentin Bourgerie
ba54560680 feat(compiler): Lower HLFHELinalg binary operators 2021-10-29 12:17:38 +02:00
Quentin Bourgerie
dea1be9d52 feat(compiler): HLFHELinalg.apply_lookup_table definition 2021-10-29 12:17:38 +02:00
Quentin Bourgerie
f72d51d98d feat(compiler): HLFHELinalg.mul_eint_int 2021-10-29 12:17:38 +02:00
Quentin Bourgerie
64e327209f feat(compiler): HLFHELinalg.sub_int_eint 2021-10-29 12:17:32 +02:00