Skip to content

Commit

Permalink
Add Hyper Threading crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Fontana authored and Pedro Fontana committed Mar 18, 2024
1 parent c4d2108 commit a21fc06
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ members = [
"hint_accountant",
"examples/wasm-demo",
"cairo1-run",
"cairo-vm-tracer"
"cairo-vm-tracer",
"examples/hyper_threading"
]
default-members = [
"cairo-vm-cli",
Expand Down
14 changes: 14 additions & 0 deletions examples/hyper_threading/Cargo.toml
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"
101 changes: 101 additions & 0 deletions examples/hyper_threading/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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};

// #[derive(Debug, Error)]
// pub enum Error {
// #[error("The cairo program execution failed")]
// Runner(#[from] CairoRunError),
// }

// Define a 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 _n_cpus = rayon::current_num_threads();

let mut programs = Vec::new();
// let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
// let program = Program::from_bytes(program.as_slice(), Some("main")).unwrap();

// dbg!(1);
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(),
];

// dbg!(2);
for bytes in &programs_bytes {
programs.push(Program::from_bytes(bytes.as_slice(), Some("main")).unwrap())
}
// dbg!(3);
let start_time = std::time::Instant::now();

// for program in programs {
// 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();

// // TODO: Add error handling
// let _result = cairo_run_program(&program, &cairo_run_config, &mut hint_executor).expect("Couldn't run program");

// }

// 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
// dbg!(4);
let _result = cairo_run_program(&program, &cairo_run_config, &mut hint_executor)
.expect("Couldn't run program");
// dbg!(5);
});
let elapsed = start_time.elapsed();
let x = &programs_bytes.clone().len();

// dbg!(6);
// dbg!(elapsed);

// TODO: Remove this tracing?
tracing::info!(%x, ?elapsed, "Finished");
}

0 comments on commit a21fc06

Please sign in to comment.