Skip to content

fill holes is builtins segments #2036

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

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

Stavbe
Copy link
Collaborator

@Stavbe Stavbe commented Mar 27, 2025

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.

This change is Reviewable

@Stavbe Stavbe marked this pull request as ready for review March 27, 2025 15:01
@Stavbe Stavbe self-assigned this Mar 27, 2025
Copy link

github-actions bot commented Mar 27, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.099 ± 0.013 2.086 2.128 1.00
head big_factorial 2.111 ± 0.017 2.096 2.156 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.037 ± 0.018 2.020 2.087 1.00 ± 0.01
head big_fibonacci 2.028 ± 0.010 2.022 2.055 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.511 ± 0.091 7.440 7.758 1.00
head blake2s_integration_benchmark 7.615 ± 0.262 7.436 8.326 1.01 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.150 ± 0.021 2.121 2.186 1.00
head compare_arrays_200000 2.158 ± 0.012 2.137 2.173 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.439 ± 0.006 1.427 1.449 1.00
head dict_integration_benchmark 1.440 ± 0.009 1.428 1.452 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.205 ± 0.003 1.202 1.212 1.00 ± 0.01
head field_arithmetic_get_square_benchmark 1.203 ± 0.006 1.190 1.211 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.538 ± 0.030 7.504 7.586 1.00
head integration_builtins 7.566 ± 0.031 7.513 7.620 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.865 ± 0.115 7.777 8.140 1.00 ± 0.02
head keccak_integration_benchmark 7.859 ± 0.036 7.807 7.900 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.147 ± 0.014 2.127 2.176 1.00 ± 0.01
head linear_search 2.142 ± 0.021 2.116 2.185 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.515 ± 0.008 1.506 1.531 1.00
head math_cmp_and_pow_integration_benchmark 1.521 ± 0.010 1.510 1.545 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.458 ± 0.013 1.445 1.491 1.00
head math_integration_benchmark 1.460 ± 0.006 1.449 1.465 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.211 ± 0.003 1.207 1.218 1.00
head memory_integration_benchmark 1.215 ± 0.013 1.206 1.251 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.562 ± 0.008 1.550 1.575 1.00
head operations_with_data_structures_benchmarks 1.570 ± 0.017 1.557 1.610 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 530.2 ± 2.4 527.5 535.6 1.00
head pedersen 531.5 ± 2.9 527.7 536.6 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 622.2 ± 4.9 617.7 629.5 1.00
head poseidon_integration_benchmark 628.5 ± 5.4 624.8 641.7 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.847 ± 0.009 1.836 1.866 1.00
head secp_integration_benchmark 1.850 ± 0.020 1.831 1.900 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 627.2 ± 3.3 622.9 631.4 1.00
head set_integration_benchmark 665.8 ± 2.5 662.6 669.4 1.06 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.179 ± 0.025 4.147 4.223 1.00
head uint256_integration_benchmark 4.181 ± 0.038 4.153 4.284 1.00 ± 0.01

Copy link

codecov bot commented Mar 27, 2025

Codecov Report

Attention: Patch coverage is 90.12346% with 8 lines in your changes missing coverage. Please review.

Project coverage is 96.51%. Comparing base (10154c6) to head (2137db8).
Report is 2 commits behind head on starkware-development.

Files with missing lines Patch % Lines
vm/src/vm/vm_core.rs 85.41% 7 Missing ⚠️
vm/src/vm/runners/cairo_runner.rs 96.87% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           starkware-development    #2036      +/-   ##
=========================================================
- Coverage                  96.54%   96.51%   -0.03%     
=========================================================
  Files                        102      102              
  Lines                      42755    42834      +79     
=========================================================
+ Hits                       41276    41340      +64     
- Misses                      1479     1494      +15     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r1, all commit messages.
Reviewable status: 2 of 3 files reviewed, 7 unresolved discussions (waiting on @Stavbe)


vm/src/vm/vm_core.rs line 755 at r1 (raw file):

    pub fn complete_builtin_auto_deductions(&mut self) -> Result<(), VirtualMachineError> {
        for builtin in self.builtin_runners.iter() {
            let index: usize = builtin.base();

move down and rename

Suggestion:

let builtin_index: usize = builtin.base();

vm/src/vm/vm_core.rs line 770 at r1 (raw file):

                    MemoryCell::NONE,
                );
            }

Skip the irrelevant builtins and put real logic below

Suggestion:

            if matches!(
                builtin,
                BuiltinRunner::Output(_) | BuiltinRunner::SegmentArena(_)
            ) {
                continue;
            }

vm/src/vm/vm_core.rs line 773 at r1 (raw file):

            // Collect the values that need to be written to the memory.
            let mut new_values: Vec<(usize, MemoryCell)> = vec![];

Nit

Suggestion:

let mut missing_values: Vec<(usize, MemoryCell)> = vec![];

vm/src/vm/vm_core.rs line 784 at r1 (raw file):

                {
                    let memory_value = cell.get_value();
                    if memory_value.is_some() {

Add comment

Suggestion:

// Checks that the value in the memory is correct.
if memory_value.is_some() {

vm/src/vm/vm_core.rs line 784 at r1 (raw file):

                {
                    let memory_value = cell.get_value();
                    if memory_value.is_some() {

Consider to change to a match statement

Code quote:

                    if memory_value.is_some() {

vm/src/vm/vm_core.rs line 791 at r1 (raw file):

                        }
                    } else {
                        new_values.push((offset, MemoryCell::new(deduced_memory_cell)));

same

Suggestion:

// Collect value to be stored in memory.
new_values.push((offset, MemoryCell::new(deduced_memory_cell)));

vm/src/vm/vm_core.rs line 796 at r1 (raw file):

            }

            for (offset, value) in new_values {

rename and add comment above

Suggestion:

for (address, value) in new_values {

@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch 4 times, most recently from 59f10c9 to c373626 Compare March 27, 2025 17:10
Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 3 files reviewed, 5 unresolved discussions (waiting on @shaharsamocha7)


vm/src/vm/vm_core.rs line 755 at r1 (raw file):

Previously, shaharsamocha7 wrote…

move down and rename

Done.


vm/src/vm/vm_core.rs line 784 at r1 (raw file):

Previously, shaharsamocha7 wrote…

Add comment

Done.


vm/src/vm/vm_core.rs line 791 at r1 (raw file):

Previously, shaharsamocha7 wrote…

same

Done.


vm/src/vm/vm_core.rs line 796 at r1 (raw file):

Previously, shaharsamocha7 wrote…

rename and add comment above

I think offset is more correct because it is not relocated to addresses at this point; only segment index and offset

Base automatically changed from stav/sync_starkware_dev to starkware-development March 27, 2025 19:31
Copy link

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2.
Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @Stavbe)


vm/src/vm/vm_core.rs line 796 at r1 (raw file):

Previously, Stavbe wrote…

I think offset is more correct because it is not relocated to addresses at this point; only segment index and offset

ok

@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch 4 times, most recently from 4532fff to 7780af2 Compare March 30, 2025 10:36
Copy link

github-actions bot commented Mar 30, 2025

**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 ± σ):     26.429 s ±  0.013 s    [User: 25.657 s, System: 0.769 s]
  Range (min … max):   26.419 s … 26.438 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     26.587 s ±  0.073 s    [User: 25.783 s, System: 0.802 s]
  Range (min … max):   26.535 s … 26.639 s    2 runs
 
Summary
  hyper_threading_main threads: 1 ran
    1.01 ± 0.00 times faster than hyper_threading_pr 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 ± σ):     14.661 s ±  0.057 s    [User: 25.711 s, System: 0.834 s]
  Range (min … max):   14.620 s … 14.701 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     14.896 s ±  0.010 s    [User: 25.915 s, System: 0.858 s]
  Range (min … max):   14.889 s … 14.903 s    2 runs
 
Summary
  hyper_threading_main threads: 2 ran
    1.02 ± 0.00 times faster than hyper_threading_pr 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 ± σ):     10.600 s ±  0.589 s    [User: 37.871 s, System: 0.930 s]
  Range (min … max):   10.184 s … 11.017 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     11.041 s ±  0.176 s    [User: 38.796 s, System: 1.024 s]
  Range (min … max):   10.917 s … 11.166 s    2 runs
 
Summary
  hyper_threading_main threads: 4 ran
    1.04 ± 0.06 times faster than hyper_threading_pr 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 ± σ):     10.389 s ±  0.227 s    [User: 38.212 s, System: 0.932 s]
  Range (min … max):   10.228 s … 10.550 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.898 s ±  0.084 s    [User: 38.699 s, System: 1.003 s]
  Range (min … max):   10.838 s … 10.957 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.05 ± 0.02 times faster than hyper_threading_pr 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 ± σ):     10.334 s ±  0.055 s    [User: 38.457 s, System: 0.956 s]
  Range (min … max):   10.295 s … 10.373 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     10.532 s ±  0.140 s    [User: 39.502 s, System: 0.989 s]
  Range (min … max):   10.432 s … 10.631 s    2 runs
 
Summary
  hyper_threading_main threads: 8 ran
    1.02 ± 0.01 times faster than hyper_threading_pr 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 ± σ):     10.332 s ±  0.142 s    [User: 38.609 s, System: 1.043 s]
  Range (min … max):   10.232 s … 10.433 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     10.616 s ±  0.196 s    [User: 39.501 s, System: 1.104 s]
  Range (min … max):   10.478 s … 10.755 s    2 runs
 
Summary
  hyper_threading_main threads: 16 ran
    1.03 ± 0.02 times faster than hyper_threading_pr threads: 16


@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch 6 times, most recently from 190d2c2 to f55117c Compare March 30, 2025 14:32
yuvalsw
yuvalsw previously approved these changes Mar 30, 2025
Copy link
Collaborator

@yuvalsw yuvalsw left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 5 files reviewed, all discussions resolved (waiting on @Stavbe)

@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch from f55117c to 2721498 Compare March 31, 2025 09:07
Copy link

@DavidLevitGurevich DavidLevitGurevich left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 5 files reviewed, 1 unresolved discussion (waiting on @Stavbe)


vm/src/tests/memory_comparator.py line 26 at r5 (raw file):

                print(f'{k}:{cairo_mem[k]}')
                mismatched = True
    

remove spaces

@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch 3 times, most recently from 34b9a28 to 20f0dfa Compare March 31, 2025 16:29
@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch 2 times, most recently from f0f4db7 to 9fc7999 Compare April 1, 2025 16:11
Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 5 files reviewed, 1 unresolved discussion (waiting on @DavidLevitGurevich and @shaharsamocha7)


vm/src/tests/memory_comparator.py line 26 at r5 (raw file):

Previously, DavidLevitGurevich wrote…

remove spaces

Done.

Copy link

@DavidLevitGurevich DavidLevitGurevich left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r4, 1 of 3 files at r7, all commit messages.
Reviewable status: 3 of 5 files reviewed, 2 unresolved discussions (waiting on @JulianGCalderon, @shaharsamocha7, and @Stavbe)


vm/src/tests/memory_comparator.py line 12 at r7 (raw file):

        compare_memory_file_contents(f1.read(), f2.read())

def compare_memory_file_contents(cairo_raw_mem, cairo_rs_raw_mem):

what does this function do now?

Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 of 5 files reviewed, 2 unresolved discussions (waiting on @DavidLevitGurevich, @JulianGCalderon, and @shaharsamocha7)


vm/src/tests/memory_comparator.py line 12 at r7 (raw file):

Previously, DavidLevitGurevich wrote…

what does this function do now?

Nothing, But I didn't want to remove all the calls for it because maybe we will add it back after the new flow will be fully supported, wdyt?

Copy link

@DavidLevitGurevich DavidLevitGurevich left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r7.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @JulianGCalderon and @Stavbe)


vm/src/tests/memory_comparator.py line 12 at r7 (raw file):

Previously, Stavbe wrote…

Nothing, But I didn't want to remove all the calls for it because maybe we will add it back after the new flow will be fully supported, wdyt?

add a Huge TODO, and don't totally delete the code, only disable it


vm/src/vm/runners/cairo_runner.rs line 5662 at r7 (raw file):

            .get_prover_input_info()
            .expect("Failed to get prover input info");
        assert!(prover_input.builtins_segments.get(&6) == Some(&BuiltinName::bitwise));

add another check that also something that is not the last was filled

@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch from 9fc7999 to 9200100 Compare April 2, 2025 12:42
@Stavbe Stavbe force-pushed the stav/fill_builtins_segments_holes branch from 9200100 to 2137db8 Compare April 2, 2025 12:43
Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 of 5 files reviewed, 3 unresolved discussions (waiting on @DavidLevitGurevich and @JulianGCalderon)


vm/src/tests/memory_comparator.py line 12 at r7 (raw file):

Previously, DavidLevitGurevich wrote…

add a Huge TODO, and don't totally delete the code, only disable it

Done.


vm/src/vm/runners/cairo_runner.rs line 5662 at r7 (raw file):

Previously, DavidLevitGurevich wrote…

add another check that also something that is not the last was filled

Added a todo at the beginning of the test

Copy link

@DavidLevitGurevich DavidLevitGurevich left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 3 files at r1, 2 of 2 files at r8, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @JulianGCalderon)

Copy link
Collaborator

@yuvalsw yuvalsw left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @JulianGCalderon)

@FrancoGiachetta
Copy link
Contributor

Hi @Stavbe! Could you add a description telling the purpose of this PR?

@Stavbe Stavbe merged commit 1d70783 into starkware-development Apr 3, 2025
91 of 93 checks passed
@Stavbe Stavbe deleted the stav/fill_builtins_segments_holes branch April 3, 2025 12:39
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.

6 participants