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

WASI-20. Low memory prover (512k possible). Native pthread support (15s wasm time). #434

Merged
merged 111 commits into from
Jun 8, 2023

Conversation

charlielye
Copy link
Contributor

@charlielye charlielye commented May 6, 2023

barretenberg

Wins:

  • Move to WASI 20.
  • Latest clang etc.
  • Proper static initialisation of globals.
  • Can remove OpenMP (for now can switch to new threading with -DOMP_MULTITHREADING=OFF).
  • Can remove asyncify (conditional variables + threads as alternative).
  • Less memory usage and copying memory.
  • Much faster performance, granular threading, (AC was very coarse).
  • Same threading model as native code.
  • Could get rid of worker queue (but don't yet, just disabled cbinds).
  • Get rid of host environment threading (PooledPippenger PooledFft) in ts code.
  • Unified bb.js browser/node code with very simple abstraction layer to deal with differences.
  • Same simple.rawtest.ts works in node and when compiled to browser via webpack.
  • No more node polyfills in bb.js.

How:

  • wasi "_initialize" solves re-entry crash, enables move to wasi 20.
  • wasi-libc bleeding edge fork for increased (not perfect) join stability.
  • parallel_for replaces OpenMP. (several versions, using "parallel_for_mutex_pool" to avoid stability bug).
  • SlabAllocator enables 512k gates within 4GB.
  • Beyond that, PolynomialStoreCache and host engine swapping (unused currently as it's kinda janky TBH).
  • Polynomial coeffs in shared_ptr + SlabAllocator.

bb.js

We are moving towards standalone prover/verifier binaries to be maintained by bb team(s), and to be consumed by noir team(s) (and whoever else).
This is the first implementation of such a prover/verifier.

Wins:

  • Completely architecture/os agnostic. As a wasm it runs everywhere, even the browser.
  • Handles up to 512k gates, proving time 18s on M1 Mac (builds off prior work).
  • New cleaned up AcirComposer interface that's simple and sane to use.

@codygunton
Copy link
Collaborator

Charlie gave me a tour of changes relevant to the cryptography team. Otherwise we are foregoing a review due to the massive scope, the amount of new code, the fact that things are very much in flux, and the fact that this is not intended for production.

@codygunton codygunton merged commit 205a3f0 into master Jun 8, 2023
@codygunton codygunton deleted the cl/wasm_pthread branch June 8, 2023 19:41
ludamad pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 22, 2023
…5s wasm time). (AztecProtocol/barretenberg#434)

* Remove foundation submodule, add build-system
* Initial bindgen work.
* GPT4 created rust bindgen.
* Debug build preset wasm-dbg for stack traces etc.
* Async call support. Refactor binds. Common is module. WASM stubs unused wasi.
* Move some c_bind to module root and make use new abi.
* Initial working pthreads.
* Polynomial cache
* Custom poly allocator. Prealloc.
* Cleanup. Several parallel_for solutions. Might be worth keeping them around until threading work stabilises.
* Improve mem usage by slab allocating large parts of pippenger runtime state, and allowing slab reuse by removing from pk.
* Don't need binaryen.
* Bump alpine to get clang 16
* Backwards compatible cbinds.
* Move slab allocator to common. Init slab allocator just before creating pk.
* Dont need bleeding edge fork of libc anymore
* bb.js is standalone prover that handles noir constraint/witness output. (AztecProtocol/barretenberg#471)
* format msgpack serialization and excldue msgpack-c from clang-format (AztecProtocol/barretenberg#467)
* Fix horrific nasty memory bug.

---------

Co-authored-by: Suyash Bagad <suyashnbagad1997@gmail.com>
Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
Co-authored-by: Maddiaa <47148561+Maddiaa0@users.noreply.github.com>
Co-authored-by: ledwards2225 <98505400+ledwards2225@users.noreply.github.com>
Co-authored-by: Innokentii Sennovskii <isennovskiy@gmail.com>
Co-authored-by: kevaundray <kevtheappdev@gmail.com>
Co-authored-by: zac-williamson <blorktronics@gmail.com>
Co-authored-by: codygunton <codygunton@gmail.com>
ludamad pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 24, 2023
…5s wasm time). (AztecProtocol/barretenberg#434)

* Remove foundation submodule, add build-system
* Initial bindgen work.
* GPT4 created rust bindgen.
* Debug build preset wasm-dbg for stack traces etc.
* Async call support. Refactor binds. Common is module. WASM stubs unused wasi.
* Move some c_bind to module root and make use new abi.
* Initial working pthreads.
* Polynomial cache
* Custom poly allocator. Prealloc.
* Cleanup. Several parallel_for solutions. Might be worth keeping them around until threading work stabilises.
* Improve mem usage by slab allocating large parts of pippenger runtime state, and allowing slab reuse by removing from pk.
* Don't need binaryen.
* Bump alpine to get clang 16
* Backwards compatible cbinds.
* Move slab allocator to common. Init slab allocator just before creating pk.
* Dont need bleeding edge fork of libc anymore
* bb.js is standalone prover that handles noir constraint/witness output. (AztecProtocol/barretenberg#471)
* format msgpack serialization and excldue msgpack-c from clang-format (AztecProtocol/barretenberg#467)
* Fix horrific nasty memory bug.

---------

Co-authored-by: Suyash Bagad <suyashnbagad1997@gmail.com>
Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
Co-authored-by: Maddiaa <47148561+Maddiaa0@users.noreply.github.com>
Co-authored-by: ledwards2225 <98505400+ledwards2225@users.noreply.github.com>
Co-authored-by: Innokentii Sennovskii <isennovskiy@gmail.com>
Co-authored-by: kevaundray <kevtheappdev@gmail.com>
Co-authored-by: zac-williamson <blorktronics@gmail.com>
Co-authored-by: codygunton <codygunton@gmail.com>
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.

5 participants