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

Replace uses of fixed-macro #1117

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ assert_matches = "1.5.0"
base64 = "0.22.1"
cfg-if = "1.0.0"
criterion = "0.5"
fixed-macro = "1.2.0"
hex-literal = "0.4.1"
iai = "0.1"
modinverse = "0.1.0"
Expand Down
39 changes: 21 additions & 18 deletions benches/speed_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criteri
#[cfg(feature = "experimental")]
use fixed::types::{I1F15, I1F31};
#[cfg(feature = "experimental")]
use fixed_macro::fixed;
#[cfg(feature = "experimental")]
use num_bigint::BigUint;
#[cfg(feature = "experimental")]
use num_rational::Ratio;
Expand Down Expand Up @@ -434,6 +432,11 @@ fn prio3(c: &mut Criterion) {

#[cfg(feature = "experimental")]
{
const FP16_ZERO: I1F15 = I1F15::lit("0");
const FP32_ZERO: I1F31 = I1F31::lit("0");
const FP16_HALF: I1F15 = I1F15::lit("0.5");
const FP32_HALF: I1F31 = I1F31::lit("0.5");

let mut group = c.benchmark_group("prio3fixedpointboundedl2vecsum_i1f15_shard");
for dimension in [10, 100, 1_000] {
group.bench_with_input(
Expand All @@ -442,8 +445,8 @@ fn prio3(c: &mut Criterion) {
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 16> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![fixed!(0: I1F15); *dimension];
measurement[0] = fixed!(0.5: I1F15);
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
},
Expand All @@ -462,8 +465,8 @@ fn prio3(c: &mut Criterion) {
num_shares, *dimension,
)
.unwrap();
let mut measurement = vec![fixed!(0: I1F15); *dimension];
measurement[0] = fixed!(0.5: I1F15);
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
},
Expand All @@ -480,8 +483,8 @@ fn prio3(c: &mut Criterion) {
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 16> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![fixed!(0: I1F15); *dimension];
measurement[0] = fixed!(0.5: I1F15);
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
Expand Down Expand Up @@ -512,8 +515,8 @@ fn prio3(c: &mut Criterion) {
num_shares, *dimension,
)
.unwrap();
let mut measurement = vec![fixed!(0: I1F15); *dimension];
measurement[0] = fixed!(0.5: I1F15);
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) =
Expand Down Expand Up @@ -543,8 +546,8 @@ fn prio3(c: &mut Criterion) {
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 16> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![fixed!(0: I1F31); *dimension];
measurement[0] = fixed!(0.5: I1F31);
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
},
Expand All @@ -563,8 +566,8 @@ fn prio3(c: &mut Criterion) {
num_shares, *dimension,
)
.unwrap();
let mut measurement = vec![fixed!(0: I1F31); *dimension];
measurement[0] = fixed!(0.5: I1F31);
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
},
Expand All @@ -581,8 +584,8 @@ fn prio3(c: &mut Criterion) {
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 16> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![fixed!(0: I1F31); *dimension];
measurement[0] = fixed!(0.5: I1F31);
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
Expand Down Expand Up @@ -613,8 +616,8 @@ fn prio3(c: &mut Criterion) {
num_shares, *dimension,
)
.unwrap();
let mut measurement = vec![fixed!(0: I1F31); *dimension];
measurement[0] = fixed!(0.5: I1F31);
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) =
Expand Down
1 change: 0 additions & 1 deletion binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ repository = "https://github.com/divviup/libprio-rs"
[dependencies]
base64 = "0.22.1"
fixed = "1.27"
fixed-macro = "1.2.0"
rand = "0.8"
prio = { path = "..", features = ["experimental", "test-util"] }
10 changes: 6 additions & 4 deletions binaries/src/bin/vdaf_message_sizes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use fixed::{types::extra::U15, FixedI16};
use fixed_macro::fixed;
use fixed::{
types::{extra::U15, I1F15},
FixedI16,
};

use prio::{
codec::Encode,
Expand Down Expand Up @@ -53,8 +55,8 @@ fn main() {

let len = 1000;
let prio3 = Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, len).unwrap();
let fp_num = fixed!(0.0001: I1F15);
let measurement = vec![fp_num; len];
const FP_NUM: I1F15 = I1F15::lit("0.0001");
let measurement = vec![FP_NUM; len];
println!(
"prio3 fixedpoint16 boundedl2 vec ({} entries) size = {}",
len,
Expand Down
30 changes: 14 additions & 16 deletions src/flp/types/fixedpoint_l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,23 @@ mod tests {
use crate::flp::test_utils::FlpTest;
use crate::vdaf::xof::SeedStreamTurboShake128;
use fixed::types::extra::{U127, U14, U63};
use fixed::types::{I1F15, I1F31, I1F63};
use fixed::{FixedI128, FixedI16, FixedI64};
use fixed_macro::fixed;
use rand::SeedableRng;

const FP16_4_INV: I1F15 = I1F15::lit("0.25");
const FP16_8_INV: I1F15 = I1F15::lit("0.125");
const FP16_16_INV: I1F15 = I1F15::lit("0.0625");
const FP32_4_INV: I1F31 = I1F31::lit("0.25");
const FP32_8_INV: I1F31 = I1F31::lit("0.125");
const FP32_16_INV: I1F31 = I1F31::lit("0.0625");
const FP64_4_INV: I1F63 = I1F63::lit("0.25");
const FP64_8_INV: I1F63 = I1F63::lit("0.125");
const FP64_16_INV: I1F63 = I1F63::lit("0.0625");

#[test]
fn test_bounded_fpvec_sum_parallel_fp16() {
let fp16_4_inv = fixed!(0.25: I1F15);
let fp16_8_inv = fixed!(0.125: I1F15);
let fp16_16_inv = fixed!(0.0625: I1F15);

let fp16_vec = vec![fp16_4_inv, fp16_8_inv, fp16_16_inv];
let fp16_vec = vec![FP16_4_INV, FP16_8_INV, FP16_16_INV];

// the encoded vector has the following entries:
// enc(0.25) = 2^(n-1) * 0.25 + 2^(n-1) = 40960
Expand All @@ -693,22 +699,14 @@ mod tests {

#[test]
fn test_bounded_fpvec_sum_parallel_fp32() {
let fp32_4_inv = fixed!(0.25: I1F31);
let fp32_8_inv = fixed!(0.125: I1F31);
let fp32_16_inv = fixed!(0.0625: I1F31);

let fp32_vec = vec![fp32_4_inv, fp32_8_inv, fp32_16_inv];
let fp32_vec = vec![FP32_4_INV, FP32_8_INV, FP32_16_INV];
// computed as above but with n=32
test_fixed(fp32_vec, vec![2684354560, 2415919104, 2281701376]);
}

#[test]
fn test_bounded_fpvec_sum_parallel_fp64() {
let fp64_4_inv = fixed!(0.25: I1F63);
let fp64_8_inv = fixed!(0.125: I1F63);
let fp64_16_inv = fixed!(0.0625: I1F63);

let fp64_vec = vec![fp64_4_inv, fp64_8_inv, fp64_16_inv];
let fp64_vec = vec![FP64_4_INV, FP64_8_INV, FP64_16_INV];
// computed as above but with n=64
test_fixed(
fp64_vec,
Expand Down
Loading