pub struct RnsInt {
pub residues: Vec<u64>,
pub channels: Channels,
pub negative: bool,
}Expand description
An exact integer in RNS form (Level 0 of the tower).
Fields§
§residues: Vec<u64>residues[i] = value mod channels[i], stored in [0, m).
channels: Channels§negative: boolSign hint: true when the represented (symmetric) value is negative.
Implementations§
Source§impl RnsInt
impl RnsInt
Sourcepub fn from_bigint(n: &BigInt, channels: Channels) -> Self
pub fn from_bigint(n: &BigInt, channels: Channels) -> Self
Construct from an arbitrary BigInt.
Sourcepub fn from_i64(n: i64, channels: Channels) -> Self
pub fn from_i64(n: i64, channels: Channels) -> Self
Construct from a machine integer.
Examples found in repository?
examples/benchmark_backends.rs (line 41)
22fn main() {
23 let exec = executor();
24 let ch = Channels::standard(32);
25 let has_gpu = exec.gpu().is_some();
26
27 println!("== adele-ring :: backend benchmark (32 channels) ==");
28 println!(
29 "GPU available: {}\n",
30 if has_gpu {
31 exec.gpu().map(|g| g.adapter_name().to_string()).unwrap_or_default()
32 } else {
33 "no (CPU-only)".to_string()
34 }
35 );
36
37 println!("{:>10} | {:>14} | {:>12} | winner", "batch_size", "cpu_rayon_us", "gpu_us");
38 println!("{}", "-".repeat(56));
39
40 for &size in &[1usize, 16, 128, 1024, 16_384, 65_536] {
41 let a = RnsBatch::from_rns_ints(&vec![RnsInt::from_i64(123, ch.clone()); size]);
42 let b = RnsBatch::from_rns_ints(&vec![RnsInt::from_i64(456, ch.clone()); size]);
43
44 let iters = if size <= 128 { 2000 } else { 100 };
45 let cpu_us = time_backend(|| exec.cpu().batch_rns_add(&a, &b), iters);
46
47 let (gpu_str, winner) = if let Some(gpu) = exec.gpu() {
48 let gpu_us = time_backend(|| gpu.batch_rns_add(&a, &b), iters);
49 let w = if cpu_us <= gpu_us { "CPU" } else { "GPU" };
50 (format!("{gpu_us:>12.2}"), w)
51 } else {
52 (" n/a".to_string(), "CPU")
53 };
54
55 println!("{size:>10} | {cpu_us:>14.2} | {gpu_str} | {winner}");
56 }
57
58 println!(
59 "\nNote: CPU wins for small batches (GPU upload/dispatch overhead ~100us);\n\
60 GPU pulls ahead once the batch is large enough to amortize that fixed cost."
61 );
62}Sourcepub fn from_residues(residues: Vec<u64>, channels: Channels) -> Self
pub fn from_residues(residues: Vec<u64>, channels: Channels) -> Self
Build directly from raw channel residues, recomputing the sign hint.
The residues must already be reduced into [0, m) for each channel.
Sourcepub fn to_bigint(&self) -> BigInt
pub fn to_bigint(&self) -> BigInt
Reconstruct the exact signed value via Garner CRT + symmetric folding.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RnsInt
impl RefUnwindSafe for RnsInt
impl Send for RnsInt
impl Sync for RnsInt
impl Unpin for RnsInt
impl UnsafeUnpin for RnsInt
impl UnwindSafe for RnsInt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more