Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Remove RAM profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Aug 14, 2024
1 parent de4b511 commit 9d5e200
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 112 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
94 changes: 0 additions & 94 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<(String, f32)>> {
static MEM_ARRAY: OnceLock<Mutex<Vec<(String, f32)>>> = OnceLock::new();
MEM_ARRAY.get_or_init(|| Mutex::new(vec![]))
}

fn time_instant() -> &'static Mutex<Instant> {
static TIME_INSTANT: OnceLock<Mutex<Instant>> = OnceLock::new();
TIME_INSTANT.get_or_init(|| Mutex::new(Instant::now()))
}

fn time_array() -> &'static Mutex<Vec<(String, Duration)>> {
static TIME_ARRAY: OnceLock<Mutex<Vec<(String, Duration)>>> = OnceLock::new();
TIME_ARRAY.get_or_init(|| Mutex::new(vec![]))
}

fn peak_mem_array() -> &'static Mutex<Vec<(String, f32)>> {
static PEAK_MEM_ARRAY: OnceLock<Mutex<Vec<(String, f32)>>> = 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]
}
Expand Down
17 changes: 0 additions & 17 deletions src/witness/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -1172,8 +1171,6 @@ fn process_memory_related_circuits<CB: FnMut(WitnessGenerationArtifact)>(
- 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.
Expand Down Expand Up @@ -1258,8 +1255,6 @@ fn process_memory_related_circuits<CB: FnMut(WitnessGenerationArtifact)>(
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");
Expand Down Expand Up @@ -1362,8 +1357,6 @@ fn process_memory_related_circuits<CB: FnMut(WitnessGenerationArtifact)>(

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,
Expand All @@ -1380,8 +1373,6 @@ fn process_memory_related_circuits<CB: FnMut(WitnessGenerationArtifact)>(
&mut artifacts_callback,
);

snapshot_prof("AFTER RAM");

(
circuits_data,
memory_artifacts_for_main_vm,
Expand Down Expand Up @@ -1468,8 +1459,6 @@ pub(crate) fn create_artifacts_from_tracer<CB: FnMut(WitnessGenerationArtifact)>
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,
Expand All @@ -1487,8 +1476,6 @@ pub(crate) fn create_artifacts_from_tracer<CB: FnMut(WitnessGenerationArtifact)>
*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();
Expand Down Expand Up @@ -1532,8 +1519,6 @@ pub(crate) fn create_artifacts_from_tracer<CB: FnMut(WitnessGenerationArtifact)>

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.
Expand All @@ -1547,8 +1532,6 @@ pub(crate) fn create_artifacts_from_tracer<CB: FnMut(WitnessGenerationArtifact)>
&mut artifacts_callback,
);

snapshot_prof("AFTER LOG CIRCUITS");

tracing::debug!("Processing memory-related circuits");

let precompiles_data = PrecompilesInputData {
Expand Down

0 comments on commit 9d5e200

Please sign in to comment.