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

Express transition constraints as circuits and autogenerate code for its evaluation #117

Merged
merged 26 commits into from
Nov 15, 2022

Conversation

Sword-Smith
Copy link
Collaborator

@Sword-Smith Sword-Smith commented Nov 11, 2022

This commit addresses two optimizations:

  • Avoid repeated transposing codewords in inner loop
  • Avoid unnecessary vector allocation in inner loop
  • Autogenerate code to evaluate transition constraints

Before this change, we transpose each table once for each inverse zerofier for each type of quotient, which is FRI domain length times. By injecting the transposed extension table, this transposition is hoisted out of those loops.

After this change, two cleanup tasks are left:

  • Change Evaluable::evaluate_transition_constraints to not rely on *_inner.
  • Change ExtHashTable::evaluate_transition_constraints to not allocate evaluation_point.

This speeds up the evaluation of the transition quotient for the processor table by x2000. On my Dell XPS machine, the evaluation took 32 seconds before these changes, and 15ms after.

Also: The tests took 270 seconds to run on my fast P17 machine prior to this PR. With this PR it takes ~50 seconds. Maybe we can enable some of the tests that were disabled because they were too slow?

To run the compiler for autogenerating the fast code:
OUTPUT_RUST_SOURCE_CODE=1 cargo run --bin constraint-evaluation-generator

Co-authored-by: Simon Shine simon@neptune.cash

@Sword-Smith Sword-Smith added ✨ enhancement Improvement or new feature 🤖 code Changes the implementation labels Nov 11, 2022
@jan-ferdinand
Copy link
Member

Relates to #11

triton-vm/src/table/extension_table.rs Outdated Show resolved Hide resolved
triton-vm/src/table/table_collection.rs Outdated Show resolved Hide resolved
triton-vm/src/vm.rs Show resolved Hide resolved
@Sword-Smith Sword-Smith force-pushed the thv-ssh/generate-transition-codeword-evaluation-code branch from 401bb84 to 2ed22ef Compare November 11, 2022 18:41
@jan-ferdinand jan-ferdinand linked an issue Nov 11, 2022 that may be closed by this pull request
9 tasks
@jan-ferdinand jan-ferdinand force-pushed the master branch 2 times, most recently from 7334757 to bd2cf06 Compare November 11, 2022 18:56
@Sword-Smith Sword-Smith force-pushed the thv-ssh/generate-transition-codeword-evaluation-code branch from b7c5baa to 08757bf Compare November 12, 2022 14:31
Comment on lines +348 to +350
if let Some(p) = maybe_profiler.as_mut() {
p.start("initial quotients")
}
Copy link
Member

Choose a reason for hiding this comment

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

I recommend using the macros prof_start and prof_stop. Example use can be seen here.

Sword-Smith and others added 16 commits November 14, 2022 12:53
This commit addresses two optimizations:

- Avoid repeated transposing codewords in inner loop
- Avoid unnecessary vector allocation in inner loop

Before this change, we transpose each table once for each inverse
zerofier for each type of quotient, which is FRI domain length times. By
injecting the transposed extension table, this transposition is hoisted
out of those loops.

After this change, two cleanup tasks are left:

- Change `Evaluable::evaluate_transition_constraints` to not rely on `*_inner`.
- Change `ExtHashTable::evaluate_transition_constraints` to not allocate `evaluation_point`.

Co-authored-by: Simon Shine <simon@neptune.cash>
Co-authored-by: Simon Shine <simon@neptune.cash>
- Generalize to work for all tables (except hash table)
- Fix how challenges are read, from index to struct fields
- Add inline pragma to generated code
- Fix minor syntax bugs
…y-first

The dependency `twenty-first` get's support for adding, subtracting, and
multiplying X field elements with B field elements. This is done to
speed up the evaluation of auto-generated code. Mutliplying a B field
element with an X field element costs 3 B field multiplications, for two X
field elements, it costs 9 B field multiplications.
Prior to this commit, this test used to different sets of challenges for
constructing the extension constraints and then later in their
evaluation. Since this argument was until now not used in the evaluation
(since the challenges were contained in the multivariate polynomials
describing the constraints), this problem did not surface. But now that
we're autogenerating code to evalaute the constraint polynomials, this
problem surfaced and it just cost me almost half a day's work.
With auto-generated code these names need to be consistent. This commit
removes an 'S' from some of their enum names.
With this draft, the tests should work without the autogenerated code.
They'll just be a lot slower.

The compiler for evaluating the constraints will overwrite the content
in the `autogen` files when it is run.
Record the time it takes to calculate each quotient: initial,
consistency, transition, and terminal.
This is necessary for being able to arbitrarily add, subtract and
multiply XFieldElements with BFieldElements.
This ensures that the constraint code generator works for all tables.
…onstraints

This commit allows single row constraints to be expressed as a circuit
and to work with the compiler for auto-generating efficient constraint
evaluating Rust code.

This is achieved by changing the input type from holding a `usize` to
holding a `InputIndicator` type that can hold either single row and dual
row constraints. In the generated code the variable name of an input
type is assumed to be the same as the `Display` implementation of the
`InputIndicator` types.
@Sword-Smith Sword-Smith force-pushed the thv-ssh/generate-transition-codeword-evaluation-code branch from 2a44cb0 to 4dc3ca4 Compare November 14, 2022 12:05
@Sword-Smith Sword-Smith changed the title Change *_quotients() to accept transposed extension table data Express transition constraints as circuits and autogenerate code for its evaluation Nov 14, 2022
sshine and others added 4 commits November 14, 2022 13:40
Co-authored-by: sword-smith <thor@neptune.cash>
- inline `evaluate_transition_constraints_inner` again
- Give up removing `evaluation_point` since `.evaluate()`
  depends on a slice.
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
triton-vm/src/table/constraint_circuit.rs Show resolved Hide resolved
triton-vm/src/table/extension_table.rs Outdated Show resolved Hide resolved
triton-vm/src/table/hash_table.rs Outdated Show resolved Hide resolved
constraint-evaluation-generator/README.md Show resolved Hide resolved
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
triton-vm/src/stark.rs Outdated Show resolved Hide resolved
constraint-evaluation-generator/src/main.rs Outdated Show resolved Hide resolved
constraint-evaluation-generator/src/main.rs Outdated Show resolved Hide resolved
constraint-evaluation-generator/src/main.rs Outdated Show resolved Hide resolved
constraint-evaluation-generator/src/main.rs Outdated Show resolved Hide resolved
constraint-evaluation-generator/src/main.rs Show resolved Hide resolved
Sword-Smith and others added 6 commits November 15, 2022 11:16
With this commit only visited counters that are present in the multitree
are checked for declarations in the compiler. This speeds up the
compiler by about a factor 60.
These are the cases that stand out syntactically.

RamTable: Name intermediate steps in extend().
- Refactor main().
- Add explanations to `InputIndicator` etc.
This gives access to transpose()
@sshine sshine dismissed jan-ferdinand’s stale review November 15, 2022 14:59

Changes were made, thank you.

@sshine sshine merged commit cd62c59 into master Nov 15, 2022
@jan-ferdinand jan-ferdinand deleted the thv-ssh/generate-transition-codeword-evaluation-code branch November 15, 2022 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 code Changes the implementation ✨ enhancement Improvement or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use arithmetic circuits to their full potential
3 participants