Commit Graph

482 Commits

Author SHA1 Message Date
Andi Drebes
fd362342f5 fix(compiler): Batching: Emit collapse/expand shape operations only for rank > 1
The batching pass passes operands to the batched operation as a flat,
one-dimensional vector produced through a `tensor.collapse_shape`
operation collapsing all dimensions of the original tensor of
operands. Similarly, the shape of the result vector of the batched
operation is expanded to the original shape afterwards using a
`tensor.expand_shape` operation.

The pass emits the `tensor.collapse_shape` and `tensor.expand_shape`
operations unconditionally, even for tensors, which already have only
a single dimension. This causes the verifiers of these operations to
fail in some cases, aborting the entire compilation process.

This patch lets the batching pass emit `tensor.collapse_shape` and
`tensor.expand_shape` for batched operands and batched results only if
the rank of the corresponding tensors is greater than one.
2022-11-21 14:53:43 +01:00
rudy
a8e2724b69 fix: use less error prone json parsing for CompilationFeedback
Both the error message and the type were wrong for complexity
2022-11-18 17:27:07 +01:00
Mayeul@Zama
0657767bae style(cmake): run format_cmake.sh 2022-11-18 15:15:41 +01:00
Andi Drebes
46366eec41 feat(compiler): Add fallback implementations for batched keyswitch and bootstrap
Add default implementations for batched keyswitch and bootstrap, which
simply call the scalar versions of these operations in a loop.
2022-11-18 12:06:07 +01:00
Andi Drebes
9f153d2129 feat(compiler): ConcreteToBConcrete: Add patterns for batched keyswitch and bootstrap 2022-11-18 12:06:07 +01:00
Andi Drebes
c9bb6541e9 feat(compiler): Add option --batch-concrete-ops and action dump-concrete-with-loops
The new option `--batch-concrete-ops` invokes the batching pass after
lowering to the Concrete dialect and after lowering linalg operations
with operations from the Concrete dialect to loops.

The new action `dump-concrete-with-loops` dumps the IR right before
batching.
2022-11-18 12:06:07 +01:00
Andi Drebes
c367a4b6fd feat(compiler): Add batching pass
This adds a new pass that is able to hoist operations implementing the
`BatchableOpInterface` out of a loop nest that applies the operation
to the elements of a tensor indexed by the loop induction variables.

Example:

  scf.for %i = c0 to %cN step %c1 {
    scf.for %j = c0 to %cM step %c1 {
      scf.for %k = c0 to %cK step %c1 {
        %s = tensor.extract %T[%i, %j, %k]
        %res = batchable_op %s
        ...
      }
    }
  }

is replaced with:

  %batchedSlice = tensor.extract_slice
       %T[%c0, %c0, %c0] [%cN, %cM, %cK] [%c1, %c1, %c1]
  %flatSlice = tensor.collapse_shape %batchedSlice
  %resTFlat = batchedOp %flatSlice
  %resT = tensor.expand_shape %resTFlat

  scf.for %i = c0 to %cN step %c1 {
    scf.for %j = c0 to %cM step %c1 {
      scf.for %k = c0 to %cK step %c1 {
        %res = tensor.extract %resT[%i, %j, %k]
        ...
      }
    }
  }

Every index of the tensor with the input values may be a quasi-affine
expression on a single loop induction variable, as long as the
difference between the results of the expression for any two
consecutive values of the referenced loop induction variable is
constant.
2022-11-18 12:06:07 +01:00
Andi Drebes
3ce7c96f3f feat(compiler): Add operation interface for batchable operations
This adds a new operation interface that allows an operation to
specify that a batched version of the operation exists that applies it
on the elements of a flat tensor in parallel.
2022-11-18 12:06:07 +01:00
youben11
52d5d908bb test(rust): complete tests of rust bindings
updated also the API to make it easier to use by:
- creating MLIR components from native rust types instead of require
  MLIR components in the API
- adding helpers around the creation of standard dialects
2022-11-17 09:54:51 +01:00
youben11
5b46a74b7f feat(CAPI): API to get the width of an eint/esint 2022-11-17 09:54:51 +01:00
youben11
5576d1d176 feat(CAPI): expose encrypted signed int in CAPI 2022-11-17 09:54:51 +01:00
youben11
0a57af37af feat(rust): add API for FHEDialect's op creation 2022-11-17 09:54:51 +01:00
youben11
ff3f1afd59 refactor(rust): separate API into modules
- mlir module contains the MLIR API and generic helper functions
- fhe module contains helper functions for the FHE dialect
2022-11-17 09:54:51 +01:00
youben11
5e1a6f0069 feat(rust): complete FHE dialect API
helper functions to create all operations of the FHE dialect
2022-11-17 09:54:51 +01:00
Luis Montero
aad2a42634 chore(ffi): support ARM64 chips 2022-11-17 01:04:36 +01:00
Samuel Tap
8a231974f7 chore(ffi): update to concrete-ffi without fftw 2022-11-16 11:44:46 +01:00
Mayeul@Zama
aaad84ee63 chore(compiler): fix string-conversion 2022-11-14 14:04:46 +01:00
Mayeul@Zama
2a6d1958fd chore(compiler): remove unused loopParallelize 2022-11-14 14:04:46 +01:00
Mayeul@Zama
dd62896bc8 chore(compiler): fix pessimizing-move 2022-11-14 14:04:46 +01:00
youben11
472e762fbf feat(rust): enhance API to create func with FHE dialect 2022-11-09 12:53:25 +01:00
youben11
eabd8b959d fix(CAPI): remove Cpp code from CAPI
this required to have a CAPI that when asked for types, returns a
structure that can report if an error was faced during type creation.
This is required since a failure at that stage in the compiler would
lead to a segfault in the python bindings for example, and we want to be
able to handle this scenario gracefully.
2022-11-09 12:53:25 +01:00
Antoniu Pop
dfe2e5e076 fix(runtime): remove logging the thread to HW bind map for dataflow workers. 2022-11-07 09:22:21 +00:00
rudy
018684fe2a chore: activate Wall Werror 2022-11-04 10:44:46 +01:00
tmontaigu
6b0f6e9f10 feat(rust): print mlir string repr directly into a String
Instead of overriding the process stderr to get
the string representation from mlir we can can
directly capture in into a string using mlir's
printOperation.

Another problem with overriding stderr is that
each `#[test]` runs as a different thread meaning that
as soon as we have 2+ tests the tests could panic
due to conflicts/races between the different overrides.

This also moves the expected string directly into the test
as a literal.
2022-11-03 22:16:24 +01:00
youben11
0ac21fd037 feat: add rust bindings
The rust bindings are intented to access both LLVM/MLIR CAPI as well as
the concrete-compiler one. This initial commit provide the API for
LLVM/MLIR only. Tests should be used as an example to how to generate a
valid DAG of operations in MLIR.
2022-11-02 14:46:38 +01:00
Quentin Bourgerie
d934553950 feat(compiler/gpu): Integrate gpu crypto optimization 2022-10-20 10:36:32 +01:00
Quentin Bourgerie
90fca9eb5e fix(runtime/gpu): Use the amortized version of the gpu boostrap as the parameter space of the lowlat one is too restrictive 2022-10-20 10:36:32 +01:00
youben11
ef778ac75b refactor: replace some operands by attrs in bs/ks 2022-10-20 10:36:32 +01:00
youben11
7cd45d1514 test: add GPU end2end tests 2022-10-20 10:36:32 +01:00
youben11
d615ff47f2 feat: support GPU keyswitching 2022-10-20 10:36:32 +01:00
youben11
7e08614e6c build: add options to build with CUDA support 2022-10-20 10:36:32 +01:00
youben11
a7a65025ff refactor: redesign GPU support
- unify CPU and GPU bootstrapping operations
- remove operations to build GLWE from table: this is now done in
  wrapper functions
- remove GPU memory management operations: done in wrappers now, but we
  will have to think about how to deal with it later in MLIR
2022-10-20 10:36:32 +01:00
youben11
d169a27fc0 feat: support GPU (bootstrapping) 2022-10-20 10:36:32 +01:00
Umut
5f845bf9ff feat: add axes argument to transpose 2022-10-17 10:46:03 +03:00
rudy
1d1dfc6b2b fix: display crypto-params global probability when it's not available 2022-10-14 09:00:35 +02:00
rudy
35d86c6093 fix: missing variance for packing keyswitch keys 2022-10-14 09:00:10 +02:00
Andi Drebes
7aab560dd6 fix(ServerLib): Add missing dependency to mlir-headers
When building the ServerLib before any other concretelang target that
depends on `mlir-headers`, compilation fails due to missing include
files generated by tablegen, e.g., `llvm/IR/Attributes.inc`.

This adds a dependency from ServerLib to `mlir-headers`, which forces
the generation of the missing header files.
2022-10-11 17:09:47 +02:00
Quentin Bourgerie
0bc2e5830b fix(optimization): Fix manp computation for addition with plaintext 2022-10-11 17:09:32 +02:00
rudy
637a004529 feat: use signed weights in optimizer dot 2022-10-10 10:48:47 +02:00
Quentin Bourgerie
090e0dbbca fix(compiler): Fix maps with symbolic offsets in memref casts for wrapper functions
This reverts commit d9363ffb27.
2022-10-07 09:16:19 +02:00
Quentin Bourgerie
cf9a36c197 feat(compiler/runtime): Support the pbs for crt encoding (enable apply_lookup_table up to 16bits) 2022-10-07 09:16:19 +02:00
Ayoub Benaissa
6a5e65631c chore: update concrete-ffi version
no major breaking changes, just enhancements
check https://github.com/zama-ai/concrete-core/releases
2022-10-06 12:48:17 +01:00
Mayeul@Zama
819da92e3a dep(optimizer): use options api from optimizer 2022-10-05 14:20:51 +02:00
Andi Drebes
a7051c2c9c enhance(client/server): Add support for scalar results
This patch adds support for scalar results to the client/server
protocol and tests. In addition to `TensorData`, a new type
`ScalarData` is added. Previous representations of scalar values using
one-dimensional `TensorData` instances have been replaced with proper
instantiations of `ScalarData`.

The generic use of `TensorData` for scalar and tensor values has been
replaced with uses of a new variant `ScalarOrTensorData`, which can
either hold an instance of `TensorData` or `ScalarData`.
2022-10-04 14:40:40 +02:00
Andi Drebes
ade86d935b enhance(jit): Add support for clear text results in ServerLambda
This removes the restriction of `ServerLambda` that the source program
must return encrypted values.
2022-10-04 14:40:40 +02:00
Andi Drebes
8255d3e190 fix(compiler): Add support for clear result tensors with element width != 64 bits
Returning tensors with elements whose width is not equal to 64 results
in garbled data. This commit extends the `TensorData` class used to
represent tensors in JIT compilation with support for signed /
unsigned elements of 8/16/32 and 64 bits, such that all clear text
tensors with up to 64 bits can be represented accurately.
2022-10-04 14:40:40 +02:00
Mayeul@Zama
f1833f06f2 feat(compiler): clarify input encryption noise variance 2022-10-03 14:00:16 +02:00
rudy
cb2c9ef6bf feat: accept no evaluation keys 2022-09-26 14:43:25 +02:00
rudy
08ed2fc49b fix: when both sol.p_error and sol.global_p_error are near 0 2022-09-21 14:23:16 +02:00
rudy
e1fb417c54 fix(optimizer): no ceiling for MANP value given to the optimizer 2022-09-19 17:59:22 +02:00