From 9d5e200a80def44fb11ad4ce57bd5d13f618d2ae Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Wed, 14 Aug 2024 12:10:12 +0200 Subject: [PATCH] Remove RAM profiling --- Cargo.toml | 1 - src/utils.rs | 94 ------------------------------------------- src/witness/oracle.rs | 17 -------- 3 files changed, 112 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c1416f0..fc1776d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,6 @@ smallvec = "1.13" structopt = "0.3.26" codegen = "0.2.0" regex = { version = "1.10.6", features = ["pattern"] } -peak_alloc = "*" [dev-dependencies] rand = "0.4" diff --git a/src/utils.rs b/src/utils.rs index 2005de17..ecc29038 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,100 +4,6 @@ use crate::witness::tree::BinaryHasher; use circuit_definitions::encodings::BytesSerializable; -use peak_alloc::PeakAlloc; -use std::sync::{Mutex, OnceLock}; -use std::time::Duration; -use std::time::Instant; - -#[global_allocator] -static PEAK_ALLOC: PeakAlloc = PeakAlloc; - -fn mem_array() -> &'static Mutex> { - static MEM_ARRAY: OnceLock>> = OnceLock::new(); - MEM_ARRAY.get_or_init(|| Mutex::new(vec![])) -} - -fn time_instant() -> &'static Mutex { - static TIME_INSTANT: OnceLock> = OnceLock::new(); - TIME_INSTANT.get_or_init(|| Mutex::new(Instant::now())) -} - -fn time_array() -> &'static Mutex> { - static TIME_ARRAY: OnceLock>> = OnceLock::new(); - TIME_ARRAY.get_or_init(|| Mutex::new(vec![])) -} - -fn peak_mem_array() -> &'static Mutex> { - static PEAK_MEM_ARRAY: OnceLock>> = OnceLock::new(); - PEAK_MEM_ARRAY.get_or_init(|| Mutex::new(vec![])) -} - -fn peak_snapshot_mem(label: &str) { - let peak_mem = PEAK_ALLOC.peak_usage_as_mb(); - println!("PEAK MEM: {}: {}", label.to_owned(), peak_mem); - peak_mem_array() - .lock() - .unwrap() - .push((label.to_owned(), peak_mem)); -} - -pub fn print_mem_snapshots() { - let mem = mem_array().lock().unwrap(); - println!("MEMORY SNAPSHOTS"); - for snapshot in mem.clone() { - println!("{}: {}", snapshot.0, snapshot.1); - } - println!(); -} - -pub fn print_peak_mem_snapshots() { - let mem = peak_mem_array().lock().unwrap(); - println!("PEAK MEMORY SNAPSHOTS"); - for snapshot in mem.clone() { - println!("{}: {}", snapshot.0, snapshot.1); - } - println!(); -} - -pub fn print_time_snapshots() { - let time = time_array().lock().unwrap(); - println!("TIME SNAPSHOTS"); - for snapshot in time.clone() { - println!("{}: {:.2?}", snapshot.0, snapshot.1); - } - println!(); -} - -pub fn snapshot_mem(label: &str) { - let current_mem = PEAK_ALLOC.current_usage_as_mb(); - println!("MEM: {}: {}", label.to_owned(), current_mem); - mem_array() - .lock() - .unwrap() - .push((label.to_owned(), current_mem)); -} - -pub fn snapshot_prof(label: &str) { - snapshot_mem(label); - peak_snapshot_mem(label); - snapshot_time(label); - reset_peak_snapshot_mem(); -} - -pub fn snapshot_time(label: &str) { - let mut instant = time_instant().lock().unwrap(); - println!("TIME: {}: {:.2?}", label.to_owned(), instant.elapsed()); - time_array() - .lock() - .unwrap() - .push((label.to_owned(), instant.elapsed())); - *instant = Instant::now(); -} - -pub fn reset_peak_snapshot_mem() { - PEAK_ALLOC.reset_peak_usage(); -} - pub fn u64_as_u32_le(value: u64) -> [u32; 2] { [value as u32, (value >> 32) as u32] } diff --git a/src/witness/oracle.rs b/src/witness/oracle.rs index 6e0192ba..5ada14e7 100644 --- a/src/witness/oracle.rs +++ b/src/witness/oracle.rs @@ -14,7 +14,6 @@ use crate::boojum::field::SmallField; use crate::boojum::gadgets::queue::QueueState; use crate::boojum::gadgets::traits::allocatable::CSAllocatable; use crate::ethereum_types::U256; -use crate::snapshot_prof; use crate::toolset::GeometryConfig; use crate::witness::artifacts::{DemuxedLogQueries, MemoryArtifacts, MemoryCircuitsArtifacts}; use crate::witness::aux_data_structs::one_per_circuit_accumulator::{ @@ -1172,8 +1171,6 @@ fn process_memory_related_circuits( - 1) / geometry.cycles_per_ram_permutation; - snapshot_prof("BEFORE QUEUES SIMULATION"); - // Memory queues simulation is a slowest part in basic witness generation. // Each queue simulation is sequential single-threaded computation of hashes. // We will simulate unsorted and sorted queues in separate threads. @@ -1258,8 +1255,6 @@ fn process_memory_related_circuits( implicit_memory_states.amount_of_states() ); - snapshot_prof("AFTER QUEUES SIMULATION"); - use crate::witness::individual_circuits::memory_related::decommit_code::compute_decommitter_circuit_snapshots; tracing::debug!("Running code code decommitter simulation"); @@ -1362,8 +1357,6 @@ fn process_memory_related_circuits( tracing::debug!("Running RAM permutation simulation"); - snapshot_prof("BEFORE RAM"); - let (ram_permutation_circuits, ram_permutation_circuits_compact_forms_witnesses) = compute_ram_circuit_snapshots( amount_of_memory_queries, @@ -1380,8 +1373,6 @@ fn process_memory_related_circuits( &mut artifacts_callback, ); - snapshot_prof("AFTER RAM"); - ( circuits_data, memory_artifacts_for_main_vm, @@ -1468,8 +1459,6 @@ pub(crate) fn create_artifacts_from_tracer std::mem::take(&mut callstack_with_aux_data.flat_new_frames_history); drop(callstack_with_aux_data); - snapshot_prof("BEFORE MUX LOG QUEUE CIRCUITS"); - tracing::debug!("Running multiplexed log queue simulation"); // We have all log queries in one multiplexed queue. We need to simulate this queue, @@ -1487,8 +1476,6 @@ pub(crate) fn create_artifacts_from_tracer *round_function, ); - snapshot_prof("AFTER MUX LOG QUEUE CIRCUITS"); - use std::thread; let callstack_handle = { let log_rollback_tails_for_frames = log_rollback_tails_for_frames.clone(); @@ -1532,8 +1519,6 @@ pub(crate) fn create_artifacts_from_tracer tracing::debug!("Processing log circuits"); - snapshot_prof("AFTER LOG DEMUX CIRCUITS"); - // Process part of log circuits that do not use memory (I/O-like). // Precompiles will be processed in process_memory_related_circuits. // Also makes storage application circuits and compact form witnesses. @@ -1547,8 +1532,6 @@ pub(crate) fn create_artifacts_from_tracer &mut artifacts_callback, ); - snapshot_prof("AFTER LOG CIRCUITS"); - tracing::debug!("Processing memory-related circuits"); let precompiles_data = PrecompilesInputData {