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

Unify single step and block processor. #2317

Merged
merged 20 commits into from
Jan 10, 2025
Merged

Unify single step and block processor. #2317

merged 20 commits into from
Jan 10, 2025

Conversation

chriseth
Copy link
Member

@chriseth chriseth commented Jan 8, 2025

Extracts the common code in single step processor and block processor into a unified "processor".

@chriseth
Copy link
Member Author

chriseth commented Jan 8, 2025

All tests except two are missing:

The first one is the "not_stackable", which is just not yet implemented.
The second is a test that expects a better error message. I think I will return a structured error instead of a string, so the caller can do the formatting.

@chriseth chriseth marked this pull request as ready for review January 8, 2025 22:43
@@ -77,8 +77,9 @@ pub fn compile_effects<T: FieldElement>(

record_start("JIT-compilation");
let start = std::time::Instant::now();
log::trace!("Calling cargo...");
let r = powdr_jit_compiler::call_cargo(&code);
let opt_level = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So now we can no longer measure the runtime speed of optimized binary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you do that regularly? If you want to, you can change this number here ;)

The thing is that cargo nextest run should just work without the need for a complicated setup where we tune environment variables.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, fine with me now. I think it should be a CLI argument, but we can do that later. In the tests we'll always want to use 0 as long as we don't share compilation between tests.

executor/src/witgen/jit/processor.rs Show resolved Hide resolved
executor/src/witgen/jit/processor.rs Outdated Show resolved Hide resolved
if complete_rows.len() >= self.block_size {
let (min, max) = complete_rows.iter().minmax().into_option().unwrap();
// TODO instead of checking for consequitive rows, we could also check
// that they "fit" the next block.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you saying that there could be gaps? Why? Eventually, we want the machine calls to be handled on all rows of the trace, right? The call being "complete" does not mean that it actually executed, it could be that the selector was 0, in which case it is also considered complete.

Copy link
Member Author

@chriseth chriseth Jan 9, 2025

Choose a reason for hiding this comment

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

But if the selector is zero, it will also be zero in the other, overlapping block. What I'm saying is that we can have

  A
B   B B B   B
          C   C C C   C
                    D   D D D
...

i.e. there is a gap of one that is filled by the previous / next block.

We should verify that with real machines, but I think the number of complete rows should be exactly block_size and row i should be complete if and only if row i + block_size is not complete.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, sure ^^ Seems very esoteric though.

executor/src/witgen/jit/block_machine_processor.rs Outdated Show resolved Hide resolved
executor/src/witgen/jit/block_machine_processor.rs Outdated Show resolved Hide resolved
let block_size = 1;
let witgen = WitgenInference::new(self.fixed_data, NoEval, known_variables);

let max_branch_depth = 6;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, please turn into a constant. Does it need to be a variable to Processor::new? Would we pass a different value in different situations? Otherwise, the constant could be in the processor file.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could pass different values for different machines. For example, a VM could find the pc lookup and use number of instruction variables * 2 or something.

executor/src/witgen/jit/processor.rs Outdated Show resolved Hide resolved

/// After solving, the known cells should be such that we can stack different blocks.
/// TODO the same is actually true for machine calls.
fn check_block_shape(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why put this here, if it is not run when called from the single step processor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the block_machine_processor does not have access to witgen any more

Copy link
Member Author

Choose a reason for hiding this comment

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

Also it needs to be run in each branch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right. But that means that the machine could have a different shape in each branch!

I think the proper way to handle this would be to let the processor do it's thing and then look at the referenced cells of the generated effects.

Copy link
Member Author

Choose a reason for hiding this comment

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

-> #2327

Copy link
Collaborator

@georgwiese georgwiese left a comment

Choose a reason for hiding this comment

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

Cool!

I think that we should pull the stackable check back into the block machine processor. But I think that can be done in a separate PR.

@chriseth chriseth added this pull request to the merge queue Jan 10, 2025
Merged via the queue into main with commit 65a2fdd Jan 10, 2025
16 checks passed
@chriseth chriseth deleted the unified_processor branch January 10, 2025 23:52
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