-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Hyper Threading crate * Add naive script * Polish code * Add MAkefile command && create README.md * Update README.md * update Changelog * cargo fmt --------- Co-authored-by: Pedro Fontana <[email protected]>
- Loading branch information
Showing
9 changed files
with
136 additions
and
3 deletions.
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"); | ||
} |