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

Wasm with Cairo 1 #1830

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open

Wasm with Cairo 1 #1830

wants to merge 40 commits into from

Conversation

FrancoGiachetta
Copy link
Contributor

@FrancoGiachetta FrancoGiachetta commented Aug 29, 2024

Wasm with Cairo 1

Closes #1827

Description

This PR adds the ability to run cairo 1 programs with wasm. The crate cairo1-run has been refactored in order for it to stop depending on the rust native standard library. There also has been added a new feature cli which allows cairo1-run to be used as a binary. This addition was made to avoid using the std library unless this specific case, where it needs to read from files and the std library must be used.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

Copy link

github-actions bot commented Aug 29, 2024

**Hyper Thereading Benchmark results**




hyperfine -r 2 -n "hyper_threading_main threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_main' -n "hyper_threading_pr threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 1
  Time (mean ± σ):     30.135 s ±  0.067 s    [User: 29.348 s, System: 0.786 s]
  Range (min … max):   30.088 s … 30.182 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     29.858 s ±  0.106 s    [User: 29.088 s, System: 0.769 s]
  Range (min … max):   29.783 s … 29.933 s    2 runs
 
Summary
  'hyper_threading_pr threads: 1' ran
    1.01 ± 0.00 times faster than 'hyper_threading_main threads: 1'




hyperfine -r 2 -n "hyper_threading_main threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_main' -n "hyper_threading_pr threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 2
  Time (mean ± σ):     16.760 s ±  0.015 s    [User: 29.475 s, System: 0.811 s]
  Range (min … max):   16.750 s … 16.771 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     16.634 s ±  0.026 s    [User: 29.190 s, System: 0.814 s]
  Range (min … max):   16.615 s … 16.652 s    2 runs
 
Summary
  'hyper_threading_pr threads: 2' ran
    1.01 ± 0.00 times faster than 'hyper_threading_main threads: 2'




hyperfine -r 2 -n "hyper_threading_main threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_main' -n "hyper_threading_pr threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 4
  Time (mean ± σ):     12.196 s ±  0.191 s    [User: 41.194 s, System: 0.955 s]
  Range (min … max):   12.062 s … 12.331 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     11.328 s ±  0.298 s    [User: 41.302 s, System: 0.970 s]
  Range (min … max):   11.117 s … 11.538 s    2 runs
 
Summary
  'hyper_threading_pr threads: 4' ran
    1.08 ± 0.03 times faster than 'hyper_threading_main threads: 4'




hyperfine -r 2 -n "hyper_threading_main threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_main' -n "hyper_threading_pr threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 6
  Time (mean ± σ):     11.562 s ±  0.665 s    [User: 41.998 s, System: 0.949 s]
  Range (min … max):   11.092 s … 12.033 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     11.348 s ±  0.334 s    [User: 41.860 s, System: 0.976 s]
  Range (min … max):   11.112 s … 11.584 s    2 runs
 
Summary
  'hyper_threading_pr threads: 6' ran
    1.02 ± 0.07 times faster than 'hyper_threading_main threads: 6'




hyperfine -r 2 -n "hyper_threading_main threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_main' -n "hyper_threading_pr threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 8
  Time (mean ± σ):     11.781 s ±  0.310 s    [User: 42.210 s, System: 0.997 s]
  Range (min … max):   11.562 s … 12.000 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     11.542 s ±  0.382 s    [User: 41.686 s, System: 0.965 s]
  Range (min … max):   11.272 s … 11.812 s    2 runs
 
Summary
  'hyper_threading_pr threads: 8' ran
    1.02 ± 0.04 times faster than 'hyper_threading_main threads: 8'




hyperfine -r 2 -n "hyper_threading_main threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_main' -n "hyper_threading_pr threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 16
  Time (mean ± σ):     11.488 s ±  0.063 s    [User: 42.595 s, System: 1.077 s]
  Range (min … max):   11.443 s … 11.532 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     11.443 s ±  0.010 s    [User: 42.649 s, System: 1.100 s]
  Range (min … max):   11.436 s … 11.450 s    2 runs
 
Summary
  'hyper_threading_pr threads: 16' ran
    1.00 ± 0.01 times faster than 'hyper_threading_main threads: 16'


Copy link

github-actions bot commented Aug 29, 2024

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.309 ± 0.020 2.290 2.354 1.00
head big_factorial 2.323 ± 0.042 2.280 2.432 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.250 ± 0.021 2.215 2.269 1.01 ± 0.01
head big_fibonacci 2.223 ± 0.019 2.204 2.260 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 8.113 ± 0.084 7.968 8.190 1.00
head blake2s_integration_benchmark 8.158 ± 0.233 7.956 8.656 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.413 ± 0.044 2.364 2.523 1.02 ± 0.02
head compare_arrays_200000 2.374 ± 0.018 2.338 2.395 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.564 ± 0.008 1.552 1.577 1.00
head dict_integration_benchmark 1.592 ± 0.047 1.559 1.682 1.02 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.318 ± 0.025 1.299 1.382 1.00 ± 0.02
head field_arithmetic_get_square_benchmark 1.317 ± 0.010 1.299 1.332 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 8.249 ± 0.072 8.085 8.302 1.01 ± 0.02
head integration_builtins 8.175 ± 0.122 8.043 8.412 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.482 ± 0.129 8.339 8.716 1.01 ± 0.02
head keccak_integration_benchmark 8.408 ± 0.084 8.256 8.468 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.410 ± 0.061 2.370 2.580 1.02 ± 0.03
head linear_search 2.362 ± 0.015 2.341 2.381 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.650 ± 0.014 1.630 1.673 1.00
head math_cmp_and_pow_integration_benchmark 1.655 ± 0.036 1.626 1.751 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.639 ± 0.037 1.598 1.691 1.01 ± 0.04
head math_integration_benchmark 1.615 ± 0.046 1.578 1.737 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.350 ± 0.024 1.333 1.413 1.02 ± 0.02
head memory_integration_benchmark 1.327 ± 0.010 1.312 1.338 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.730 ± 0.019 1.710 1.779 1.00 ± 0.02
head operations_with_data_structures_benchmarks 1.723 ± 0.025 1.697 1.789 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 559.5 ± 2.0 557.2 562.0 1.00
head pedersen 560.9 ± 4.7 556.1 571.8 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 678.5 ± 19.5 661.4 724.5 1.01 ± 0.03
head poseidon_integration_benchmark 668.8 ± 6.1 662.9 680.5 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.943 ± 0.009 1.928 1.961 1.00 ± 0.01
head secp_integration_benchmark 1.943 ± 0.017 1.921 1.987 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 669.0 ± 4.3 663.4 675.8 1.00 ± 0.01
head set_integration_benchmark 667.9 ± 4.7 662.7 680.1 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.564 ± 0.033 4.502 4.601 1.00
head uint256_integration_benchmark 4.597 ± 0.136 4.500 4.905 1.01 ± 0.03

@FrancoGiachetta FrancoGiachetta changed the title refeactor cairo1-run to use no-std Wasm with Cairo 1 Aug 30, 2024
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.95%. Comparing base (ed31170) to head (50bd9ee).

Files with missing lines Patch % Lines
cairo1-run/src/cairo_run.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1830      +/-   ##
==========================================
- Coverage   94.89%   93.95%   -0.95%     
==========================================
  Files         102      101       -1     
  Lines       40305    40125     -180     
==========================================
- Hits        38247    37698     -549     
- Misses       2058     2427     +369     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

serialize_output: true,
..Default::default()
};
let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment here what program and compiler version are we using for this sierra

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

cairo1-run/fibonacci.cairo Outdated Show resolved Hide resolved
examples/wasm-demo-cairo1/README.md Outdated Show resolved Hide resolved
examples/wasm-demo-cairo1/README.md Outdated Show resolved Hide resolved
examples/wasm-demo-cairo1/src/lib.rs Outdated Show resolved Hide resolved
@FrancoGiachetta
Copy link
Contributor Author

Done!

cairo1-run/README.md Outdated Show resolved Hide resolved
vm/Cargo.toml Outdated Show resolved Hide resolved
examples/wasm-demo-cairo1/README.md Outdated Show resolved Hide resolved
examples/wasm-demo-cairo1/README.md Outdated Show resolved Hide resolved
.github/workflows/rust.yml Outdated Show resolved Hide resolved
examples/wasm-demo-cairo1/src/lib.rs Show resolved Hide resolved
cairo1-run/src/main.rs Outdated Show resolved Hide resolved
@FrancoGiachetta
Copy link
Contributor Author

Everything done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Cairo 1 run wasm compatible
3 participants