Skip to content

feat: ahead of time (AOT) compilation of VmExe on x86_64#2195

Merged
jonathanpwang merged 67 commits into
mainfrom
feat/aot
Nov 17, 2025
Merged

feat: ahead of time (AOT) compilation of VmExe on x86_64#2195
jonathanpwang merged 67 commits into
mainfrom
feat/aot

Conversation

@nyunyunyunyu

Copy link
Copy Markdown
Contributor

No description provided.

GunaDD and others added 27 commits October 17, 2025 23:18
…and Metered execution mode (#2166)

## Description
This PR adds support for AOT execution mode with interpreter fallback. 
Check `crates/vm/src/arch/aot.md` for a detailed description of AOT.

In the AOT execution, we generate an assembly code and build it along
with the rust bridge crate into a dynamic library. We also generate
`pre_compute_instructions` and store it in the `AotInstance` struct.

This `AotInstance` struct is analogous to the `InterpretedInstance`
struct we have for interpreter mode. During execution phase, we create a
vmstate and pass its pointer to the assembly.

## How Has This Been Tested?

I configured `air_test_impl` of `stark_utils.py` to run both the AOT and
Interpreted Pure & Metered Execution. Then I asserted that the `instret`
and `pc` are equal and also the segments generated for the Metered
Execution to be equal.

```
/*
    Assertions for Pure Execution AOT
    */
    {
        let interp_state = vm
            .interpreter(&exe)?
            .execute(input.clone(), None)
            .expect("Failed to execute");

        let aot_state = vm
            .get_aot_instance(&exe)?
            .execute(input.clone(), None)
            .expect("Failed to execute");

        assert_eq!(interp_state.pc(), aot_state.pc());
        assert_eq!(interp_state.instret(), aot_state.instret());

        let system_config: &SystemConfig = config.as_ref();
        let addr_spaces = &system_config.memory_config.addr_spaces; 
        
        for r in 0..addr_spaces[1].num_cells  {
            let interp = unsafe {
                interp_state.memory.read::<u8, 1>(1, r as u32)
            };
            let aot_interp = unsafe {
                aot_state.memory.read::<u8, 1>(1, r as u32)
            };
            assert_eq!(interp, aot_interp);
        }
    }

    /*
    Assertions for Metered AOT
    */
    {
        let (aot_segments, aot_state) = vm
            .get_metered_aot_instance(&exe)?
            .execute_metered(input.clone(), metered_ctx.clone())?;

        let (segments, interp_state) = vm
            .metered_interpreter(&exe)?
            .execute_metered(input.clone(), metered_ctx.clone())?;

        assert_eq!(interp_state.pc(), aot_state.pc());
        assert_eq!(interp_state.instret(), aot_state.instret());

        let system_config: &SystemConfig = config.as_ref();
        let addr_spaces = &system_config.memory_config.addr_spaces; 

        for r in 0..addr_spaces[1].num_cells  {
            let interp = unsafe {
                interp_state.memory.read::<u8, 1>(1, r as u32)
            };
            let aot_interp = unsafe {
                aot_state.memory.read::<u8, 1>(1, r as u32)
            };
            assert_eq!(interp, aot_interp);
        }

        assert_eq!(segments.len(), aot_segments.len());
        for i in 0..segments.len() {
            assert_eq!(segments[i].instret_start, aot_segments[i].instret_start);
            assert_eq!(segments[i].num_insns, aot_segments[i].num_insns);
            assert_eq!(segments[i].trace_heights, aot_segments[i].trace_heights);
        }
    }
```

**Test Configuration:**
- [x] Unit tests pass
- [x] Integration tests pass
- [x] Manual testing completed

## Checklist
- [x] I have performed a self-review of my own code
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added new tests to CI

Closes INT-5195
Closes INT-5196

---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-18-208.ec2.internal>
Co-authored-by: Maillew <lin.s.william0147@gmail.com>
Add starting code for `AotTraits` to handle x86 assembly generation.

Refer to design overview here:
https://hackmd.io/iSSvk3HsQ0uDqS3i_9UyAA?both#AOT-Traits

---------

Co-authored-by: Gunadi Gani <87816385+GunaDD@users.noreply.github.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-18-208.ec2.internal>
Closes INT-5263, INT-5261, INT-5262
closes INT-5259

---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-18-208.ec2.internal>
Co-authored-by: Xinding Wei <weixinding@gmail.com>
@nyunyunyunyu nyunyunyunyu marked this pull request as ready for review November 3, 2025 00:14
Maillew and others added 2 commits November 3, 2025 16:26
Closes INT-5263, INT-5262

---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-18-208.ec2.internal>
Co-authored-by: Xinding Wei <weixinding@gmail.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+7 [+3.1%]) 236 322,700 2,058,654 - - -
fibonacci (+1 [+0.1%]) 973 1,500,209 2,100,402 - - -
regex (-37 [-1.6%]) 2,312 4,137,502 17,695,216 - - -
ecrecover (+4 [+0.6%]) 727 122,859 2,262,718 - - -
pairing (+52 [+3.6%]) 1,478 1,745,742 25,468,210 - - -

Commit: 3cd5959

Benchmark Workflow

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+39 [+17.0%]) 268 322,610 2,058,654 - - -
fibonacci (-10 [-1.0%]) 962 1,500,209 2,100,402 - - -
regex (-14 [-0.6%]) 2,335 4,137,502 17,695,216 - - -
ecrecover (-10 [-1.4%]) 713 122,859 2,262,718 - - -
pairing (+75 [+5.3%]) 1,501 1,745,742 25,468,210 - - -

Commit: 14bef6c

Benchmark Workflow

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+6 [+2.6%]) 235 322,610 2,058,654 - - -
fibonacci (-8 [-0.8%]) 964 1,500,209 2,100,402 - - -
regex 2,347 4,137,502 17,695,216 - - -
ecrecover (+2 [+0.3%]) 725 122,859 2,262,718 - - -
pairing (+72 [+5.0%]) 1,498 1,745,742 25,468,210 - - -

Commit: d164be5

Benchmark Workflow

closes INT-5486

---------

Co-authored-by: Xinding Wei <weixinding@gmail.com>
@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (-8 [-3.5%]) 221 322,658 2,058,654 - - -
fibonacci (+12 [+1.2%]) 984 1,500,209 2,100,402 - - -
regex (+33 [+1.4%]) 2,382 4,137,502 17,695,216 - - -
ecrecover (-4 [-0.6%]) 719 122,859 2,262,718 - - -
pairing (+37 [+2.6%]) 1,463 1,745,742 25,468,210 - - -

Commit: c4606d0

Benchmark Workflow

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (-2 [-0.9%]) 227 322,677 2,058,654 - - -
fibonacci (+4 [+0.4%]) 976 1,500,209 2,100,402 - - -
regex (-12 [-0.5%]) 2,337 4,137,502 17,695,216 - - -
ecrecover (-16 [-2.2%]) 707 122,859 (+2382 [+0.1%]) 2,265,100 - - -
pairing (+53 [+3.7%]) 1,479 1,745,742 25,468,210 - - -

Commit: e1afe83

Benchmark Workflow

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+27 [+11.8%]) 256 322,610 2,058,654 - - -
fibonacci (-1 [-0.1%]) 971 1,500,209 2,100,402 - - -
regex (+25 [+1.1%]) 2,374 4,137,502 17,695,216 - - -
ecrecover (-6 [-0.8%]) 717 122,859 (+2382 [+0.1%]) 2,265,100 - - -
pairing (+74 [+5.2%]) 1,500 1,745,742 25,468,210 - - -

Commit: b0a067d

Benchmark Workflow

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (-6 [-2.6%]) 223 322,658 2,058,654 - - -
fibonacci (-3 [-0.3%]) 969 1,500,209 2,100,402 - - -
regex (+35 [+1.5%]) 2,384 4,137,502 17,695,216 - - -
ecrecover (-20 [-2.8%]) 703 122,859 (+2382 [+0.1%]) 2,265,100 - - -
pairing (+31 [+2.2%]) 1,457 1,745,742 25,468,210 - - -

Commit: de55e29

Benchmark Workflow

@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+1 [+0.4%]) 230 322,610 2,058,654 - - -
fibonacci (+19 [+2.0%]) 991 1,500,209 2,100,402 - - -
regex (-20 [-0.9%]) 2,329 4,137,502 17,695,216 - - -
ecrecover (-13 [-1.8%]) 710 122,859 (+2382 [+0.1%]) 2,265,100 - - -
pairing (+32 [+2.2%]) 1,458 1,745,742 25,468,210 - - -

Commit: 0cbc78c

Benchmark Workflow

Co-authored-by: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+2 [+0.9%]) 231 322,610 2,058,654 - - -
fibonacci (+6 [+0.6%]) 978 1,500,209 2,100,402 - - -
regex (+9 [+0.4%]) 2,358 4,137,502 17,695,216 - - -
ecrecover (-17 [-2.4%]) 706 122,859 (+2382 [+0.1%]) 2,265,100 - - -
pairing (+58 [+4.1%]) 1,484 1,745,742 25,468,210 - - -

Commit: 47f0e0a

Benchmark Workflow

@jonathanpwang jonathanpwang changed the title feat: AOT main PR feat: ahead of time (AOT) compilation of VmExe on x86_64 Nov 17, 2025
@jonathanpwang jonathanpwang merged commit 432dada into main Nov 17, 2025
126 of 129 checks passed
@jonathanpwang jonathanpwang deleted the feat/aot branch November 17, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants