Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arith.select Pattern to --secret-to-bgv #825

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AlexanderViand-Intel
Copy link
Collaborator

@AlexanderViand-Intel AlexanderViand-Intel commented Jul 25, 2024

This adds the following rewrite pattern:

%res = arith.select %c, %t, %f
// turns into
%ct = bgv.mul %c, %t
%nc = bgv.negate %c  // EDIT: actually a bug, this should be logical negation, i.e., bgv.sub %one, %c 
%ncf = bgv.mul %nc, %f
%sum = bgv.add %nc, %ncf
%res = bgv.relinearize %sum 

However, as-is, this pattern actually produces invalid IR: %c has (element/self) type i1 while %t and %f can have any IntegerLike type, e.g., i32. In the current TypeConverter, this means that the condition is mapped to a ciphertext with encoding #lwe.polynomial_evaluation_encoding<cleartext_start = 1, cleartext_bitwidth = 1> while the other values are mapped to ciphertexts with encoding #lwe.polynomial_evaluation_encoding<cleartext_start = 32, cleartext_bitwidth = 32>. Since bgv.mul requires the types of its operands to match, this is invalid IR.

In the current draft, I've simply hardcoded the typeconverter to map everything to 32 bits (that's why this is a Draft PR only for now), but we'll need to think about how to handle such cases. I think this is a special case of "what is the plaintext-FHE semantics mapping" (Step 1 in #785).

@AlexanderViand-Intel AlexanderViand-Intel added dialect: bgv Issues concerning the bgv dialect dialect: secret Issues related to the secret dialect labels Jul 25, 2024
@AlexanderViand-Intel
Copy link
Collaborator Author

AlexanderViand-Intel commented Aug 8, 2024

@asraa In today's meeting, I said this only needed a small bugfix, because I only remembered that I still need to swap bgv.negate %c to bgv.sub_plain %one, %c, However, I had forgotten about the real blocker here, which is the typing issue.

I.e., this does indeed hang on the attribute/type rework (though probably not even the LWE one, but a future one for cleartext<>plaintext semantics cleanup)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect: bgv Issues concerning the bgv dialect dialect: secret Issues related to the secret dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant