Commit Graph

67 Commits

Author SHA1 Message Date
youben11
b953d57fe4 feat(compiler): warn when there is overflow in sim (native encoding) 2024-05-15 10:53:42 +01:00
Umut
6e36d0f801 feat(compiler): tensor.generate to scf.forall 2024-05-15 11:21:46 +03:00
Antoniu Pop
a431c9d4ef feat(compiler): [GPU backend] enable parallel loop collapsing for GPU backend using batching and fix loop coalescing infrastructure in MLIR to allow operation before bufferization. 2024-05-03 11:58:56 +01:00
Alexandre Péré
d033102a3c feat(optimizer): allow circuit manipulation in optimizer dag 2024-04-30 10:16:52 +02:00
Bourgerie Quentin
676a787ff2 fix(compiler): Use concrete-cpu function to compute key size in compilation feedbacks 2024-04-18 14:55:43 +02:00
Miles
5d68424531 fix typos 2024-04-11 14:50:16 +02:00
Andi Drebes
d620fa9a44 feat(compiler): Add pass hoisting RT.await_future out of scf.forall loops
The new pass hoists `RT.await_future` operations whose results are
yielded by scf.forall operations out of the loops in order to avoid
over-synchronization of data-flow tasks.

E.g., the following IR:

```
scf.forall (%arg) in (16)
  shared_outs(%o1 = %sometensor, %o2 = %someothertensor)
  -> (tensor<...>, tensor<...>)
{
  ...
  %rph = "RT.build_return_ptr_placeholder"() :
    () -> !RT.rtptr<!RT.future<tensor<...>>>
  "RT.create_async_task"(..., %rph, ...) { ... } : ...
  %future = "RT.deref_return_ptr_placeholder"(%rph) :
    (!RT.rtptr<!RT.future<...>>) -> !RT.future<tensor<...>>
  %res = "RT.await_future"(%future) : (!RT.future<tensor<...>>) -> tensor<...>
  ...
  scf.forall.in_parallel {
    ...
    tensor.parallel_insert_slice %res into %o1[..., %arg2, ...] [...] [...] :
      tensor<...> into tensor<...>
    ...
  }
}
```

is transformed into:

```
%tensoroffutures = tensor.empty() : tensor<16x!RT.future<tensor<...>>>

scf.forall (%arg) in (16)
  shared_outs(%otfut = %tensoroffutures, %o2 = %someothertensor)
  -> (tensor<...>, tensor<...>)
{
  ...
  %rph = "RT.build_return_ptr_placeholder"() :
    () -> !RT.rtptr<!RT.future<tensor<...>>>
  "RT.create_async_task"(..., %rph, ...) { ... } : ...
  %future = "RT.deref_return_ptr_placeholder"(%rph) :
    (!RT.rtptr<!RT.future<...>>) -> !RT.future<tensor<...>>
  %wrappedfuture = tensor.from_elements %future :
    tensor<1x!RT.future<tensor<...>>>
  ...
  scf.forall.in_parallel {
    ...
    tensor.parallel_insert_slice %wrappedfuture into %otfut[%arg] [1] [1] :
      tensor<1xRT.future<tensor<...>>> into tensor<16x!RT.future<tensor<...>>>
    ...
  }
}

scf.forall (%arg) in (16) shared_outs(%o = %sometensor) -> (tensor<...>) {
  %future = tensor.extract %tensoroffutures[%arg] :
    tensor<4x!RT.future<tensor<...>>>
  %res = "RT.await_future"(%future) : (!RT.future<tensor<...>>) -> tensor<...>
  scf.forall.in_parallel {
    tensor.parallel_insert_slice %res into %o[..., %arg, ...] [...] [...] :
      tensor<...> into tensor<...>
  }
}
```
2024-04-08 16:16:07 +02:00
Andi Drebes
5c81882704 feat(compiler): Add new action dump-fhe-df-parallelized
This adds a new option `dump-fhe-df-parallelized` to
`concretecompiler` that dumps the IR after the generation of data-flow
tasks.
2024-04-08 12:02:49 +02:00
Umut
d13b283f98 feat(frontend-python): disable and print tlu fusing 2024-03-19 09:39:06 +01:00
Andi Drebes
d79c76a872 feat(compiler): Add support for tiling of linalg.generic operations
This adds support for the tiling of `linalg.generic` operations that
have only parallel iterators or only parallel iterators and a single
reduction dimension via the linalg tiling infrastructure (i.e.,
`mlir::linalg::tileToForallOpUsingTileSizes()` and
`mlir::linalg::tileReductionUsingForall()`).

This allows for the tiling of FHELinalg operations by first replacing
them with appropriate `linalg.generic` oeprations and then invoking
the tiling pass in the pipeline. In order for the tiling to take
place, tile sizes must be specified using the `tile-sizes` operation
attribute, either directly for `linalg.generic` operations or
indirectly for the FHELinalg operation, e.g.,

  "FHELinalg.matmul_eint_int"(%a, %b) { "tile-sizes" = [0, 0, 7] } : ...

Tiling of operations with a reduction dimension is currently limited
to tiling of the reduction dimension, i.e., the tile sizes for the
parallel dimensions must be zero.
2024-03-14 06:45:53 +01:00
Andi Drebes
55d54a9c7f feat(compiler): Add pass replacing linalg.fill with linalg.generic 2024-03-14 06:32:19 +01:00
Andi Drebes
ff20f88c44 feat(compiler): Run SCFForallToSCFFor pass before lowering to LLVM dialect
This adds an invocation of the `SCFForallToSCFFor` pass to the
compilation pipeline before lowering to the LLVM dialect as a
sequential fallback path to future passes exploiting the parallelism
of `scf.forall` further up in the pipeline.
2024-03-14 06:32:19 +01:00
Andi Drebes
7a295f89bd feat(compiler): Make trip counts and memory usage optional in statistics passes
This makes the trip counts of operations in the TFHE statistics pass
as well as the per-location memory usage statistics in the memory
usage statistics pass optional. These values are unset if the trip
count could not be determined statically.
2024-03-14 06:32:19 +01:00
Benoit Chevallier-Mames
e37a840e7e docs(compiler): adding API doc 2024-03-13 17:10:00 +01:00
Bourgerie Quentin
6b4ce8889b feat(compiler): Add input ciphertext compression with seeded ciphertext 2024-03-12 16:57:06 +01:00
Andi Drebes
9b6878316f fix(compiler): Preserve explicit optimizer partition boundaries through the pipeline
The Concrete Optimizer is invoked on a representation of the program
in the high-level FHELinalg / FHE Dialects and yields a solution with
a one-to-one mapping of operations to keys. However, the abstractions
used by these dialects do not allow for references to keys and the
application of the solution is delayed until the pipeline reaches a
representation of the program in the lower-level TFHE dialect. Various
transformations applied by the pipeline along the way may break the
one-to-one mapping and add indirections into producer-consumer
relationships, resulting in ambiguous or partial mappings of TFHE
operations to the keys. In particular, explicit frontiers between
optimizer partitions may not be recovered.

This commit preserves explicit frontiers between optimizer partitions
as `optimizer.partition_frontier` operations and lowers these to
keyswitch operations before parametrization of TFHE operations.
2024-03-07 15:42:26 +01:00
Andi Drebes
a701b3a742 feat(compiler): Add support for tensor.empty in the pipeline from FHE to std 2024-03-06 14:50:27 +01:00
Alexandre Péré
9b5a2e46da feat(compiler): support multi-circuit compilation 2024-03-01 15:35:52 +01:00
Andi Drebes
21a7eead6c refactor(compiler): Re-implement TFHE multi-parameter parametrization with type inference
The current pass applying the parameters determined by the optimizer
to the IR propagates the parametrized TFHE types to operations not
directly tagged with an optimizer ID only under certain conditions. In
particular, it does not always properly propagate types into nested
regions (e.g., of `scf.for` loops).

This burdens preceding transformations that are applied in between the
invocation of the optimizer and the parametrization pass with
data-flow analysis and book-keeping in order to tag newly inserted
operations with the right optimizer IDs that ensure proper
parametrization.

This commit replaces the current parametrization pass with a new pass
that propagates parametrized TFHE types up and down def-use chains
using type inference and a proper rewriter. The pass is limited to the
operations supported by `TFHEParametrizationTypeResolver::resolve`.
2024-02-01 16:18:45 +01:00
Andi Drebes
775171c69d fix(compiler): Run canonicalizer after TFHE circuit parametrization
In order to avoid leftover TFHE operations to be lowered further down
the pipeline after parametrization, run the canonicalizer, which
includes dead code eliminiation.
2024-02-01 16:18:45 +01:00
Andi Drebes
79d8337026 feat(compiler): Add support for batched keyswitch ops in TFHE key normalization 2024-02-01 16:18:45 +01:00
rudy
c298408f26 feat(optimizer): multi-parameters, partitionning using norm2 2024-01-08 20:32:27 +01:00
Bourgerie Quentin
f9c7a79183 refactor(compiler/frontend): Rename option to compress_evaluation_keys 2024-01-08 09:49:06 +01:00
Bourgerie Quentin
f3ec1976ef fix(compiler/optimizer): Returns NotComposable error if not lookup table in dag 2024-01-04 15:00:25 +01:00
Alexandre Péré
60da713312 feat(optimizer): adds support for function composition 2024-01-04 15:00:25 +01:00
Bourgerie Quentin
c67fac4082 feat(compiler): Introduce input compression and use tfhe-rs as backend
- added --compress-input compiler option which forces the use of seeded
  bootstrap keys and keyswitch keys
- replaced the concrete-cpu FHE implementation with tfhe-rs

Co-authored-by: Nikita Frolov <nf@mkmks.org>
2023-12-22 15:51:02 +01:00
Alexandre Péré
e8ef48ffd8 feat(compiler): introduce concrete-protocol
This commit:
 + Adds support for a protocol which enables inter-op between concrete,
   tfhe-rs and potentially other contributors to the fhe ecosystem.
 + Gets rid of hand-made serialization in the compiler, and
   client/server libs.
 + Refactors client/server libs to allow more pre/post processing of
   circuit inputs/outputs.

The protocol is supported by a definition in the shape of a capnp file,
which defines different types of objects among which:
 + ProgramInfo object, which is a precise description of a set of fhe
   circuit coming from the same compilation (understand function type
   information), and the associated key set.
 + *Key objects, which represent secret/public keys used to
   encrypt/execute fhe circuits.
 + Value object, which represent values that can be transferred between
   client and server to support calls to fhe circuits.

The hand-rolled serialization that was previously used is completely
dropped in favor of capnp in the whole codebase.

The client/server libs, are refactored to introduce a modular design for
pre-post processing. Reading the ProgramInfo file associated with a
compilation, the client and server libs assemble a pipeline of
transformers (functions) for pre and post processing of values coming in
and out of a circuit. This design properly decouples various aspects of
the processing, and allows these capabilities to be safely extended.

In practice this commit includes the following:
 + Defines the specification in a concreteprotocol package
 + Integrate the compilation of this package as a compiler dependency
   via cmake
 + Modify the compiler to use the Encodings objects defined in the
   protocol
 + Modify the compiler to emit ProgramInfo files as compilation
   artifact, and gets rid of the bloated ClientParameters.
 + Introduces a new Common library containing the functionalities shared
   between the compiler and the client/server libs.
 + Introduces a functional pre-post processing pipeline to this common
   library
 + Modify the client/server libs to support loading ProgramInfo objects,
   and calling circuits using Value messages.
 + Drops support of JIT.
 + Drops support of C-api.
 + Drops support of Rust bindings.

Co-authored-by: Nikita Frolov <nf@mkmks.org>
2023-11-09 17:09:04 +01:00
youben11
88dd13756a feat(compiler): support linalg.generic in the MANP Analysis 2023-10-03 16:17:27 +01:00
rudy
d64c9b0f25 fix(optimizer): multi-parameters, shorter_dump for the compiler --display-optimizer-choice 2023-09-25 15:55:22 +02:00
rudy
90e62f551b feat(optimizer): multi-params, key sharing 2023-09-19 12:13:25 +02:00
aPere3
1e726a50ed feat(compiler): add support for dynamic luts in compiler. 2023-09-11 10:29:59 +02:00
Alexandre Péré
083ab1103f chore(compiler): moves EncryptMulToDoubleTLU includes 2023-09-11 10:29:59 +02:00
rudy
229bbc2327 fix(compiler): do not optimize llvm twice 2023-09-08 15:26:24 +02:00
rudy
74c4a7eae5 fix(compiler): check minimal lwe size 2023-09-08 14:26:32 +02:00
rudy
4244ae3b41 fix(compiler): explicit global_p_error disable high error warning 2023-09-07 09:20:37 +02:00
youben11
530bacb2e3 refactor(compiler): clean statistic passes 2023-09-04 09:22:28 +01:00
youben11
54089186ae refactor(compiler): reorganize passes and add memory usage pass 2023-08-29 15:47:25 +01:00
youben11
d88b2c87ac feat(compiler): compute memory usage per location 2023-08-29 15:47:25 +01:00
Umut
ade83d5335 feat(compiler): add more detailed statistics 2023-08-01 18:40:08 +02:00
Umut
79b38a72ec feat(compiler): provide circuit statistics 2023-07-26 11:08:15 +02:00
Umut
d1b004c87d fix(compiler): move simulation before batching 2023-07-26 11:08:15 +02:00
rudy
885d25424d fix(compiler): revert Workaround fallback to Strategy::V0 when solving with Strategy::DAG_MONO
This reverts commit caee0bae66.
2023-07-24 18:07:59 +02:00
youben11
022b1879a1 feat(compiler): support compiling in-memory module 2023-07-21 14:14:55 +01:00
Antoniu Pop
5082cea110 fix(compiler): disable dataflow parallelization when the optimiser strategy is dag-multi. Currently the two don't work well together because dataflow task outlining obfuscates the code early on in the compilation pipeline. 2023-07-20 14:39:28 +01:00
youben11
32ad46f7c5 feat(compiler): disable runtimeCtx pass in simulation 2023-06-27 14:21:42 +01:00
youben11
b8e462c1cc feat(compiler): add option to compile in simulation mode 2023-06-27 14:21:42 +01:00
youben11
e58b46d86d feat(compiler): add a pass to simulate TFHE ops
lowering is done to CAPI calls that implement simulation as well as
standard MLIR ops
2023-06-27 14:21:42 +01:00
Ayoub Benaissa
3bdebae1f6 fix(compiler): fix plaintext tensor shape when using crt
client parameter generation was removing last dimension of a tensor when using CRT including plaintext ones, while it should only be done for encrypted ones.
2023-06-21 12:14:11 +01:00
Mayeul@Zama
97b13e871c feat(optimizer): introduce fft precision 2023-06-15 10:48:07 +02:00
Mayeul@Zama
5659195dbc feat(optimizer): accept any ciphertext_modulus_log 2023-06-15 10:48:07 +02:00