Skip to content

Commit

Permalink
cleanup API
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanting Zhang committed Feb 8, 2024
1 parent 51850c8 commit 047f8e6
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 204 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# VSCode
.vscode
140 changes: 0 additions & 140 deletions .vscode/launch.json

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

20 changes: 13 additions & 7 deletions benches/grumpkin_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn criterion_benchmark(c: &mut Criterion) {

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

Expand All @@ -40,7 +40,9 @@ fn criterion_benchmark(c: &mut Criterion) {
format!("\"preallocate\" 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::bn256::with(&context, &scalars, None);
let _ = grumpkin_msm::bn256::with_context_aux(
&context, &scalars, None,
);
})
},
);
Expand All @@ -65,7 +67,7 @@ fn criterion_benchmark(c: &mut Criterion) {

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

Expand All @@ -76,8 +78,11 @@ fn criterion_benchmark(c: &mut Criterion) {
format!("preallocate 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ =
grumpkin_msm::bn256::with(&context, &scalars, Some(indices.as_slice()));
let _ = grumpkin_msm::bn256::with_context_aux(
&context,
&scalars,
Some(indices.as_slice()),
);
})
},
);
Expand All @@ -87,8 +92,9 @@ fn criterion_benchmark(c: &mut Criterion) {
format!("preallocate 2**{} points rev", bench_npow),
|b| {
b.iter(|| {
let _ =
grumpkin_msm::bn256::with(&context, &scalars, None);
let _ = grumpkin_msm::bn256::with_context_aux(
&context, &scalars, None,
);
})
},
);
Expand Down
30 changes: 25 additions & 5 deletions benches/pasta_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ fn criterion_benchmark(c: &mut Criterion) {

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

Expand All @@ -40,7 +41,9 @@ fn criterion_benchmark(c: &mut Criterion) {
format!("\"preallocate\" 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::pasta::pallas::with(&context, &scalars);
let _ = grumpkin_msm::pasta::pallas::with_context_aux(
&context, &scalars, None,
);
})
},
);
Expand All @@ -65,18 +68,35 @@ fn criterion_benchmark(c: &mut Criterion) {

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

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

let indices = (0..(npoints as u32)).rev().collect::<Vec<_>>();
group.bench_function(
format!("preallocate 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ =
grumpkin_msm::pasta::pallas::with(&context, &scalars);
let _ = grumpkin_msm::pasta::pallas::with_context_aux(
&context,
&scalars,
Some(indices.as_slice()),
);
})
},
);

group.bench_function(
format!("preallocate 2**{} points rev", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::pasta::pallas::with_context_aux(
&context, &scalars, None,
);
})
},
);
Expand Down
4 changes: 2 additions & 2 deletions cuda/bn254.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ cuda_bn254_init(const affine_t points[], size_t npoints, msm_context_t<affine_t:
}

extern "C" RustError cuda_bn254(point_t *out, const affine_t points[], size_t npoints,
const scalar_t scalars[], size_t nscalars)
const scalar_t scalars[], size_t nscalars, uint32_t pidx[])
{
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars);
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars, pidx);
}

extern "C" RustError cuda_bn254_with(point_t *out, msm_context_t<affine_t::mem_t> *msm_context,
Expand Down
8 changes: 4 additions & 4 deletions cuda/grumpkin.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ cuda_grumpkin_init(const affine_t points[], size_t npoints, msm_context_t<affine
}

extern "C" RustError cuda_grumpkin(point_t *out, const affine_t points[], size_t npoints,
const scalar_t scalars[], size_t nscalars)
const scalar_t scalars[], size_t nscalars, uint32_t pidx[])
{
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars);
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars, pidx);
}

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[], size_t nscalars, uint32_t pidx[])
{
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, npoints, scalars, nscalars, pidx);
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, scalars, nscalars, pidx);
}
#endif
8 changes: 4 additions & 4 deletions cuda/pallas.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ cuda_pallas_init(const affine_t points[], size_t npoints, msm_context_t<affine_t
}

extern "C" RustError cuda_pallas(point_t *out, const affine_t points[], size_t npoints,
const scalar_t scalars[], size_t nscalars)
const scalar_t scalars[], size_t nscalars, uint32_t pidx[])
{
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars);
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars, pidx);
}

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[], size_t nscalars, uint32_t pidx[])
{
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, npoints, scalars, nscalars, pidx);
return mult_pippenger_with<bucket_t, point_t, affine_t, scalar_t>(out, msm_context, scalars, nscalars, pidx);
}

#endif
8 changes: 4 additions & 4 deletions cuda/vesta.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ cuda_vesta_init(const affine_t points[], size_t npoints, msm_context_t<affine_t:
}

extern "C" RustError cuda_vesta(point_t *out, const affine_t points[], size_t npoints,
const scalar_t scalars[], size_t nscalars)
const scalar_t scalars[], size_t nscalars, uint32_t pidx[])
{
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars);
return mult_pippenger<bucket_t>(out, points, npoints, scalars, nscalars, pidx);
}

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

#endif
23 changes: 17 additions & 6 deletions examples/grumpkin_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use grumpkin_msm::cuda_available;

fn main() {
let bench_npow: usize = std::env::var("BENCH_NPOW")
.unwrap_or("23".to_string())
.unwrap_or("22".to_string())
.parse()
.unwrap();
let npoints: usize = 1 << bench_npow;
Expand All @@ -23,11 +23,22 @@ fn main() {
let context = grumpkin_msm::bn256::init(&points);

let indices = (0..(npoints as u32)).rev().collect::<Vec<_>>();
let res =
grumpkin_msm::bn256::with(&context, &scalars, Some(indices.as_slice()))
.to_affine();
let res = grumpkin_msm::bn256::with_context_aux(
&context,
&scalars,
Some(indices.as_slice()),
)
.to_affine();
println!("res: {:?}", res);
let res2 = grumpkin_msm::bn256::msm_aux(
&points,
&scalars,
Some(indices.as_slice()),
)
.to_affine();
println!("res2: {:?}", res2);
scalars.reverse();
let native = grumpkin_msm::bn256::msm(&points, &scalars).to_affine();
assert_eq!(res, native);
let native = naive_multiscalar_mul(&points, &scalars);
println!("native: {:?}", native);
println!("success!")
}
Loading

0 comments on commit 047f8e6

Please sign in to comment.