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

serialize program and shared data #3

Merged
merged 6 commits into from
Nov 27, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/cancel_duplicate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
cancelMode: allDuplicates
cancelFutureDuplicates: true
token: ${{ secrets.GITHUB_TOKEN }}
workflowFileName: bench_pull_request.yml
workflowFileName: bench.yml
208 changes: 103 additions & 105 deletions .github/workflows/hyperfine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Hyperfine Benchmark

on:
pull_request:
branches: [ '**' ]
branches: ["**"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -15,7 +15,7 @@ jobs:
build-programs:
strategy:
matrix:
branch: [ base, head ]
branch: [base, head]
name: Build Cairo programs for ${{ matrix.branch }}
runs-on: ubuntu-22.04
outputs:
Expand All @@ -39,7 +39,7 @@ jobs:
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: "3.9"

- name: Install Cairo compiler
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand All @@ -54,20 +54,18 @@ jobs:

- name: Export benchmark hashes
id: export-hashes
run:
echo "benchmark-hashes-${{ matrix.branch }}=${{ hashFiles( 'cairo_programs/benchmarks/*.cairo' ) }}" >> "$GITHUB_OUTPUT"

run: echo "benchmark-hashes-${{ matrix.branch }}=${{ hashFiles( 'cairo_programs/benchmarks/*.cairo' ) }}" >> "$GITHUB_OUTPUT"

build-binaries:
strategy:
matrix:
branch: [ base, head ]
branch: [base, head]
name: Build cairo-vm-cli for ${{ matrix.branch }}
runs-on: ubuntu-22.04
steps:
- name: Populate cache
uses: actions/cache@v3
id: cache
id: cache
with:
path: bin/cairo-vm-cli-${{ matrix.branch }}
key: binary-${{ github.event.pull_request[matrix.branch].sha }}
Expand All @@ -93,106 +91,106 @@ jobs:
mkdir bin
cp target/release/cairo-vm-cli bin/cairo-vm-cli-${{ matrix.branch }}


run-hyperfine:
strategy:
matrix:
program_state: [ modified, unmodified ]
program_state: [modified, unmodified]
name: Run benchmarks for ${{ matrix.program_state }} programs
needs: [ build-programs, build-binaries ]
needs: [build-programs, build-binaries]
runs-on: ubuntu-22.04
steps:
- name: Install Hyperfine
uses: taiki-e/install-action@v2
with:
tool: [email protected]

- name: Fetch base binary
uses: actions/cache/restore@v3
with:
path: bin/cairo-vm-cli-base
key: binary-${{ github.event.pull_request.base.sha }}

- name: Fetch HEAD binary
uses: actions/cache/restore@v3
with:
path: bin/cairo-vm-cli-head
key: binary-${{ github.event.pull_request.head.sha }}

- name: Fetch base programs
uses: actions/cache/restore@v3
with:
path: base_programs/*.json
key: benchmarks-base-${{ needs.build-programs.outputs.benchmark-hashes-base }}

- name: Fetch head programs
uses: actions/cache/restore@v3
with:
path: head_programs/*.json
key: benchmarks-head-${{ needs.build-programs.outputs.benchmark-hashes-head }}

- name: Benchmark ${{ matrix.program_state }} programs
id: run-benchmarks
run: |
sudo swapoff -a
mkdir target_programs
if [ 'modified' = ${{ matrix.program_state }} ]; then
BINS=head
for f in head_programs/*.json; do
# Only run new or modified benchmarks
if ! cmp -s ${f/head/base} $f; then
cp $f target_programs/
fi
done
else
BINS="base,head"
for f in base_programs/*.json; do
# Only run unmodified benchmarks
if cmp -s ${f/base/head} $f; then
cp $f target_programs/
fi
done
fi
find target_programs -name '*.json' -exec basename -s .json '{}' '+' | \
sort | xargs -I '{program}' \
hyperfine -N -r 10 --export-markdown "target_programs/{program}.md" \
-L bin "$BINS" -n "{bin} {program}" \
-s "cat ./bin/cairo-vm-cli-{bin} target_programs/{program}.json" \
"./bin/cairo-vm-cli-{bin} --proof_mode --layout starknet_with_keccak \
--memory_file /dev/null --trace_file /dev/null target_programs/{program}.json"
echo "benchmark_count=$(ls target_programs/*.md | wc -l)" >> $GITHUB_OUTPUT

- name: Print tables
if: steps.run-benchmarks.outputs.benchmark_count != 0
run: |
{
echo "Benchmark Results for ${{ matrix.program_state }} programs :rocket:"
for f in target_programs/*.md; do
echo
cat $f
done
} | tee -a comment_body.md

- name: Find comment
if: ${{ steps.run-benchmarks.outputs.benchmark_count != 0 }}
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Benchmark Results for ${{ matrix.program_state }} programs

- name: Create comment
if: steps.fc.outputs.comment-id == '' && steps.run-benchmarks.outputs.benchmark_count != 0
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: comment_body.md

- name: Update comment
if: steps.fc.outputs.comment-id != '' && steps.run-benchmarks.outputs.benchmark_count != 0
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body-path: comment_body.md
edit-mode: replace
- name: Install Hyperfine
uses: taiki-e/install-action@v2
with:
tool: [email protected]

- name: Fetch base binary
uses: actions/cache/restore@v3
with:
path: bin/cairo-vm-cli-base
key: binary-${{ github.event.pull_request.base.sha }}

- name: Fetch HEAD binary
uses: actions/cache/restore@v3
with:
path: bin/cairo-vm-cli-head
key: binary-${{ github.event.pull_request.head.sha }}

- name: Fetch base programs
uses: actions/cache/restore@v3
with:
path: base_programs/*.json
key: benchmarks-base-${{ needs.build-programs.outputs.benchmark-hashes-base }}

- name: Fetch head programs
uses: actions/cache/restore@v3
with:
path: head_programs/*.json
key: benchmarks-head-${{ needs.build-programs.outputs.benchmark-hashes-head }}

- name: Benchmark ${{ matrix.program_state }} programs
id: run-benchmarks
run: |
sudo swapoff -a
mkdir target_programs
if [ 'modified' = ${{ matrix.program_state }} ]; then
BINS=head
for f in head_programs/*.json; do
# Only run new or modified benchmarks
if ! cmp -s ${f/head/base} $f; then
cp $f target_programs/
fi
done
else
BINS="base,head"
for f in base_programs/*.json; do
# Only run unmodified benchmarks
if cmp -s ${f/base/head} $f; then
cp $f target_programs/
fi
done
fi
find target_programs -name '*.json' -exec basename -s .json '{}' '+' | \
sort | xargs -I '{program}' \
hyperfine -N -r 10 --export-markdown "target_programs/{program}.md" \
-L bin "$BINS" -n "{bin} {program}" \
-s "cat ./bin/cairo-vm-cli-{bin} target_programs/{program}.json" \
"./bin/cairo-vm-cli-{bin} --proof_mode --layout starknet_with_keccak \
--memory_file /dev/null --trace_file /dev/null target_programs/{program}.json"
echo "benchmark_count=$(ls target_programs/*.md | wc -l)" >> $GITHUB_OUTPUT

- name: Print tables
if: steps.run-benchmarks.outputs.benchmark_count != 0
run: |
{
echo "Benchmark Results for ${{ matrix.program_state }} programs :rocket:"
for f in target_programs/*.md; do
echo
cat $f
done
} | tee -a comment_body.md

- name: Find comment
if: ${{ steps.run-benchmarks.outputs.benchmark_count != 0 }}
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Benchmark Results for ${{ matrix.program_state }} programs

- name: Create comment
if: steps.fc.outputs.comment-id == '' && steps.run-benchmarks.outputs.benchmark_count != 0
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: comment_body.md
permissions: write

- name: Update comment
if: steps.fc.outputs.comment-id != '' && steps.run-benchmarks.outputs.benchmark_count != 0
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body-path: comment_body.md
edit-mode: replace
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Cairo-VM Changelog

* feat: add Serialize and Deserialize derivation for Program.

#### Upcoming Changes

* BREAKING: Partially Revert `Optimize trace relocation #906` [#1492](https://github.com/lambdaclass/cairo-vm/pull/1492)
Expand Down
3 changes: 2 additions & 1 deletion vm/src/hint_processor/hint_processor_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::vm::vm_core::VirtualMachine;

use super::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use felt::Felt252;
use serde::{Deserialize, Serialize};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down Expand Up @@ -79,7 +80,7 @@ fn get_ids_data(
}

#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct HintReference {
pub offset1: OffsetValue,
pub offset2: OffsetValue,
Expand Down
Loading
Loading