bgv-to-lattigo: lower client-interface and plain op #1226
+239
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this PR we can lower the dot_product_8 example with client interface. The emitter/tests has not been added as there are hacks in this pass that needs discussion.
lwe-add-client-interface
will add helper function for encryption/decryption, and the function signature is__encrypt(value, sk/pk)
. However, this is only for openfhe backend, as openfhe needsCryptoContext
andsk/pk
to encrypt/decrypt, and openfhe lowering will add its own CryptoContext arg.For lattigo, things are different in that we have
evaluator/encryptor/decryptor/encoder/decoder
instead of one context, and all of them should be passed on-demand.This brings the complicacy that a lot of predicating is needed to make sure things are added in correct order, otherwise the function signature is not stable.
Currently I add evaluator in a specified order with predicate, so we can have more predictable function signature.
With
--mlir-to-secret-arithmetic --secret-insert-mgmt-bgv --secret-distribute-generic --secret-to-bgv="poly-mod-degree=8" --lwe-add-client-interface --bgv-to-lwe --bgv-to-lattigo
we can get the following IR (of course with some ASM trick locally #1219)Discussion
__encrypt/decrypt
theskey
is not needed. This is produced bylwe-add-client-interface
but not used by furthur backend pass, so should we either not produce it or detele it here. (involves some ordering/validity check of function signature update)--<bgv/ckks>-to-openfhe
into--lwe-to-openfhe
#1196 as a--lwe-to-lattigo
.lwe.reinterpret_underlying_type
should be moved earlier (packing pipeline). Backend should not care about them (only care about ct types but not pt types). It used to work because we forward lwe type to openfhe dialect, but not this way for lattigo dialect. Similarlybgv.extract
should be moved earlier, which I usedbgv-to-lwe
to handle it (Use tensor_ext::ExtractOp for extracting an element out of a slot of a single ciphertext #1174).