Commit Graph

3095 Commits

Author SHA1 Message Date
Thibaut Schaeffer
6048ba8239 Move field conversion to the autoprecompile crate (#3041)
Based on #3040, this PR makes the autoprecompile crate responsible for
converting from and to the user's field type. As a result, the openvm
crate only deals with the openvm Babybear, the powdr Babybear is only
used inside the APC crate. This leads to a lot of simplification, and
enables some derives.

TODO:
- [x] fix the cargo tree clash
2025-07-16 09:18:44 +00:00
Georg Wiese
bd45df06e4 Generalize InstructionMachineHandler (#3049)
This way, the selected AIR can depend on the entire instruction, not
just the opcode.
2025-07-15 13:28:06 +00:00
chriseth
57ed5b9bba Detect unsatisfiable first. (#3047) 2025-07-15 13:26:25 +00:00
Thibaut Schaeffer
922aa523c7 Trait based apc (#3040)
Group all traits under a single `Adapter` trait.
2025-07-15 11:56:56 +00:00
Steve Wang
9a07095cf3 Apc stats and columns saved tests (#3039)
Key design choices revolve around passing `ApcCandidate` stats out from
`create_apcs_with_cell_pgo`, `create_apcs_with_pgo`, etc. I explored a
few ways:
1. [Current solution] Add an `ApcStats` struct that wraps stats we want
to pass to `PowdrPrecompile`. I believe this is the most versatile
solution and avoids defects from the two solutions below.
2. Return `ApcCandidate` for `create_apcs_with_[x]_pgo` and
`create_apcs_with_pgo`. This solution requires filling dummy zeros for
`execution_frequency`, `width_before`, and `width_after`, which I think
aren't very clean. Besides, passing these values still require computing
the stats we care about later, so I think it's cleaner to explicitly
declare what we care about in `ApcStats` instead.
3. Use `Either::Left(ApcCandidate)` for cell PGO while
`Either::Right(Apc)` for other PGO modes. This isn't very clean, and
also has the disadvantage of requiring match clauses when constructing
elements of `PowdrExtension`.

```
struct ApcCandidate<P> {
    apc: Apc<P>,
    execution_frequency: usize,
    width_before: AirWidths,
    width_after: AirWidths,
}
```
2025-07-15 10:39:19 +00:00
chriseth
314da34308 Print function name for basic blocks. (#3032) 2025-07-14 15:52:45 +00:00
Thibaut Schaeffer
4f6eee46de Point reth to main (#3045)
omission in #3036
2025-07-14 15:43:47 +00:00
Thibaut Schaeffer
54861dd793 Move pgo to apc crate (#3036)
Larger PR, but after this basically everything that can be made agnostic
is agnostic.
`PowdrConfig` is split in two, as the `autoprecompile` crate does not
care about the arithmetization method. This could be cleaned up a bit
though.

Need to merge
https://github.com/powdr-labs/openvm-reth-benchmark/pull/24/ first and
update the hashes.

TODO:
- [x] merge #3033 
- [x] fix reth
- [x] remove POWDR_OPCODE constant in apc and pass it instead
2025-07-14 12:53:01 +00:00
Georg Wiese
5806f36c3a Better effectiveness plot (#3038)
Changes the effectiveness plot to this (example: Reth benchmark):
<img width="3323" height="1768" alt="reth"
src="https://github.com/user-attachments/assets/78f4eb2c-bd9b-4d83-b1c3-e2ea20286270"
/>

I think it is more intuitive that the [previous
version](https://github.com/powdr-labs/bench-results/blob/gh-pages/results/2025-07-10-0155/reth/effectiveness.png_stacked_histogram.png).

Also prints this summary of the largest blocks:
```
Top 10 Basic Blocks by Trace Cells:
 Opcode Trace Cells  Effectiveness  Instructions  Width Before  Width After
   4372      784.9M       3.358650            12           796          237
   4361      358.3M       4.085859            13           809          198
   8079      248.9M       3.692737            10           661          179
   4391      158.6M       2.861345            21          1362          476
   4359      130.3M       3.560976             5           292           82
   4390      128.9M       2.847418            37          2426          852
   9105      105.6M       5.720029           116          7968         1393
   4368       99.4M       6.938776            24          1700          245
   9104       97.2M       4.342214           104          7334         1689
   4385       87.8M       2.671587            11           724          271
```
2025-07-11 11:11:28 +00:00
Thibaut Schaeffer
55048cfd32 Move block detection to APC crate (#3033)
Moving block detection to the APC crate. 
After this PR, a larger chunk of the `customize` function is
openvm-agnostic.
2025-07-11 08:59:40 +00:00
Steve Wang
616492258c Improve OVM compilation tests (#3026)
In general, it makes more sense to always test:
- The full `AirMetrics` (including log up and preprocessed columns),
instead of just the main columns.
- The sum of `AirMetrics` for all APCs used, instead of just the first
APC in a testing profile (because of wasted data, and we can always just
create one APC if we only want to test one).

These won't add any cost to the testing CI run, because all data are
already there but we just aren't testing them fully yet.
2025-07-11 08:45:37 +00:00
Leandro Pacheco
6c9903d0a6 Fix effectiveness plot (#3037)
fix the script for the new apc candidates json format
2025-07-10 19:33:50 +00:00
Georg Wiese
f0a0e3a804 Benchmarks: Generate effectiveness plots (#3024)
Builds on #3023 and
https://github.com/powdr-labs/openvm-reth-benchmark/pull/23

Worked on this manually triggered nightly run:

https://github.com/powdr-labs/powdr/actions/runs/16182186333/job/45680988436

See these results:

https://github.com/powdr-labs/bench-results/tree/gh-pages/results/2025-07-10-0155
2025-07-10 09:29:52 +00:00
Thibaut Schaeffer
59c1ff6e8a Introduce constant for log blowup (#3002)
1 is recommended, and having a constant is an improvement over the
current way the blowup factor can be set everywhere.

update: 1 does not work, so set to 2 for now, as it was before.
2025-07-10 09:15:23 +00:00
Thibaut Schaeffer
89378a3d01 Move APC export to APC crate (#3021)
We currently export the APCs to disk in the openvm crate.
Now that the APCs are generic, we can export them in the APC crate
already.
The json file is still generated in openvm, since it contains some
openvm-specific data, such as the number of logup columns (which depends
on the stark config, which the APC crate does not know about)
2025-07-10 08:48:42 +00:00
chriseth
8d11daa952 Rename effect. (#3029) 2025-07-10 08:13:34 +00:00
chriseth
3281eb57ac Rename / remove QuadraticSymbolicExpression. (#3028) 2025-07-10 07:50:52 +00:00
Thibaut Schaeffer
d6844422f6 Move concept of block to APC crate (#3020)
Simplify and make the concept of block less openvm specific.
The next step will be to move the saving the apcs to disk to the apc
crate.
2025-07-10 07:43:35 +00:00
chriseth
2793df62a1 Rename constraint system. (#3025) 2025-07-09 22:28:18 +00:00
Georg Wiese
1d9635f709 Add plot_effectiveness.py (#3023)
Creates this plot from an `apc_candidates.json`:
![effectiveness
png_stacked_histogram](https://github.com/user-attachments/assets/cf419b81-0609-453e-89c5-5d1207b51385)

To reproduce the above plot, see the example in #3022 and run:
`python openvm/scripts/plot_effectiveness.py
cli-openvm/apcs/apc_candidates.json`
2025-07-09 19:52:52 +00:00
Georg Wiese
4b3441d560 Add --apcs-candidates-dir argument (#3022)
Exposes the changes of #3015 to the CLI

To test, run this from `cli-openvm`:
`mkdir -p apcs && cargo run -r prove $(pwd)/../openvm/guest-keccak
--input 1 --autoprecompiles 1 --apc-candidates-dir apcs`
2025-07-09 15:13:47 +00:00
Thibaut Schaeffer
c19bc488a3 Generate APC candidate json (#3015)
Follow up to #3008
2025-07-09 14:16:42 +00:00
ShuangWu121
d17f2a0da5 Add sha256 guest (#2956)
Co-authored-by: Leo Alt <leo@powdrlabs.com>
2025-07-09 12:28:06 +00:00
Thibaut Schaeffer
0598605c68 Write APC candidates to disk (#3008)
@georgwiese built some graphs from the APC candidates by exporting the
main stats to CSV. This PR start extending that by persisting the
candidates to disk for further inspection.

This first PR creates one file per APC, and #3015 creates a single JSON
which has the main stats and points to this APC file.
2025-07-09 10:41:53 +00:00
Georg Wiese
ea088e0789 Refactor reassign_ids (#3019)
See [this
comment](https://github.com/powdr-labs/powdr/pull/2995/files#diff-7edc0d0adead528c534e3938578e77a31c59b70a6a9ea75e53e595ab05569dbfR98).
2025-07-09 09:50:07 +00:00
Steve Wang
65598bfcf6 Refactor air metric (#3016)
Depend on #2962.

- `Add` and `Sum` traits for `AirMetric`, so that we don't need to
manually add them in tests.
- Removed `name` field from `AirMetric`, because they currently live in
`OriginalAirs`, which already contains a map from air name `String` to
`AirMetric`.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2025-07-09 09:14:42 +00:00
Steve Wang
1289666525 Display powdr opcode for debug.pil (#3017)
Currently all Powdr symbolic machines in `debug.pil` appear as
`PowdrAir<BabyBear>`, which gives no way of distinguishing one from
another.

This PR fixes this by using the existing `air_name` API of powdr
executor and plonk executor, which gives names like:
`powdr_air_for_opcode_4381`. This makes it easier to debug and in the
future, cross reference to `ApcCandidates` cbor and json files written
in #3008 and #3015.
2025-07-09 08:37:27 +00:00
Steve Wang
454816c7a4 Comprehensive Cell Pgo Test (#2962)
Depends on #2960. I think we've long needed a more comprehensive test
for PGO, especially the cell mode.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2025-07-09 08:18:49 +00:00
chriseth
65371114f9 Field elements in autoprecompiles (#2996) 2025-07-09 08:08:20 +00:00
chriseth
9f88ae22a5 Test for shift by 8 (#3006) 2025-07-08 20:19:11 +00:00
chriseth
fe958ce42f Simplify memory bus interaction handler and add another test. (#3013)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-07-08 16:19:23 +00:00
chriseth
c800d22ecd Print high-frequency basic blocks. (#3009) 2025-07-08 16:17:58 +00:00
Georg Wiese
d7053e276c Simplify statements_to_symbolic_machine (#3014)
Fixes some TODOs from #2995.
2025-07-08 15:07:38 +00:00
Georg Wiese
c0cf02a491 Remove simplify_expression in some places (#3011)
Just so we don't do this:
```rust
quadratic_symbolic_expression_to_algebraic(
    &algebraic_to_quadratic_symbolic_expression(
        &quadratic_symbolic_expression_to_algebraic(&expr)))
```
😉
2025-07-08 14:50:51 +00:00
Thibaut Schaeffer
3d2d2b756c Use all columns in pgo (#3007)
When looking at metrics to rank apcs, we currently only take into
account main columns (excluding second stage columns)
Fix that.
2025-07-08 14:29:14 +00:00
chriseth
c6caf5a8fa Generic solver (#2991) 2025-07-08 12:25:23 +00:00
Georg Wiese
18a549c599 basic_metrics.py: Report OpenVM precompile ratio (#3004)
Adds a heuristic to separate "normal" CPU instructions (which we can
hope to accelerate with APCs) from OpenVM precompiles.

Example:
```
python openvm/scripts/basic_metrics.py ../bench-results/results/2025-07-07-0624/reth/*.json
                                                 filename  num_segments  app_proof_cells  app_proof_time_ms  app_execute_time_ms  app_trace_gen_time_ms  leaf_proof_time_ms  inner_recursion_proof_time_ms  normal_instruction_cells  openvm_precompile_cells  powdr_cells  normal_instruction_ratio  openvm_precompile_ratio  powdr_ratio  powdr_rows
../bench-results/results/2025-07-07-0624/reth/100apc.json             3      15062260062             163682                23767                  64627               89913                          12532                4982516224               7190029662   2889714176                  0.330795                 0.477354     0.191851    16826880
 ../bench-results/results/2025-07-07-0624/reth/noapc.json             6      19633824920             217899                24907                  55865               82750                          30175               11659639296               7974185624            0                  0.593855                 0.406145     0.000000           0
```

Note that `normal_instruction_cells + openvm_precompile_cells` adds to
`non_powdr_cells`
[here](https://github.com/powdr-labs/bench-results/blob/gh-pages/results/2025-07-07-0624/reth/basic_metrics.csv).
2025-07-07 23:00:12 +00:00
Georg Wiese
33c5b45943 plot_trace_cells.py: Only count app proofs (#3003)
- Extracted a function to load the metrics file, which already separates
the different proof stages
- Use it in `openvm/scripts/plot_trace_cells.py`
2025-07-07 15:23:16 +00:00
Thibaut Schaeffer
621d0cf010 Avoid collecting into pc vector (#2989)
When we generate the PGO data, we first collect all visited pcs in
execution order which is linear in the execution length.
Then we reduce this to a map of unique PC to number of occurrences,
which is linear in the program size.

This PR removes the first collection, generating the map directly.

Update: since for reth we do ~300 million additions to the hashmap, this
PR also switches to using a vector to keep track of the count as opposed
to a hashmap. Not to be confused: before this PR the vector is the
sequence of all pcs visited. After this PR, it is the number of times a
pc was visited, by pc.

Other update:
copilot made a good point about switching away from
`Arc<Mutex<Vec<u32>>>` to `Arc<Vec<AtomicU32>>`. Done.
2025-07-04 13:59:11 +00:00
Steve Wang
4471c7580d Update reth CI commit hash (#2999)
Final one to be merged after
https://github.com/powdr-labs/openvm-reth-benchmark/pull/21/files
2025-07-04 13:58:23 +00:00
Leandro Pacheco
770e948c64 nightly benchmarks (#2982)
This PR runs a few benchmarks nightly, saving the results to a separate
repo: `bench-results`.
Idea is to get something going on and improve reporting later.
Currently, it runs `keccak` and `reth`.
2025-07-04 12:09:45 +00:00
Leandro Pacheco
e7a1838c97 fix guest-matmul (#2997)
added a test to at least catch it on nightly
2025-07-04 11:29:43 +00:00
Steve Wang
4064d3f3d3 Patch P3 extension field size (#3001)
Make shift solution via a const till we have the deps sorted out.
2025-07-04 10:47:51 +00:00
Steve Wang
5ae915d7fd Calculate non-APC LogUp columns for PGO (#2960)
Need to first merge https://github.com/powdr-labs/stark-backend/pull/11.
And then merge https://github.com/powdr-labs/openvm/pull/32.

Original comment by @Schaeff:
```
so here's my suspicion:

to get the number of columns of an air, we use executor.air().width(), in fully qualified syntax openvm_stark_backend::p3_air::BaseAir::width(&executor.air())
this is the number of main trace columns, which does not include interaction columns
in order to get the full number of columns, we need to do what we already do for get_constraints but additionally call InteractionPhaseAirBuilder::finalize_interactions on the symbolic builder to materialize the interactions. Sadly InteractionPhaseAirBuilder is pub(crate) so it seems we need to change stark-backend
```

This PR follows the comment above, but has additional changes:
1. Instead of using `finalize_interactions`, call lower level functions
for greater efficiency.
2. Refactored `AirMetrics` related functions, so we always show the
number of main constraint vs bus interaction columns.

Next step:
1. We should calculate log up columns for APCs as well during PGO.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2025-07-04 07:33:31 +00:00
Leandro Pacheco
6d6c811939 get SdkVmConfig from the openvm.toml file (#2984)
instead of hardcoding extensions, load the SdkVmConfig from the
openvm.toml file in the guest
2025-07-03 13:35:02 +00:00
chriseth
7ca7a2b3f1 Generic exhaustive search. (#2992) 2025-07-03 13:03:11 +00:00
chriseth
d209dedef5 Generic inliner (#2990) 2025-07-03 13:01:14 +00:00
Thibaut Schaeffer
7e49009e8e Avoid clone (#2988) 2025-07-03 12:17:12 +00:00
chriseth
a5d648e856 Generic journaling constraint system. (#2987) 2025-07-03 11:56:46 +00:00
Thibaut Schaeffer
1418069ea1 Remove option (#2986) 2025-07-03 11:06:19 +00:00