-
Notifications
You must be signed in to change notification settings - Fork 69
feat(new-execution): make vm segment executor generic #1582
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
feat(new-execution): make vm segment executor generic #1582
Conversation
VC: VmConfig<F>, | ||
{ | ||
/// Guest memory type | ||
type Mem: GuestMemory; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
- 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
VmSegmentExecutor
generic on<Mem, Ctx, Ctrl>
where:Mem
: struct that implementsGuestMemory
Ctx
: struct that stores host context during executionCtrl
: struct that implements pre/post segment execution hooks, termination condition and instruction execution logicTracegenVmSegmentExecutor
that implements the current execution flow