Commit Graph

81 Commits

Author SHA1 Message Date
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
Andi Drebes
cb580f16d2 feat(compiler): Add operation HLFHE.zero generating an encrypted zero 2021-08-17 16:53:32 +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
96c50d5dca fix/chore(docker/zamalang-env): Update to the latest concrete-api-env 2021-08-16 18:54:56 +02:00
Quentin Bourgerie
ed7dd36e70 fix(compiler): Remove the type conversion workaround, actually the order of addConversion calls matters (lifo) 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
Quentin Bourgerie
e290447389 chore(compiler): Get the concrete capi release 2021-08-13 14:05:29 +02:00
youben11
4d3c7a68de feat(compiler): MidToLowLFHE lowering 2021-08-12 13:48:51 +01:00
youben11
e401d9fb69 feat(compiler): update LowLFHE for MidLFHE lowering
-Encoding Cleartext to Plaintext Op
-Encoding Int to Plaintext Op
-Cleartext/Plaintext should add a bits field as `p`
-Op to create a constant Cleartext
-IntToCleartextOp: kind of casting an int to be later encoded, I'm not
sure if there is a better mechanism for this (e.g. auto casting in Ops),
but we currently need a way to encode int into plaintext, and we need to
go through cleartexts
2021-08-12 13:48:51 +01:00
youben11
3d8d5c438a refactor(compiler): generalize LinalgGenericPattern
also fixes an issue regarding populateWithGenerated, which can be
duplicated across different pattern files. So I redefined a different
function that is more unique to the pass that should be ran, and hide
the populateWithGenerated from the global namespace
2021-08-12 13:48:51 +01: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
6e86082807 test(compiler): Add testing for run-jit (#63) 2021-08-05 13:43:08 +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
youben11
c58abe6565 chore(ci): add python testing 2021-08-05 13:49:29 +02:00
youben11
0aa9f93e20 tests(python): compiler bindings. round_trip func 2021-08-05 13:49:29 +02:00
youben11
30d33ee45f feat(python): compiler api with round_trip func 2021-08-04 14:14:37 +02: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
youben11
59d9844bc2 chore(ci): update registry server url 2021-08-03 14:35:39 +01:00
youben11
89d16bbea7 chore(ci): update to GHCR to store mlir image 2021-08-03 14:23:15 +01:00
youben11
33f5911ac2 chore(ci): build zamalang image on push to master 2021-08-03 14:23:15 +01:00
youben11
3707f3a350 chore(ci): docker image for zamalang compiler 2021-08-03 08:53:26 +01: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
61382b3cdb chore(ci): Fixing mlir-env image to a specific commit since python bidings has been modified 2021-07-29 10:49:09 +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
Ayoub Benaissa
812268000c CI: docker image workflow
build and push whenever the docker file has changed. Push with two tags, latest, and commit's hash
2021-07-22 15:32:44 +02:00
Andi Drebes
4504f090c5 feat(compiler): Add option --convert-hlfhe-tensor-ops-to-linalg
This adds a new command line option
`--convert-hlfhe-tensor-ops-to-linalg` that invokes a conversion pass
replacing any HLFHE tensor operation with an appropriate instance of
`linalg.generic`.
2021-07-16 18:03:49 +02: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
27990a8302 feat(compiler): Add option --verify-diagnostics
The option `--verify-diagnostics` allows the user to interleave
invalid source code with diagnostic messages that should be produced
during parsing and checks if these messages are actually produced. The
expected diagnostic messages are specified using `// expected-error`
markers.
2021-07-16 18:03:49 +02:00
Andi Drebes
ee03a48447 feat(compiler): Add option --split-input-file
The new option `--split-input-file` allows the user to add `// -----`
markers to a source file, causing the file to be split into multiple
chunks that are treated as if they were specified in different files.
2021-07-16 18:03:49 +02:00
Andi Drebes
74671794e3 refactor(compiler): Use idiomatic approach for I/O management
Use a more idiomatic approach for I/O using `llvm::SourceManager` to
manage input files and `mlir::openOutputFile` to write to the
output. This commit prepares management of diagnostics in subsequent
changes.
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
Andi Drebes
3bfda58eb8 feat(compiler): Make HLFHE.EncryptedInteger usable as memref element type
Make `HLFHE.EncryptedInteger` implement the
`MemRefElementTypeInterface` trait to allow the type to be used for
elements of memrefs.

The invocation of the `add_mlir_dialect` macro in
`include/zamalang/Dialect/HLFHE/IR/CMakeLists.txt` had to be broken
into its parts in order to pass `-typedefs-dialect=HLFHE` to
`mlir-tablegen`. This is required due to the inclusion of
`mlir/IR/BuiltinTypes.td` in
`include/zamalang/Dialect/HLFHE/IR/HLFHETypes.td`, resulting in
definitions from multiple dialects.

Add a small test actually using `HLFE.EncryptedInteger` in a `memref`.
2021-06-23 10:15:35 +02:00
Quentin Bourgerie
3aa5457b84 fix(compiler): Fixing some typos 2021-06-23 10:10:31 +02:00
Quentin Bourgerie
a760ade545 enhance(compiler): Better error message for glwe error 2021-06-23 10:10:31 +02:00
Quentin Bourgerie
c783d85a84 doc(compiler): comments on MidLFHE verifiers 2021-06-23 10:10:31 +02:00
Quentin Bourgerie
8f73863e00 fix(compiler): Fixing MidLFHE.h_add verifier and adding tests 2021-06-23 10:10:31 +02:00
Quentin Bourgerie
4e41969f3e test(compiler): Add another test for mul_plain padding verification 2021-06-23 10:10:31 +02:00
Quentin Bourgerie
aafc9e44e9 fix(compiler): Fixing test ref 2021-06-23 10:10:31 +02:00