Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bbarbakadze committed Nov 14, 2024
1 parent adf2c04 commit 33542b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
22 changes: 17 additions & 5 deletions tfhe/src/integer/gpu/server_key/radix/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl CudaServerKey {
///
/// - [CudaStreams::synchronize] __must__ be called after this function as soon as
/// synchronization is required
pub unsafe fn signed_unchecked_abs_assign_async<T>(&self, ct: &mut T, streams: &CudaStreams)
pub unsafe fn unchecked_abs_assign_async<T>(&self, ct: &mut T, streams: &CudaStreams)
where
T: CudaIntegerRadixCiphertext,
{
Expand Down Expand Up @@ -74,11 +74,23 @@ impl CudaServerKey {
{
let mut res = unsafe { ct.duplicate_async(streams) };
if T::IS_SIGNED {
unsafe { self.signed_unchecked_abs_assign_async(&mut res, streams) };
streams.synchronize();
unsafe { self.unchecked_abs_assign_async(&mut res, streams) };
}
streams.synchronize();
res
}

/// Computes homomorphically an absolute value of ciphertext encrypting integer
/// values.
///
/// This function, like all "default" operations (i.e. not smart, checked or unchecked), will
/// check that the input ciphertext block carries are empty and clears them if it's not the
/// case and the operation requires it. It outputs a ciphertext whose block carries are always
/// empty.
///
/// # Warning
///
/// - Multithreaded
pub fn abs<T>(&self, ct: &T, streams: &CudaStreams) -> T
where
T: CudaIntegerRadixCiphertext,
Expand All @@ -88,9 +100,9 @@ impl CudaServerKey {
unsafe { self.full_propagate_assign_async(&mut res, streams) };
};
if T::IS_SIGNED {
unsafe { self.signed_unchecked_abs_assign_async(&mut res, streams) };
streams.synchronize();
unsafe { self.unchecked_abs_assign_async(&mut res, streams) };
}
streams.synchronize();
res
}
}
13 changes: 0 additions & 13 deletions tfhe/src/integer/server_key/radix_parallel/abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,11 @@ impl ServerKey {
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs
let num_bits_in_ciphertext =
self.key.message_modulus.0.ilog2() * ct.blocks().len() as u32;

for block in ct.blocks() {
println!("before: {:?}", block.ct.get_body());
}
let mask = self.unchecked_scalar_right_shift_arithmetic_parallelized(
ct,
num_bits_in_ciphertext - 1,
);

for block in mask.blocks() {
println!("after: {:?}", block.ct.get_body());
}
let mut abs = self.add_parallelized(ct, &mask);

for block in abs.blocks() {
println!("after add: {:?}", block.ct.get_body());
}

self.bitxor_assign_parallelized(&mut abs, &mask);
abs
} else {
Expand Down
1 change: 0 additions & 1 deletion tfhe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
#![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))]
#![cfg_attr(all(doc, not(doctest)), feature(doc_cfg))]
#![warn(rustdoc::broken_intra_doc_links)]
extern crate core;

#[cfg(feature = "__c_api")]
pub mod c_api;
Expand Down

0 comments on commit 33542b8

Please sign in to comment.