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

Ohadn/u128 encoded instr #1940

Merged
merged 1 commit into from
Feb 11, 2025
Merged

Ohadn/u128 encoded instr #1940

merged 1 commit into from
Feb 11, 2025

Conversation

ohad-nir-starkware
Copy link
Collaborator

@ohad-nir-starkware ohad-nir-starkware commented Feb 10, 2025

u128 encoded instr

Description

Set the encoded instruction to be u128 for opcode_extensions to come.

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

@ohad-nir-starkware ohad-nir-starkware self-assigned this Feb 10, 2025
@ohad-nir-starkware ohad-nir-starkware changed the base branch from main to ohadn/stwo_exclusive_programs_folder February 10, 2025 09:47
Copy link

github-actions bot commented Feb 10, 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 ± σ):     31.878 s ±  0.124 s    [User: 31.085 s, System: 0.791 s]
  Range (min … max):   31.790 s … 31.965 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     27.658 s ±  0.040 s    [User: 26.836 s, System: 0.821 s]
  Range (min … max):   27.630 s … 27.687 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.15 ± 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 ± σ):     17.912 s ±  0.297 s    [User: 31.313 s, System: 0.789 s]
  Range (min … max):   17.702 s … 18.122 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     15.340 s ±  0.024 s    [User: 26.981 s, System: 0.793 s]
  Range (min … max):   15.323 s … 15.357 s    2 runs
 
Summary
  hyper_threading_pr threads: 2 ran
    1.17 ± 0.02 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.302 s ±  0.714 s    [User: 44.308 s, System: 0.947 s]
  Range (min … max):   11.797 s … 12.807 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     11.037 s ±  0.198 s    [User: 40.610 s, System: 0.910 s]
  Range (min … max):   10.897 s … 11.177 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.11 ± 0.07 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 ± σ):     12.198 s ±  0.059 s    [User: 44.559 s, System: 0.936 s]
  Range (min … max):   12.156 s … 12.240 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     11.219 s ±  0.118 s    [User: 40.313 s, System: 0.933 s]
  Range (min … max):   11.136 s … 11.302 s    2 runs
 
Summary
  hyper_threading_pr threads: 6 ran
    1.09 ± 0.01 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 ± σ):     12.199 s ±  0.001 s    [User: 44.806 s, System: 0.935 s]
  Range (min … max):   12.198 s … 12.199 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     11.043 s ±  0.040 s    [User: 41.051 s, System: 0.944 s]
  Range (min … max):   11.015 s … 11.072 s    2 runs
 
Summary
  hyper_threading_pr threads: 8 ran
    1.10 ± 0.00 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.896 s ±  0.009 s    [User: 44.874 s, System: 1.068 s]
  Range (min … max):   11.890 s … 11.902 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     11.242 s ±  0.061 s    [User: 41.318 s, System: 1.024 s]
  Range (min … max):   11.199 s … 11.285 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.06 ± 0.01 times faster than hyper_threading_main threads: 16


Copy link

github-actions bot commented Feb 10, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.508 ± 0.026 2.473 2.548 1.13 ± 0.01
head big_factorial 2.219 ± 0.012 2.206 2.242 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.482 ± 0.069 2.426 2.635 1.13 ± 0.04
head big_fibonacci 2.202 ± 0.040 2.168 2.309 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 9.266 ± 0.267 9.143 10.012 1.12 ± 0.04
head blake2s_integration_benchmark 8.276 ± 0.200 8.195 8.842 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.626 ± 0.060 2.579 2.785 1.12 ± 0.03
head compare_arrays_200000 2.337 ± 0.023 2.319 2.391 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.718 ± 0.013 1.702 1.739 1.13 ± 0.01
head dict_integration_benchmark 1.520 ± 0.008 1.508 1.530 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.451 ± 0.039 1.431 1.560 1.11 ± 0.03
head field_arithmetic_get_square_benchmark 1.304 ± 0.008 1.295 1.319 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 9.416 ± 0.328 9.197 10.318 1.13 ± 0.04
head integration_builtins 8.314 ± 0.063 8.263 8.479 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 9.534 ± 0.140 9.414 9.911 1.12 ± 0.02
head keccak_integration_benchmark 8.521 ± 0.012 8.499 8.538 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.575 ± 0.016 2.555 2.605 1.13 ± 0.01
head linear_search 2.281 ± 0.006 2.271 2.291 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.766 ± 0.010 1.750 1.780 1.12 ± 0.01
head math_cmp_and_pow_integration_benchmark 1.581 ± 0.004 1.575 1.588 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.723 ± 0.049 1.696 1.859 1.12 ± 0.03
head math_integration_benchmark 1.537 ± 0.008 1.526 1.548 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.463 ± 0.019 1.438 1.489 1.15 ± 0.02
head memory_integration_benchmark 1.277 ± 0.009 1.261 1.289 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.817 ± 0.009 1.801 1.834 1.10 ± 0.01
head operations_with_data_structures_benchmarks 1.656 ± 0.007 1.646 1.671 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 592.7 ± 4.1 587.7 600.1 1.08 ± 0.01
head pedersen 549.4 ± 1.4 547.5 552.1 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 718.6 ± 9.2 703.7 735.2 1.09 ± 0.02
head poseidon_integration_benchmark 662.3 ± 3.6 657.3 667.3 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 2.067 ± 0.022 2.050 2.125 1.08 ± 0.01
head secp_integration_benchmark 1.921 ± 0.013 1.907 1.944 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 683.1 ± 2.1 679.0 685.3 1.01 ± 0.00
head set_integration_benchmark 674.2 ± 1.3 672.7 676.3 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 5.150 ± 0.125 5.051 5.427 1.13 ± 0.03
head uint256_integration_benchmark 4.546 ± 0.037 4.522 4.649 1.00

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.37%. Comparing base (1a135db) to head (43f4ba4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cairo-vm-tracer/src/tracer_data.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1940   +/-   ##
=======================================
  Coverage   96.37%   96.37%           
=======================================
  Files         102      102           
  Lines       41238    41250   +12     
=======================================
+ Hits        39742    39754   +12     
  Misses       1496     1496           

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

@ohad-nir-starkware ohad-nir-starkware changed the base branch from ohadn/stwo_exclusive_programs_folder to ohadn/get_u32_range February 10, 2025 11:54
@ohad-nir-starkware ohad-nir-starkware changed the base branch from ohadn/get_u32_range to ohadn/stwo_exclusive_programs_folder February 10, 2025 12:18
@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/stwo_exclusive_programs_folder branch from e7382da to 4f53823 Compare February 11, 2025 09:29
@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/u128_encoded_instr branch 2 times, most recently from 1bec5ba to afcbcea Compare February 11, 2025 10:05
@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/stwo_exclusive_programs_folder branch from 4f53823 to 51f7f4d Compare February 11, 2025 18:06
@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/stwo_exclusive_programs_folder branch from 51f7f4d to e4a3cb4 Compare February 11, 2025 18:29
@ohad-nir-starkware ohad-nir-starkware force-pushed the ohadn/stwo_exclusive_programs_folder branch from 1019002 to 23b291c Compare February 11, 2025 19:28
Copy link
Collaborator Author

@ohad-nir-starkware ohad-nir-starkware 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 9 files reviewed, 1 unresolved discussion (waiting on @fmoletta, @gabrielbosio, @igaray, @juanbono, @JulianGCalderon, @Oppen, @pefontana, and @YairVaknin-starkware)

vm/src/vm/decoding/decoder.rs Outdated Show resolved Hide resolved
@ohad-nir-starkware ohad-nir-starkware changed the base branch from ohadn/stwo_exclusive_programs_folder to main February 11, 2025 20:11
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.

LGTM

Copy link
Collaborator Author

@ohad-nir-starkware ohad-nir-starkware left a comment

Choose a reason for hiding this comment

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

@JulianGCalderon somehow reviewable marks you as both approving and blocking

Reviewable status: 0 of 9 files reviewed, 1 unresolved discussion (waiting on @fmoletta, @gabrielbosio, @igaray, @juanbono, @JulianGCalderon, @Oppen, @pefontana, and @YairVaknin-starkware)

const OPCODE_EXTENSION_OFF: u64 = 63;
/// opcode_extension_num>0 is for new Stwo opcodes.
pub fn decode_instruction(encoded_instr: u128) -> Result<Instruction, VirtualMachineError> {
const HIGH_BITS: u128 = ((1 << 127) - (1 << 64)) << 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rename this variable to HIGH_BITS_MASK and document its purpose.

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.

fn decode_offset(offset: u64) -> isize {
let vectorized_offset: [u8; 8] = offset.to_le_bytes();
fn decode_offset(offset: u128) -> isize {
let vectorized_offset: [u8; 8] = (offset as u64).to_le_bytes();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let vectorized_offset: [u8; 8] = (offset as u64).to_le_bytes();
let vectorized_offset: [u8; 16] = offset.to_le_bytes();

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
Collaborator Author

@ohad-nir-starkware ohad-nir-starkware 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 9 files reviewed, 3 unresolved discussions (waiting on @fmoletta, @gabrielbosio, @igaray, @juanbono, @JulianGCalderon, @Oppen, @pefontana, and @YairVaknin-starkware)

const OPCODE_EXTENSION_OFF: u64 = 63;
/// opcode_extension_num>0 is for new Stwo opcodes.
pub fn decode_instruction(encoded_instr: u128) -> Result<Instruction, VirtualMachineError> {
const HIGH_BITS: u128 = ((1 << 127) - (1 << 64)) << 1;
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.

fn decode_offset(offset: u64) -> isize {
let vectorized_offset: [u8; 8] = offset.to_le_bytes();
fn decode_offset(offset: u128) -> isize {
let vectorized_offset: [u8; 8] = (offset as u64).to_le_bytes();
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.

@gabrielbosio gabrielbosio added this pull request to the merge queue Feb 11, 2025
Merged via the queue into main with commit 5420908 Feb 11, 2025
93 checks passed
@gabrielbosio gabrielbosio deleted the ohadn/u128_encoded_instr branch February 11, 2025 23:14
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: 0 of 9 files reviewed, 4 unresolved discussions


a discussion (no related file):
this PR is irrelevant anymore right?

Copy link
Collaborator Author

@ohad-nir-starkware ohad-nir-starkware 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 9 files reviewed, 4 unresolved discussions


a discussion (no related file):

Previously, DavidLevitGurevich wrote…

this PR is irrelevant anymore right?

It has been merged and then PR 1948 has been merged to remove NonZeroReservedBits.

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