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

feat(integer): Adds bitslice operation #1453

Merged
merged 2 commits into from
Aug 13, 2024
Merged

Conversation

nsarlin-zama
Copy link
Contributor

@nsarlin-zama nsarlin-zama commented Aug 2, 2024

closes: https://github.com/zama-ai/tfhe-rs-internal/issues/640

PR content/description

Adds a bitslice operation to the integer API. This operation extracts a range of bits from an integer. On native rust integers, this is roughly equivalent to the following operation:

fn bitslice(val: u64, start_bit: usize, end_bit: usize)  -> u64 {
    (val % (1 << end_bit)) >> start_bit
}

On FHE radix integers, we have different cases based on the alignment of the slice bounds w.r.t the block size:

  • If start_bit is block aligned, we can simply copy full blocks until we are left with fewer bits than the block size
  • If start_bit is not aligned, we have to create blocks by "merging" higher bits from a block and lower bits from its successor. This is done using PBS with bivariate LUTs (one per block).
  • In both cases, if the slice size is not block aligned, we have to do one last PBS to create the last block.

The returned ciphertext is filled with 0-trivial ciphertexts to match the input ciphertext size.

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Relevant issues are marked as resolved/closed, related issues are linked in the description
  • Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

@cla-bot cla-bot bot added the cla-signed label Aug 2, 2024
@nsarlin-zama nsarlin-zama force-pushed the ns/feat/integer_slice branch 9 times, most recently from c613d85 to a70b139 Compare August 6, 2024 10:40
@nsarlin-zama
Copy link
Contributor Author

Some questions:

  • The operations are called scalar_bitslice because the range parameters are cleartexts, and we could technically add support for encrypted ranges later. Does it make sense ? Or should I call them just bitslice because there is no encrypted version ?
  • This is only implemented for unsigned integers. We could technically create a version where the sign is kept but I find this more confusing, would this be usefull ?

@nsarlin-zama nsarlin-zama marked this pull request as ready for review August 6, 2024 11:24
@nsarlin-zama nsarlin-zama requested a review from tmontaigu August 6, 2024 11:27
@nsarlin-zama nsarlin-zama force-pushed the ns/feat/integer_slice branch 2 times, most recently from 6db0e90 to 9f8afe6 Compare August 6, 2024 13:09
@tmontaigu
Copy link
Contributor

  • The operations are called scalar_bitslice because the range parameters are cleartexts, and we could technically add support for encrypted ranges later. Does it make sense ? Or should I call them just bitslice because there is no encrypted version ?

scalar_bitslice is good as as you said, we may add the encrypted version later

@nsarlin-zama nsarlin-zama force-pushed the ns/feat/integer_slice branch 2 times, most recently from 43a02d5 to 0e7d849 Compare August 8, 2024 09:42
@nsarlin-zama nsarlin-zama requested a review from tmontaigu August 8, 2024 14:16
@nsarlin-zama nsarlin-zama force-pushed the ns/feat/integer_slice branch from 0e7d849 to 9abbc25 Compare August 12, 2024 07:46
@nsarlin-zama nsarlin-zama force-pushed the ns/feat/integer_slice branch from 9abbc25 to 14014c9 Compare August 12, 2024 13:58
@nsarlin-zama nsarlin-zama merged commit 401cfc5 into main Aug 13, 2024
88 checks passed
@nsarlin-zama nsarlin-zama deleted the ns/feat/integer_slice branch August 13, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants