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

Enable Bus in tests #2289

Merged
merged 11 commits into from
Dec 30, 2024
Merged

Enable Bus in tests #2289

merged 11 commits into from
Dec 30, 2024

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Dec 30, 2024

This PR uses LinkerMode::Bus in all tests which:

  • Are on Goldilocks or BN254 (the bus is not implemented for smaller fields), AND
  • Are tested with the mock prover or Plonky3 (while Halo2 does support the bus in principle, its runtime is exponential, because it inlines intermediate polynomials)

This is true for most tests.

Doing so, I came across a few bugs. I added comments for them below.

@@ -22,7 +22,8 @@ fn slice_to_vec<T: FieldElement>(arr: &[i32]) -> Vec<T> {
fn sqrt_asm() {
let f = "asm/sqrt.asm";
let i = [3];
let pipeline: Pipeline<GoldilocksField> = make_prepared_pipeline(f, slice_to_vec(&i), vec![]);
let pipeline: Pipeline<GoldilocksField> =
make_prepared_pipeline(f, slice_to_vec(&i), vec![], LinkerMode::Bus);
Copy link
Member

Choose a reason for hiding this comment

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

So these are only testing with bus mode?

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, I think it should be the default now, whenever possible.

@@ -110,7 +111,8 @@ fn fibonacci() {
fn fibonacci_with_public() {
// Public references are not supported by the backends yet, but we can test witness generation.
let f = "pil/fibonacci_with_public.pil";
let mut pipeline: Pipeline<GoldilocksField> = make_prepared_pipeline(f, vec![], vec![]);
let mut pipeline: Pipeline<GoldilocksField> =
make_prepared_pipeline(f, vec![], vec![], LinkerMode::Bus);
Copy link
Member

Choose a reason for hiding this comment

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

Why only bus?

..
}) => self.process_call(can_process, *id, multiplicity, &tuple.0, row_offset),
// TODO(bus_interaction)
Identity::PhantomBusInteraction(_) => ProcessResult::empty(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bug: Witgen filters out Bus interactions, so processing a call here leads to witgen not being able to find the called machine by the identity ID. This is also not trivial, because we'd probably want to use the receiving bus interaction.

Right now, all bus interactions also come with a phantom lookup / permutation, so they can safely be ignored. // TODO(bus_interaction) mark the places that need to be adjusted once this is removed as part of #2184.

@@ -445,7 +445,7 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {

let updates = updates.report_side_effect();

let global_latch_row_index = self.data.len() - 1 - self.block_size + self.latch_row;
let global_latch_row_index = self.data.len() - self.block_size + self.latch_row;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bug: This -1 is just wrong.

let latch_row = self.data.len() - 1;
// The block we just added contains the first row of the next block,
// so the latch row is the second-to-last row.
let latch_row = self.data.len() - 2;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bug: See comment.

refs.path = SymbolPath::from_parts(
once(Part::Named(namespace.clone())).chain(refs.path.clone().into_parts()),
);
if !refs.path.is_std() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bug: We used to namespace std namespaces as well. So, if there was a lookup from main into main_sub, using something in std::* in its expressions, it would turn into main::std::*.

test_mock_backend(pipeline_gl_native.clone());
run_pilcom_with_backend_variant(pipeline_gl_native, BackendVariant::Composite).unwrap();

let pipeline_gl_bus =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that this means we now run steps such as constant generation, witgen, etc twice, once for each linker mode.

@@ -127,6 +129,8 @@ fn empty() {
}

#[test]
// TODO: https://github.com/powdr-labs/powdr/issues/2292
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this is really worth fixing, see my comment in #2292. But in principle, we could track which namespace identities are generated in.

Comment on lines +18 to +19
col witness w;
w = w * w;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Somehow, without this, the columns generated by the bus interaction end up in the std::well_known namespace, which doesn't have a degree... I thought it's not worth fixing it, because a machine without a column is very unrealistic.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 737bd78 Previous: 2ad6c4f Ratio
evaluator-benchmark/sqrt_879882356 36805 ns/iter (± 23) 29318 ns/iter (± 28) 1.26
evaluator-benchmark/sqrt_1882356 31520 ns/iter (± 16) 24558 ns/iter (± 16) 1.28
evaluator-benchmark/sqrt_1187956 31052 ns/iter (± 13) 24467 ns/iter (± 27) 1.27
evaluator-benchmark/sqrt_56 22249 ns/iter (± 8) 17424 ns/iter (± 9) 1.28

This comment was automatically generated by workflow using github-action-benchmark.

@georgwiese
Copy link
Collaborator Author

Hmm, I reverted 6b949ad, because I'm getting a panic in the RISC-V executor. Guess that can be done in another PR.

@georgwiese georgwiese marked this pull request as ready for review December 30, 2024 14:23
@@ -263,9 +270,6 @@ fn dynamic_vadcop() {
assert_eq!(witness_by_name["main_arith::y"].len(), 32);
assert_eq!(witness_by_name["main_memory::m_addr"].len(), 32);

// Because machines have different lengths, this can only be proven
// with a composite proof.
run_pilcom_with_backend_variant(pipeline_gl.clone(), BackendVariant::Composite).unwrap();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if it is important to test PILCOM here? If we already have the mock prover? If yes, we'd have to make a new pipeline with LinkerMode::Native (which implies re-computing everything until the witness).

With a bus, PILCOM ends in some infinite loop. See this CI run.

Copy link
Collaborator

@Schaeff Schaeff left a comment

Choose a reason for hiding this comment

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

Looks good to me

@georgwiese georgwiese added this pull request to the merge queue Dec 30, 2024
Merged via the queue into main with commit 816e8c7 Dec 30, 2024
16 checks passed
@georgwiese georgwiese deleted the enable-bus branch December 30, 2024 18:20
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.

3 participants