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

chore: add bench programs #6566

Merged
merged 18 commits into from
May 29, 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
11 changes: 7 additions & 4 deletions barretenberg/acir_tests/bench_acir_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash
set -e

cd "$(dirname "$0")"

./clone_test_vectors.sh

TEST_NAMES=("$@")
THREADS=(1 4 16 32 64)
BENCHMARKS=$LOG_FILE
Expand All @@ -11,7 +14,7 @@ if [[ -z "${LOG_FILE}" ]]; then
fi

if [ "${#TEST_NAMES[@]}" -eq 0 ]; then
TEST_NAMES=(sha256 ecdsa_secp256k1 ecdsa_secp256r1 schnorr double_verify_proof)
TEST_NAMES=$(find acir_tests/bench_* -maxdepth 0 -type d -printf '%f ')
fi

for TEST in ${TEST_NAMES[@]}; do
Expand All @@ -23,13 +26,13 @@ done
# Build results into string with \n delimited rows and space delimited values.
TABLE_DATA=""
for TEST in ${TEST_NAMES[@]}; do
GATE_COUNT=$(jq -r --arg test "$TEST" 'select(.name == "gate_count" and .acir_test == $test) | .value' $BENCHMARKS | uniq)
SUBGROUP_SIZE=$(jq -r --arg test "$TEST" 'select(.name == "subgroup_size" and .acir_test == $test) | .value' $BENCHMARKS | uniq)
GATE_COUNT=$(jq -r --arg test "$TEST" 'select(.eventName == "gate_count" and .acir_test == $test) | .value' $BENCHMARKS | uniq)
SUBGROUP_SIZE=$(jq -r --arg test "$TEST" 'select(.eventName == "subgroup_size" and .acir_test == $test) | .value' $BENCHMARKS | uniq)
# Name in col 1, gate count in col 2, subgroup size in col 3.
TABLE_DATA+="$TEST $GATE_COUNT $SUBGROUP_SIZE"
# Each thread timing in subsequent cols.
for HC in "${THREADS[@]}"; do
RESULT=$(cat $BENCHMARKS | jq -r --arg test "$TEST" --argjson hc $HC 'select(.name == "proof_construction_time" and .acir_test == $test and .threads == $hc) | .value')
RESULT=$(cat $BENCHMARKS | jq -r --arg test "$TEST" --argjson hc $HC 'select(.eventName == "proof_construction_time" and .acir_test == $test and .threads == $hc) | .value')
TABLE_DATA+=" $RESULT"
done
TABLE_DATA+=$'\n'
Expand Down
10 changes: 8 additions & 2 deletions noir/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,17 @@ barretenberg-acir-benches-bb:

WORKDIR /usr/src/barretenberg/acir_tests

bench-acir-bb:
# This target is used for debugging the benchmarking target.
# For precise benchmarks in CI use `bench-publish-acir-bb`
FROM +barretenberg-acir-benches-bb
RUN ./bench_acir_tests.sh

export-bench-acir-bb:
ARG EARTHLY_GIT_HASH
FROM +barretenberg-acir-benches-bb
SAVE IMAGE aztecprotocol/barretenberg-acir-benches:$EARTHLY_GIT_HASH

bench-publish-acir-bb:
ARG PULL_REQUEST
ARG BRANCH
Expand All @@ -256,6 +262,6 @@ bench-publish-acir-bb:
END

RUN mkdir -p ./log
RUN docker run -v "$(pwd)/log":/log -e LOG_FILE=/log/bench-acir.jsonl --rm aztecprotocol/barretenberg-acir-benches:$AZTEC_DOCKER_TAG ./bench_acir_tests.sh sha256
RUN docker run -v "$(pwd)/log":/log -e LOG_FILE=/log/bench-acir.jsonl --rm aztecprotocol/barretenberg-acir-benches:$AZTEC_DOCKER_TAG ./bench_acir_tests.sh

DO ../+UPLOAD_LOGS --PULL_REQUEST=$PULL_REQUEST --BRANCH=$BRANCH --COMMIT_HASH=$COMMIT_HASH
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_eddsa_poseidon"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
msg = 789
pub_key_x = "0x16b051f37589e0dcf4ad3c415c090798c10d3095bedeedabfcc709ad787f3507"
pub_key_y = "0x062800ac9e60839fab9218e5ed9d541f4586e41275f4071816a975895d349a5e"
r8_x = "0x163814666f04c4d2969059a6b63ee26a0f9f0f81bd5957b0796e2e8f4a8a2f06"
r8_y = "0x1255b17d9e4bfb81831625b788f8a1665128079ac4b6c8c3cd1b857666a05a54"
s = "1230930278088778318663840827871215383007447616379808164955640681455510074924"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use dep::std::eddsa::{eddsa_poseidon_verify};

fn main(
msg: pub Field,
pub_key_x: Field,
pub_key_y: Field,
r8_x: Field,
r8_y: Field,
s: Field
) -> pub bool {
eddsa_poseidon_verify(pub_key_x, pub_key_y, s, r8_x, r8_y, msg)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon_hash"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input = [1,2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use dep::std::hash::poseidon;

fn main(input: [Field; 2]) -> pub Field {
poseidon::bn254::hash_2(input)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon_hash_100"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
input = [
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use dep::std::hash;

global SIZE = 100;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
for i in 0..SIZE {
results[i] = hash::poseidon::bn254::hash_2(input[i]);
}

results
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_poseidon_hash_30"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
input = [
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
[1,2],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use dep::std::hash;

global SIZE = 30;

fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
let mut results: [Field; SIZE] = [0; SIZE];
for i in 0..SIZE {
results[i] = hash::poseidon::bn254::hash_2(input[i]);
}

results
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_sha256"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input = [1,2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use dep::std;

fn main(input: [u8; 2]) -> pub [u8; 32] {
std::hash::sha256(input)
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bench_sha256_100"
version = "0.1.0"
type = "bin"
authors = [""]

[dependencies]
Loading
Loading