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

Implement run resources funcs #1175

Merged
merged 24 commits into from
Jun 6, 2023
Merged

Implement run resources funcs #1175

merged 24 commits into from
Jun 6, 2023

Conversation

mmsc2
Copy link
Contributor

@mmsc2 mmsc2 commented May 22, 2023

TITLE

Description

Description of the pull request changes and motivation.

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.

@mmsc2 mmsc2 marked this pull request as ready for review May 22, 2023 20:10
src/utils.rs Outdated Show resolved Hide resolved
src/utils.rs Outdated Show resolved Hide resolved
@@ -516,20 +517,26 @@ impl CairoRunner {
pub fn run_until_pc(
&mut self,
address: Relocatable,
run_resources: &mut Option<RunResources>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could be Option<&mut RunResources> instead?
As to avoid having to call it with &mut None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was unsure which one would be a better option but the suggestion is fair enough, besides it matches the behavior it has in the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was trying to apply the suggestion but it doesn't like that i mutated the Option value without setting &mut Option in the parameters, maybe there is a work around.

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be ugly but I think mut Option<&mut RunResources> is likely to work.

CHANGELOG.md Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented May 23, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 15.310 ± 0.184 15.117 15.701 1.01 ± 0.02
head blake2s_integration_benchmark 15.213 ± 0.138 14.999 15.519 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 4.997 ± 0.071 4.900 5.080 1.02 ± 0.02
head compare_arrays_200000 4.914 ± 0.065 4.830 5.030 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 3.224 ± 0.077 3.131 3.386 1.00
head dict_integration_benchmark 3.230 ± 0.046 3.159 3.308 1.00 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base factorial_multirun 5.259 ± 0.066 5.173 5.348 1.01 ± 0.02
head factorial_multirun 5.185 ± 0.066 5.075 5.308 1.00
Command Mean [s] Min [s] Max [s] Relative
base fibonacci_1000_multirun 4.563 ± 0.097 4.430 4.691 1.00
head fibonacci_1000_multirun 4.574 ± 0.047 4.503 4.655 1.00 ± 0.02
Command Mean [ms] Min [ms] Max [ms] Relative
base field_arithmetic_get_square_benchmark 225.3 ± 37.2 199.9 303.4 1.08 ± 0.18
head field_arithmetic_get_square_benchmark 208.4 ± 4.3 202.4 216.6 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 14.500 ± 0.354 14.185 15.156 1.01 ± 0.03
head integration_builtins 14.364 ± 0.248 13.999 14.716 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 15.957 ± 0.357 15.422 16.780 1.01 ± 0.03
head keccak_integration_benchmark 15.768 ± 0.233 15.377 16.238 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 5.046 ± 0.047 4.989 5.122 1.00 ± 0.02
head linear_search 5.040 ± 0.090 4.945 5.243 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 3.462 ± 0.065 3.333 3.585 1.01 ± 0.02
head math_cmp_and_pow_integration_benchmark 3.439 ± 0.047 3.362 3.533 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 3.262 ± 0.031 3.221 3.304 1.00
head math_integration_benchmark 3.278 ± 0.032 3.241 3.327 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 2.829 ± 0.030 2.796 2.903 1.00 ± 0.02
head memory_integration_benchmark 2.824 ± 0.031 2.784 2.881 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 3.185 ± 0.037 3.114 3.232 1.01 ± 0.02
head operations_with_data_structures_benchmarks 3.154 ± 0.065 3.086 3.306 1.00
Command Mean [s] Min [s] Max [s] Relative
base pedersen 1.087 ± 0.015 1.059 1.122 1.00 ± 0.03
head pedersen 1.086 ± 0.027 1.055 1.140 1.00
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.897 ± 0.027 1.854 1.933 1.00 ± 0.02
head poseidon_integration_benchmark 1.897 ± 0.019 1.871 1.923 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 4.182 ± 0.032 4.127 4.230 1.01 ± 0.02
head secp_integration_benchmark 4.126 ± 0.053 4.006 4.195 1.00
Command Mean [s] Min [s] Max [s] Relative
base set_integration_benchmark 2.146 ± 0.044 2.083 2.234 1.00 ± 0.02
head set_integration_benchmark 2.145 ± 0.030 2.111 2.187 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 9.320 ± 0.182 9.109 9.719 1.00
head uint256_integration_benchmark 9.370 ± 0.269 9.088 10.070 1.01 ± 0.03

@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Merging #1175 (2a8a8a8) into main (de6a232) will decrease coverage by 0.01%.
The diff coverage is 97.68%.

@@            Coverage Diff             @@
##             main    #1175      +/-   ##
==========================================
- Coverage   97.60%   97.60%   -0.01%     
==========================================
  Files          89       89              
  Lines       36066    36198     +132     
==========================================
+ Hits        35202    35330     +128     
- Misses        864      868       +4     
Impacted Files Coverage Δ
src/vm/runners/cairo_runner.rs 97.95% <97.14%> (-0.04%) ⬇️
src/cairo_run.rs 99.51% <100.00%> (+<0.01%) ⬆️
src/vm/hooks.rs 100.00% <100.00%> (ø)
src/vm/runners/builtin_runner/bitwise.rs 96.11% <100.00%> (ø)
src/vm/runners/builtin_runner/ec_op.rs 98.69% <100.00%> (ø)
src/vm/runners/builtin_runner/hash.rs 98.54% <100.00%> (ø)
src/vm/runners/builtin_runner/keccak.rs 99.08% <100.00%> (ø)
src/vm/runners/builtin_runner/mod.rs 99.37% <100.00%> (ø)
src/vm/runners/builtin_runner/poseidon.rs 97.48% <100.00%> (ø)
src/vm/runners/builtin_runner/range_check.rs 98.62% <100.00%> (ø)
... and 1 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@Oppen Oppen left a comment

Choose a reason for hiding this comment

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

LGTM but see comment.

Comment on lines 530 to 536
while vm.run_context.pc != address
&& !if let Some(r) = run_resources.as_ref() {
r.consumed()
} else {
false
}
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks confusing. Can you find a way to make it more straightforward?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think i can pull out a solution by calling a function that engulfs that behavior.

Copy link
Collaborator

@pefontana pefontana left a comment

Choose a reason for hiding this comment

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

I think that this PR #1181 will add this feature without making changes to the CairoRunner.run_from_entrypoint API
For now, let's leave this PR on stand by

@pefontana pefontana mentioned this pull request May 29, 2023
6 tasks
@pefontana pefontana requested review from fmoletta, Oppen and pefontana May 31, 2023 15:52
@pefontana pefontana enabled auto-merge June 6, 2023 16:17
@pefontana pefontana added this pull request to the merge queue Jun 6, 2023
Merged via the queue into main with commit 46ad0b8 Jun 6, 2023
@pefontana pefontana deleted the ImplementRunResourcesFuncs branch June 6, 2023 16:46
kariy pushed a commit to dojoengine/cairo-rs that referenced this pull request Jun 23, 2023
* Add RunResources structure

* Modify changelog

* change data type of n_steps from u64 to usize

* Implement run resources functions

* Fix tests

* set comment about calculation in cairo_run

* Change CHangelog and remove option from RunResources

* Fix clippy

* Add clone trait to run resources

* Add debug and default traits to RunResources

* Fix error in while loop inside run_until_pc

* Add helper function for clarity in run_until_pc loop

* Add test for cairo 0 contracts

* Add tests with Cairo 1 contracts

* Move RunResources struct to vm::runners::cairo_runner::RunResources

* Update CHANGELOG.md

* Fix wasm and no-std compilation

---------

Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
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.

5 participants