-
Notifications
You must be signed in to change notification settings - Fork 11
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: added simple benchmarks and tooling #100
Draft
kashbrti
wants to merge
10
commits into
main
Choose a base branch
from
kb/simple_benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a412c1
changed the workflow and the compiler version requirement
5352776
built from main
98844ad
added simple benchmarks and tooling
5371fbd
added simple benchmarks and tooling
f1d4cd1
included exports in gitignore
c11c7ec
git clean
232bf1a
formatter
09ddac8
some fixes carried from another PR
9279eb8
minimum version
f6d5116
formatter version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Benchmarks | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Benchmark library | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Nargo | ||
uses: noir-lang/[email protected] | ||
with: | ||
toolchain: 1.0.0-beta.0 | ||
|
||
- name: Install bb | ||
run: | | ||
npm install -g bbup | ||
bbup -nv 1.0.0-beta.0 | ||
- name: Build Noir benchmark programs | ||
run: nargo export | ||
|
||
- name: Generate gates report | ||
run: ./scripts/build-gates-report.sh | ||
env: | ||
BACKEND: /home/runner/.bb/bb | ||
|
||
- name: Compare gates reports | ||
id: gates_diff | ||
uses: noir-lang/noir-gates-diff@1931aaaa848a1a009363d6115293f7b7fc72bb87 | ||
with: | ||
report: gates_report.json | ||
summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%) | ||
|
||
- name: Add gates diff to sticky comment | ||
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
# delete the comment in case changes no longer impact circuit sizes | ||
delete: ${{ !steps.gates_diff.outputs.markdown }} | ||
message: ${{ steps.gates_diff.outputs.markdown }} |
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 |
---|---|---|
|
@@ -16,10 +16,11 @@ jobs: | |
runs-on: ubuntu-latest | ||
outputs: | ||
noir_versions: ${{ steps.get_versions.outputs.versions }} | ||
|
||
steps: | ||
- name: Checkout sources | ||
id: get_versions | ||
run: | | ||
run: | | ||
# gh returns the Noir releases in reverse chronological order so we keep all releases published after the minimum supported version. | ||
VERSIONS=$(gh release list -R noir-lang/noir --exclude-pre-releases --json tagName -q 'map(.tagName) | index(env.MINIMUM_NOIR_VERSION) as $index | if $index then .[0:$index+1] else [env.MINIMUM_NOIR_VERSION] end') | ||
echo "versions=$VERSIONS" | ||
|
@@ -58,13 +59,11 @@ jobs: | |
- name: Install Nargo | ||
uses: noir-lang/[email protected] | ||
with: | ||
toolchain: ${{ env.MINIMUM_NOIR_VERSION }} | ||
|
||
toolchain: ${{env.MINIMUM_NOIR_VERSION}} | ||
- name: Run formatter | ||
run: nargo fmt --check | ||
|
||
|
||
# This is a job which depends on all test jobs and reports the overall status. | ||
# This is a job which depends on all test jobs and reports the overall status. | ||
# This allows us to add/remove test jobs without having to update the required workflows. | ||
tests-end: | ||
name: Noir End | ||
|
@@ -85,4 +84,4 @@ jobs: | |
fi | ||
env: | ||
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole. | ||
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} | ||
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
target | ||
.vscode/launch.json | ||
export/* | ||
gates_report.json |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
BACKEND=${BACKEND:-bb} | ||
|
||
cd $(dirname "$0")/../ | ||
|
||
artifacts_path="./export" | ||
artifacts=$(ls $artifacts_path) | ||
|
||
echo "{\"programs\": [" > gates_report.json | ||
|
||
# Bound for checking where to place last parentheses | ||
NUM_ARTIFACTS=$(ls -1q "$artifacts_path" | wc -l) | ||
|
||
ITER="1" | ||
for artifact in $artifacts; do | ||
ARTIFACT_NAME=$(basename "$artifact") | ||
|
||
GATES_INFO=$($BACKEND gates -b "$artifacts_path/$artifact") | ||
MAIN_FUNCTION_INFO=$(echo $GATES_INFO | jq -r '.functions[0] | .name = "main"') | ||
echo "{\"package_name\": \"$ARTIFACT_NAME\", \"functions\": [$MAIN_FUNCTION_INFO]" >> gates_report.json | ||
|
||
if (($ITER == $NUM_ARTIFACTS)); then | ||
echo "}" >> gates_report.json | ||
else | ||
echo "}, " >> gates_report.json | ||
fi | ||
|
||
ITER=$(( $ITER + 1 )) | ||
done | ||
|
||
echo "]}" >> gates_report.json | ||
|
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,90 @@ | ||
use crate::utils::u60_representation::U60Repr; | ||
|
||
use crate::bignum::BigNum; | ||
use crate::bignum::BigNumTrait; | ||
|
||
use crate::params::BigNumParams; | ||
use crate::params::BigNumParamsGetter; | ||
|
||
use crate::fields::bls12_381Fq::BLS12_381_Fq_Params; | ||
use crate::fields::bn254Fq::BN254_Fq_Params; | ||
use crate::fields::U256::U256Params; | ||
|
||
// the types we will be benchmarking | ||
|
||
type Fq = BigNum<3, 254, BN254_Fq_Params>; | ||
type BN256 = BigNum<3, 257, U256Params>; | ||
type BN381 = BigNum<4, 381, BLS12_381_Fq_Params>; | ||
|
||
// macro magic to generate the benchmarks | ||
fn bench_add<let N: u32, BN>(a: BN, b: BN) | ||
where | ||
BN: BigNumTrait, | ||
{ | ||
let c = a + b; | ||
} | ||
|
||
fn bench_sub<let N: u32, BN>(a: BN, b: BN) | ||
where | ||
BN: BigNumTrait, | ||
{ | ||
let c = a - b; | ||
} | ||
|
||
fn bench_mul<let N: u32, BN>(a: BN, b: BN) | ||
where | ||
BN: BigNumTrait, | ||
{ | ||
let c = a * b; | ||
} | ||
|
||
fn bench_div<let N: u32, BN>(a: BN, b: BN) | ||
where | ||
BN: BigNumTrait, | ||
{ | ||
let c = a / b; | ||
} | ||
|
||
// type Fq | ||
// type BN256 | ||
// type BN381 | ||
// type BN2048 | ||
#[export] | ||
fn bench_add_Fq(a: Fq, b: Fq) { | ||
bench_add::<3, Fq>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_sub_Fq(a: Fq, b: Fq) { | ||
bench_sub::<3, Fq>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_mul_Fq(a: Fq, b: Fq) { | ||
bench_mul::<3, Fq>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_div_Fq(a: Fq, b: Fq) { | ||
bench_div::<3, Fq>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_add_BN256(a: BN256, b: BN256) { | ||
bench_add::<3, BN256>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_sub_BN256(a: BN256, b: BN256) { | ||
bench_sub::<3, BN256>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_mul_BN256(a: BN256, b: BN256) { | ||
bench_mul::<3, BN256>(a, b); | ||
} | ||
|
||
#[export] | ||
fn bench_div_BN256(a: BN256, b: BN256) { | ||
bench_div::<3, BN256>(a, b); | ||
} |
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 @@ | ||
pub mod bignum_benchmarks; |
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 |
---|---|---|
|
@@ -21,3 +21,6 @@ pub use runtime_bignum::RuntimeBigNum; | |
|
||
// Tests | ||
mod tests; | ||
|
||
// Benchmarks | ||
pub mod benchmarks; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on why we need these functions rather than putting the arithmetic directly inside the #[export] functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for these, it doesn't matter much I guess, but I thought it might be a good framework for more complicated functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if this introduces unnecessary memory gates for bb though.