Skip to content

Commit

Permalink
fix: release lock when compiling recursion program
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwen01 committed Feb 26, 2025
1 parent 5a957a5 commit d65cb0f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 108 deletions.
4 changes: 4 additions & 0 deletions crates/core/machine/src/cpu/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ impl<F: PrimeField32> MachineAir<F> for CpuChip {
shard.contains_cpu()
}
}

fn num_rows(&self, shard: &Self::Record) -> Option<usize> {
Some(shard.cpu_events.len())
}
}

impl CpuChip {
Expand Down
18 changes: 14 additions & 4 deletions crates/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,14 @@ impl<C: SP1ProverComponents> SP1Prover<C> {
&self,
input: &SP1RecursionWitnessValues<CoreSC>,
) -> Arc<RecursionProgram<BabyBear>> {
// Check if the program is in the cache.
let mut cache = self.lift_programs_lru.lock().unwrap_or_else(|e| e.into_inner());
cache
.get_or_insert(input.shape(), || {
let shape = input.shape();
let program = cache.get(&shape).cloned();
drop(cache);
match program {
Some(program) => program,
None => {
let misses = self.lift_cache_misses.fetch_add(1, Ordering::Relaxed);
tracing::debug!("core cache miss, misses: {}", misses);
// Get the operations.
Expand Down Expand Up @@ -971,9 +976,14 @@ impl<C: SP1ProverComponents> SP1Prover<C> {
}
let program = Arc::new(program);
compiler_span.exit();

// Insert the program into the cache.
let mut cache = self.lift_programs_lru.lock().unwrap_or_else(|e| e.into_inner());
cache.put(shape, program.clone());
drop(cache);
program
})
.clone()
}
}
}

pub fn compress_program(
Expand Down
Loading

0 comments on commit d65cb0f

Please sign in to comment.