Skip to content

Conversation

shuklaayush
Copy link
Contributor

  • make VmSegmentExecutor generic on <Mem, Ctx, Ctrl> where:
    • Mem: struct that implements GuestMemory
    • Ctx: struct that stores host context during execution
    • Ctrl: struct that implements pre/post segment execution hooks, termination condition and instruction execution logic
  • add TracegenVmSegmentExecutor that implements the current execution flow
  • move segmentation strategies to new file

VC: VmConfig<F>,
{
/// Guest memory type
type Mem: GuestMemory;
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the reasoning to have these as associated types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can make them generic too. the reasoning to make these associated types is because i figured that the struct implementing the trait will usually implement it with a specific Mem and Ctx so the trait would never have to be implemented more than once for a struct and doesn't need to generic

.program_chip
.get_instruction(vm_state.pc)?;

let &Instruction { opcode, .. } = instruction;
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not know you could do &Instruction!

where
F: PrimeField32,
{
let memory = memory_controller.memory_image().clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

this is pretty bad to clone? is this temporary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, temporary. i need to figure out how to get memory here since it is owned by the memory controller atm

segment.set_override_trace_heights(overridden_heights.clone());
}
metrics_span("execute_time_ms", || segment.execute_from_pc(pc_start))?;
let mut vm_state = TracegenVmExecutionState::from_pc_and_memory_controller(
Copy link
Contributor

Choose a reason for hiding this comment

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

this flow seems a bit weird - ok if it's just temporary until we get rid of or refactor memory controller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it's temporary until i figure out how to get rid of memory controller owning the memory and timestamp

pub pc: u32,
pub is_terminated: bool,
pub struct TracegenCtx {
pub timestamp: u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi: timestamp seems like it will need to be inside TracingMemory later since that is what really manages it most of time, but I expect we move Streams inside Ctx eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay. i was wondering if it was possible to keep all execution state here and make all the controllers etc. stateless, and take a reference to this vm state as argument

Copy link
Contributor

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

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

LGTM, except somehow the current flow of using/constructing VmExecutionState seems not quite right. But that seems like it will change anyways with future refactors.

@jonathanpwang jonathanpwang merged commit 2cd346f into feat/new-execution Apr 15, 2025
6 of 25 checks passed
@jonathanpwang jonathanpwang deleted the feat/generic-vm-segment-executor branch April 15, 2025 23:53
jonathanpwang pushed a commit that referenced this pull request May 2, 2025
- make `VmSegmentExecutor` generic on `<Mem, Ctx, Ctrl>` where:
  - `Mem`: struct that implements `GuestMemory`
  - `Ctx`: struct that stores host context during execution
- `Ctrl`: struct that implements pre/post segment execution hooks,
termination condition and instruction execution logic
- add `TracegenVmSegmentExecutor` that implements the current execution
flow
- move segmentation strategies to new file
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.

2 participants