-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hanting Zhang
committed
Jan 6, 2024
1 parent
9e7a36d
commit 9cfc26b
Showing
6 changed files
with
204 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright Supranational LLC | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#![allow(unused_mut)] | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use grumpkin_msm::pasta::utils::{gen_points, gen_scalars}; | ||
|
||
#[cfg(feature = "cuda")] | ||
use grumpkin_msm::cuda_available; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let bench_npow: usize = std::env::var("BENCH_NPOW") | ||
.unwrap_or("17".to_string()) | ||
.parse() | ||
.unwrap(); | ||
let npoints: usize = 1 << bench_npow; | ||
|
||
// println!("generating {} random points, just hang on...", npoints); | ||
let mut points = gen_points(npoints); | ||
let mut scalars = gen_scalars(npoints); | ||
|
||
#[cfg(feature = "cuda")] | ||
{ | ||
unsafe { grumpkin_msm::CUDA_OFF = true }; | ||
} | ||
|
||
let mut group = c.benchmark_group("CPU"); | ||
group.sample_size(10); | ||
|
||
group.bench_function(format!("2**{} points", bench_npow), |b| { | ||
b.iter(|| { | ||
let _ = grumpkin_msm::pasta::pallas(&points, &scalars); | ||
}) | ||
}); | ||
|
||
group.finish(); | ||
|
||
#[cfg(feature = "cuda")] | ||
if unsafe { cuda_available() } { | ||
unsafe { grumpkin_msm::CUDA_OFF = false }; | ||
|
||
const EXTRA: usize = 5; | ||
let bench_npow = bench_npow + EXTRA; | ||
let npoints: usize = 1 << bench_npow; | ||
|
||
while points.len() < npoints { | ||
points.append(&mut points.clone()); | ||
} | ||
scalars.append(&mut gen_scalars(npoints - scalars.len())); | ||
|
||
let mut group = c.benchmark_group("GPU"); | ||
group.sample_size(20); | ||
|
||
group.bench_function(format!("2**{} points", bench_npow), |b| { | ||
b.iter(|| { | ||
let _ = grumpkin_msm::pasta::pallas(&points, &scalars); | ||
}) | ||
}); | ||
|
||
group.finish(); | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.