Skip to content

Commit 7588f5a

Browse files
committed
Move more code
1 parent 5f6bfbc commit 7588f5a

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

openvm/src/customize_exe.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ use crate::extraction_utils::{get_air_metrics, AirWidthsDiff, OriginalAirs, Orig
1111
use crate::instruction_formatter::openvm_instruction_formatter;
1212
use crate::memory_bus_interaction::OpenVmMemoryBusInteraction;
1313
use crate::powdr_extension::chip::PowdrAir;
14+
use crate::program::Prog;
1415
use crate::utils::UnsupportedOpenVmReferenceError;
1516
use crate::OriginalCompiledProgram;
1617
use crate::{CompiledProgram, SpecializedConfig};
1718
use itertools::Itertools;
1819
use openvm_instructions::instruction::Instruction as OpenVmInstruction;
19-
use openvm_instructions::program::{Program as OpenVmProgram, DEFAULT_PC_STEP};
20+
use openvm_instructions::program::DEFAULT_PC_STEP;
2021
use openvm_instructions::VmOpcode;
2122
use openvm_stark_backend::{
2223
interaction::SymbolicInteraction,
@@ -26,7 +27,7 @@ use openvm_stark_sdk::p3_baby_bear::BabyBear;
2627
use powdr_autoprecompiles::adapter::{
2728
Adapter, AdapterApc, AdapterApcWithStats, AdapterVmConfig, ApcWithStats, PgoAdapter,
2829
};
29-
use powdr_autoprecompiles::blocks::{BasicBlock, Instruction, Program};
30+
use powdr_autoprecompiles::blocks::{BasicBlock, Instruction};
3031
use powdr_autoprecompiles::evaluation::{evaluate_apc, EvaluationResult};
3132
use powdr_autoprecompiles::expression::try_convert;
3233
use powdr_autoprecompiles::pgo::{ApcCandidateJsonExport, Candidate, KnapsackItem};
@@ -75,16 +76,6 @@ impl<'a> Adapter for BabyBearOpenVmApcAdapter<'a> {
7576
}
7677
}
7778

78-
/// A newtype wrapper around `OpenVmProgram` to implement the `Program` trait.
79-
/// This is necessary because we cannot implement a foreign trait for a foreign type.
80-
pub struct Prog<'a, F>(pub &'a OpenVmProgram<F>);
81-
82-
impl<'a, F> From<&'a OpenVmProgram<F>> for Prog<'a, F> {
83-
fn from(program: &'a OpenVmProgram<F>) -> Self {
84-
Prog(program)
85-
}
86-
}
87-
8879
/// A newtype wrapper around `OpenVmInstruction` to implement the `Instruction` trait.
8980
/// This is necessary because we cannot implement a foreign trait for a foreign type.
9081
#[derive(Clone, Serialize, Deserialize)]
@@ -115,29 +106,6 @@ impl<F: PrimeField32> Instruction<F> for Instr<F> {
115106
}
116107
}
117108

118-
impl<'a, F: PrimeField32> Program<Instr<F>> for Prog<'a, F> {
119-
fn base_pc(&self) -> u64 {
120-
self.0.pc_base as u64
121-
}
122-
123-
fn pc_step(&self) -> u32 {
124-
DEFAULT_PC_STEP
125-
}
126-
127-
fn instructions(&self) -> Box<dyn Iterator<Item = Instr<F>> + '_> {
128-
Box::new(
129-
self.0
130-
.instructions_and_debug_infos
131-
.iter()
132-
.filter_map(|x| x.as_ref().map(|i| Instr(i.0.clone()))),
133-
)
134-
}
135-
136-
fn length(&self) -> u32 {
137-
self.0.instructions_and_debug_infos.len() as u32
138-
}
139-
}
140-
141109
pub fn customize<'a, P: PgoAdapter<Adapter = BabyBearOpenVmApcAdapter<'a>>>(
142110
original_program: OriginalCompiledProgram,
143111
config: PowdrConfig,

openvm/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ use std::{
5353
};
5454

5555
use crate::customize_exe::OpenVmApcCandidate;
56-
pub use crate::customize_exe::Prog;
5756
use crate::powdr_extension::chip::PowdrAir;
57+
use crate::program::Prog;
5858
pub use crate::program::{CompiledProgram, OriginalCompiledProgram};
5959
use crate::trace_generation::do_with_trace;
6060

@@ -225,6 +225,7 @@ impl VmProverExtension<GpuBabyBearPoseidon2Engine, DenseRecordArena, PowdrExtens
225225
extension: &PowdrExtension<BabyBear>,
226226
inventory: &mut ChipInventory<BabyBearSC, DenseRecordArena, GpuBackend>,
227227
) -> Result<(), ChipInventoryError> {
228+
use std::sync::Arc;
228229
// TODO: here we make assumptions about the existence of some chips in the periphery. Make this more flexible
229230

230231
use crate::powdr_extension::trace_generator::cuda::PowdrPeripheryInstancesGpu;

openvm/src/program.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use openvm_instructions::exe::VmExe;
44
use openvm_instructions::program::{Program as OpenVmProgram, DEFAULT_PC_STEP};
55
use openvm_stark_backend::p3_field::PrimeField32;
66
use openvm_stark_sdk::p3_baby_bear::BabyBear;
7-
use powdr_autoprecompiles::blocks::{collect_basic_blocks, BasicBlock};
7+
use powdr_autoprecompiles::blocks::{collect_basic_blocks, BasicBlock, Program};
88
use powdr_riscv_elf::debug_info::DebugInfo;
99
use powdr_riscv_elf::ElfProgram;
1010
use serde::{Deserialize, Serialize};
1111

1212
use crate::extraction_utils::OriginalVmConfig;
1313
use crate::opcode::branch_opcodes_bigint_set;
14-
use crate::{BabyBearOpenVmApcAdapter, ExtendedVmConfig, Instr, Prog, SpecializedConfig};
14+
use crate::{BabyBearOpenVmApcAdapter, ExtendedVmConfig, Instr, SpecializedConfig};
1515

1616
#[derive(Serialize, Deserialize, Clone)]
1717
pub struct CompiledProgram {
@@ -88,3 +88,36 @@ impl OriginalCompiledProgram {
8888
self.elf.debug_info()
8989
}
9090
}
91+
92+
/// A newtype wrapper around `OpenVmProgram` to implement the `Program` trait.
93+
/// This is necessary because we cannot implement a foreign trait for a foreign type.
94+
pub struct Prog<'a, F>(&'a OpenVmProgram<F>);
95+
96+
impl<'a, F> From<&'a OpenVmProgram<F>> for Prog<'a, F> {
97+
fn from(program: &'a OpenVmProgram<F>) -> Self {
98+
Prog(program)
99+
}
100+
}
101+
102+
impl<'a, F: PrimeField32> Program<Instr<F>> for Prog<'a, F> {
103+
fn base_pc(&self) -> u64 {
104+
self.0.pc_base as u64
105+
}
106+
107+
fn pc_step(&self) -> u32 {
108+
DEFAULT_PC_STEP
109+
}
110+
111+
fn instructions(&self) -> Box<dyn Iterator<Item = Instr<F>> + '_> {
112+
Box::new(
113+
self.0
114+
.instructions_and_debug_infos
115+
.iter()
116+
.filter_map(|x| x.as_ref().map(|i| Instr(i.0.clone()))),
117+
)
118+
}
119+
120+
fn length(&self) -> u32 {
121+
self.0.instructions_and_debug_infos.len() as u32
122+
}
123+
}

0 commit comments

Comments
 (0)