From 7bb1c4541e81bb4fb963336f9411230174cfebe3 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 27 Oct 2020 12:05:55 +0100 Subject: [PATCH] better integration of gbench, including ci checks --- .circleci/config.yml | 20 ++++++++++++++++++++ Cargo.toml | 13 +++++++++---- benches/hash.rs | 15 +++++++-------- gbench/Cargo.toml | 12 ++++++------ gbench/src/{bin/gbench.rs => main.rs} | 4 ++-- 5 files changed, 44 insertions(+), 20 deletions(-) rename gbench/src/{bin/gbench.rs => main.rs} (99%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 371c7d69..8df48df3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,6 +68,7 @@ jobs: - run: cargo fetch - run: rustup install $(cat rust-toolchain) - run: rustup default $(cat rust-toolchain) + - run: rustup install nightly - run: rustup component add rustfmt-preview - run: rustup component add clippy-preview - run: rustc --version @@ -162,6 +163,22 @@ jobs: name: Run cargo release build (blst, gpu) command: cargo build --release --no-default-features --features blst,gpu + build_gbench: + executor: default + steps: + - *restore-workspace + - *restore-cache + - run: echo 'export PATH="$HOME:~/.cargo/bin:$PATH"' >> $BASH_ENV + - run: source $BASH_ENV + - run: sudo apt-get update -y + - run: apt-cache search opencl + - run: sudo apt install -y ocl-icd-opencl-dev + - run: + name: Run cargo release build (pairing, gpu) + command: cargo +nightly build -Zpackage-features --release -p gbench --no-default-features --features pairing,gpu + - run: + name: Run cargo release build (blst, gpu) + command: cargo +nightly build -Zpackage-features --release -p gbench --no-default-features --features blst,gpu benches: executor: default @@ -201,6 +218,9 @@ workflows: - build: requires: - cargo_fetch + - build_gbench: + requires: + - cargo_fetch - benches: requires: - cargo_fetch diff --git a/Cargo.toml b/Cargo.toml index 351c52e0..ad063a4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,24 +9,24 @@ repository = "https://github.com/porcuquine/poseidon" [dependencies] lazy_static = "1.4.0" -bellperson = { git = "https://github.com/filecoin-project/bellman", branch = "blstrs", default-features = false } +bellperson = { git = "https://github.com/filecoin-project/bellperson", branch = "blstrs", default-features = false } blake2s_simd = "0.5" byteorder = "1" ff = { version = "0.2.1", package = "fff" } -generic-array = "0.13.2" +generic-array = "0.14.4" triton = { version = "2.0.0", package = "neptune-triton", default-features = false, features = ["opencl"], optional = true } log = "0.4.8" [dev-dependencies] criterion = "0.3" rand = "0.7.0" -sha2 = "0.8" +sha2 = "0.9" tempdir = "0.3" rand_xorshift = "0.2.0" serde_json = "1.0.53" [build-dependencies] -bellperson = { git = "https://github.com/filecoin-project/bellman", branch = "blstrs", default-features = false } +bellperson = { git = "https://github.com/filecoin-project/bellperson", branch = "blstrs", default-features = false } ff = { version = "0.2.1", package = "fff" } [[bench]] @@ -46,3 +46,8 @@ default = ["pairing"] gpu = ["triton"] pairing = ["bellperson/pairing"] blst = ["bellperson/blst"] + +[workspace] +members = [ + "gbench", +] \ No newline at end of file diff --git a/benches/hash.rs b/benches/hash.rs index e5846a36..7026bb83 100644 --- a/benches/hash.rs +++ b/benches/hash.rs @@ -24,19 +24,18 @@ where BenchmarkId::new("Sha2 256", "Generated scalars"), &scalars, |b, s| { + let mut h = Sha256::new(); b.iter(|| { - let mut h = Sha256::new(); - std::iter::repeat(()) .take(A::to_usize()) .map(|_| s.choose(&mut OsRng).unwrap()) .for_each(|scalar| { for val in scalar.into_repr().as_ref() { - h.input(&val.to_le_bytes()); + h.update(&val.to_le_bytes()); } }); - h.result(); + h.finalize_reset() }) }, ); @@ -45,19 +44,19 @@ where BenchmarkId::new("Sha2 512", "Generated scalars"), &scalars, |b, s| { - b.iter(|| { - let mut h = Sha512::new(); + let mut h = Sha512::new(); + b.iter(|| { std::iter::repeat(()) .take(A::to_usize()) .map(|_| s.choose(&mut OsRng).unwrap()) .for_each(|scalar| { for val in scalar.into_repr().as_ref() { - h.input(&val.to_le_bytes()); + h.update(&val.to_le_bytes()); } }); - h.result(); + h.finalize_reset() }) }, ); diff --git a/gbench/Cargo.toml b/gbench/Cargo.toml index 045e43e5..120b487b 100644 --- a/gbench/Cargo.toml +++ b/gbench/Cargo.toml @@ -8,18 +8,18 @@ license = "MIT OR Apache-2.0" [dependencies] lazy_static = "1.4.0" -bellperson = "0.6.3" +bellperson = { git = "https://github.com/filecoin-project/bellperson", branch = "blstrs", default-features = false } blake2s_simd = "0.5" byteorder = "1" env_logger = "0.7.1" ff = { version = "0.2.1", package = "fff" } -generic-array = "0.13.2" +generic-array = "0.14.4" log = "0.4.8" -neptune = { path = "../", features = ["gpu"] } +neptune = { path = "../", default-features = false } [features] -default = ["pairing"] +default = ["pairing", "gpu"] gpu = ["neptune/gpu"] -pairing = ["neptune/pairing"] -blst = ["neptune/blst"] +pairing = ["neptune/pairing", "bellperson/pairing"] +blst = ["neptune/blst", "bellperson/blst"] diff --git a/gbench/src/bin/gbench.rs b/gbench/src/main.rs similarity index 99% rename from gbench/src/bin/gbench.rs rename to gbench/src/main.rs index 6334a171..4e5d76c5 100644 --- a/gbench/src/bin/gbench.rs +++ b/gbench/src/main.rs @@ -1,3 +1,4 @@ +use bellperson::bls::Fr; use ff::Field; use generic_array::sequence::GenericSequence; use generic_array::typenum::{U11, U8}; @@ -7,7 +8,6 @@ use neptune::batch_hasher::BatcherType; use neptune::column_tree_builder::{ColumnTreeBuilder, ColumnTreeBuilderTrait}; use neptune::error::Error; use neptune::BatchHasher; -use bellperson::bls::Fr; use std::result::Result; use std::thread; use std::time::Instant; @@ -57,7 +57,7 @@ fn bench_column_building( let _ = builder.add_columns(columns.as_slice()).unwrap(); total_columns += columns.len(); } - println!(""); + println!(); let final_columns: Vec<_> = (0..leaves - total_columns) .map(|_| GenericArray::::generate(|_| constant_element))