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

add preallocated and indexed MSMs #13

Closed
wants to merge 11 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
reorg code
Hanting Zhang committed Feb 1, 2024
commit 0c2b29d7c92d93b812571fea543844f3cd2df02d
19 changes: 15 additions & 4 deletions benches/grumpkin_msm.rs
Original file line number Diff line number Diff line change
@@ -30,10 +30,21 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function(format!("2**{} points", bench_npow), |b| {
b.iter(|| {
let _ = grumpkin_msm::bn256(&points, &scalars);
let _ = grumpkin_msm::bn256::msm(&points, &scalars);
})
});

let context = grumpkin_msm::bn256::init(points.clone());

group.bench_function(
format!("\"preallocate\" 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::bn256::with(&context, &scalars);
})
},
);

group.finish();

#[cfg(feature = "cuda")]
@@ -54,18 +65,18 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function(format!("2**{} points", bench_npow), |b| {
b.iter(|| {
let _ = grumpkin_msm::bn256(&points, &scalars);
let _ = grumpkin_msm::bn256::msm(&points, &scalars);
})
});

let context = grumpkin_msm::bn256_init(&points, npoints);
let context = grumpkin_msm::bn256::init(points);

group.bench_function(
format!("preallocate 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ =
grumpkin_msm::bn256_with(&context, npoints, &scalars);
grumpkin_msm::bn256::with(&context, &scalars);
})
},
);
22 changes: 16 additions & 6 deletions benches/pasta_msm.rs
Original file line number Diff line number Diff line change
@@ -30,10 +30,21 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function(format!("2**{} points", bench_npow), |b| {
b.iter(|| {
let _ = grumpkin_msm::pasta::pallas(&points, &scalars);
let _ = grumpkin_msm::pasta::pallas::msm(&points, &scalars);
})
});

let context = grumpkin_msm::pasta::pallas::init(points.clone());

group.bench_function(
format!("\"preallocate\" 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::pasta::pallas::with(&context, &scalars);
})
},
);

group.finish();

#[cfg(feature = "cuda")]
@@ -54,19 +65,18 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function(format!("2**{} points", bench_npow), |b| {
b.iter(|| {
let _ = grumpkin_msm::pasta::pallas(&points, &scalars);
let _ = grumpkin_msm::pasta::pallas::msm(&points, &scalars);
})
});

let context = grumpkin_msm::pasta::pallas_init(&points, npoints);
let context = grumpkin_msm::pasta::pallas::init(points);

group.bench_function(
format!("preallocate 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::pasta::pallas_with(
&context, npoints, &scalars,
);
let _ =
grumpkin_msm::pasta::pallas::with(&context, &scalars);
})
},
);
4 changes: 2 additions & 2 deletions cuda/bn254.cu
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ extern "C" RustError cuda_bn254(point_t *out, const affine_t points[], size_t np
return mult_pippenger<bucket_t>(out, points, npoints, scalars);
}

extern "C" RustError cuda_bn254_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context, size_t npoints,
extern "C" RustError cuda_bn254_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context,
const scalar_t scalars[])
{
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, npoints, scalars);
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, scalars);
}
#endif
4 changes: 2 additions & 2 deletions cuda/grumpkin.cu
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ extern "C" RustError cuda_grumpkin(point_t *out, const affine_t points[], size_t
return mult_pippenger<bucket_t>(out, points, npoints, scalars);
}

extern "C" RustError cuda_grumpkin_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context, size_t npoints,
extern "C" RustError cuda_grumpkin_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context,
const scalar_t scalars[])
{
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, npoints, scalars);
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, scalars);
}
#endif
4 changes: 2 additions & 2 deletions cuda/pallas.cu
Original file line number Diff line number Diff line change
@@ -34,10 +34,10 @@ extern "C" RustError cuda_pallas(point_t *out, const affine_t points[], size_t n
return mult_pippenger<bucket_t>(out, points, npoints, scalars);
}

extern "C" RustError cuda_pallas_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context, size_t npoints,
extern "C" RustError cuda_pallas_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context,
const scalar_t scalars[])
{
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, npoints, scalars);
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, scalars);
}

#endif
4 changes: 2 additions & 2 deletions cuda/vesta.cu
Original file line number Diff line number Diff line change
@@ -34,10 +34,10 @@ extern "C" RustError cuda_grumpkin(point_t *out, const affine_t points[], size_t
return mult_pippenger<bucket_t>(out, points, npoints, scalars);
}

extern "C" RustError cuda_grumpkin_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context, size_t npoints,
extern "C" RustError cuda_grumpkin_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context,
const scalar_t scalars[])
{
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, npoints, scalars);
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, scalars);
}

#endif
2 changes: 1 addition & 1 deletion examples/grumpkin_msm.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ fn main() {
unsafe { grumpkin_msm::CUDA_OFF = false };
}

let res = grumpkin_msm::bn256(&points, &scalars).to_affine();
let res = grumpkin_msm::bn256::msm(&points, &scalars).to_affine();
let native = naive_multiscalar_mul(&points, &scalars);
assert_eq!(res, native);
println!("success!")
6 changes: 4 additions & 2 deletions examples/pasta_msm.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use pasta_curves::group::Curve;

fn main() {
let bench_npow: usize = std::env::var("BENCH_NPOW")
.unwrap_or("17".to_string())
.unwrap_or("22".to_string())
.parse()
.unwrap();
let npoints: usize = 1 << bench_npow;
@@ -22,8 +22,10 @@ fn main() {
unsafe { grumpkin_msm::CUDA_OFF = false };
}

let res = grumpkin_msm::pasta::pallas(&points, &scalars).to_affine();
let native = naive_multiscalar_mul(&points, &scalars);
let context = grumpkin_msm::pasta::pallas::init(points);
let res = grumpkin_msm::pasta::pallas::with(&context, &scalars).to_affine();

assert_eq!(res, native);
println!("success!")
}
479 changes: 203 additions & 276 deletions src/lib.rs

Large diffs are not rendered by default.

434 changes: 182 additions & 252 deletions src/pasta.rs

Large diffs are not rendered by default.