Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile identities #1473

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Profile identities #1473

wants to merge 3 commits into from

Conversation

chriseth
Copy link
Member

No description provided.

/// The event log is a list of (event, <ID>, time) tuples.
static EVENT_LOG: RefCell<Vec<(Event, usize, Instant)>> = const { RefCell::new(Vec::new()) };
/// The event log is a list of events.
static EVENT_LOG: RefCell<Vec<Event>> = const { RefCell::new(Vec::new()) };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we rename this to EVENT_LOG_BY_MACHINE?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, same goes for a few names in this file that are specific to the by-machine profiling, like NAME_TO_ID, record_start, record_end, reset_and_print_profile_summary, ...


use crate::witgen::FixedData;

pub static UNUSED_IDENTITY_ID: u64 = u64::MAX;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub static UNUSED_IDENTITY_ID: u64 = u64::MAX;
pub static NO_IDENTITY_ID: u64 = u64::MAX;

Maybe this?

Comment on lines +245 to +251
let updates = match updates {
Ok(updates) => updates,
Err(e) => {
record_end_identity(identity.id);
return Err(e);
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should we wrap this function instead? I can imagining somebody to put a question mark in the future and then the log is inconsistent.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nooo ^^

I debugged the error I mentioned in the other comment, and it's actually not because of that but because there is an record_end_identity(identity.id); missing before the return in 256...

Comment on lines +357 to +362
record_start_identity(profiling::PROCESS_PROVER_QUERIES_ID);
progress |= self.processor.process_queries(row_index).map_err(|e| {
record_end_identity(profiling::PROCESS_PROVER_QUERIES_ID);
vec![e]
})?;
record_end_identity(profiling::PROCESS_PROVER_QUERIES_ID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inside the Processor, no? It is also used by block machines, so then we wouldn't measure it here?

Comment on lines +160 to +162
record_end_identity(profiling::UNUSED_IDENTITY_ID);
profiling::reset_and_print_profile_summary_identity(self.fixed_data);
record_start_identity(profiling::UNUSED_IDENTITY_ID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this breaks if there is more than one VM:

$ RUST_LOG=debug cargo run pil test_data/asm/vm_to_vm.asm -o output -f

...
[00:00:00 (ETA: 00:00:00)] ████████████████████ 100% - Starting...                                                                                                                Finalizing VM: Main Machine
Transposing 256 rows with 19 columns...
Finalizing remaining rows...
Needed to finalize 256 / 256 rows.
Done transposing.
Finalizing VM: Secondary machine 0: main_vm (Vm)
Found loop with period 1 starting at row 100

 == Identities processing profile (7464 events)
thread 'main' panicked at executor/src/witgen/machines/profiling.rs:158:17:
Unexpected recursive call!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, would you think it's a good fix to add a boolean flag to just output the partial profile summary (and then temporarily closing all open calls) and do not reset?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the error was something else: https://github.com/powdr-labs/powdr/pull/1473/files#r1657169269

I still think it's a bit confusing, and at least we should add a debug log here which machine reached the loop and that all future profiling logs will not include any events before this point. As far as I understand, what happens now in vm_to_vm.asm is:

  1. Profiling starts
  2. Main machine reaches the loop -> profiling printed & reseted
  3. Generator::run() finishes the loop and returns
  4. We call take_witness_col_values on the secondary machines, which includes the secondary VM. This invokes the VM processor and immediately finds a loop -> profiling printed & reseted
  5. Then, we call reset_and_print_profile_summary_identity in WitnessGenerator::generate()

Not sure this is what we want! I think it would be cleanest to get 3 profiles:

  1. Main machine reaches the loop
  2. Generator::run() returns
  3. All the take_witness_col_values have completed (this is probably the least important)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants