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

make the RISCV executor look at the optimized PIL for link information #2232

Merged
merged 39 commits into from
Dec 17, 2024

Conversation

pacheco
Copy link
Collaborator

@pacheco pacheco commented Dec 13, 2024

This PR modifies the RISCV executor to look into the optimized PIL for lookup/permutation definitions.
In particular, to figure out which selectors are assigned for each link, but also with the intent of later integration with witgen (which needs the identity ids for "submachine calls")

@pacheco pacheco marked this pull request as ready for review December 16, 2024 16:19
@pacheco pacheco changed the title (WIP) make the RISCV executor look at the optimized PIL for link information make the RISCV executor look at the optimized PIL for link information Dec 16, 2024
let end = s.find(']').unwrap();
s[start..end].parse::<u8>().unwrap()
})
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

This seems kinda costly if it has to run every time? Wouldn't it be better to have a map in the caller and just pass the number like before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, this is ugly, i'm working on a separate PR for these details/performance (this here should be cached)

@@ -4,17 +4,20 @@ use powdr_number::{FieldElement, LargeInt};

use std::collections::HashMap;

fn only_column_name(name: &str) -> &str {
name.rfind("::").map(|i| &name[i + 2..]).unwrap_or(name)
Copy link
Member

Choose a reason for hiding this comment

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

maybe leave a comment on why i + 2?

/// Which of the witness columns are selectors, if any
const SELECTORS: &'static str;
/// Row block size
const BLOCK_SIZE: u32;
/// Add an operation to the submachine trace
fn add_operation<F: FieldElement>(
trace: &mut SubmachineTrace<F>,
// pil lookup RHS values (including selector idx, if present)
selector_idx: Option<u8>,
selector: Option<&str>,
Copy link
Member

Choose a reason for hiding this comment

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

same question here re number vs string, string sounds costly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here the string is actually better, we just use the string as a key (before we had to actually construct the string here)

pub fn links_from_pil<F: FieldElement>(pil: &Analyzed<F>) -> Vec<Identity<F>> {
pil.identities
.iter()
.filter(|id| matches!(id, Identity::Permutation(_) | Identity::Lookup(_)))
Copy link
Member

Choose a reason for hiding this comment

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

I guess later we'll also need to support the Phantom versions, and/or bus sends/receives. It might actually be simpler at that point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I didn't really look into it here, but should not be to bad I imagine

}
}
}
panic!("identity {id} doesnt exist")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
panic!("identity {id} doesnt exist")
panic!("identity {id} doesn't exist")

}
if let Identity::Lookup(lookup) = l {
if lookup.id == id {
return None;
Copy link
Member

Choose a reason for hiding this comment

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

Why do lookups return None?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only Permutations have a selector

// main_keccakf,
// main_arith,
/// Enum with asm machine RISCV instruction. Helps avoid using raw strings in the code.
macro_rules! instructions {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we somehow get the same info from the asm file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it won't be an enum then...

Copy link
Member

Choose a reason for hiding this comment

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

ok

loop {
let stm = statements[curr_pc as usize];

log::trace!("l {curr_pc}: {stm}",);

e.step += 4;

count += 1;
if count % 10000 == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make this number larger otherwise it might be too many messages for large programs. Maybe 100k?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the message is printed every second, this is just how frequently we sample the clock

Copy link
Member

Choose a reason for hiding this comment

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

ah ok

columns should still be present but empty
.par_bridge()
.flat_map(|(m, mut machine, ops)| {
// apply the operation to the submachine
println!("machine: {:?}", m.name());
Copy link
Member

Choose a reason for hiding this comment

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

leftover

@leonardoalt leonardoalt added this pull request to the merge queue Dec 17, 2024
Merged via the queue into main with commit e32108d Dec 17, 2024
16 checks passed
@leonardoalt leonardoalt deleted the executor-use-pil branch December 17, 2024 09:17
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.

2 participants