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): add count_ones/zeros #1503

Merged
merged 1 commit into from
Sep 23, 2024
Merged

feat(integer): add count_ones/zeros #1503

merged 1 commit into from
Sep 23, 2024

Conversation

tmontaigu
Copy link
Contributor

The non naive version made for 2_2 parameters
only bring slight (10-15%) for some small sizes like (64, 128, 256 bits) but reduces number of PBS. The place where it brings the best improvements it for very large numbers (e.g 6400 blocks 1.8s for naive, 1.1 sec for non-naive)

fixes https://github.com/zama-ai/tfhe-rs-internal/issues/638

@cla-bot cla-bot bot added the cla-signed label Sep 2, 2024
@tmontaigu tmontaigu force-pushed the tm/count_ones branch 2 times, most recently from df1bfcc to 1e2d237 Compare September 2, 2024 15:46
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, some questions

tfhe/src/integer/server_key/mod.rs Outdated Show resolved Hide resolved
Comment on lines +315 to +320
// In 2_2, each block may have between 0 and 2 bits set.
// 2_2 also allows 5 additions maximum (noise wise)
// 2 * 5 = 10 which is less than the max value storable (15 = (2**4) -1)
//
// Since in 2_2 bivariate PBS is possible, we can actually group blocks by two.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not applicable but kind of makes me think of it for the eq and ne implems ? as we will get a slower version to be safe at the moment

/// * ct must not have any carries
/// * The returned result has enough blocks to encrypt 32bits (e.g. 1_1 parameters -> 32 blocks,
/// 3_3 parameters -> 11 blocks == 33 bits)
fn count_bits_2_2<T>(&self, ct: &T, count_kind: BitCountKind) -> RadixCiphertext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perf gains of this variant ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said in the commit its none on small sizes (< 64bits) and rather small on 64 bits (iirc naive 64 bits its ~135 ms, while non naive is ~115ms), where its really interesting is for really big sizes like 12800 bits where we go from 1.8s for naive, 1.1 sec for non-naive likely because the number of pbs reduced starts to be noticeable and there are less things to sum

The non naive version made for 2_2 parameters
only bring slight (10-15%) for some small sizes like (64, 128, 256 bits)
but reduces number of PBS. The place where it brings the best
improvements it for very large numbers (e.g 6400 blocks 1.8s for naive,
1.1 sec for non-naive)
@tmontaigu
Copy link
Contributor Author

Changes since last time is just a rebase + small comment adressed + use of the max_sum_size

@tmontaigu tmontaigu merged commit 0259886 into main Sep 23, 2024
87 checks passed
@tmontaigu tmontaigu deleted the tm/count_ones branch September 23, 2024 20:21
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