Skip to content

Added hints felt unpacking for blake #2032

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 7, 2025

Conversation

yuvalsw
Copy link
Collaborator

@yuvalsw yuvalsw commented Mar 27, 2025

This PR is an as-is copy of AlonT's PR pushed to a fork repo.


This change is Reviewable

@yuvalsw yuvalsw force-pushed the yuval/blake_felt_unpacking branch from bd562f4 to 327c665 Compare March 27, 2025 19:33
Copy link
Collaborator

@YairVaknin-starkware YairVaknin-starkware 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: 0 of 4 files reviewed, all discussions resolved

@@ -947,13 +958,13 @@ ids.res.d2 = res_split[2]"#}),
a = []
for _ in range(length):
a.append( num & ((1 << num_bits_shift) - 1) )
num = num >> num_bits_shift
Copy link
Collaborator

Choose a reason for hiding this comment

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

revert

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return tuple(a)

def pack(z, num_bits_shift: int) -> int:
limbs = (z.d0, z.d1, z.d2)
return sum(limb << (num_bits_shift * i) for i, limb in enumerate(limbs))

Copy link
Collaborator

Choose a reason for hiding this comment

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

revert

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

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

Hi @yuvalsw! I left you a minor comment.

Also, some CI jobs seem to be failing.

@@ -426,6 +426,17 @@ segments.write_arg(ids.data + 4, [(ids.high >> (B * i)) & MASK for i in range(4)
MASK = 2 ** 32 - 1
segments.write_arg(ids.data, [(ids.high >> (B * (3 - i))) & MASK for i in range(4)])
segments.write_arg(ids.data + 4, [(ids.low >> (B * (3 - i))) & MASK for i in range(4)])"#}),
(IS_MORE_THAN_63_BITS_AND_NOT_END, indoc! {r#"memory[ap] = to_felt_or_relocatable((ids.end != ids.packed_values) and (memory[ids.packed_values] < 2**63))"#}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the python code:

memory[ap] = to_felt_or_relocatable(
    (ids.end != ids.packed_values) and
    (memory[ids.packed_values] < 2**63)
)

Shouldn't the hint be called IS_LESS_THAN_63_BITS_AND_NOT_END?

If so, could you update other mentions to this hint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@yuvalsw yuvalsw force-pushed the yuval/blake_felt_unpacking branch from 327c665 to 71770c9 Compare April 5, 2025 10:51
Copy link

github-actions bot commented Apr 5, 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.277 s ±  0.035 s    [User: 25.521 s, System: 0.755 s]
  Range (min … max):   26.253 s … 26.302 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     26.457 s ±  0.029 s    [User: 25.646 s, System: 0.808 s]
  Range (min … max):   26.436 s … 26.477 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.568 s ±  0.034 s    [User: 25.588 s, System: 0.759 s]
  Range (min … max):   14.544 s … 14.592 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     14.793 s ±  0.066 s    [User: 25.763 s, System: 0.853 s]
  Range (min … max):   14.746 s … 14.840 s    2 runs
 
Summary
  hyper_threading_main threads: 2 ran
    1.02 ± 0.01 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.762 s ±  0.107 s    [User: 37.459 s, System: 0.943 s]
  Range (min … max):   10.687 s … 10.838 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.914 s ±  0.273 s    [User: 38.077 s, System: 0.987 s]
  Range (min … max):   10.721 s … 11.107 s    2 runs
 
Summary
  hyper_threading_main threads: 4 ran
    1.01 ± 0.03 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.395 s ±  0.046 s    [User: 37.658 s, System: 0.940 s]
  Range (min … max):   10.362 s … 10.428 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.496 s ±  0.120 s    [User: 38.913 s, System: 1.007 s]
  Range (min … max):   10.411 s … 10.581 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.01 ± 0.01 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.371 s ±  0.053 s    [User: 38.458 s, System: 0.912 s]
  Range (min … max):   10.334 s … 10.409 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     10.533 s ±  0.161 s    [User: 38.817 s, System: 1.000 s]
  Range (min … max):   10.420 s … 10.647 s    2 runs
 
Summary
  hyper_threading_main threads: 8 ran
    1.02 ± 0.02 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.235 s ±  0.173 s    [User: 38.619 s, System: 1.041 s]
  Range (min … max):   10.113 s … 10.357 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     10.384 s ±  0.207 s    [User: 39.210 s, System: 1.098 s]
  Range (min … max):   10.238 s … 10.530 s    2 runs
 
Summary
  hyper_threading_main threads: 16 ran
    1.01 ± 0.03 times faster than hyper_threading_pr threads: 16


Copy link
Collaborator Author

@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: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @FrancoGiachetta, @JulianGCalderon, and @YairVaknin-starkware)

@@ -947,13 +958,13 @@ ids.res.d2 = res_split[2]"#}),
a = []
for _ in range(length):
a.append( num & ((1 << num_bits_shift) - 1) )
num = num >> num_bits_shift
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return tuple(a)

def pack(z, num_bits_shift: int) -> int:
limbs = (z.d0, z.d1, z.d2)
return sum(limb << (num_bits_shift * i) for i, limb in enumerate(limbs))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link

github-actions bot commented Apr 5, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.022 ± 0.018 2.003 2.058 1.00
head big_factorial 2.066 ± 0.024 2.021 2.095 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 1.937 ± 0.011 1.920 1.957 1.00
head big_fibonacci 1.975 ± 0.013 1.956 1.993 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.274 ± 0.109 7.184 7.473 1.00
head blake2s_integration_benchmark 7.639 ± 0.101 7.503 7.863 1.05 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.072 ± 0.025 2.042 2.120 1.00
head compare_arrays_200000 2.102 ± 0.015 2.085 2.128 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.375 ± 0.008 1.361 1.383 1.00
head dict_integration_benchmark 1.389 ± 0.019 1.366 1.418 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.148 ± 0.009 1.136 1.162 1.00
head field_arithmetic_get_square_benchmark 1.195 ± 0.017 1.172 1.223 1.04 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.250 ± 0.041 7.186 7.318 1.00
head integration_builtins 7.666 ± 0.054 7.606 7.748 1.06 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.569 ± 0.100 7.480 7.754 1.00
head keccak_integration_benchmark 7.947 ± 0.050 7.876 8.045 1.05 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.054 ± 0.018 2.033 2.083 1.00
head linear_search 2.083 ± 0.019 2.057 2.108 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.437 ± 0.011 1.418 1.454 1.00
head math_cmp_and_pow_integration_benchmark 1.452 ± 0.014 1.436 1.477 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.392 ± 0.020 1.356 1.428 1.00
head math_integration_benchmark 1.413 ± 0.015 1.395 1.446 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.163 ± 0.015 1.142 1.195 1.00
head memory_integration_benchmark 1.174 ± 0.011 1.160 1.189 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.504 ± 0.020 1.481 1.540 1.00
head operations_with_data_structures_benchmarks 1.517 ± 0.009 1.507 1.538 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 513.3 ± 7.9 500.7 526.7 1.00
head pedersen 516.8 ± 10.4 501.1 528.5 1.01 ± 0.03
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 604.4 ± 8.4 593.6 619.8 1.00
head poseidon_integration_benchmark 610.4 ± 6.0 601.3 621.8 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.784 ± 0.024 1.758 1.840 1.00
head secp_integration_benchmark 1.797 ± 0.021 1.774 1.840 1.01 ± 0.02
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 641.0 ± 11.3 629.9 660.1 1.00
head set_integration_benchmark 651.8 ± 8.2 639.4 666.6 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.020 ± 0.049 3.966 4.144 1.00
head uint256_integration_benchmark 4.143 ± 0.020 4.117 4.174 1.03 ± 0.01

@yuvalsw yuvalsw force-pushed the yuval/blake_felt_unpacking branch from 71770c9 to 33d88a3 Compare April 6, 2025 05:49
Copy link
Collaborator Author

@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: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @FrancoGiachetta, @JulianGCalderon, and @YairVaknin-starkware)

@@ -426,6 +426,17 @@ segments.write_arg(ids.data + 4, [(ids.high >> (B * i)) & MASK for i in range(4)
MASK = 2 ** 32 - 1
segments.write_arg(ids.data, [(ids.high >> (B * (3 - i))) & MASK for i in range(4)])
segments.write_arg(ids.data + 4, [(ids.low >> (B * (3 - i))) & MASK for i in range(4)])"#}),
(IS_MORE_THAN_63_BITS_AND_NOT_END, indoc! {r#"memory[ap] = to_felt_or_relocatable((ids.end != ids.packed_values) and (memory[ids.packed_values] < 2**63))"#}),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

This PR is an as-is copy of AlonT's PR pushed to a fork repo.
@yuvalsw yuvalsw force-pushed the yuval/blake_felt_unpacking branch from 33d88a3 to a402928 Compare April 6, 2025 12:42
@yuvalsw yuvalsw changed the base branch from starkware-development to yuval/rebase_on_main April 6, 2025 12:44
Copy link

codecov bot commented Apr 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.53%. Comparing base (6dfd853) to head (a402928).
Report is 11 commits behind head on starkware-development.

Additional details and impacted files
@@                    Coverage Diff                    @@
##           starkware-development    #2032      +/-   ##
=========================================================
+ Coverage                  96.52%   96.53%   +0.01%     
=========================================================
  Files                        102      102              
  Lines                      42951    43082     +131     
=========================================================
+ Hits                       41458    41589     +131     
  Misses                      1493     1493              

☔ 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.

Base automatically changed from yuval/rebase_on_main to starkware-development April 7, 2025 05:04
Copy link
Collaborator

@YairVaknin-starkware YairVaknin-starkware 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: 0 of 4 files reviewed, 2 unresolved discussions (waiting on @FrancoGiachetta and @JulianGCalderon)

@yuvalsw yuvalsw merged commit 895be71 into starkware-development Apr 7, 2025
93 checks passed
@yuvalsw yuvalsw deleted the yuval/blake_felt_unpacking branch April 7, 2025 06:05
enitrat pushed a commit to kkrt-labs/cairo-vm that referenced this pull request Apr 22, 2025
This PR is an as-is copy of AlonT's PR pushed to a fork repo.
enitrat pushed a commit to kkrt-labs/cairo-vm that referenced this pull request May 6, 2025
This PR is an as-is copy of AlonT's PR pushed to a fork repo.
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.

4 participants