-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ffi to translate to llvm ir * better * progress * module to object * ld * compile * add compile * clean * fix ci * fix macos * progress * progress * progress * try * investigate * needed 1 more argument * changes * weird * realloc * clean a bit * cleanup * AOT preview. * Fix ARM trampoline. * Fix stuff. * Fix support for any number of arguments (stack alignment). * Prepare for x86_64 support. * Make it work on x86_64 linux. * Document x86_64 trampoline assembly. * Add call arguments flattening. * Updates. * Fix return values in `aarch64`. * Add AOT versions of NativeExecutor and ProgramCache. * Rename `JITValue` to `JitValue` to comply with Rust's naming convention. * Add enum ABI testing. * Fix docs. * Handle enum arguments. * Refactor enums into the stack. * Minor fix. * Make structures optionally memory-allocated. * Fix tail recursion with memory-allocated arguments. * Fix JIT value deserialization when memory allocated. * Fix typo. * Fix bool libfuncs. * Add `print_i8` debug utillity. * Fix invocation arguments. * Register debug utils on integration tests. * Fix memory-allocated enum payloads. * Fix JitValue deserialization. * Add `print_i128` debug utility. * Fix JIT invoke return pointer offsets. * Fix stuff. * Merge `src/jit_runtime.rs` into `src/executor/jit.rs`. Unify APIs. Various fixes. * Fix stuff. * It seems to be working now. * Support stack-allocated C-style enums. * Remove unused file. * Remove builtins from function signatures. Fix `enum_init` for non-memory-allocated enums. * Fix boolean libfuncs (bools are not memory-allocated). * Implement multi-variant non-memory-allocated enum support. * Support non-memory-allocated enum matches. * Fix gas handling. * Fix `enum_match` libfunc for C-style and single-variant non-memory-allocated enums. * Add support for `sint8`, `sint16` and `sint32`. * Lots of fixes. * Reorganize code for DRY. Support Starknet contracts. * Support `EcPoint`, `EcState` and `NonZero<T>` return types. * Support the syscall handler when calling `invoke_dynamic` directly. * Make contracts accept only felts and convert to `Span<felt252>` internally. Support snapshot arguments. Various fixes. * Fix gas on integration tests. * Minor fix. * Fix non-syscall-handler Starknet types. * Support dictionaries. Minor fixes. * Fix non-syscall-handler Starknet types support. * Minor fix. * Fix linker. * Merge branch 'main' into aot-with-stack-enums * Remove irrelevant autogenerated files. * Remove calling convention discovery testing code. * Revert "Remove irrelevant autogenerated files.". Reason: those files weren't autogenerated by my testing. This reverts commit 53f65ed. * Undo conditional benchmark execution. * Fix formatting and clippy issues. * Remove unsafe transmute that is no longer necessary. * Sort dependencies alphabetically. * Implement `Debug` for the contract caches. * Refactor out the necessary refcell. * Actually remove the refcell. * Fix stuff from previous changes. * Fix stuff. * Fix warnings. * Fix errors. * Fix argument stack align. * Fix warnings. * use env var to add aditional dir to search for runtime lib (#400) * use env var to add aditional dir to search for runtime lib * oops * Ignore failing tests. * Rename env var to something that makes more sense. Set the variable on the CI runners. * Fix macOS and coverage CI runs. * Fix CI again. * Add new bench to bench script. * Remove debug utils commented code. * Add optimization level flag to CLI. * Add shortcuts. * Add benchmarks. * Add direct invoke benchmarks. * Remove merge duplicates. * Fix after merge (tests). * Fix tests (workaround). * Fix fmt and issue (workaround). * Fix issue (workaround). * Add optimization level warning in the CLIs. * Limit the scope of an `unsafe` block. * Disable optimizations for criterion benchmarks. * Fix formatting. * Disable optimizations on compile time benchmarks. * Fix benches. * Disable direct invoke benches on Mac OS. --------- Co-authored-by: Edgar Luque <[email protected]>
- Loading branch information
1 parent
82884eb
commit 9ec1790
Showing
23 changed files
with
371 additions
and
69 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
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,154 @@ | ||
use cairo_lang_compiler::{ | ||
compile_prepared_db, db::RootDatabase, project::setup_project, CompilerConfig, | ||
}; | ||
use cairo_lang_sierra::program::Program; | ||
use cairo_native::{ | ||
cache::{AotProgramCache, JitProgramCache}, | ||
context::NativeContext, | ||
utils::find_function_id, | ||
OptLevel, | ||
}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use starknet_types_core::felt::Felt; | ||
use std::path::Path; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let context = NativeContext::new(); | ||
let mut aot_cache = AotProgramCache::new(&context); | ||
let mut jit_cache = JitProgramCache::new(&context); | ||
|
||
let factorial = load_contract("programs/benches/factorial_2M.cairo"); | ||
let fibonacci = load_contract("programs/benches/fib_2M.cairo"); | ||
let logistic_map = load_contract("programs/benches/logistic_map.cairo"); | ||
|
||
let aot_factorial = aot_cache.compile_and_insert(Felt::from(0), &factorial, OptLevel::None); | ||
let aot_fibonacci = aot_cache.compile_and_insert(Felt::from(1), &fibonacci, OptLevel::None); | ||
let aot_logistic_map = | ||
aot_cache.compile_and_insert(Felt::from(2), &logistic_map, OptLevel::None); | ||
|
||
let jit_factorial = jit_cache.compile_and_insert(Felt::from(0), &factorial, OptLevel::None); | ||
let jit_fibonacci = jit_cache.compile_and_insert(Felt::from(1), &fibonacci, OptLevel::None); | ||
let jit_logistic_map = | ||
jit_cache.compile_and_insert(Felt::from(2), &logistic_map, OptLevel::None); | ||
|
||
let factorial_function_id = find_function_id(&factorial, "factorial_2M::factorial_2M::main"); | ||
let fibonacci_function_id = find_function_id(&fibonacci, "fib_2M::fib_2M::main"); | ||
let logistic_map_function_id = | ||
find_function_id(&logistic_map, "logistic_map::logistic_map::main"); | ||
|
||
c.bench_function("Cached JIT factorial_2M", |b| { | ||
b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX), None)); | ||
}); | ||
c.bench_function("Cached JIT fib_2M", |b| { | ||
b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX), None)); | ||
}); | ||
c.bench_function("Cached JIT logistic_map", |b| { | ||
b.iter(|| { | ||
jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX), None) | ||
}); | ||
}); | ||
|
||
c.bench_function("Cached AOT factorial_2M", |b| { | ||
b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX), None)); | ||
}); | ||
c.bench_function("Cached AOT fib_2M", |b| { | ||
b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX), None)); | ||
}); | ||
c.bench_function("Cached AOT logistic_map", |b| { | ||
b.iter(|| { | ||
aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX), None) | ||
}); | ||
}); | ||
|
||
#[cfg(target_arch = "x86_64")] | ||
{ | ||
use std::mem::MaybeUninit; | ||
|
||
#[allow(dead_code)] | ||
struct PanicResult { | ||
tag: u8, | ||
payload: MaybeUninit<(i32, i32, *mut [u64; 4])>, | ||
} | ||
|
||
let aot_factorial_fn = unsafe { | ||
std::mem::transmute::<*const (), extern "C" fn(u128) -> (u128, PanicResult)>( | ||
aot_factorial | ||
.find_function_ptr(factorial_function_id) | ||
.cast(), | ||
) | ||
}; | ||
let aot_fibonacci_fn = unsafe { | ||
std::mem::transmute::<*const (), extern "C" fn(u128) -> (u128, PanicResult)>( | ||
aot_fibonacci | ||
.find_function_ptr(fibonacci_function_id) | ||
.cast(), | ||
) | ||
}; | ||
let aot_logistic_map_fn = unsafe { | ||
std::mem::transmute::<*const (), extern "C" fn(u128) -> (u128, PanicResult)>( | ||
aot_logistic_map | ||
.find_function_ptr(logistic_map_function_id) | ||
.cast(), | ||
) | ||
}; | ||
let jit_factorial_fn = unsafe { | ||
std::mem::transmute::<*const (), extern "C" fn(u128) -> (u128, PanicResult)>( | ||
jit_factorial | ||
.find_function_ptr(factorial_function_id) | ||
.cast(), | ||
) | ||
}; | ||
let jit_fibonacci_fn = unsafe { | ||
std::mem::transmute::<*const (), extern "C" fn(u128) -> (u128, PanicResult)>( | ||
jit_fibonacci | ||
.find_function_ptr(fibonacci_function_id) | ||
.cast(), | ||
) | ||
}; | ||
let jit_logistic_map_fn = unsafe { | ||
std::mem::transmute::<*const (), extern "C" fn(u128) -> (u128, PanicResult)>( | ||
jit_logistic_map | ||
.find_function_ptr(logistic_map_function_id) | ||
.cast(), | ||
) | ||
}; | ||
|
||
c.bench_function("Cached JIT factorial_2M (direct invoke)", |b| { | ||
b.iter(|| jit_factorial_fn(u128::MAX)); | ||
}); | ||
c.bench_function("Cached JIT fib_2M (direct invoke)", |b| { | ||
b.iter(|| jit_fibonacci_fn(u128::MAX)); | ||
}); | ||
c.bench_function("Cached JIT logistic_map (direct invoke)", |b| { | ||
b.iter(|| jit_logistic_map_fn(u128::MAX)); | ||
}); | ||
|
||
c.bench_function("Cached AOT factorial_2M (direct invoke)", |b| { | ||
b.iter(|| aot_factorial_fn(u128::MAX)); | ||
}); | ||
c.bench_function("Cached AOT fib_2M (direct invoke)", |b| { | ||
b.iter(|| aot_fibonacci_fn(u128::MAX)); | ||
}); | ||
c.bench_function("Cached AOT logistic_map (direct invoke)", |b| { | ||
b.iter(|| aot_logistic_map_fn(u128::MAX)); | ||
}); | ||
} | ||
} | ||
|
||
fn load_contract(path: impl AsRef<Path>) -> Program { | ||
let mut db = RootDatabase::builder().detect_corelib().build().unwrap(); | ||
let main_crate_ids = setup_project(&mut db, path.as_ref()).unwrap(); | ||
(*compile_prepared_db( | ||
&mut db, | ||
main_crate_ids, | ||
CompilerConfig { | ||
replace_ids: true, | ||
..Default::default() | ||
}, | ||
) | ||
.unwrap()) | ||
.clone() | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
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
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
Oops, something went wrong.