Skip to content

Commit

Permalink
Change gas from u128 to u64 (#890)
Browse files Browse the repository at this point in the history
* Revert "Revert builtin cost rework (#874)"

This reverts commit 355c250.

* x

* fix gas

* add paralel test

* Add entry point info to AotContractExecutor (#889)

* store entry point info, optimize abi storage

* use felt

* update hash

* upd replay

* try with thread local

* try to fix with thread local in runtime2

* fix

* upd ref ci

* upd replay

* fix macos

* try to fix macos

* try to fix bench

* fix

* try to fix bench ci

* save space

* upd rev

* try to fix broken pipe

* try to fix bench on ci

* remove all features

* add cache key

* update replay rev

* fix cargo.lock

* Revert "update replay rev"

This reverts commit 40f1acc.

* fix cargo.lock

* works with leaks

* fix

* upd replay

* fix bench

* Reorder deps

* start porting gas to u64

* u64 on syscalls

* fix

* Fix benches.

* clippy

* fix gas refund

* fmt

* fix

* fix get gas

* update resource bounds

* upd ci

* upd replay

* fix ci

* try

* fix align

* fix bench pr

* better fix for u256

* upd replay

* upd replay

* fix

* remove dbg!

* upd replay

* fix

* Revert conversion of `ResourceBounds` field type.

* Update sequencer revision (for CI runs).

* Update replay dependency.

* read invoke data end pad

* upd ci

---------

Co-authored-by: Pedro Fontana <[email protected]>
Co-authored-by: Franco Giachetta <[email protected]>
Co-authored-by: Julián González Calderón <[email protected]>
Co-authored-by: Esteve Soler Arderiu <[email protected]>
  • Loading branch information
5 people authored Nov 15, 2024
1 parent 59febb8 commit f1554de
Show file tree
Hide file tree
Showing 45 changed files with 691 additions and 714 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/bench-hyperfine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ jobs:
--export-markdown "${f%.*}.md" \
--export-json "${f%.*}.json" \
--warmup 3 \
-n "head $(basename $f) (JIT)" "./bin/cairo-native-run-head --run-mode=jit -s $f --opt-level 3 --available-gas 19446744073709551615" \
-n "base $(basename $f) (JIT)" "./bin/cairo-native-run-base --run-mode=jit -s $f --opt-level 3 --available-gas 19446744073709551615" \
-n "head $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-head.a ./bin/cairo-native-run-head --run-mode=aot -s $f --opt-level 3 --available-gas 19446744073709551615" \
-n "base $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-base.a ./bin/cairo-native-run-base --run-mode=aot -s $f --opt-level 3 --available-gas 19446744073709551615" \
-n "head $(basename $f) (JIT)" "./bin/cairo-native-run-head --run-mode=jit -s $f --opt-level 3 --available-gas 18446744073709551615" \
-n "base $(basename $f) (JIT)" "./bin/cairo-native-run-base --run-mode=jit -s $f --opt-level 3 --available-gas 18446744073709551615" \
-n "head $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-head.a ./bin/cairo-native-run-head --run-mode=aot -s $f --opt-level 3 --available-gas 18446744073709551615" \
-n "base $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-base.a ./bin/cairo-native-run-base --run-mode=aot -s $f --opt-level 3 --available-gas 18446744073709551615" \
>> /dev/stderr
done
- name: Print tables
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Daily Block Run

on:
schedule:
# At the end of every day
- cron: "0 0 * * *"
# At the end of every day
- cron: "0 0 * * *"

env:
RANGE_SIZE: 25
SEQUENCER_REV: 1b1b95cae7ae07b9bc778443ca75ee18008a6bc8
SEQUENCER_REV: 93b6da848802297626556950a0c715952aca552d

jobs:
run:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
# Install dependencies
- uses: ./cairo_native/.github/actions/install-linux-deps
- name: Setup rust env
uses: dtolnay/rust-toolchain@1.80.0
uses: dtolnay/rust-toolchain@1.82.0
- name: Retreive cached dependecies
uses: Swatinem/rust-cache@v2
- name: Build Cairo Native Runtime Library
Expand All @@ -65,7 +65,7 @@ jobs:
cd ../cairo_native
make runtime
echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a" > $GITHUB_ENV
- name: Patch dependencies
run: |
# Patches native dependency to local path, to use current cairo native version
Expand All @@ -79,7 +79,7 @@ jobs:
NEW_REV="$SEQUENCER_REV"
sed -Ei "s#(\"$GIT\" *, *rev *= *\").?*(\".*)#\1$NEW_REV\2#" Cargo.toml
grep $GIT Cargo.toml
- name: Run with Native
if: ${{ matrix.runner == 'native' }}
run: |
Expand All @@ -101,7 +101,6 @@ jobs:
name: dump-${{matrix.block}}-${{matrix.runner}}
path: starknet-replay/state_dumps/${{matrix.runner}}


compare:
needs: [run]
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/starknet-blocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: "ref-dc35685315f4df544d5d1cf006d3a2a25d8c2c9a"
key: "ref-3da09d1b6f3d5c089900f5521cf05b6444893e61"

- name: Check and free hdd space left
if: ${{ matrix.runner == 'native' }}
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: lambdaclass/starknet-replay
ref: dc35685315f4df544d5d1cf006d3a2a25d8c2c9a
ref: 3da09d1b6f3d5c089900f5521cf05b6444893e61
path: replay

- name: Install Starknet Replay deps
Expand Down
12 changes: 6 additions & 6 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ fn criterion_benchmark(c: &mut Criterion) {
find_function_id(&logistic_map, "logistic_map::logistic_map::main").unwrap();

c.bench_function("Cached JIT factorial_2M", |b| {
b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX)));
b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u64::MAX)));
});
c.bench_function("Cached JIT fib_2M", |b| {
b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX)));
b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u64::MAX)));
});
c.bench_function("Cached JIT logistic_map", |b| {
b.iter(|| jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX)));
b.iter(|| jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u64::MAX)));
});

c.bench_function("Cached AOT factorial_2M", |b| {
b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX)));
b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u64::MAX)));
});
c.bench_function("Cached AOT fib_2M", |b| {
b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX)));
b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u64::MAX)));
});
c.bench_function("Cached AOT logistic_map", |b| {
b.iter(|| aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX)));
b.iter(|| aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u64::MAX)));
});
}

Expand Down
12 changes: 6 additions & 6 deletions benches/libfuncs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn bench_libfuncs(c: &mut Criterion) {

// Execute the program.
let result = native_executor
.invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128))
.invoke_dynamic(&entry.id, &[], Some(u64::MAX))
.unwrap();
black_box(result)
})
Expand All @@ -81,14 +81,14 @@ pub fn bench_libfuncs(c: &mut Criterion) {
// warmup
for _ in 0..5 {
native_executor
.invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128))
.invoke_dynamic(&entry.id, &[], Some(u64::MAX))
.unwrap();
}

b.iter(|| {
// Execute the program.
let result = native_executor
.invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128))
.invoke_dynamic(&entry.id, &[], Some(u64::MAX))
.unwrap();
black_box(result)
})
Expand All @@ -108,7 +108,7 @@ pub fn bench_libfuncs(c: &mut Criterion) {

// Execute the program.
let result = native_executor
.invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128))
.invoke_dynamic(&entry.id, &[], Some(u64::MAX))
.unwrap();
black_box(result)
})
Expand All @@ -128,14 +128,14 @@ pub fn bench_libfuncs(c: &mut Criterion) {
// warmup
for _ in 0..5 {
native_executor
.invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128))
.invoke_dynamic(&entry.id, &[], Some(u64::MAX))
.unwrap();
}

b.iter(|| {
// Execute the program.
let result = native_executor
.invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128))
.invoke_dynamic(&entry.id, &[], Some(u64::MAX))
.unwrap();
black_box(result)
})
Expand Down
3 changes: 1 addition & 2 deletions docs/gas_builtin_accounting.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and greged’s about
### Gas builtin
The gas builtin is used in Sierra in order to perform gas accounting. It is
passed as an input to all function calls and holds the current remaining
gas. It is represented in MLIR by a simple `u128`.
gas. It is represented in MLIR by a simple `u64`.

### Gas metadata
The process of calculating gas begins at the very outset of the compilation
Expand Down Expand Up @@ -236,4 +236,3 @@ constant 1.
When this compiled MLIR code is called, the initial value of all builtin
counters is set to `0` as can be seen in the
[`invoke_dynamic` function](../src/executor.rs#L240).

Loading

0 comments on commit f1554de

Please sign in to comment.