Skip to content
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

Change tests to use sierra generator #1057

Closed
wants to merge 82 commits into from
Closed

Conversation

FrancoGiachetta
Copy link
Contributor

@FrancoGiachetta FrancoGiachetta commented Jan 16, 2025

This PR uses the sierra generator to test libfuncs. This is to prevent us from any possible change in the sierra generator which could generate false positives in tests. Some tests were left untouched either because the libfunc they were targeting was already being tested in another test, or because they were using the libfunc explicitly.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.

Copy link

github-actions bot commented Jan 16, 2025

✅ Code is now correctly formatted.

Copy link

github-actions bot commented Jan 16, 2025

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 4.100 ± 0.051 4.007 4.163 1.03 ± 0.01
base dict_insert.cairo (AOT) 3.984 ± 0.029 3.936 4.023 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 3.874 ± 0.044 3.808 3.968 1.03 ± 0.01
head dict_insert.cairo (AOT) 3.776 ± 0.028 3.746 3.826 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 3.914 ± 0.060 3.843 4.030 1.04 ± 0.02
base dict_snapshot.cairo (AOT) 3.752 ± 0.019 3.707 3.773 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 3.731 ± 0.021 3.700 3.767 1.02 ± 0.02
head dict_snapshot.cairo (AOT) 3.673 ± 0.059 3.611 3.784 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 4.213 ± 0.041 4.163 4.280 1.00 ± 0.01
base factorial_2M.cairo (AOT) 4.199 ± 0.032 4.161 4.250 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 4.134 ± 0.058 4.063 4.266 1.02 ± 0.02
head factorial_2M.cairo (AOT) 4.062 ± 0.024 4.021 4.089 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 3.800 ± 0.038 3.751 3.876 1.01 ± 0.01
base fib_2M.cairo (AOT) 3.764 ± 0.029 3.708 3.804 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 3.622 ± 0.028 3.592 3.672 1.00
head fib_2M.cairo (AOT) 3.654 ± 0.013 3.639 3.679 1.01 ± 0.01

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 3.963 ± 0.023 3.915 3.992 1.04 ± 0.01
base linear_search.cairo (AOT) 3.814 ± 0.017 3.777 3.837 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 3.863 ± 0.025 3.813 3.908 1.04 ± 0.01
head linear_search.cairo (AOT) 3.701 ± 0.028 3.647 3.743 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 4.031 ± 0.040 3.984 4.106 1.03 ± 0.02
base logistic_map.cairo (AOT) 3.900 ± 0.043 3.836 3.984 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 3.976 ± 0.064 3.878 4.072 1.06 ± 0.02
head logistic_map.cairo (AOT) 3.744 ± 0.018 3.717 3.778 1.00

Copy link

github-actions bot commented Jan 16, 2025

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 20.682 ± 0.052 20.622 20.755 5.24 ± 0.03
cairo-native (embedded AOT) 3.950 ± 0.021 3.908 3.976 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.020 ± 0.026 3.991 4.065 1.02 ± 0.01

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 6.030 ± 0.038 5.956 6.080 1.62 ± 0.02
cairo-native (embedded AOT) 3.722 ± 0.033 3.668 3.791 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.787 ± 0.016 3.767 3.819 1.02 ± 0.01

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 14.159 ± 0.055 14.103 14.250 3.43 ± 0.02
cairo-native (embedded AOT) 4.125 ± 0.025 4.088 4.164 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.206 ± 0.055 4.141 4.310 1.02 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 14.117 ± 0.071 14.005 14.247 3.87 ± 0.05
cairo-native (embedded AOT) 3.650 ± 0.039 3.588 3.720 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.688 ± 0.034 3.650 3.762 1.01 ± 0.01

Benchmark for program linear_search

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 6.023 ± 0.036 5.966 6.073 1.58 ± 0.02
cairo-native (embedded AOT) 3.803 ± 0.031 3.775 3.879 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.947 ± 0.035 3.898 4.013 1.04 ± 0.01

Benchmark for program logistic_map

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.885 ± 0.051 5.810 5.977 1.52 ± 0.02
cairo-native (embedded AOT) 3.869 ± 0.031 3.820 3.926 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.041 ± 0.039 3.993 4.106 1.04 ± 0.01

Comment on lines +178 to +186
match ty {
CoreTypeConcrete::Box(info)
| CoreTypeConcrete::NonZero(info)
| CoreTypeConcrete::Nullable(info)
| CoreTypeConcrete::Snapshot(info) => {
return self.to_ptr(arena, registry, &info.ty, find_dict_overrides);
}
_ => {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this logic be in the match just below, rather than in a separate match?

Copy link
Contributor Author

@FrancoGiachetta FrancoGiachetta Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That match below is different, it is a match of self which is a Value. However, ty is a CoreTypeConcrete

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The programs in this file are very complex, and the sierra generator is not easy to follow. Maybe we should leave them as sierra code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, is true that is quite complex. I agree that leaving those in sierra could be better. What are you thoughts on this @gabrielbosio?

Comment on lines +763 to +767
if cfg!(test) {
Self::Null
} else {
native_panic!("todo: implement uint128mulguarantee from_ptr")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it only implemented in tests?

Comment on lines +211 to +221
let Value::Struct {
fields,
debug_name: _,
} = run_sierra_program(&UINT512_DIVMOD_U256, &[lhs, rhs]).return_value
else {
panic!("should be a struct");
};

let result = jit_struct!(fields[0].clone(), fields[1].clone());

assert_eq!(result, jit_struct!(output_u512, output_u256));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also assert the output of all the fields, instead of only the first two?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready A PR that is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants