Commit Graph

65 Commits

Author SHA1 Message Date
Andi Drebes
4883eebfa3 feat(compiler): Add HLFHELinalg.zero operation
Add a new operation `HLFHELinalg.zero`, broadcasting an encrypted,
zero-valued integer into a tensor of encrypted integers with static
shape.

Example creating a one-dimensional tensor with five elements all
initialized to an encrypted zero:

  %tensor = "HLFHELinalg.zero"() : () -> tensor<5x!HLFHE.eint<4>>
2021-12-01 11:24:27 +01:00
Quentin Bourgerie
ddbafd713d feat(compiler): Add the HLFHELinalg.matmul_int_eint operator 2021-11-24 09:19:25 +01:00
Quentin Bourgerie
100862e484 feat(compiler): Add the support of linalg.tensor_expand_shape and linalg.tensor_collapse_shape on encrypted tensors 2021-11-17 14:19:15 +01:00
youben11
ac7f1f5a6b feat(compiler): add HLFHELinalg.apply_multi_lut
Apply a lookup table on the different elements of the encrypted tensors,
but using different lookup tables.

MANP support as well as tests
2021-11-15 11:25:44 +01:00
Quentin Bourgerie
5df775a51b feat(compiler): MANP Analysis of HLFHELinalg.matmul (closes #178) 2021-11-12 16:50:29 +01:00
Quentin Bourgerie
12b4771405 feat(compiler/linalg): Definition of HLFHELinalg.matmul_eint_int (closes #176) 2021-11-12 16:50:29 +01:00
youben11
a888a6b329 typo: bad function name 2021-11-10 15:24:31 +01:00
youben11
99d6d11616 feat(compiler): support HLFHELinalg.neg_eint in MANP 2021-11-10 15:24:31 +01:00
youben11
d9adbab036 feat(compiler): add HLFHELinalg.neg_eint op 2021-11-10 15:24:31 +01:00
youben11
efacd7d8a1 feat(compiler): support HLFHE.neg_eint in MANP 2021-11-10 15:24:31 +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
rudy
97389a3b06 Move HLFHE.dot_eint_int to HLFHELinalg.
Resolves #183
2021-11-09 11:39:08 +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
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
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
dea1be9d52 feat(compiler): HLFHELinalg.apply_lookup_table definition 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
Quentin Bourgerie
3b02a16f7b feat(compiler): HLFHELinalg.add_eint definition 2021-10-29 12:16:41 +02:00
Quentin Bourgerie
0d4e10169b feat(compiler): Introduce the HLFHELinalg dialect and a first operator HLFHELinalg.add_eint_int 2021-10-29 12:16:41 +02:00
Quentin Bourgerie
1c202ebaff enhance(compiler): Support of tensor operators in MANP pass (close #169) 2021-10-20 16:21:52 +02:00
Quentin Bourgerie
966160bc2c fix(compiler): apply_lookup_table operators take tensor of i64
We decide to make this choice as they are issue to crate tensor of custom integer type in python.
+ we don't do the integer extension before convert to the concrete CAPI that requires i64
2021-10-13 10:28:35 +02:00
youben11
ebdc95f827 chore: update llvm and fix API breaks 2021-10-08 12:11:34 +01:00
Andi Drebes
5ce3fd5f43 refactor(compiler): Move ceilLog2 to separate header file 2021-09-28 11:35:58 +02:00
Andi Drebes
1200a46e49 feat(compiler): Add HLFHE pass selecting maximum MANP and encrypted integer width
This pass calculates the squared Minimal Arithmetic Noise Padding
(MANP) for each operation using the MANP pass and extracts the maximum
(non-squared) Minimal Arithmetic Noise Padding and the maximum
ecrypted integer width from.
2021-09-28 11:35:58 +02:00
Andi Drebes
ed762942c1 feat(compiler): Add pass for Minimal Arithmetic Noise Padding
This pass calculates the squared Minimal Arithmetic Noise Padding
(MANP) for each operation of a function and stores the result in an
integer attribute named "sqMANP". This metric is identical to the
squared 2-norm of the constant vector of an equivalent dot product
between a vector of encrypted integers resulting directly from an
encryption and a vector of plaintext constants.

The pass supports the following operations:

 - HLFHE.dot_eint_int
 - HLFHE.zero
 - HLFHE.add_eint_int
 - HLFHE.add_eint
 - HLFHE.sub_int_eint
 - HLFHE.mul_eint_int
 - HLFHE.apply_lookup_table

If any other operation is encountered, the pass conservatively
fails. The pass further makes the optimistic assumption that all
values passed to a function are either the direct result of an
encryption of a noise-refreshing operation.
2021-09-28 11:35:58 +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
5f16cfabbf fix(Runtime): link missing libraries
We currently use LD_PRELOAD with the python extension to make the JIT
execution find the appropriate symbols, however, not linking with some
libraries caused other tools such as make to complain of not finding
symbols from libpthread and others
2021-09-09 20:35:28 +02:00
youben11
50d2ff82af chore(compiler): disable bitwidth check for table lookup 2021-09-09 20:35:28 +02:00
Quentin Bourgerie
70fb5fcd8e fix(compiler/midlfhe): Change constraint on operators with integers (just too large integers are forbidden) 2021-08-24 16:21:31 +02:00
Quentin Bourgerie
fa62e1f0e5 refactor(compiler): Move memref HLFHE and MidLFHE operators to tensor 2021-08-18 11:15:30 +02:00
Quentin Bourgerie
7372cd3d0a fix(compiler/hlfhe): More verification on dot_eint_int 2021-08-17 16:53:32 +02:00
Andi Drebes
8b9c9f2da1 refactor(compiler): HLFHE.dot_eint_int: Switch from reference to value semantics
This changes the semantics of `HLFHE.dot_eint_int` from memref-based
reference semantics to tensor-based value semantics. The former:

  "HLFHE.dot_eint_int"(%arg0, %arg1, %arg2) :
     (memref<Nx!HLFHE.eint<0>>, memref<Nxi32>, memref<!HLFHE.eint<0>>) -> ()

becomes:

  "HLFHE.dot_eint_int"(%arg0, %arg1) :
     (tensor<Nx!HLFHE.eint<0>>, tensor<Nxi32>) -> !HLFHE.eint<0>

As a side effect, data-flow analyses become much easier. With the
previous memref type of the plaintext argument it is difficult to
check whether the plaintext values are statically defined constants or
originate from a memory region changed at execution time (e.g., for
analyses evaluating the impact on noise). Changing the plaintext type
from `memref` to `vector` makes such analyses significantly easier.
2021-08-17 16:53:32 +02:00
Ayoub Benaissa
7a2511b3d4 feat(compiler): LowLFHE dialect (#77)
* feat(compiler): low level fhe dialect

* feat(compiler): using generated printer/parser in LowLFHE

* feat(compiler): new types and ops for LowLFHE

* tests(compiler): LowLFHE types and ops

* feat(compiler): fill ops

* cleanup

* summary + description

* tests(compiler): use new CLI args

* formatting
2021-08-05 14:32:46 +01:00
Quentin Bourgerie
4e6579e019 feat/refactor(compiler): Add --passes options to activate only a subset of passes (#57) 2021-08-04 14:03:05 +02:00
Quentin Bourgerie
1605551f1a feat(compiler): HLFHEToMidLFHE pass (#57) 2021-08-04 14:03:05 +02:00
Quentin Bourgerie
ed40b1ef91 feat(compiler): Add HLFHE.sub_int_eint (#54) 2021-08-03 09:23:11 +02:00
Quentin Bourgerie
143a2384fd enhance(compiler): Add verifier of HLFHE operators 2021-08-03 09:23:11 +02:00
Quentin Bourgerie
cb635f8a55 feat(compiler): HLFHE.apply_lookup_table (#54) 2021-08-03 09:23:11 +02:00
Quentin Bourgerie
ea77ee696a enhance(compiler): Add verify for HLFHE.eint, precision ]0;7] (#54) 2021-08-03 09:23:11 +02:00
Quentin Bourgerie
3c326c09d6 clean(compiler): Remove unecessary operators for compiler v0 (#54) 2021-08-03 09:23:11 +02:00
Quentin Bourgerie
be62755401 fix(compiler): Fixing MidLFHE Dialect for the compiler v0 2021-07-29 09:53:45 +02:00
Ayoub Benaissa
ab53ef71c6 feat(compiler): Python bindings (#53)
- feat(compiler): python bindings
- build: update docker image for python bindings
- pin pybind11 to 2.6.2, 2.7 is not having correct include_dirs set (still
a question why?)
- using generated parser/printer
2021-07-28 15:58:51 +01:00
Andi Drebes
9d1cdc6a0c feat(compiler): Add lowering pass from HLFHE.dot_eint_int to linalg.generic
This pass transforms any instance of `HLFHE.dot_eint_int` to an
instance of `linalg.generic` with an appropriate region using
`HLFHE.mul_eint_int` and `HLFHE.add_eint` operations and an
appropriate specification for the iteration dimensions.

Example:

  "HLFHE.dot_eint_int"(%arg0, %arg1, %arg2) :
    (memref<?x!HLFHE.eint<0>>, memref<?xi32>, memref<!HLFHE.eint<0>>) -> ()

becomes:

  linalg.generic {
    indexing_maps = [affine_map<(d0) -> (d0)>,
                     affine_map<(d0) -> (d0)>,
		     affine_map<(d0) -> ()>],
    iterator_types = ["reduction"]
  } ins(%arg0, %arg1 : memref<?x!HLFHE.eint<0>>, memref<?xi32>) outs(%arg2 : memref<!HLFHE.eint<0>>) {
    ^bb0(%arg3: !HLFHE.eint<0>, %arg4: i32, %arg5: !HLFHE.eint<0>):  // no predecessors
      %0 = "HLFHE.mul_eint_int"(%arg3, %arg4) : (!HLFHE.eint<0>, i32) -> !HLFHE.eint<0>
      %1 = "HLFHE.add_eint"(%0, %arg5) : (!HLFHE.eint<0>, !HLFHE.eint<0>) -> !HLFHE.eint<0>
      linalg.yield %1 : !HLFHE.eint<0>
  }
2021-07-16 18:03:49 +02:00
Andi Drebes
b433627821 feat(compiler): Add Dot operation to HLFHE dialect
Add a simple dot product between a vector of encrypted integers and a
vector of plaintext integers to the HLFHE dialect.

The operation takes two input operands and one output operand, all
modeled as memrefs. Example:

  "HLFHE.dot_eint_int"(%lhs, %rhs, %out) :
    (memref<?x!HLFHE.eint<0>>, memref<?xi32>, memref<!HLFHE.eint<0>>) -> ()
2021-07-16 18:03:49 +02:00
Andi Drebes
cef0e569d4 fix(compiler): Generate and include autogenerated dialect definitions (#52)
* fix(compiler): Generate and include autogenerated dialect definitions

Since commit 485cc55edfb875628e19bb6d9de4706af2865d3e in llvm-project,
dialects are now required to include a file with autogenerated
definitions. This commit generates the definition files and includes
them in appropriate dialect source files for MidLFHE and HLFHE.

* CI: update docker image ref

Co-authored-by: Andi Drebes <andi.drebes@zama.ai>
Co-authored-by: Ayoub Benaissa <ayoub.benaissa@zama.ai>
2021-07-08 15:54:10 +01:00
Quentin Bourgerie
3aa5457b84 fix(compiler): Fixing some typos 2021-06-23 10:10:31 +02:00