-
Notifications
You must be signed in to change notification settings - Fork 164
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
Hyper Threading Crate #1679
Merged
Merged
Hyper Threading Crate #1679
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a21fc06
Add Hyper Threading crate
e1a8b2b
Add naive script
aa47d07
Polish code
a8a2ebc
Add MAkefile command && create README.md
bad7979
Update README.md
e599688
update Changelog
e6a6d93
cargo fmt
f96f139
Merge branch 'main' into hyper-threading-crate
pefontana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "hyper_threading" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
keywords.workspace = true | ||
|
||
|
||
[dependencies] | ||
cairo-vm = { workspace = true } | ||
rayon = "1.9.0" | ||
tracing = "0.1.40" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Hyper-Threading Benchmarks for Cairo-VM | ||
|
||
## Overview | ||
This crate is designed to benchmark the performance of Cairo-VM in a hyper-threaded environment. By leveraging the [Rayon library](https://docs.rs/rayon/latest/rayon/), we can transform sequential computations into parallel ones, maximizing the utilization of available CPU cores. | ||
|
||
### Running Benchmarks | ||
To execute the benchmarks, navigate to the project's root directory and run the following command: | ||
|
||
```bash | ||
make hyper-threading-benchmarks | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
thread_counts=(1 2 4 6 8 10 12 16 24 32 ) | ||
binary="target/release/hyper_threading" | ||
|
||
|
||
cmd="hyperfine -r 1" | ||
|
||
# Build the command string with all thread counts | ||
for threads in "${thread_counts[@]}"; do | ||
# For hyperfine, wrap each command in 'sh -c' to correctly handle the environment variable | ||
cmd+=" -n \"threads: ${threads}\" 'sh -c \"RAYON_NUM_THREADS=${threads} ${binary}\"'" | ||
done | ||
|
||
# Execute the hyperfine command | ||
echo "Executing benchmark for all thread counts" | ||
eval $cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use cairo_vm::{ | ||
cairo_run::{cairo_run_program, CairoRunConfig}, | ||
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, | ||
types::program::Program, | ||
}; | ||
use rayon::iter::{IntoParallelIterator, ParallelIterator}; | ||
|
||
// Define include_bytes_relative macro to prepend a relative path to the file names | ||
macro_rules! include_bytes_relative { | ||
($fname:expr) => { | ||
include_bytes!(concat!("../../../cairo_programs/benchmarks/", $fname)) | ||
}; | ||
} | ||
|
||
fn main() { | ||
let mut programs = Vec::new(); | ||
|
||
let programs_bytes: [Vec<u8>; 18] = [ | ||
include_bytes_relative!("big_factorial.json").to_vec(), | ||
include_bytes_relative!("big_fibonacci.json").to_vec(), | ||
include_bytes_relative!("blake2s_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("compare_arrays_200000.json").to_vec(), | ||
include_bytes_relative!("dict_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("field_arithmetic_get_square_benchmark.json").to_vec(), | ||
include_bytes_relative!("integration_builtins.json").to_vec(), | ||
include_bytes_relative!("keccak_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("linear_search.json").to_vec(), | ||
include_bytes_relative!("math_cmp_and_pow_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("math_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("memory_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("operations_with_data_structures_benchmarks.json").to_vec(), | ||
include_bytes_relative!("pedersen.json").to_vec(), | ||
include_bytes_relative!("poseidon_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("secp_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("set_integration_benchmark.json").to_vec(), | ||
include_bytes_relative!("uint256_integration_benchmark.json").to_vec(), | ||
]; | ||
|
||
for bytes in &programs_bytes { | ||
programs.push(Program::from_bytes(bytes.as_slice(), Some("main")).unwrap()) | ||
} | ||
|
||
let start_time = std::time::Instant::now(); | ||
|
||
// Parallel execution of the program processing | ||
programs.into_par_iter().for_each(|program| { | ||
let cairo_run_config = CairoRunConfig { | ||
entrypoint: "main", | ||
trace_enabled: false, | ||
relocate_mem: false, | ||
layout: "all_cairo", | ||
proof_mode: true, | ||
secure_run: Some(false), | ||
..Default::default() | ||
}; | ||
let mut hint_executor = BuiltinHintProcessor::new_empty(); | ||
|
||
// Execute each program in parallel | ||
let _result = cairo_run_program(&program, &cairo_run_config, &mut hint_executor) | ||
.expect("Couldn't run program"); | ||
}); | ||
let elapsed = start_time.elapsed(); | ||
|
||
let programs_len: &usize = &programs_bytes.clone().len(); | ||
|
||
tracing::info!(%programs_len, ?elapsed, "Finished"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
hyperfine
own options here:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also no need to fire up the shell explicitly. The default behavior is to spawn one, unless you pass the
-N
option.