heir
heir copied to clipboard
Generate a helper that configures OpenFHE crypto context based on the IR content
Right now the user must manually call functions like EvalMultKeyGen if the IR contains EvalMult, and EvalRotateKeyGen with known rotation shifts (which requires looking at the generated code to determine), as well as SetMultiplicativeDepth and SetPlaintextModulus.
We should have a pass in the OpenFHE dialect that generates a function that configures the cryptoContext appropriately.
I've looked over this issue, and I would like to give it a try :) I'm currently preparing for my master's thesis defense, so I will probably be able to start it next Tuesday.
Also one more note: we can add the pub/priv key generation to the context generation function (https://github.com/google/heir/pull/696#discussion_r1636688307), if we remove the restriction to return only one value.
Maybe something like:
(context, pubkey, privkey) = my_func__generate_crypto_context()
or it could go in configure
After removing that restriction, we also can remove the return parameter in configure_crypto_context. See https://github.com/google/heir/pull/696#discussion_r1636695254
https://github.com/google/heir/pull/696#issuecomment-2143834856
Now, I'm trying to determine the appropriate values for
mulDepthandplainMod. My plan is as follows:
Finding
mulDepth:
- Determine the maximum multiplication depth through forward dataflow analysis.
muldepth(op) = max_i (muldepth(operand_i(op))) + 1ifopismulOp(ormulPlainOp)muldepth(op) = max_i (muldepth(operand_i(op)))otherwiseFinding
plainMod:
- Considering the following post (https://openfhe.discourse.group/t/automaticly-find-a-good-plaintext-modulus/312), I think the best approach is to determine the maximum number of plaintext bits (
nBits) that can appear in the program and then call OpenFHE'sFirstPrime(nBits, 2*65536)to calculateplainMod. To do this, it seems reasonable to receive the maximum plaintext bit count of the inputs given as arguments to the program and then use forward dataflow analysis to determine the maximum plaintext bits of the program.
Before I forget, I would like to seek some advice and explain what I have attempted so far.
First, I thought it would be easy to implement dataflow analysis for both mulDepth and plainMod using IntegerRangeAnalysis. So, I tried to follow the awesome blog post by @j2kun.
If I understand correctly, IntegerRangeAnalysis performs dataflow analysis by implementing transfer functions for each operation using the InferIntRangeInterface. During this process, I encountered two issues:
-
I need to implement two types of transfer functions for each operation (one for
mulDepthand another forplainMod), but it seemsInferIntRangeInterfaceallows for only one transfer function per operation (via theinferResultRangesmethod). Can this be resolved by implementing two interfaces that inherit fromInferIntRangeInterface? -
At the time this analysis is performed, the IR may include operations not only from the
openfhedialect but also from other dialects, such asarithdialect. Is there a way to initialize these operations easily? For instance, in the analysis for computingmulDepth, I think operations likearith.constantshould all be initialized with a range of (0,0). I'm not sure if writing such initializations for all possible ops is feasible. Is there a better way?
I'm not very familiar with C++ and mlir, so these might be dumb questions. Any comments are welcome!
I don't necessarily think you should use IntRangeAnalysis directly for this. If I were you I would write a new analysis that uses the same base framework (I'm mobile so I forget the name, something like AbstractForwardDataflowAnalysis, we have some examples already in HEIR I believe).
Awesome, thank you for your comments! I will take a closer look.