From 67f99dfdc7210844cabee4ebb3824105174b8ac6 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Mon, 11 Nov 2024 12:31:27 +0000 Subject: [PATCH 01/10] initial mem reductions to successfully run the blob --- acvm-repo/acir/Cargo.toml | 1 + acvm-repo/acir_field/Cargo.toml | 2 +- acvm-repo/acir_field/src/field_element.rs | 172 ++++++++++++++++++ acvm-repo/acir_field/src/lib.rs | 8 +- acvm-repo/acvm/Cargo.toml | 1 + acvm-repo/blackbox_solver/Cargo.toml | 1 + acvm-repo/bn254_blackbox_solver/Cargo.toml | 4 + tooling/profiler/Cargo.toml | 4 - .../src/cli/execution_flamegraph_cmd.rs | 18 +- .../profiler/src/cli/gates_flamegraph_cmd.rs | 8 +- .../src/cli/opcodes_flamegraph_cmd.rs | 10 +- tooling/profiler/src/flamegraph.rs | 38 ++-- tooling/profiler/src/opcode_formatter.rs | 14 +- 13 files changed, 237 insertions(+), 44 deletions(-) diff --git a/acvm-repo/acir/Cargo.toml b/acvm-repo/acir/Cargo.toml index 2d164e3a983..4c36ec307af 100644 --- a/acvm-repo/acir/Cargo.toml +++ b/acvm-repo/acir/Cargo.toml @@ -36,6 +36,7 @@ criterion.workspace = true pprof.workspace = true [features] +default = ["bn254"] bn254 = ["acir_field/bn254"] bls12_381 = ["acir_field/bls12_381"] diff --git a/acvm-repo/acir_field/Cargo.toml b/acvm-repo/acir_field/Cargo.toml index a8e7f34a374..0e6ea38f591 100644 --- a/acvm-repo/acir_field/Cargo.toml +++ b/acvm-repo/acir_field/Cargo.toml @@ -31,4 +31,4 @@ proptest.workspace = true [features] bn254 = [] -bls12_381 = ["dep:ark-bls12-381"] +bls12_381 = ["dep:ark-bls12-381"] \ No newline at end of file diff --git a/acvm-repo/acir_field/src/field_element.rs b/acvm-repo/acir_field/src/field_element.rs index 47ceb903111..805cc2dab00 100644 --- a/acvm-repo/acir_field/src/field_element.rs +++ b/acvm-repo/acir_field/src/field_element.rs @@ -369,6 +369,178 @@ impl SubAssign for FieldElement { } } +#[derive( + Default, Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, +)] +pub struct ProfilingField {} + +impl std::fmt::Display for ProfilingField { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "profiling_field") + } +} + +impl AcirField for ProfilingField { + fn one() -> Self { + todo!() + } + + fn zero() -> Self { + todo!() + } + + fn is_zero(&self) -> bool { + todo!() + } + + fn is_one(&self) -> bool { + todo!() + } + + fn pow(&self, exponent: &Self) -> Self { + todo!() + } + + fn max_num_bits() -> u32 { + todo!() + } + + fn max_num_bytes() -> u32 { + todo!() + } + + fn modulus() -> BigUint { + todo!() + } + + fn num_bits(&self) -> u32 { + todo!() + } + + fn to_u128(self) -> u128 { + todo!() + } + + fn try_into_u128(self) -> Option { + todo!() + } + + fn to_i128(self) -> i128 { + todo!() + } + + fn try_to_u64(&self) -> Option { + todo!() + } + + fn try_to_u32(&self) -> Option { + todo!() + } + + fn inverse(&self) -> Self { + todo!() + } + + fn to_hex(self) -> String { + todo!() + } + + fn from_hex(hex_str: &str) -> Option { + todo!() + } + + fn to_be_bytes(self) -> Vec { + todo!() + } + + fn from_be_bytes_reduce(bytes: &[u8]) -> Self { + todo!() + } + + fn fetch_nearest_bytes(&self, num_bits: usize) -> Vec { + todo!() + } +} + +impl Neg for ProfilingField { + type Output = ProfilingField; + fn neg(self) -> Self::Output { + todo!(); + } +} + +impl Mul for ProfilingField { + type Output = ProfilingField; + fn mul(mut self, rhs: ProfilingField) -> Self::Output { + todo!(); + } +} +impl Div for ProfilingField { + type Output = ProfilingField; + #[allow(clippy::suspicious_arithmetic_impl)] + fn div(mut self, rhs: ProfilingField) -> Self::Output { + todo!(); + } +} +impl Add for ProfilingField { + type Output = ProfilingField; + fn add(mut self, rhs: ProfilingField) -> Self::Output { + todo!(); + } +} +impl AddAssign for ProfilingField { + fn add_assign(&mut self, rhs: ProfilingField) { + todo!(); + } +} + +impl Sub for ProfilingField { + type Output = ProfilingField; + fn sub(mut self, rhs: ProfilingField) -> Self::Output { + todo!(); + } +} +impl SubAssign for ProfilingField { + fn sub_assign(&mut self, rhs: ProfilingField) { + todo!(); + } +} + +impl From for ProfilingField { + fn from(a: u128) -> ProfilingField { + ProfilingField {} + } +} +impl From for ProfilingField { + fn from(a: i128) -> ProfilingField { + ProfilingField {} + } +} + +impl From for ProfilingField { + fn from(a: usize) -> ProfilingField { + ProfilingField {} + } +} + +impl From for ProfilingField { + fn from(a: u64) -> ProfilingField { + ProfilingField {} + } +} + +impl From for ProfilingField { + fn from(a: u32) -> ProfilingField { + ProfilingField {} + } +} + +impl From for ProfilingField { + fn from(boolean: bool) -> ProfilingField { + ProfilingField {} + } +} + #[cfg(test)] mod tests { use super::{AcirField, FieldElement}; diff --git a/acvm-repo/acir_field/src/lib.rs b/acvm-repo/acir_field/src/lib.rs index 1ad9a5b0037..53b91297678 100644 --- a/acvm-repo/acir_field/src/lib.rs +++ b/acvm-repo/acir_field/src/lib.rs @@ -14,8 +14,14 @@ pub use field_element::FieldElement as GenericFieldElement; cfg_if::cfg_if! { if #[cfg(feature = "bls12_381")] { pub type FieldElement = field_element::FieldElement; - } else { + } + // else if #[cfg(feature = "profiling")] { + // pub type FieldElement = field_element::ProfilingField; + // // pub type FieldElement = field_element::FieldElement; + // } + else { pub type FieldElement = field_element::FieldElement; + // pub type FieldElement = field_element::ProfilingField; } } diff --git a/acvm-repo/acvm/Cargo.toml b/acvm-repo/acvm/Cargo.toml index 145c07a4a00..cc3f9e2908f 100644 --- a/acvm-repo/acvm/Cargo.toml +++ b/acvm-repo/acvm/Cargo.toml @@ -26,6 +26,7 @@ acvm_blackbox_solver.workspace = true indexmap = "1.7.0" [features] +default = ["bn254"] bn254 = [ "acir/bn254", "brillig_vm/bn254", diff --git a/acvm-repo/blackbox_solver/Cargo.toml b/acvm-repo/blackbox_solver/Cargo.toml index 4c341a42a04..c94fb090c0c 100644 --- a/acvm-repo/blackbox_solver/Cargo.toml +++ b/acvm-repo/blackbox_solver/Cargo.toml @@ -45,5 +45,6 @@ libaes = "0.7.0" proptest.workspace = true [features] +default = ["bn254"] bn254 = ["acir/bn254"] bls12_381 = ["acir/bls12_381"] diff --git a/acvm-repo/bn254_blackbox_solver/Cargo.toml b/acvm-repo/bn254_blackbox_solver/Cargo.toml index 97f6b76a9a3..b20ad182f0c 100644 --- a/acvm-repo/bn254_blackbox_solver/Cargo.toml +++ b/acvm-repo/bn254_blackbox_solver/Cargo.toml @@ -39,3 +39,7 @@ pprof = { version = "0.12", features = [ [[bench]] name = "criterion" harness = false + +[features] +default = ["bn254"] +bn254 = ["acir/bn254", "acvm_blackbox_solver/bn254"] diff --git a/tooling/profiler/Cargo.toml b/tooling/profiler/Cargo.toml index 604208b5a54..7b06fbaf1aa 100644 --- a/tooling/profiler/Cargo.toml +++ b/tooling/profiler/Cargo.toml @@ -43,7 +43,3 @@ tracing-appender = "0.2.3" noirc_abi.workspace = true noirc_driver.workspace = true tempfile.workspace = true - -[features] -default = ["bn254"] -bn254 = ["acir/bn254"] diff --git a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs index a0b3d6a3128..50c644df419 100644 --- a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs @@ -7,7 +7,7 @@ use color_eyre::eyre::{self, Context}; use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; use crate::fs::{read_inputs_from_file, read_program_from_file}; -use crate::opcode_formatter::AcirOrBrilligOpcode; +use crate::opcode_formatter::{format_brillig_opcode, format_opcode, AcirOrBrilligOpcode}; use bn254_blackbox_solver::Bn254BlackBoxSolver; use nargo::ops::DefaultForeignCallExecutor; use noirc_abi::input_parser::Format; @@ -49,9 +49,11 @@ fn run_with_generator( let (inputs_map, _) = read_inputs_from_file(prover_toml_path, Format::Toml, &program.abi)?; let initial_witness = program.abi.encode(&inputs_map, None)?; + println!("Size of opcode {}", std::mem::size_of::>()); + println!("Size of sample {}", std::mem::size_of::()); println!("Executing"); - let (_, profiling_samples) = nargo::ops::execute_program_with_profiling( + let (_, mut profiling_samples) = nargo::ops::execute_program_with_profiling( &program.bytecode, initial_witness, &Bn254BlackBoxSolver, @@ -59,10 +61,14 @@ fn run_with_generator( )?; println!("Executed"); - let profiling_samples: Vec> = profiling_samples - .into_iter() + println!("Collecting {} samples", profiling_samples.len()); + println!("{} debug infos", program.debug_symbols.debug_infos.len()); + println!("{} unconstrained fns", program.bytecode.unconstrained_functions.len()); + + let profiling_samples: Vec = profiling_samples + .iter_mut() .map(|sample| { - let call_stack = sample.call_stack; + let call_stack = std::mem::take(&mut sample.call_stack); let brillig_function_id = sample.brillig_function_id; let last_entry = call_stack.last(); let opcode = brillig_function_id @@ -74,7 +80,7 @@ fn run_with_generator( None } }) - .map(|opcode| AcirOrBrilligOpcode::Brillig(opcode.clone())); + .map(|opcode| format_brillig_opcode(opcode)); Sample { opcode, call_stack, count: 1, brillig_function_id } }) .collect(); diff --git a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs index 20cc1b747c3..7815ade197e 100644 --- a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -9,7 +9,7 @@ use noirc_artifacts::debug::DebugArtifact; use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; use crate::fs::read_program_from_file; use crate::gates_provider::{BackendGatesProvider, GatesProvider}; -use crate::opcode_formatter::AcirOrBrilligOpcode; +use crate::opcode_formatter::{format_acir_opcode, AcirOrBrilligOpcode}; #[derive(Debug, Clone, Args)] pub(crate) struct GatesFlamegraphCommand { @@ -84,7 +84,7 @@ fn run_with_provider( .zip(bytecode.opcodes) .enumerate() .map(|(index, (gates, opcode))| Sample { - opcode: Some(AcirOrBrilligOpcode::Acir(opcode)), + opcode: Some(format_acir_opcode(&opcode)), call_stack: vec![OpcodeLocation::Acir(index)], count: gates, brillig_function_id: None, @@ -143,9 +143,9 @@ mod tests { struct TestFlamegraphGenerator {} impl super::FlamegraphGenerator for TestFlamegraphGenerator { - fn generate_flamegraph<'files, F: AcirField>( + fn generate_flamegraph<'files>( &self, - _samples: Vec>, + _samples: Vec, _debug_symbols: &DebugInfo, _files: &'files impl Files<'files, FileId = fm::FileId>, _artifact_name: &str, diff --git a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs index bb3df86c339..1fca8c0319f 100644 --- a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs @@ -9,7 +9,7 @@ use noirc_artifacts::debug::DebugArtifact; use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; use crate::fs::read_program_from_file; -use crate::opcode_formatter::AcirOrBrilligOpcode; +use crate::opcode_formatter::{format_acir_opcode, format_brillig_opcode, AcirOrBrilligOpcode}; #[derive(Debug, Clone, Args)] pub(crate) struct OpcodesFlamegraphCommand { @@ -60,7 +60,7 @@ fn run_with_generator( .iter() .enumerate() .map(|(index, opcode)| Sample { - opcode: Some(AcirOrBrilligOpcode::Acir(opcode.clone())), + opcode: Some(format_acir_opcode(opcode)), call_stack: vec![OpcodeLocation::Acir(index)], count: 1, brillig_function_id: None, @@ -97,7 +97,7 @@ fn run_with_generator( .into_iter() .enumerate() .map(|(brillig_index, opcode)| Sample { - opcode: Some(AcirOrBrilligOpcode::Brillig(opcode)), + opcode: Some(format_brillig_opcode(&opcode)), call_stack: vec![OpcodeLocation::Brillig { acir_index: acir_opcode_index, brillig_index, @@ -160,9 +160,9 @@ mod tests { struct TestFlamegraphGenerator {} impl super::FlamegraphGenerator for TestFlamegraphGenerator { - fn generate_flamegraph<'files, F: AcirField>( + fn generate_flamegraph<'files>( &self, - _samples: Vec>, + _samples: Vec, _debug_symbols: &DebugInfo, _files: &'files impl Files<'files, FileId = fm::FileId>, _artifact_name: &str, diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index 7882ac903ef..6633d5ebfb2 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -13,13 +13,9 @@ use noirc_errors::reporter::line_and_column_from_span; use noirc_errors::Location; use noirc_evaluator::brillig::ProcedureId; -use crate::opcode_formatter::AcirOrBrilligOpcode; - -use super::opcode_formatter::format_opcode; - #[derive(Debug)] -pub(crate) struct Sample { - pub(crate) opcode: Option>, +pub(crate) struct Sample { + pub(crate) opcode: Option, pub(crate) call_stack: Vec, pub(crate) count: usize, pub(crate) brillig_function_id: Option, @@ -33,9 +29,9 @@ pub(crate) struct FoldedStackItem { pub(crate) trait FlamegraphGenerator { #[allow(clippy::too_many_arguments)] - fn generate_flamegraph<'files, F: AcirField>( + fn generate_flamegraph<'files>( &self, - samples: Vec>, + samples: Vec, debug_symbols: &DebugInfo, files: &'files impl Files<'files, FileId = fm::FileId>, artifact_name: &str, @@ -49,9 +45,9 @@ pub(crate) struct InfernoFlamegraphGenerator { } impl FlamegraphGenerator for InfernoFlamegraphGenerator { - fn generate_flamegraph<'files, F: AcirField>( + fn generate_flamegraph<'files>( &self, - samples: Vec>, + samples: Vec, debug_symbols: &DebugInfo, files: &'files impl Files<'files, FileId = fm::FileId>, artifact_name: &str, @@ -82,11 +78,12 @@ impl FlamegraphGenerator for InfernoFlamegraphGenerator { } } -fn generate_folded_sorted_lines<'files, F: AcirField>( - samples: Vec>, +fn generate_folded_sorted_lines<'files>( + samples: Vec, debug_symbols: &DebugInfo, files: &'files impl Files<'files, FileId = fm::FileId>, ) -> Vec { + println!("About to generate sorted lines"); // Create a nested hashmap with the stack items, folding the gates for all the callsites that are equal let mut folded_stack_items = BTreeMap::new(); @@ -109,8 +106,8 @@ fn generate_folded_sorted_lines<'files, F: AcirField>( location_names.extend(callsite_labels); } - if let Some(opcode) = &sample.opcode { - location_names.push(format_opcode(opcode)); + if let Some(opcode) = sample.opcode { + location_names.push(opcode); } add_locations_to_folded_stack_items(&mut folded_stack_items, location_names, sample.count); @@ -251,7 +248,10 @@ mod tests { use noirc_errors::{debug_info::DebugInfo, Location, Span}; use std::{collections::BTreeMap, path::Path}; - use crate::{flamegraph::Sample, opcode_formatter::AcirOrBrilligOpcode}; + use crate::{ + flamegraph::Sample, + opcode_formatter::{format_acir_opcode, AcirOrBrilligOpcode}, + }; use super::generate_folded_sorted_lines; @@ -338,9 +338,9 @@ mod tests { BTreeMap::default(), ); - let samples: Vec> = vec![ + let samples: Vec = vec![ Sample { - opcode: Some(AcirOrBrilligOpcode::Acir(AcirOpcode::AssertZero( + opcode: Some(format_acir_opcode(&AcirOpcode::AssertZero::( Expression::default(), ))), call_stack: vec![OpcodeLocation::Acir(0)], @@ -348,7 +348,7 @@ mod tests { brillig_function_id: None, }, Sample { - opcode: Some(AcirOrBrilligOpcode::Acir(AcirOpcode::AssertZero( + opcode: Some(format_acir_opcode(&AcirOpcode::AssertZero::( Expression::default(), ))), call_stack: vec![OpcodeLocation::Acir(1)], @@ -356,7 +356,7 @@ mod tests { brillig_function_id: None, }, Sample { - opcode: Some(AcirOrBrilligOpcode::Acir(AcirOpcode::MemoryInit { + opcode: Some(format_acir_opcode(&AcirOpcode::MemoryInit:: { block_id: BlockId(0), init: vec![], block_type: acir::circuit::opcodes::BlockType::Memory, diff --git a/tooling/profiler/src/opcode_formatter.rs b/tooling/profiler/src/opcode_formatter.rs index 68057b6d86f..73c678b971f 100644 --- a/tooling/profiler/src/opcode_formatter.rs +++ b/tooling/profiler/src/opcode_formatter.rs @@ -136,11 +136,17 @@ fn format_brillig_opcode_kind(opcode: &BrilligOpcode) -> String { } } +pub(crate) fn format_acir_opcode(opcode: &AcirOpcode) -> String { + format!("acir::{}", format_acir_opcode_kind(opcode)) +} + +pub(crate) fn format_brillig_opcode(opcode: &BrilligOpcode) -> String { + format!("brillig::{}", format_brillig_opcode_kind(opcode)) +} + pub(crate) fn format_opcode(opcode: &AcirOrBrilligOpcode) -> String { match opcode { - AcirOrBrilligOpcode::Acir(opcode) => format!("acir::{}", format_acir_opcode_kind(opcode)), - AcirOrBrilligOpcode::Brillig(opcode) => { - format!("brillig::{}", format_brillig_opcode_kind(opcode)) - } + AcirOrBrilligOpcode::Acir(opcode) => format_acir_opcode(opcode), + AcirOrBrilligOpcode::Brillig(opcode) => format_brillig_opcode(opcode), } } From eb59bffeab1379cf86d08e353b92387899533d2e Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Mon, 11 Nov 2024 12:44:29 +0000 Subject: [PATCH 02/10] cleanup --- acvm-repo/acir/Cargo.toml | 1 - acvm-repo/acir_field/Cargo.toml | 2 +- acvm-repo/acir_field/src/field_element.rs | 172 ------------------ acvm-repo/acir_field/src/lib.rs | 8 +- acvm-repo/acvm/Cargo.toml | 1 - acvm-repo/blackbox_solver/Cargo.toml | 1 - acvm-repo/bn254_blackbox_solver/Cargo.toml | 4 - tooling/profiler/Cargo.toml | 1 + .../src/cli/execution_flamegraph_cmd.rs | 9 +- .../profiler/src/cli/gates_flamegraph_cmd.rs | 2 +- .../src/cli/opcodes_flamegraph_cmd.rs | 2 +- tooling/profiler/src/flamegraph.rs | 6 +- tooling/profiler/src/opcode_formatter.rs | 13 -- 13 files changed, 8 insertions(+), 214 deletions(-) diff --git a/acvm-repo/acir/Cargo.toml b/acvm-repo/acir/Cargo.toml index 726eecd1917..ff6c9b1954e 100644 --- a/acvm-repo/acir/Cargo.toml +++ b/acvm-repo/acir/Cargo.toml @@ -36,7 +36,6 @@ criterion.workspace = true pprof.workspace = true [features] -default = ["bn254"] bn254 = ["acir_field/bn254"] bls12_381 = ["acir_field/bls12_381"] diff --git a/acvm-repo/acir_field/Cargo.toml b/acvm-repo/acir_field/Cargo.toml index e4911ffa15e..66a01848a54 100644 --- a/acvm-repo/acir_field/Cargo.toml +++ b/acvm-repo/acir_field/Cargo.toml @@ -31,4 +31,4 @@ proptest.workspace = true [features] bn254 = [] -bls12_381 = ["dep:ark-bls12-381"] \ No newline at end of file +bls12_381 = ["dep:ark-bls12-381"] diff --git a/acvm-repo/acir_field/src/field_element.rs b/acvm-repo/acir_field/src/field_element.rs index 805cc2dab00..47ceb903111 100644 --- a/acvm-repo/acir_field/src/field_element.rs +++ b/acvm-repo/acir_field/src/field_element.rs @@ -369,178 +369,6 @@ impl SubAssign for FieldElement { } } -#[derive( - Default, Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, -)] -pub struct ProfilingField {} - -impl std::fmt::Display for ProfilingField { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "profiling_field") - } -} - -impl AcirField for ProfilingField { - fn one() -> Self { - todo!() - } - - fn zero() -> Self { - todo!() - } - - fn is_zero(&self) -> bool { - todo!() - } - - fn is_one(&self) -> bool { - todo!() - } - - fn pow(&self, exponent: &Self) -> Self { - todo!() - } - - fn max_num_bits() -> u32 { - todo!() - } - - fn max_num_bytes() -> u32 { - todo!() - } - - fn modulus() -> BigUint { - todo!() - } - - fn num_bits(&self) -> u32 { - todo!() - } - - fn to_u128(self) -> u128 { - todo!() - } - - fn try_into_u128(self) -> Option { - todo!() - } - - fn to_i128(self) -> i128 { - todo!() - } - - fn try_to_u64(&self) -> Option { - todo!() - } - - fn try_to_u32(&self) -> Option { - todo!() - } - - fn inverse(&self) -> Self { - todo!() - } - - fn to_hex(self) -> String { - todo!() - } - - fn from_hex(hex_str: &str) -> Option { - todo!() - } - - fn to_be_bytes(self) -> Vec { - todo!() - } - - fn from_be_bytes_reduce(bytes: &[u8]) -> Self { - todo!() - } - - fn fetch_nearest_bytes(&self, num_bits: usize) -> Vec { - todo!() - } -} - -impl Neg for ProfilingField { - type Output = ProfilingField; - fn neg(self) -> Self::Output { - todo!(); - } -} - -impl Mul for ProfilingField { - type Output = ProfilingField; - fn mul(mut self, rhs: ProfilingField) -> Self::Output { - todo!(); - } -} -impl Div for ProfilingField { - type Output = ProfilingField; - #[allow(clippy::suspicious_arithmetic_impl)] - fn div(mut self, rhs: ProfilingField) -> Self::Output { - todo!(); - } -} -impl Add for ProfilingField { - type Output = ProfilingField; - fn add(mut self, rhs: ProfilingField) -> Self::Output { - todo!(); - } -} -impl AddAssign for ProfilingField { - fn add_assign(&mut self, rhs: ProfilingField) { - todo!(); - } -} - -impl Sub for ProfilingField { - type Output = ProfilingField; - fn sub(mut self, rhs: ProfilingField) -> Self::Output { - todo!(); - } -} -impl SubAssign for ProfilingField { - fn sub_assign(&mut self, rhs: ProfilingField) { - todo!(); - } -} - -impl From for ProfilingField { - fn from(a: u128) -> ProfilingField { - ProfilingField {} - } -} -impl From for ProfilingField { - fn from(a: i128) -> ProfilingField { - ProfilingField {} - } -} - -impl From for ProfilingField { - fn from(a: usize) -> ProfilingField { - ProfilingField {} - } -} - -impl From for ProfilingField { - fn from(a: u64) -> ProfilingField { - ProfilingField {} - } -} - -impl From for ProfilingField { - fn from(a: u32) -> ProfilingField { - ProfilingField {} - } -} - -impl From for ProfilingField { - fn from(boolean: bool) -> ProfilingField { - ProfilingField {} - } -} - #[cfg(test)] mod tests { use super::{AcirField, FieldElement}; diff --git a/acvm-repo/acir_field/src/lib.rs b/acvm-repo/acir_field/src/lib.rs index 53b91297678..1ad9a5b0037 100644 --- a/acvm-repo/acir_field/src/lib.rs +++ b/acvm-repo/acir_field/src/lib.rs @@ -14,14 +14,8 @@ pub use field_element::FieldElement as GenericFieldElement; cfg_if::cfg_if! { if #[cfg(feature = "bls12_381")] { pub type FieldElement = field_element::FieldElement; - } - // else if #[cfg(feature = "profiling")] { - // pub type FieldElement = field_element::ProfilingField; - // // pub type FieldElement = field_element::FieldElement; - // } - else { + } else { pub type FieldElement = field_element::FieldElement; - // pub type FieldElement = field_element::ProfilingField; } } diff --git a/acvm-repo/acvm/Cargo.toml b/acvm-repo/acvm/Cargo.toml index afcda0ad1ed..2b143ebe475 100644 --- a/acvm-repo/acvm/Cargo.toml +++ b/acvm-repo/acvm/Cargo.toml @@ -26,7 +26,6 @@ acvm_blackbox_solver.workspace = true indexmap = "1.7.0" [features] -default = ["bn254"] bn254 = [ "acir/bn254", "brillig_vm/bn254", diff --git a/acvm-repo/blackbox_solver/Cargo.toml b/acvm-repo/blackbox_solver/Cargo.toml index 455b77d3951..944b17c7dc6 100644 --- a/acvm-repo/blackbox_solver/Cargo.toml +++ b/acvm-repo/blackbox_solver/Cargo.toml @@ -45,6 +45,5 @@ libaes = "0.7.0" proptest.workspace = true [features] -default = ["bn254"] bn254 = ["acir/bn254"] bls12_381 = ["acir/bls12_381"] diff --git a/acvm-repo/bn254_blackbox_solver/Cargo.toml b/acvm-repo/bn254_blackbox_solver/Cargo.toml index 476fe4abcb6..7541fe239c9 100644 --- a/acvm-repo/bn254_blackbox_solver/Cargo.toml +++ b/acvm-repo/bn254_blackbox_solver/Cargo.toml @@ -39,7 +39,3 @@ pprof = { version = "0.12", features = [ [[bench]] name = "criterion" harness = false - -[features] -default = ["bn254"] -bn254 = ["acir/bn254", "acvm_blackbox_solver/bn254"] diff --git a/tooling/profiler/Cargo.toml b/tooling/profiler/Cargo.toml index 7b06fbaf1aa..798a21ea0d6 100644 --- a/tooling/profiler/Cargo.toml +++ b/tooling/profiler/Cargo.toml @@ -43,3 +43,4 @@ tracing-appender = "0.2.3" noirc_abi.workspace = true noirc_driver.workspace = true tempfile.workspace = true + diff --git a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs index 50c644df419..02e218c037f 100644 --- a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs @@ -1,13 +1,12 @@ use std::path::{Path, PathBuf}; use acir::circuit::OpcodeLocation; -use acir::FieldElement; use clap::Args; use color_eyre::eyre::{self, Context}; use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; use crate::fs::{read_inputs_from_file, read_program_from_file}; -use crate::opcode_formatter::{format_brillig_opcode, format_opcode, AcirOrBrilligOpcode}; +use crate::opcode_formatter::format_brillig_opcode; use bn254_blackbox_solver::Bn254BlackBoxSolver; use nargo::ops::DefaultForeignCallExecutor; use noirc_abi::input_parser::Format; @@ -49,8 +48,6 @@ fn run_with_generator( let (inputs_map, _) = read_inputs_from_file(prover_toml_path, Format::Toml, &program.abi)?; let initial_witness = program.abi.encode(&inputs_map, None)?; - println!("Size of opcode {}", std::mem::size_of::>()); - println!("Size of sample {}", std::mem::size_of::()); println!("Executing"); let (_, mut profiling_samples) = nargo::ops::execute_program_with_profiling( @@ -62,8 +59,6 @@ fn run_with_generator( println!("Executed"); println!("Collecting {} samples", profiling_samples.len()); - println!("{} debug infos", program.debug_symbols.debug_infos.len()); - println!("{} unconstrained fns", program.bytecode.unconstrained_functions.len()); let profiling_samples: Vec = profiling_samples .iter_mut() @@ -80,7 +75,7 @@ fn run_with_generator( None } }) - .map(|opcode| format_brillig_opcode(opcode)); + .map(format_brillig_opcode); Sample { opcode, call_stack, count: 1, brillig_function_id } }) .collect(); diff --git a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs index 7815ade197e..f292baca9ea 100644 --- a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -9,7 +9,7 @@ use noirc_artifacts::debug::DebugArtifact; use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; use crate::fs::read_program_from_file; use crate::gates_provider::{BackendGatesProvider, GatesProvider}; -use crate::opcode_formatter::{format_acir_opcode, AcirOrBrilligOpcode}; +use crate::opcode_formatter::format_acir_opcode; #[derive(Debug, Clone, Args)] pub(crate) struct GatesFlamegraphCommand { diff --git a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs index 1fca8c0319f..8a1ea9c7765 100644 --- a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs @@ -9,7 +9,7 @@ use noirc_artifacts::debug::DebugArtifact; use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; use crate::fs::read_program_from_file; -use crate::opcode_formatter::{format_acir_opcode, format_brillig_opcode, AcirOrBrilligOpcode}; +use crate::opcode_formatter::{format_acir_opcode, format_brillig_opcode}; #[derive(Debug, Clone, Args)] pub(crate) struct OpcodesFlamegraphCommand { diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index 6633d5ebfb2..027c00c205f 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -3,7 +3,6 @@ use std::{collections::BTreeMap, io::BufWriter}; use acir::circuit::brillig::BrilligFunctionId; use acir::circuit::OpcodeLocation; -use acir::AcirField; use color_eyre::eyre::{self}; use fm::codespan_files::Files; use fxhash::FxHashMap as HashMap; @@ -248,10 +247,7 @@ mod tests { use noirc_errors::{debug_info::DebugInfo, Location, Span}; use std::{collections::BTreeMap, path::Path}; - use crate::{ - flamegraph::Sample, - opcode_formatter::{format_acir_opcode, AcirOrBrilligOpcode}, - }; + use crate::{flamegraph::Sample, opcode_formatter::format_acir_opcode}; use super::generate_folded_sorted_lines; diff --git a/tooling/profiler/src/opcode_formatter.rs b/tooling/profiler/src/opcode_formatter.rs index 73c678b971f..32aa9980b88 100644 --- a/tooling/profiler/src/opcode_formatter.rs +++ b/tooling/profiler/src/opcode_formatter.rs @@ -2,12 +2,6 @@ use acir::brillig::{BinaryFieldOp, BinaryIntOp, BlackBoxOp, Opcode as BrilligOpc use acir::circuit::{directives::Directive, opcodes::BlackBoxFuncCall, Opcode as AcirOpcode}; use acir::AcirField; -#[derive(Debug)] -pub(crate) enum AcirOrBrilligOpcode { - Acir(AcirOpcode), - Brillig(BrilligOpcode), -} - fn format_blackbox_function(call: &BlackBoxFuncCall) -> String { match call { BlackBoxFuncCall::AES128Encrypt { .. } => "aes128_encrypt".to_string(), @@ -143,10 +137,3 @@ pub(crate) fn format_acir_opcode(opcode: &AcirOpcode) -> String pub(crate) fn format_brillig_opcode(opcode: &BrilligOpcode) -> String { format!("brillig::{}", format_brillig_opcode_kind(opcode)) } - -pub(crate) fn format_opcode(opcode: &AcirOrBrilligOpcode) -> String { - match opcode { - AcirOrBrilligOpcode::Acir(opcode) => format_acir_opcode(opcode), - AcirOrBrilligOpcode::Brillig(opcode) => format_brillig_opcode(opcode), - } -} From 882c00502987ec46818e3093434386bd974812fe Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Sun, 17 Nov 2024 14:26:29 +0000 Subject: [PATCH 03/10] Sample trait --- tooling/nargo/src/ops/execute.rs | 5 +- .../src/cli/execution_flamegraph_cmd.rs | 12 ++- .../profiler/src/cli/gates_flamegraph_cmd.rs | 14 ++- .../src/cli/opcodes_flamegraph_cmd.rs | 18 ++-- tooling/profiler/src/flamegraph.rs | 95 +++++++++++++++---- 5 files changed, 109 insertions(+), 35 deletions(-) diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index 09ef554d2aa..fa197c1ad81 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -4,7 +4,8 @@ use acvm::acir::circuit::{ }; use acvm::acir::native_types::WitnessStack; use acvm::pwg::{ - ACVMStatus, ErrorLocation, OpcodeNotSolvable, OpcodeResolutionError, ProfilingSamples, ACVM, + ACVMStatus, ErrorLocation, OpcodeNotSolvable, OpcodeResolutionError, ProfilingSample, + ProfilingSamples, ACVM, }; use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap}; use acvm::{AcirField, BlackBoxFunctionSolver}; @@ -229,6 +230,8 @@ pub fn execute_program_with_profiling< foreign_call_executor: &mut E, ) -> Result<(WitnessStack, ProfilingSamples), NargoError> { let profiling_active = true; + let prof_sample_size = std::mem::size_of::(); + println!("prof sample size: {}", prof_sample_size); execute_program_inner( program, initial_witness, diff --git a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs index 02e218c037f..c2d5ffda580 100644 --- a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs @@ -3,8 +3,11 @@ use std::path::{Path, PathBuf}; use acir::circuit::OpcodeLocation; use clap::Args; use color_eyre::eyre::{self, Context}; +use fxhash::FxHashMap as HashMap; -use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; +use crate::flamegraph::{ + BrilligExecutionSample, CompilationSample, FlamegraphGenerator, InfernoFlamegraphGenerator, +}; use crate::fs::{read_inputs_from_file, read_program_from_file}; use crate::opcode_formatter::format_brillig_opcode; use bn254_blackbox_solver::Bn254BlackBoxSolver; @@ -60,11 +63,11 @@ fn run_with_generator( println!("Collecting {} samples", profiling_samples.len()); - let profiling_samples: Vec = profiling_samples + let profiling_samples: Vec = profiling_samples .iter_mut() .map(|sample| { let call_stack = std::mem::take(&mut sample.call_stack); - let brillig_function_id = sample.brillig_function_id; + let brillig_function_id = std::mem::take(&mut sample.brillig_function_id); let last_entry = call_stack.last(); let opcode = brillig_function_id .and_then(|id| program.bytecode.unconstrained_functions.get(id.0 as usize)) @@ -76,7 +79,7 @@ fn run_with_generator( } }) .map(format_brillig_opcode); - Sample { opcode, call_stack, count: 1, brillig_function_id } + BrilligExecutionSample { opcode, call_stack } }) .collect(); @@ -87,6 +90,7 @@ fn run_with_generator( flamegraph_generator.generate_flamegraph( profiling_samples, &debug_artifact.debug_symbols[0], + true, &debug_artifact, artifact_path.to_str().unwrap(), "main", diff --git a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs index f292baca9ea..d6ae3400a91 100644 --- a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -6,7 +6,7 @@ use color_eyre::eyre::{self, Context}; use noirc_artifacts::debug::DebugArtifact; -use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; +use crate::flamegraph::{CompilationSample, FlamegraphGenerator, InfernoFlamegraphGenerator}; use crate::fs::read_program_from_file; use crate::gates_provider::{BackendGatesProvider, GatesProvider}; use crate::opcode_formatter::format_acir_opcode; @@ -83,9 +83,11 @@ fn run_with_provider( .into_iter() .zip(bytecode.opcodes) .enumerate() - .map(|(index, (gates, opcode))| Sample { + .map(|(index, (gates, opcode))| CompilationSample { opcode: Some(format_acir_opcode(&opcode)), call_stack: vec![OpcodeLocation::Acir(index)], + // call_stack_index: 0, + // count: Some(gates), count: gates, brillig_function_id: None, }) @@ -94,6 +96,7 @@ fn run_with_provider( flamegraph_generator.generate_flamegraph( samples, &debug_artifact.debug_symbols[func_idx], + false, &debug_artifact, artifact_path.to_str().unwrap(), &func_name, @@ -120,7 +123,7 @@ mod tests { }; use crate::{ - flamegraph::Sample, + flamegraph::{CompilationSample, Sample}, gates_provider::{BackendGatesReport, BackendGatesResponse, GatesProvider}, }; @@ -143,10 +146,11 @@ mod tests { struct TestFlamegraphGenerator {} impl super::FlamegraphGenerator for TestFlamegraphGenerator { - fn generate_flamegraph<'files>( + fn generate_flamegraph<'files, S: Sample>( &self, - _samples: Vec, + _samples: Vec, _debug_symbols: &DebugInfo, + _forced_brillig: bool, _files: &'files impl Files<'files, FileId = fm::FileId>, _artifact_name: &str, _function_name: &str, diff --git a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs index 8a1ea9c7765..301d928215c 100644 --- a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs @@ -7,7 +7,7 @@ use color_eyre::eyre::{self, Context}; use noirc_artifacts::debug::DebugArtifact; -use crate::flamegraph::{FlamegraphGenerator, InfernoFlamegraphGenerator, Sample}; +use crate::flamegraph::{CompilationSample, FlamegraphGenerator, InfernoFlamegraphGenerator}; use crate::fs::read_program_from_file; use crate::opcode_formatter::{format_acir_opcode, format_brillig_opcode}; @@ -59,9 +59,10 @@ fn run_with_generator( .opcodes .iter() .enumerate() - .map(|(index, opcode)| Sample { + .map(|(index, opcode)| CompilationSample { opcode: Some(format_acir_opcode(opcode)), call_stack: vec![OpcodeLocation::Acir(index)], + // call_stack_index: 0, count: 1, brillig_function_id: None, }) @@ -70,6 +71,7 @@ fn run_with_generator( flamegraph_generator.generate_flamegraph( samples, &debug_artifact.debug_symbols[func_idx], + false, &debug_artifact, artifact_path.to_str().unwrap(), &func_name, @@ -96,12 +98,14 @@ fn run_with_generator( .bytecode .into_iter() .enumerate() - .map(|(brillig_index, opcode)| Sample { + .map(|(brillig_index, opcode)| CompilationSample { opcode: Some(format_brillig_opcode(&opcode)), call_stack: vec![OpcodeLocation::Brillig { acir_index: acir_opcode_index, brillig_index, }], + // call_stack_index: 0, + // count: None, count: 1, brillig_function_id: Some(BrilligFunctionId(brillig_fn_index as u32)), }) @@ -110,6 +114,7 @@ fn run_with_generator( flamegraph_generator.generate_flamegraph( samples, &debug_artifact.debug_symbols[acir_fn_index], + false, &debug_artifact, artifact_path.to_str().unwrap(), &format!("brillig_{}", brillig_fn_index), @@ -146,7 +151,7 @@ mod tests { brillig::{BrilligBytecode, BrilligFunctionId}, Circuit, Opcode, Program, }, - AcirField, FieldElement, + FieldElement, }; use color_eyre::eyre::{self}; use fm::codespan_files::Files; @@ -160,10 +165,11 @@ mod tests { struct TestFlamegraphGenerator {} impl super::FlamegraphGenerator for TestFlamegraphGenerator { - fn generate_flamegraph<'files>( + fn generate_flamegraph<'files, S: Sample>( &self, - _samples: Vec, + _samples: Vec, _debug_symbols: &DebugInfo, + _forced_brillig: bool, _files: &'files impl Files<'files, FileId = fm::FileId>, _artifact_name: &str, _function_name: &str, diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index 027c00c205f..20d477709c8 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -12,14 +12,66 @@ use noirc_errors::reporter::line_and_column_from_span; use noirc_errors::Location; use noirc_evaluator::brillig::ProcedureId; +pub(crate) trait Sample { + fn count(&self) -> usize; + + fn brillig_function_id(&self) -> Option; + + fn call_stack(&self) -> &[OpcodeLocation]; + + fn opcode(self) -> Option; +} + #[derive(Debug)] -pub(crate) struct Sample { +pub(crate) struct CompilationSample { pub(crate) opcode: Option, pub(crate) call_stack: Vec, + // pub(crate) call_stack_index: u32, pub(crate) count: usize, pub(crate) brillig_function_id: Option, } +impl Sample for CompilationSample { + fn count(&self) -> usize { + self.count + } + + fn brillig_function_id(&self) -> Option { + self.brillig_function_id + } + + fn call_stack(&self) -> &[OpcodeLocation] { + &self.call_stack + } + + fn opcode(self) -> Option { + self.opcode + } +} + +pub(crate) struct BrilligExecutionSample { + pub(crate) opcode: Option, + pub(crate) call_stack: Vec, +} + +impl Sample for BrilligExecutionSample { + fn count(&self) -> usize { + 1 + } + + fn brillig_function_id(&self) -> Option { + Some(BrilligFunctionId(0)) + } + + fn call_stack(&self) -> &[OpcodeLocation] { + &self.call_stack + } + + fn opcode(self) -> Option { + self.opcode + } +} + #[derive(Debug, Default)] pub(crate) struct FoldedStackItem { pub(crate) total_samples: usize, @@ -28,10 +80,11 @@ pub(crate) struct FoldedStackItem { pub(crate) trait FlamegraphGenerator { #[allow(clippy::too_many_arguments)] - fn generate_flamegraph<'files>( + fn generate_flamegraph<'files, S: Sample>( &self, - samples: Vec, + samples: Vec, debug_symbols: &DebugInfo, + forced_brillig: bool, files: &'files impl Files<'files, FileId = fm::FileId>, artifact_name: &str, function_name: &str, @@ -44,10 +97,11 @@ pub(crate) struct InfernoFlamegraphGenerator { } impl FlamegraphGenerator for InfernoFlamegraphGenerator { - fn generate_flamegraph<'files>( + fn generate_flamegraph<'files, S: Sample>( &self, - samples: Vec, + samples: Vec, debug_symbols: &DebugInfo, + forced_brillig: bool, files: &'files impl Files<'files, FileId = fm::FileId>, artifact_name: &str, function_name: &str, @@ -77,8 +131,8 @@ impl FlamegraphGenerator for InfernoFlamegraphGenerator { } } -fn generate_folded_sorted_lines<'files>( - samples: Vec, +fn generate_folded_sorted_lines<'files, S: Sample>( + samples: Vec, debug_symbols: &DebugInfo, files: &'files impl Files<'files, FileId = fm::FileId>, ) -> Vec { @@ -88,15 +142,15 @@ fn generate_folded_sorted_lines<'files>( let mut resolution_cache: HashMap> = HashMap::default(); for sample in samples { - let mut location_names = Vec::with_capacity(sample.call_stack.len()); - for opcode_location in sample.call_stack { + let mut location_names = Vec::with_capacity(sample.call_stack().len()); + for opcode_location in sample.call_stack() { let callsite_labels = resolution_cache - .entry(opcode_location) + .entry(*opcode_location) .or_insert_with(|| { find_callsite_labels( debug_symbols, - &opcode_location, - sample.brillig_function_id, + opcode_location, + sample.brillig_function_id(), files, ) }) @@ -105,11 +159,14 @@ fn generate_folded_sorted_lines<'files>( location_names.extend(callsite_labels); } - if let Some(opcode) = sample.opcode { + // We move `sample` by calling `sample.opcode()` so we want to fetch the sample count here. + let count = sample.count(); + + if let Some(opcode) = sample.opcode() { location_names.push(opcode); } - add_locations_to_folded_stack_items(&mut folded_stack_items, location_names, sample.count); + add_locations_to_folded_stack_items(&mut folded_stack_items, location_names, count); } to_folded_sorted_lines(&folded_stack_items, Default::default()) @@ -247,7 +304,7 @@ mod tests { use noirc_errors::{debug_info::DebugInfo, Location, Span}; use std::{collections::BTreeMap, path::Path}; - use crate::{flamegraph::Sample, opcode_formatter::format_acir_opcode}; + use crate::{flamegraph::CompilationSample, opcode_formatter::format_acir_opcode}; use super::generate_folded_sorted_lines; @@ -334,8 +391,8 @@ mod tests { BTreeMap::default(), ); - let samples: Vec = vec![ - Sample { + let samples: Vec = vec![ + CompilationSample { opcode: Some(format_acir_opcode(&AcirOpcode::AssertZero::( Expression::default(), ))), @@ -343,7 +400,7 @@ mod tests { count: 10, brillig_function_id: None, }, - Sample { + CompilationSample { opcode: Some(format_acir_opcode(&AcirOpcode::AssertZero::( Expression::default(), ))), @@ -351,7 +408,7 @@ mod tests { count: 20, brillig_function_id: None, }, - Sample { + CompilationSample { opcode: Some(format_acir_opcode(&AcirOpcode::MemoryInit:: { block_id: BlockId(0), init: vec![], From e7231ef9f6f7a74633041f5913acd0af274218be Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Sun, 17 Nov 2024 14:51:31 +0000 Subject: [PATCH 04/10] fmt --- tooling/profiler/src/cli/gates_flamegraph_cmd.rs | 2 -- tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs | 3 --- tooling/profiler/src/flamegraph.rs | 1 - 3 files changed, 6 deletions(-) diff --git a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs index d6ae3400a91..bcccc6f8d5d 100644 --- a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -86,8 +86,6 @@ fn run_with_provider( .map(|(index, (gates, opcode))| CompilationSample { opcode: Some(format_acir_opcode(&opcode)), call_stack: vec![OpcodeLocation::Acir(index)], - // call_stack_index: 0, - // count: Some(gates), count: gates, brillig_function_id: None, }) diff --git a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs index 301d928215c..d8f40253d78 100644 --- a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs @@ -62,7 +62,6 @@ fn run_with_generator( .map(|(index, opcode)| CompilationSample { opcode: Some(format_acir_opcode(opcode)), call_stack: vec![OpcodeLocation::Acir(index)], - // call_stack_index: 0, count: 1, brillig_function_id: None, }) @@ -104,8 +103,6 @@ fn run_with_generator( acir_index: acir_opcode_index, brillig_index, }], - // call_stack_index: 0, - // count: None, count: 1, brillig_function_id: Some(BrilligFunctionId(brillig_fn_index as u32)), }) diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index 20d477709c8..f9ed8169613 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -26,7 +26,6 @@ pub(crate) trait Sample { pub(crate) struct CompilationSample { pub(crate) opcode: Option, pub(crate) call_stack: Vec, - // pub(crate) call_stack_index: u32, pub(crate) count: usize, pub(crate) brillig_function_id: Option, } From 1a0d9dc5b426493990c765a8d76f834547cf0fa0 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Sun, 17 Nov 2024 14:54:06 +0000 Subject: [PATCH 05/10] cleanup --- tooling/nargo/src/ops/execute.rs | 2 -- tooling/profiler/src/cli/execution_flamegraph_cmd.rs | 6 +----- tooling/profiler/src/cli/gates_flamegraph_cmd.rs | 2 -- tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs | 3 --- tooling/profiler/src/flamegraph.rs | 2 -- 5 files changed, 1 insertion(+), 14 deletions(-) diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index fa197c1ad81..0ffa3459bd9 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -230,8 +230,6 @@ pub fn execute_program_with_profiling< foreign_call_executor: &mut E, ) -> Result<(WitnessStack, ProfilingSamples), NargoError> { let profiling_active = true; - let prof_sample_size = std::mem::size_of::(); - println!("prof sample size: {}", prof_sample_size); execute_program_inner( program, initial_witness, diff --git a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs index c2d5ffda580..e9df2326160 100644 --- a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs @@ -3,11 +3,8 @@ use std::path::{Path, PathBuf}; use acir::circuit::OpcodeLocation; use clap::Args; use color_eyre::eyre::{self, Context}; -use fxhash::FxHashMap as HashMap; -use crate::flamegraph::{ - BrilligExecutionSample, CompilationSample, FlamegraphGenerator, InfernoFlamegraphGenerator, -}; +use crate::flamegraph::{BrilligExecutionSample, FlamegraphGenerator, InfernoFlamegraphGenerator}; use crate::fs::{read_inputs_from_file, read_program_from_file}; use crate::opcode_formatter::format_brillig_opcode; use bn254_blackbox_solver::Bn254BlackBoxSolver; @@ -90,7 +87,6 @@ fn run_with_generator( flamegraph_generator.generate_flamegraph( profiling_samples, &debug_artifact.debug_symbols[0], - true, &debug_artifact, artifact_path.to_str().unwrap(), "main", diff --git a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs index bcccc6f8d5d..886dfc65892 100644 --- a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -94,7 +94,6 @@ fn run_with_provider( flamegraph_generator.generate_flamegraph( samples, &debug_artifact.debug_symbols[func_idx], - false, &debug_artifact, artifact_path.to_str().unwrap(), &func_name, @@ -148,7 +147,6 @@ mod tests { &self, _samples: Vec, _debug_symbols: &DebugInfo, - _forced_brillig: bool, _files: &'files impl Files<'files, FileId = fm::FileId>, _artifact_name: &str, _function_name: &str, diff --git a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs index d8f40253d78..4e271c9f838 100644 --- a/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs @@ -70,7 +70,6 @@ fn run_with_generator( flamegraph_generator.generate_flamegraph( samples, &debug_artifact.debug_symbols[func_idx], - false, &debug_artifact, artifact_path.to_str().unwrap(), &func_name, @@ -111,7 +110,6 @@ fn run_with_generator( flamegraph_generator.generate_flamegraph( samples, &debug_artifact.debug_symbols[acir_fn_index], - false, &debug_artifact, artifact_path.to_str().unwrap(), &format!("brillig_{}", brillig_fn_index), @@ -166,7 +164,6 @@ mod tests { &self, _samples: Vec, _debug_symbols: &DebugInfo, - _forced_brillig: bool, _files: &'files impl Files<'files, FileId = fm::FileId>, _artifact_name: &str, _function_name: &str, diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index f9ed8169613..cc62903781a 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -83,7 +83,6 @@ pub(crate) trait FlamegraphGenerator { &self, samples: Vec, debug_symbols: &DebugInfo, - forced_brillig: bool, files: &'files impl Files<'files, FileId = fm::FileId>, artifact_name: &str, function_name: &str, @@ -100,7 +99,6 @@ impl FlamegraphGenerator for InfernoFlamegraphGenerator { &self, samples: Vec, debug_symbols: &DebugInfo, - forced_brillig: bool, files: &'files impl Files<'files, FileId = fm::FileId>, artifact_name: &str, function_name: &str, From 2108d7358ccd8ae3ea8226530bbab80b8c74846d Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Sun, 17 Nov 2024 15:29:16 +0000 Subject: [PATCH 06/10] bring back brillig function id --- tooling/nargo/src/ops/execute.rs | 3 +-- tooling/profiler/src/cli/execution_flamegraph_cmd.rs | 8 +++++++- tooling/profiler/src/flamegraph.rs | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index 0ffa3459bd9..09ef554d2aa 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -4,8 +4,7 @@ use acvm::acir::circuit::{ }; use acvm::acir::native_types::WitnessStack; use acvm::pwg::{ - ACVMStatus, ErrorLocation, OpcodeNotSolvable, OpcodeResolutionError, ProfilingSample, - ProfilingSamples, ACVM, + ACVMStatus, ErrorLocation, OpcodeNotSolvable, OpcodeResolutionError, ProfilingSamples, ACVM, }; use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap}; use acvm::{AcirField, BlackBoxFunctionSolver}; diff --git a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs index e9df2326160..cf9a2fcc207 100644 --- a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs @@ -45,6 +45,12 @@ fn run_with_generator( let program = read_program_from_file(artifact_path).context("Error reading program from file")?; + assert_eq!( + program.bytecode.unconstrained_functions.len(), + 1, + "This command should only be run with a program force compiled to Brillig" + ); + let (inputs_map, _) = read_inputs_from_file(prover_toml_path, Format::Toml, &program.abi)?; let initial_witness = program.abi.encode(&inputs_map, None)?; @@ -76,7 +82,7 @@ fn run_with_generator( } }) .map(format_brillig_opcode); - BrilligExecutionSample { opcode, call_stack } + BrilligExecutionSample { opcode, call_stack, brillig_function_id } }) .collect(); diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index cc62903781a..df45a0174d4 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -51,6 +51,7 @@ impl Sample for CompilationSample { pub(crate) struct BrilligExecutionSample { pub(crate) opcode: Option, pub(crate) call_stack: Vec, + pub(crate) brillig_function_id: Option, } impl Sample for BrilligExecutionSample { @@ -59,7 +60,8 @@ impl Sample for BrilligExecutionSample { } fn brillig_function_id(&self) -> Option { - Some(BrilligFunctionId(0)) + // Some(BrilligFunctionId(0)) + self.brillig_function_id } fn call_stack(&self) -> &[OpcodeLocation] { From 8265cfe82bc47192cf4d5ce2ca73769d211aad2e Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Sun, 17 Nov 2024 15:30:02 +0000 Subject: [PATCH 07/10] cleanup --- tooling/profiler/src/cli/execution_flamegraph_cmd.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs index cf9a2fcc207..981d08a3eb1 100644 --- a/tooling/profiler/src/cli/execution_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/execution_flamegraph_cmd.rs @@ -45,12 +45,6 @@ fn run_with_generator( let program = read_program_from_file(artifact_path).context("Error reading program from file")?; - assert_eq!( - program.bytecode.unconstrained_functions.len(), - 1, - "This command should only be run with a program force compiled to Brillig" - ); - let (inputs_map, _) = read_inputs_from_file(prover_toml_path, Format::Toml, &program.abi)?; let initial_witness = program.abi.encode(&inputs_map, None)?; From 5b231a63f3c57025af030357292ddf26b1de106d Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Sun, 17 Nov 2024 15:48:02 +0000 Subject: [PATCH 08/10] clippy test --- tooling/profiler/src/cli/gates_flamegraph_cmd.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs index 886dfc65892..c3ae29de058 100644 --- a/tooling/profiler/src/cli/gates_flamegraph_cmd.rs +++ b/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -106,10 +106,7 @@ fn run_with_provider( #[cfg(test)] mod tests { - use acir::{ - circuit::{Circuit, Program}, - AcirField, - }; + use acir::circuit::{Circuit, Program}; use color_eyre::eyre::{self}; use fm::codespan_files::Files; use noirc_artifacts::program::ProgramArtifact; @@ -120,7 +117,7 @@ mod tests { }; use crate::{ - flamegraph::{CompilationSample, Sample}, + flamegraph::Sample, gates_provider::{BackendGatesReport, BackendGatesResponse, GatesProvider}, }; From 3dd15ce1d479e4ac0372e5189249dac03a7e739c Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Mon, 18 Nov 2024 06:51:00 -0500 Subject: [PATCH 09/10] Update tooling/profiler/src/flamegraph.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/profiler/src/flamegraph.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index df45a0174d4..ba82f289c54 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -135,7 +135,6 @@ fn generate_folded_sorted_lines<'files, S: Sample>( debug_symbols: &DebugInfo, files: &'files impl Files<'files, FileId = fm::FileId>, ) -> Vec { - println!("About to generate sorted lines"); // Create a nested hashmap with the stack items, folding the gates for all the callsites that are equal let mut folded_stack_items = BTreeMap::new(); From 179a4f0a9724ccfe80ea94c195a5bba8ec049f0c Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Mon, 18 Nov 2024 08:36:36 -0500 Subject: [PATCH 10/10] Update tooling/profiler/src/flamegraph.rs --- tooling/profiler/src/flamegraph.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tooling/profiler/src/flamegraph.rs b/tooling/profiler/src/flamegraph.rs index ba82f289c54..38966902314 100644 --- a/tooling/profiler/src/flamegraph.rs +++ b/tooling/profiler/src/flamegraph.rs @@ -60,7 +60,6 @@ impl Sample for BrilligExecutionSample { } fn brillig_function_id(&self) -> Option { - // Some(BrilligFunctionId(0)) self.brillig_function_id }