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

JIT: ignore bus interactions & reduce block machine row range #2322

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

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Jan 9, 2025

I noticed that JITing never succeeds if we run with --linker-mode bus. This PR fixes it, as can be verified by running this with debug log:

$ RUST_LOG=debug cargo run pil test_data/std/binary_large_test.asm -o output -f --linker-mode bus
...
Secondary machine 0: main_binary (BlockMachine): 18 / 18 blocks computed via JIT.
72 of 128 rows are used in machine 'Secondary machine 0: main_binary (BlockMachine)'.

 == Witgen profile (484 events)
   67.2% (    5.6s): JIT-compilation
   19.1% (    1.6s): Secondary machine 0: main_binary (BlockMachine)
   11.2% ( 944.5ms): FixedLookup
    1.5% ( 124.4ms): multiplicity witgen
    0.8% (  69.3ms): witgen (outer code)
    0.1% (  10.4ms): Main machine (Dynamic)
  ---------------------------
    ==> Total: 8.397369458s

Doing so, I came across an issue cause by the block machine processor processing rows -1..(self.block_size + 1): It can actually write to the first row of the next block, in which case we panic, because we don't have that row yet. It would also be pretty annoying to need to support that and not needed in practice. But it turns out, this row range was actually more generous that what we use in the run-time solver, see this line! So I'm reducing it in this PR.

@georgwiese georgwiese marked this pull request as ready for review January 9, 2025 23:14
@georgwiese georgwiese mentioned this pull request Jan 9, 2025
@georgwiese georgwiese marked this pull request as draft January 10, 2025 00:29
@georgwiese
Copy link
Collaborator Author

Failing, one test, to reproduce: RUST_LOG=debug cargo run pil test_data/asm/permutations/call_selectors_with_no_permutation.asm -o output -f --linker-mode bus

Issue is that it solves for the multiplicity column in the next block, but writing to the next block is not currently supported...

github-merge-queue bot pushed a commit that referenced this pull request Jan 10, 2025
Cleans up the log a little bit, moving some logs to trace level.
Especially related to JIT, which fails quite frequently still.

For example, this exposes the issue fixed by #2322:
```
$ RUST_LOG=debug cargo run pil test_data/std/binary_large_test.asm -o output -f --linker-mode bus
...
[00:00:00 (ETA: 00:00:00)] ░░░░░░░░░░░░░░░░░░░░ 0% - Starting...                                                                                                                           Compiling JIT function for 
  Machine: Secondary machine 0: main_binary (BlockMachine)
  Identity: main::instr_and $ [0, main::X0, main::X1, main::X2] is main_binary::latch * main_binary::sel[0] $ [main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C]
   Known args: 1110
=> Error generating JIT code: Code generation failed: Incomplete machine calls:
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row -1)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 0)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 1)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 2)
...
Compiling JIT function for 
  Machine: Secondary machine 0: main_binary (BlockMachine)
  Identity: main::instr_or $ [1, main::X0, main::X1, main::X2] is main_binary::latch * main_binary::sel[1] $ [main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C]
   Known args: 1110
=> Error generating JIT code: Code generation failed: Incomplete machine calls:
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row -1)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 0)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 1)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 2)
...
Compiling JIT function for 
  Machine: Secondary machine 0: main_binary (BlockMachine)
  Identity: main::instr_xor $ [2, main::X0, main::X1, main::X2] is main_binary::latch * main_binary::sel[2] $ [main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C]
   Known args: 1110
=> Error generating JIT code: Code generation failed: Incomplete machine calls:
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row -1)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 0)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 1)
  Constr::PhantomBusInteraction(18446744069414584320 * (main_binary::latch * main_binary::sel[0]), [1, main_binary::operation_id, main_binary::A, main_binary::B, main_binary::C], main_binary::latch); (row 2)
...
Found loop with period 1 starting at row 100
101 of 128 rows are used in machine 'Main machine (Dynamic)'.
Looping failed. Trying to generate regularly again. (Use RUST_LOG=debug to see whether this happens more often.) 128 / 129
[00:00:00 (ETA: 00:00:00)] ████████████████████ 100% - Starting...                                                                                                                         Finalizing VM: Main machine (Dynamic)
Secondary machine 0: main_binary (BlockMachine): 0 / 18 blocks computed via JIT.
72 of 128 rows are used in machine 'Secondary machine 0: main_binary (BlockMachine)'.

 == Witgen profile (570 events)
   45.5% ( 975.3ms): Secondary machine 0: main_binary (BlockMachine)
   44.6% ( 956.3ms): FixedLookup
    6.1% ( 131.3ms): multiplicity witgen
    3.5% (  75.7ms): witgen (outer code)
    0.2% (   4.2ms): Main machine (Dynamic)
  ---------------------------
    ==> Total: 2.142724334s
```

---------

Co-authored-by: chriseth <[email protected]>
@georgwiese georgwiese changed the title JIT: ignore bus interactions JIT: ignore bus interactions & reduce block machine row range Jan 10, 2025
@georgwiese georgwiese marked this pull request as ready for review January 10, 2025 18:30
@chriseth
Copy link
Member

What was the value it tried to write to the next row?

@georgwiese
Copy link
Collaborator Author

The multiplicity. There was a constraint like (1 - LATCH) * multiplicity = 0, and it figured out that it can set the multiplicity to 0 in all rows but the latch row.

@georgwiese georgwiese force-pushed the jit-ignore-bus-interactions branch from 63d68f7 to cb11fb6 Compare January 11, 2025 00:29
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