Commit Graph

37 Commits

Author SHA1 Message Date
youben11
01757fa6d5 fix: forward errors instead of creating new ones
LLVM errors should be handled/consumed. Creating a new one and leaving
the previous one alive will crash the compiler. Whenever we don't want a
crash (e.g. logging the error is enough), but still wanna continue the
execution, we can just consume it.
2021-10-12 11:50:15 +01:00
youben11
3406b322d5 fix: prefix builtin ops w/ builtin. 2021-10-07 14:38:50 +01:00
youben11
7a48900fae chore: build zamacompiler as an LLVM external proj 2021-10-07 14:38:50 +01:00
Andi Drebes
2acfa63eb7 feat(compiler): Determine FHE circuit constraints instead of using default values
This replaces the default FHE circuit constrains (maximum encrypted
integer width of 7 bits and a Minimal Arithmetic Noise Padding of 10
with the results of the `MaxMANP` pass, which determines these values
automatically from the input program.

Since the maximum encrypted integer width and the maximum value for
the Minimal Arithmetic Noise Padding can only be derived from HLFHE
operations, the circuit constraints are determined automatically by
`zamacompiler` only if the option `--entry-dialect=hlfhe` was
specified.

For lower-level dialects, `zamacompiler` has been provided with the
options `--assume-max-eint-precision=...` and `--assume-max-manp=...`
that allow a user to specify the values for the maximum required
precision and maximum values for the Minimal Arithmetic Noise Padding.
2021-09-28 11:35:58 +02:00
Andi Drebes
2ed1720234 bugfix(compiler): Do not apply offset of -1 to 2-norm in getV0Parameter
A value of 1 is perfectly valid for the 2-norm of the constant vector
of a dot operation. Hence, the log2 of that value of 0 is also
perfectly valid. However, the offset of -1 in `getV0Parameter` applied
to that value yields an offset into a static lookup table of -1, which
triggers a segmentation fault.

This patch removes the offset of -1 for the log2 value of the 2-norm
in `getV0Parameter`.
2021-09-28 11:35:58 +02:00
Andi Drebes
54661528a8 feat(compiler): Add action dump-hlfhe-manp
The new option --acion=dump-hlfhe-manp invokes the Minimal Arithmetic
Noise Padding Analysis pass based on the squared 2-norm metric from
`lib/Dialect/HLFHE/Analysis/MANP.cpp` and dumps the module afterwards
with an extra attribute `MANP` for each HLFHE operation.
2021-09-28 11:35:58 +02:00
Andi Drebes
30374ebb2c refactor(compiler): Introduce compilation pipeline with multiple entries / exits
This refactoring commit restructures the compilation pipeline of
`zamacompiler`, such that it is possible to enter and exit the
pipeline at different points, effectively defining the level of
abstraction at the input and the required level of abstraction for the
output.

The entry point is specified using the `--entry-dialect`
argument. Valid choices are:

  `--entry-dialect=hlfhe`:   Source contains HLFHE operations
  `--entry-dialect=midlfhe`: Source contains MidLFHE operations
  `--entry-dialect=lowlfhe`: Source contains LowLFHE operations
  `--entry-dialect=std`:     Source does not contain any FHE Operations
  `--entry-dialect=llvm`:    Source is in LLVM dialect

The exit point is defined by an action, specified using --action.

  `--action=roundtrip`:
     Parse the source file to in-memory representation and immediately
     dump as text without any processing

  `--action=dump-midlfhe`:
     Lower source to MidLFHE and dump result as text

  `--action=dump-lowlfhe`:
     Lower source to LowLFHE and dump result as text

  `--action=dump-std`:
     Lower source to only standard MLIR dialects (i.e., all FHE
     operations have already been lowered)

  `--action=dump-llvm-dialect`:
     Lower source to MLIR's LLVM dialect (i.e., the LLVM dialect, not
     LLVM IR)

  `--action=dump-llvm-ir`:
     Lower source to plain LLVM IR (i.e., not the LLVM dialect, but
     actual LLVM IR)

  `--action=dump-optimized-llvm-ir`:
     Lower source to plain LLVM IR (i.e., not the LLVM dialect, but
     actual LLVM IR), pass the result through the LLVM optimizer and
     print the result.

  `--action=dump-jit-invoke`:
     Execute the full lowering pipeline to optimized LLVM IR, JIT
     compile the result, invoke the function specified in
     `--jit-funcname` with the parameters from `--jit-args` and print
     the functions return value.
2021-09-28 11:35:58 +02:00
Andi Drebes
ddebedd1d6 refactor(compiler): Make function getV0Parameter return a pointer to a constant
The function `getV0Parameter()` returns a pointer to a static array,
which is not intended to be mutable. Reflect this in the return type
of the function.
2021-09-28 11:35:58 +02:00
Andi Drebes
6a76177a47 refactor(compiler): Move JIT functionality to separate source file 2021-09-28 11:35:58 +02:00
Andi Drebes
b9e2690823 refactor(compiler): Replace LOG_{VERBOSE,ERROR} macros with C++-style streams
Replace the macros `LOG_VERBOSE` and `LOG_ERROR` with C++-style
streams retrieved through `log_verbose()` and `log_error()`. This
aligns with the `MLIR` infrastructure and avoids pollution of the
global namespace through a common header file in subsequent
refactoring commits splitting the functionality of `src/main.cpp` into
multiple files.
2021-09-28 11:35:58 +02:00
Quentin Bourgerie
b4776a619d test(compiler): Reenable 7 bits test, we should change how the test are done to take care of the probability of exactness 2021-09-27 13:37:11 +02:00
Quentin Bourgerie
0f93fa1dcc fix(compiler/parameters): new parameters for v0 (p=0.99993 for 1-6 and 0.95 for 7) 2021-09-27 13:37:11 +02:00
Quentin Bourgerie
7454c30485 fix(compiler/parameters): Update parameters 2021-09-27 13:37:11 +02:00
Quentin Bourgerie
d9be22c1b1 fix(compiler/runtime): decode with integers 2021-09-27 13:37:11 +02:00
Quentin Bourgerie
3a254bcb87 fix(compiler): Integrate the security estimator to compute variances 2021-09-20 13:46:08 +02:00
Quentin Bourgerie
8cc0af1220 fix(compiler): Add a pass to unparametrize LowLFHE ciphertext to remove unrelized_convesrion_cast for linalg bufferization 2021-09-09 20:35:28 +02:00
youben11
746d991af6 refactor: ins forward decl w generic ty @pass-init
Insert forward declarations with generic types at pass initialization.
More docs for all the pass for lowering LUT
2021-09-09 20:35:28 +02:00
youben11
3893ad39bb fix: divide and round to decode decrypted ct
Doing a right shift will ommit the bits that can be used to round to the
nearest integer
2021-09-09 20:35:28 +02:00
youben11
c6b1480cc6 feat: generate runtime context at Argument creation 2021-09-09 20:35:28 +02:00
youben11
8aee5dd5c3 chore(runtime): link concrete statically with runtime lib 2021-09-09 20:35:28 +02:00
Quentin Bourgerie
d03adbd7dc enhance(compiler): Add options for verbose passes 2021-09-08 11:44:51 +02:00
Quentin Bourgerie
de7129fe8e feat(compiler/llvm-pipeline): Bufferize linalg and convert to loops 2021-09-08 11:44:51 +02:00
Quentin Bourgerie
697d4033e1 fix(compiler): typo 2021-09-06 10:26:40 +02:00
Quentin Bourgerie
af0789f128 enhance(compiler/runtime): Add runtime tools to handle tensor inputs and outputs 2021-09-06 10:26:40 +02:00
Quentin Bourgerie
bc975d904e feat(compiler): introduce bufferization passes in lowering pipeline to llvm 2021-09-06 10:26:40 +02:00
Quentin Bourgerie
19704b4b13 fix(compiler/lowlfhe): Use the lwe ciphertext parameters to allocate instead of global fhe context 2021-08-24 16:29:04 +02:00
Quentin Bourgerie
67f0fc0f45 enhance(compiler): Introduce MidLFHE dag parametrization 2021-08-24 16:21:31 +02:00
Quentin Bourgerie
8057ee7553 refactor(compiler): Prepare the MidLFHE parameters injection 2021-08-24 16:21:31 +02:00
youben11
f948db1228 feat(python): CompilerEngine to compile and run 2021-08-18 17:38:46 +02:00
Quentin Bourgerie
8796754513 fix(compiler/lowlfhe): Fix wrong shift value for EncodeIntOp lowering
That's work before because we enfoce 6 as global constraint while our runJit tests are on 7 bits
2021-08-16 18:54:56 +02:00
Quentin Bourgerie
42f12b22da fix(compiler): move the midlfhe to lowlfhe pass to the right place 2021-08-16 18:54:56 +02:00
Quentin Bourgerie
f45abce604 feat(compiler): More lowlfhe operators conversion to mlir std dialects 2021-08-16 18:54:56 +02:00
Quentin Bourgerie
03297fd50d fix(compiler/lowlfhe): for the v0 give the lweSize of ciphertext as a global parameter of the lowering pass to concrete api call (#62) 2021-08-16 18:54:56 +02:00
Quentin Bourgerie
b22f585380 feat(compiler): First draft of lowering from LowLFHE to std with fct call (#62) 2021-08-16 18:54:56 +02:00
Quentin Bourgerie
d0877536ed feat(compiler): First draft of client parameters generation, runtime support for encrypting and decrypting circuit gates, integration of fhe parameters for the v0 (#65, #66, #56) 2021-08-13 14:05:29 +02:00
youben11
4d3c7a68de feat(compiler): MidToLowLFHE lowering 2021-08-12 13:48:51 +01:00
Quentin Bourgerie
b4e57984b1 feat(compiler): Add passes to lower mlir to mlir llvm ir and run jit and emit llvm code (#63) 2021-08-05 13:43:08 +01:00