Skip to content

Commit 3706b09

Browse files
committed
testing rv32 with access_adapters disabled
1 parent beee07a commit 3706b09

File tree

8 files changed

+39
-18
lines changed

8 files changed

+39
-18
lines changed

crates/vm/src/arch/execution_mode/metered/ctx.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
6464
air_names[merkle_tree_index]
6565
);
6666
}
67-
debug_assert!(
68-
air_names[memory_ctx.adapter_offset].contains("AccessAdapterAir<2>"),
69-
"air_name={}",
70-
air_names[memory_ctx.adapter_offset]
71-
);
67+
if memory_ctx.access_adapters_enabled {
68+
debug_assert!(
69+
air_names[memory_ctx.adapter_offset].contains("AccessAdapterAir<2>"),
70+
"air_name={}",
71+
air_names[memory_ctx.adapter_offset]
72+
);
73+
}
7274

7375
let segmentation_ctx =
7476
SegmentationCtx::new(air_names, widths, interactions, config.segmentation_limits);

crates/vm/src/arch/execution_mode/metered/memory_ctx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct MemoryCtx<const PAGE_BITS: usize> {
105105
pub boundary_idx: usize,
106106
pub merkle_tree_index: Option<usize>,
107107
pub adapter_offset: usize,
108-
access_adapters_enabled: bool,
108+
pub access_adapters_enabled: bool,
109109
continuations_enabled: bool,
110110
chunk: u32,
111111
chunk_bits: u32,

crates/vm/src/arch/testing/cpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<F: PrimeField32> Default for VmChipTestBuilder<F> {
404404
// removed when tests are updated.
405405
mem_config.addr_spaces[RV32_REGISTER_AS as usize].num_cells = 1 << 29;
406406
mem_config.addr_spaces[NATIVE_AS as usize].num_cells = 0;
407-
Self::volatile(mem_config)
407+
Self::persistent(mem_config)
408408
}
409409
}
410410

crates/vm/src/arch/vm.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,13 @@ where
622622
let system_config: &SystemConfig = self.config().as_ref();
623623
let adapter_offset = system_config.access_adapter_air_id_offset();
624624
// ATTENTION: this must agree with `num_memory_airs`
625-
let num_adapters = log2_strict_usize(system_config.memory_config.max_access_adapter_n);
625+
626+
let num_adapters = if system_config.memory_config.access_adapters_enabled {
627+
log2_strict_usize(system_config.memory_config.max_access_adapter_n)
628+
} else {
629+
0
630+
};
631+
626632
assert_eq!(adapter_offset + num_adapters, system_config.num_airs());
627633
let access_adapter_arena_size_bound = records::arena_size_bound(
628634
&trace_heights[adapter_offset..adapter_offset + num_adapters],

crates/vm/src/system/memory/online.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ impl TracingMemory {
580580
if header.block_size == header.lowest_block_size {
581581
return;
582582
}
583+
assert_eq!(1, 0);
583584
// SAFETY:
584585
// - header.address_space is validated during instruction decoding and within bounds
585586
// - header.pointer and header.type_size define valid memory bounds within the address space
@@ -612,7 +613,7 @@ impl TracingMemory {
612613
if header.block_size == header.lowest_block_size {
613614
return;
614615
}
615-
616+
assert_eq!(1, 0);
616617
let record_mut = self
617618
.access_adapter_records
618619
.alloc(AccessLayout::from_record_header(&header));

extensions/rv32im/circuit/src/base_alu/tests.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ fn rand_rv32_alu_test(opcode: BaseAluOpcode, num_ops: usize) {
163163
// TODO(AG): make a more meaningful test for memory accesses
164164
tester.write(2, 1024, [F::ONE; 4]);
165165
tester.write(2, 1028, [F::ONE; 4]);
166-
let sm = tester.read(2, 1024);
167-
assert_eq!(sm, [F::ONE; 8]);
166+
// Avoid wider-than-min-block accesses when access adapters are disabled
167+
let sm1 = tester.read(2, 1024);
168+
let sm2 = tester.read(2, 1028);
169+
assert_eq!(sm1, [F::ONE; 4]);
170+
assert_eq!(sm2, [F::ONE; 4]);
168171

169172
for _ in 0..num_ops {
170173
set_and_execute(
@@ -201,8 +204,11 @@ fn rand_rv32_alu_test_persistent(opcode: BaseAluOpcode, num_ops: usize) {
201204
// TODO(AG): make a more meaningful test for memory accesses
202205
tester.write(2, 1024, [F::ONE; 4]);
203206
tester.write(2, 1028, [F::ONE; 4]);
204-
let sm = tester.read(2, 1024);
205-
assert_eq!(sm, [F::ONE; 8]);
207+
// Avoid wider-than-min-block accesses when access adapters are disabled
208+
let sm1 = tester.read(2, 1024);
209+
let sm2 = tester.read(2, 1028);
210+
assert_eq!(sm1, [F::ONE; 4]);
211+
assert_eq!(sm2, [F::ONE; 4]);
206212

207213
for _ in 0..num_ops {
208214
set_and_execute(

extensions/rv32im/circuit/src/loadstore/tests.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use openvm_circuit::{
1010
},
1111
};
1212
use openvm_circuit_primitives::var_range::VariableRangeCheckerChip;
13-
use openvm_instructions::{instruction::Instruction, riscv::RV32_REGISTER_AS, LocalOpcode};
13+
use openvm_instructions::{instruction::Instruction, riscv::RV32_REGISTER_AS, LocalOpcode, NATIVE_AS};
1414
use openvm_rv32im_transpiler::Rv32LoadStoreOpcode::{self, *};
1515
use openvm_stark_backend::{
1616
p3_air::BaseAir,
@@ -131,7 +131,8 @@ fn set_and_execute<RA: Arena, E: PreflightExecutor<F, RA>>(
131131
let mem_as = mem_as.unwrap_or(if is_load {
132132
2
133133
} else {
134-
*[2, 3, 4].choose(rng).unwrap()
134+
// Avoid Native AS while access adapters are disabled.
135+
*[2, 3].choose(rng).unwrap()
135136
});
136137

137138
let shift_amount = ptr_val % 4;
@@ -215,10 +216,13 @@ fn rand_loadstore_test(opcode: Rv32LoadStoreOpcode, num_ops: usize) {
215216
let mut rng = create_seeded_rng();
216217
let mut mem_config = MemoryConfig::default();
217218
mem_config.addr_spaces[RV32_REGISTER_AS as usize].num_cells = 1 << 29;
219+
mem_config.addr_spaces[NATIVE_AS as usize].num_cells = 0;
218220
if [STOREW, STOREB, STOREH].contains(&opcode) {
219221
mem_config.addr_spaces[PUBLIC_VALUES_AS as usize].num_cells = 1 << 29;
220222
}
221-
let mut tester = VmChipTestBuilder::volatile(mem_config);
223+
// Use persistent memory so initial block size matches the 4-byte alignment and
224+
// avoids access-adapter split/merge paths when adapters are disabled.
225+
let mut tester = VmChipTestBuilder::persistent(mem_config);
222226
let mut harness = create_harness(&mut tester);
223227

224228
for _ in 0..num_ops {
@@ -268,10 +272,12 @@ fn run_negative_loadstore_test(
268272
let mut rng = create_seeded_rng();
269273
let mut mem_config = MemoryConfig::default();
270274
mem_config.addr_spaces[RV32_REGISTER_AS as usize].num_cells = 1 << 29;
275+
mem_config.addr_spaces[NATIVE_AS as usize].num_cells = 0;
271276
if [STOREW, STOREB, STOREH].contains(&opcode) {
272277
mem_config.addr_spaces[PUBLIC_VALUES_AS as usize].num_cells = 1 << 29;
273278
}
274-
let mut tester = VmChipTestBuilder::volatile(mem_config);
279+
// Use persistent memory so the min block size matches alignment without needing adapters.
280+
let mut tester = VmChipTestBuilder::persistent(mem_config);
275281
let mut harness = create_harness(&mut tester);
276282

277283
set_and_execute(

extensions/rv32im/tests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod tests {
3333
fn test_rv32im_config() -> Rv32ImConfig {
3434
Rv32ImConfig {
3535
rv32i: Rv32IConfig {
36-
system: test_system_config(),
36+
system: test_system_config().without_access_adapters(),
3737
..Default::default()
3838
},
3939
..Default::default()

0 commit comments

Comments
 (0)