Skip to content

Commit

Permalink
simplifies sigverify copy_return_values
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri committed Jan 3, 2023
1 parent 89deecb commit efc3d73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
7 changes: 2 additions & 5 deletions ledger/src/sigverify_shreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,9 @@ pub fn verify_shreds_gpu(
trace!("out buf {:?}", out);

// Each shred has exactly one signature.
let v_sig_lens: Vec<_> = batches
.iter()
.map(|batch| vec![1u32; batch.len()])
.collect();
let v_sig_lens = batches.iter().map(|batch| repeat(1u32).take(batch.len()));
let mut rvs: Vec<_> = batches.iter().map(|batch| vec![0u8; batch.len()]).collect();
sigverify::copy_return_values(&v_sig_lens, &out, &mut rvs);
sigverify::copy_return_values(v_sig_lens, &out, &mut rvs);

inc_new_counter_debug!("ed25519_shred_verify_gpu", out.len());
rvs
Expand Down
34 changes: 13 additions & 21 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,26 +664,18 @@ pub fn ed25519_verify_disabled(batches: &mut [PacketBatch]) {
inc_new_counter_debug!("ed25519_verify_disabled", packet_count);
}

pub fn copy_return_values(sig_lens: &[Vec<u32>], out: &PinnedVec<u8>, rvs: &mut [Vec<u8>]) {
let mut num = 0;
for (vs, sig_vs) in rvs.iter_mut().zip(sig_lens.iter()) {
for (v, sig_v) in vs.iter_mut().zip(sig_vs.iter()) {
if *sig_v == 0 {
*v = 0;
} else {
let mut vout = 1;
for _ in 0..*sig_v {
if 0 == out[num] {
vout = 0;
}
num = num.saturating_add(1);
}
*v = vout;
}
if *v != 0 {
trace!("VERIFIED PACKET!!!!!");
}
}
pub fn copy_return_values<I, T>(sig_lens: I, out: &PinnedVec<u8>, rvs: &mut [Vec<u8>])
where
I: IntoIterator<Item = T>,
T: IntoIterator<Item = u32>,
{
debug_assert!(rvs.iter().flatten().all(|&rv| rv == 0u8));
let mut offset = 0;
let rvs = rvs.iter_mut().flatten();
for (k, rv) in sig_lens.into_iter().flatten().zip(rvs) {
let out = out[offset..].iter().take(k as usize).all(|&x| x == 1);
*rv = u8::from(k != 0 && out);
offset = offset.saturating_add(k as usize);
}
}

Expand Down Expand Up @@ -796,7 +788,7 @@ pub fn ed25519_verify(
}
}
trace!("done verify");
copy_return_values(&sig_lens, &out, &mut rvs);
copy_return_values(sig_lens, &out, &mut rvs);
mark_disabled(batches, &rvs);
inc_new_counter_debug!("ed25519_verify_gpu", valid_packet_count);
}
Expand Down

0 comments on commit efc3d73

Please sign in to comment.