Commit Graph

143 Commits

Author SHA1 Message Date
youben11
971cb56182 chore: licensing 2021-12-29 15:13:34 +01:00
rudy
d8fee32cea feat(HLFHELinalg): add apply_mapped_table_lookup
Resolves #182
2021-12-27 15:34:33 +01:00
aquint-zama
7f88d6553e docs: add first documentation 2021-12-27 09:55:57 +01:00
Antoniu Pop
cdca7ca6f7 feat(compiler): add Dataflow/RT dialect and code generation for dataflow auto parallelization. 2021-12-23 15:57:53 +00:00
Quentin Bourgerie
db683f4a0e feat(compiler/runtime): Introduce a RT dialect 2021-12-23 15:57:53 +00:00
Antoniu Pop
bc3d647453 fix(dfr): make HPX runtime environment persistent and deallocate temporaries. 2021-12-23 15:57:53 +00:00
Antoniu Pop
23d3dca3f2 formatting(dfr): add .hpp to the formatting script and format the relevant files. 2021-12-23 15:57:53 +00:00
Andi Drebes
f319ba37d2 feat(compiler): Integrate HLFHELinalg tiling passes into compilation pipeline 2021-12-17 16:09:59 +01:00
Andi Drebes
bc75831c86 feat(compiler): Add passes for tiling of HLFHELinalg.matmul_eint_int
Add two passes related to the tiling of `HLFHELinalg.matmul_eint_int`
operations.

The `HLFHELinalgTilingMarker` pass takes a vector of tile sizes and
adds an integer array attribute "tile-sizes" to each instance of
`HLFHELinalg.matmul_eint_int`, e.g.,

  "HLFHELinalg.matmul_eint_int"(%arg0, %arg1) {"tile-sizes" = [2, 2, 2]} :
    (tensor<4x2x!HLFHE.eint<6>>, tensor<2x2xi7>) -> tensor<4x2x!HLFHE.eint<6>>

The `HLFHELinalgTiling` performs the actual tiling of each
`HLFHELinalg.matmul_eint_int` operation marked with a "tile-sizes"
attribute. The tiling preserves the level of abstraction of
HLFHELinalg and is implemented as a perfect loop nest of SCF for loops
with a `HLFHELinalg.matmul_eint_int` in the body.

For example,

  func @main(%arg0: tensor<4x2x!HLFHE.eint<6>>, %arg1: tensor<2x2xi7>)
    -> tensor<4x2x!HLFHE.eint<6>>
  {
    %0 = "HLFHELinalg.matmul_eint_int"(%arg0, %arg1) {"tile-sizes" = [2, 2, 2]} :
           (tensor<4x2x!HLFHE.eint<6>>, tensor<2x2xi7>) -> tensor<4x2x!HLFHE.eint<6>>
    return %0 : tensor<4x2x!HLFHE.eint<6>>
  }

becomes:

  func @main(%arg0: tensor<4x2x!HLFHE.eint<6>>, %arg1: tensor<2x2xi7>)
    -> tensor<4x2x!HLFHE.eint<6>>
  {
    %c2 = arith.constant 2 : index
    %c0 = arith.constant 0 : index
    %c4 = arith.constant 4 : index

    %0 = "HLFHELinalg.zero"() : () -> tensor<4x2x!HLFHE.eint<6>>
    %1 = scf.for %arg2 = %c0 to %c4 step %c2 iter_args(%arg3 = %0)
           -> (tensor<4x2x!HLFHE.eint<6>>) {
      %2 = scf.for %arg4 = %c0 to %c2 step %c2 iter_args(%arg5 = %arg3)
             -> (tensor<4x2x!HLFHE.eint<6>>) {
        %3 = scf.for %arg6 = %c0 to %c2 step %c2 iter_args(%arg7 = %arg5)
	       -> (tensor<4x2x!HLFHE.eint<6>>) {
          %4 = tensor.extract_slice %arg0[%arg2, %arg4] [2, 2] [1, 1] :
	         tensor<4x2x!HLFHE.eint<6>> to tensor<2x2x!HLFHE.eint<6>>
          %5 = tensor.extract_slice %arg1[%arg4, %arg6] [2, 2] [1, 1] :
	         tensor<2x2xi7> to tensor<2x2xi7>
          %6 = tensor.extract_slice %arg7[%arg2, %arg6] [2, 2] [1, 1] :
	         tensor<4x2x!HLFHE.eint<6>> to tensor<2x2x!HLFHE.eint<6>>

          %7 = "HLFHELinalg.matmul_eint_int"(%4, %5) :
	         (tensor<2x2x!HLFHE.eint<6>>, tensor<2x2xi7>)
		 -> tensor<2x2x!HLFHE.eint<6>>

          %8 = "HLFHELinalg.add_eint"(%6, %7) :
	         (tensor<2x2x!HLFHE.eint<6>>, tensor<2x2x!HLFHE.eint<6>>)
		 -> tensor<2x2x!HLFHE.eint<6>>

          %9 = tensor.insert_slice %8 into %arg7[%arg2, %arg6] [2, 2] [1, 1] :
	         tensor<2x2x!HLFHE.eint<6>> into tensor<4x2x!HLFHE.eint<6>>

          scf.yield %9 : tensor<4x2x!HLFHE.eint<6>>
        }
        scf.yield %3 : tensor<4x2x!HLFHE.eint<6>>
      }
      scf.yield %2 : tensor<4x2x!HLFHE.eint<6>>
    }
    return %1 : tensor<4x2x!HLFHE.eint<6>>
  }

Only full tiles are supported, i.e., the size of the dimensions of the
operands must be a multiple of the respective tile sizes.
2021-12-17 16:09:59 +01:00
Andi Drebes
27ca5122bc enhance(compiler): Use named constant for the default pattern rewriting benefit
This introduces a new header file `zamalang/Support/Constants.h` for
constants, currently only populated with a constant for the default
pattern rewriting benefit of 1.
2021-12-17 15:28:21 +01:00
youben11
60b2cfd9b7 feat: support more dtype for scalars/tensors
dtype supported now: uint8, uint16, uint32, uint64
2021-12-13 17:40:28 +01:00
Antoniu Pop
bb44124999 feat(dfr): add the DFR (DataFlow Runtime). 2021-12-08 18:35:29 +00:00
rudy
cc58608589 chore(Lambda): simplify, extract, enhance message for bit width rounding
bit with rounding: 5bit element is widen to a standard 8bit word
2021-12-07 15:29:05 +01:00
rudy
2c56a26c75 fix(Lambda): missing superfluous check in setArg
[----------] Global test environment tear-down
[==========] 7 tests from 1 test suite ran. (1513 ms total)
[  PASSED  ] 7 tests.

  YOU HAVE 2 DISABLED TESTS
2021-12-07 15:29:05 +01:00
Mayeul@Zama
dad4390518 feat(compiler): add a key cache 2021-12-07 12:11:56 +01:00
Mayeul@Zama
f193fd71a2 fix(compiler): fix mixed-up (g)lwe dimension/size
add dimension -> size conversion
rename k -> glweDimension, polynomialSize -> logPolynomialSize
remove (in/out)putLweSize from KeySwitchLweOp
remove GlweSizeType from LowLFHE
2021-12-07 12:11:56 +01:00
Quentin Bourgerie
fb58dcc59d enhance(compiler/lowlfhe): Give the runtime context as function argument instead of a global variable (close #195) 2021-12-02 10:56:47 +01:00
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
rudy
975ee86a5e feat(compiler): add --compile option
Resolves #196
2021-11-30 17:42:28 +01:00
Quentin Bourgerie
b1e7a66b09 cleanup(compiler/lowlfhe): Remove useless LowLFHE ops and types
Some of these operators/types could be usefull but they are not yet use on the compiler pipeline it's preferable to remove them, and reintroduce if needed.
2021-11-30 16:11:33 +01:00
Andi Drebes
8c06a5a1b2 enhance(compiler): Replace linalg type converter pattern with generic pattern
Replace `LinalgGenericTypeConverterPattern`, specialized for
`linalg.generic` with a generic type converter pattern
`RegionOpTypeConverterPattern` that can be instantiated for any
operation that has one or more regions.

Further enhancements:
- Supports multiple regions
- Uses more idiomatic instantiations of `llvm::for_each` instead of
  manual iterations using for loops
2021-11-26 17:05:21 +01:00
Quentin Bourgerie
ddbafd713d feat(compiler): Add the HLFHELinalg.matmul_int_eint operator 2021-11-24 09:19:25 +01:00
Andi Drebes
ffe32f5e90 fix(compiler): Suppress various warnings about expressions with different signedness 2021-11-19 16:23:15 +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
12b4771405 feat(compiler/linalg): Definition of HLFHELinalg.matmul_eint_int (closes #176) 2021-11-12 16:50:29 +01:00
youben11
99cce18c6a feat: get RT lib path from py and use as sharedlib
Try to find the runtime library automatically (should only work on
proper installation of the package), and fail silently by not passing
any RT lib. The RT lib can also be specified manually. The RT lib will
be used as a shared library by the JIT compiler.
2021-11-12 15:06:49 +01:00
Andi Drebes
f54c0dd8d8 enhance(compiler): JitCompilerEngine: Add support for arbitrary int result tensors
Add support for result tensors composed of uint8_t, uint16_t, uint32_t
and uint64_t elements, replacing the current implementation, which
only supports uint64_t tensors.
2021-11-12 12:00:39 +01:00
Andi Drebes
3118983287 enhance(compiler): Add function JITLambda::Arguments::getResultWidth
Add a new method `JITLambda::Arguments::getResultWidth` returning the
width of a scalar result or the element type of a tensor result at a
given position.
2021-11-12 12:00:39 +01:00
Andi Drebes
e4cd340e36 enhance(compiler): JIT: Support result tensors with arbitrary element types
Currently, `JITLambda::Arguments` assumes result tensors are always
composed of `uint64_t` elements. This change adds support for
arbitrary scalar element types.
2021-11-12 12:00:39 +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
aee493392b feat(compiler): lower neg_eint from HLFHE to LowLFHE 2021-11-10 15:24:21 +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
59e859177c refactor: replace ExecutionArg by TensorLambdaArg
This add support for tensor inputs from the python bindings
2021-11-08 11:55:02 +01:00
youben11
56e261d140 fix(compiler): pass dimensions at TensorLambdaArg creation 2021-11-08 11:55:02 +01:00
youben11
b501e3d6c0 feat(python): support functions returning tensors 2021-11-08 11:55:02 +01:00
Andi Drebes
c92f047721 fix(compiler): TensorLambdaArgument: Copy input data instead of using a reference
`TensorLambdaArgument` uses an `llvm::MutableArrayRef` to reference
the tensor values. This prevents temporary tensors from being used as
an argument, due to the data of the `TensorLambdaArgument` being
accessed after the destruction of the temporary.

This patch changes the type of the data field of
`TensorLambdaArgument` from `llvm::MutableArrayRef` to `std::vector`
and causes input data to be copied in order to guarantee that all data
remains available until invocation of the destructor.
2021-11-04 19:07:54 +01:00
Andi Drebes
a670ee3f85 enhance(compiler): Use const pointers in JITLambda::Arguments::setArg
All results in code compiled by zamacompiler are passed as return
values, which means that all tensors passed as function arguments are
constant inputs that are never written.

This patch changes the arguments used as data pointers for input
tensors in `JITLambda::Arguments::setArg()` from `void*` to `const
void*` to emphasize their use as inputs and to allow for constant
arrays to be passed as function inputs.
2021-11-04 19:07:54 +01:00
Andi Drebes
9040e5ab00 feat(compiler): Add generic overload for result of JitCompilerEngine::Lambda
This adds a new overload for `JitCompilerEngine::Lambda::operator()`,
returning a result wrapped in a `std::unique_ptr<LambdaArgument>` with
meta information about the result. This allows for generic invocations
of JitCompilerEngine::Lambda::operator(), where the result type is
unknown before the invocation.
2021-11-03 18:32:06 +01:00
Andi Drebes
1ad3d57f66 feat(compiler): Add method JITLambda::Argument::getResultType(size_t)
Add a method `JITLambda::Argument::getResultType(size_t pos)` that
returns the type of the result with the index `pos` of a
`JITLambda::Argument`.
2021-11-03 18:32:06 +01:00
youben11
97ee8134ed fix(python): register hlfhelinalg dialect 2021-11-03 15:37:43 +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
ccaf1bff15 feat(compiler): Lower HLFHELinalg.apply_lookup_table (close #174) 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
Quentin Bourgerie
85d102c9b2 refactor(compiler): Simplify the compiler flow and re enable --passes compiler option
No more need to compute the fhe context at high level
2021-10-29 13:44:34 +02:00
Quentin Bourgerie
41cba63113 refactor(compiler): Move the keyset generation from CompilerEngine to JitCompilerEngine 2021-10-29 13:44:34 +02:00
Andi Drebes
1187cfbd62 refactor(compiler): Refactor CompilerEngine and related classes
This commit contains several incremental improvements towards a clear
interface for lambdas:

  - Unification of static and JIT compilation by using the static
    compilation path of `CompilerEngine` within a new subclass
    `JitCompilerEngine`.

  - Clear ownership for compilation artefacts through
    `CompilationContext`, making it impossible to destroy objects used
    directly or indirectly before destruction of their users.

  - Clear interface for lambdas generated by the compiler through
    `JitCompilerEngine::Lambda` with a templated call operator,
    encapsulating otherwise manual orchestration of `CompilerEngine`,
    `JITLambda`, and `CompilerEngine::Argument`.

  - Improved error handling through `llvm::Expected<T>` and proper
    error checking following the conventions for `llvm::Expected<T>`
    and `llvm::Error`.

Co-authored-by: youben11 <ayoub.benaissa@zama.ai>
2021-10-29 13:44:34 +02:00