swezkl
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Steps in Hardware, Leaps in Performance ![Acceleration Cover](https://hackmd.io/_uploads/H14Fljfr6.jpg) > This is written in collaboration with the team at [Ingonyama](https://www.ingonyama.com/). Special thanks to [@jeremyfelder](https://github.com/jeremyfelder) for making this [happen](https://github.com/zkonduit/ezkl/pull/586). ## ZKML with Acceleration We've recently [integrated](https://github.com/zkonduit/ezkl/pull/586) the open-source [Icicle GPU acceleration library](https://github.com/ingonyama-zk/icicle) built by the [Ingonyama team](https://www.ingonyama.com/). This enables developers to leverage hardware acceleration with a simple [environment configuration](https://github.com/zkonduit/ezkl#gpu-acceleration). The integration is a strategic enhancement to the EZKL engine, addressing the computational bottlenecks inherent in current ZK proof systems. It is especially relevant for large circuits, like those generated for machine learning models. We observe a [~98% reduction](https://hackmd.io/ftEdP5GgT5WxiN6r5ZaRuw#Benchmarking-Results) in MSM times against baseline CPU runs for aggregate circuits, and a [~35% reduction](https://hackmd.io/ftEdP5GgT5WxiN6r5ZaRuw#Benchmarking-Results) in total aggregate proof time against baseline CPU prover times. This is the first step in a comprehensive hardware integration. With the Ingonyama team, we're continuing to work towards full range support for GPU operations. And further, we're working towards integration with alternative hardware providers — ideally demonstrating tangible benchmarks for the broader domain. We provide context and technical specification below. Or feel free to jump right into the libraries [here](https://github.com/zkonduit/ezkl#gpu-acceleration). ### Zero Knowledge Bottlenecks Citing [Hardware Review: GPUs, FPGAs, and Zero Knowledge Proofs,](https://hackmd.io/@0xMonia/SkQ6-oRz3?utm_source=substack&utm_medium=email#What-are-we-accelerating) there are two components to zero knowledge applications: 1. **DSLs and Low-Level Libraries**: These are essential for expressing computations in a ZK-friendly manner. Examples include [Circom](https://docs.circom.io/), [Halo2](https://zcash.github.io/halo2/), [Noir](https://medium.com/aztec-protocol/introducing-noir-the-universal-language-of-zero-knowledge-ff43f38d86d9), and low-level libraries like [Arkworks](https://github.com/arkworks-rs). These tools convert programs into [constraint systems](https://hackmd.io/@0xMonia/SkQ6-oRz3?utm_source=substack&utm_medium=email#DSLs-domain-specific-language-and-low-level-libraries) (or read more [here](https://coders-errand.com/constraint-systems-for-zk-snarks/)), where operations like addition and multiplication are represented as single constraints. Bit manipulation is trickier, requiring many more constraints. 2. **Proving Systems:** They play a crucial role in generating and verifying proofs. Proving systems process inputs like Circuit, witness, and parameters. Generalized systems include Groth16 and PLONK, while specialized systems like EZKL cater to specific inputs like machine learning models. The major bottlenecks in in the most widely deployed ZK systems are: - **Multi-scalar Multiplications (MSMs)**: Large-scale multiplications over vectors, consuming significant time and memory, even when parallelized. - **Fast Fourier Transforms (FFTs)**: Algorithms that require frequent data shuffling, making them challenging to accelerate, especially on distributed infrastructure. ### The Role of Hardware Hardware accelerations, such as GPUs and FPGAs, offer significant advantages over software optimizations by enhancing parallelism and optimizing memory access: - **GPUs**: Provide rapid development and massive parallelism, but are power-intensive. - **FPGAs**: Offer lower latency, especially for large data streams, and are more energy-efficient but have a complex development cycle. For more extensive discussion around optimal hardware design and performance, see [here](https://hackmd.io/@0xMonia/SkQ6-oRz3?utm_source=substack&utm_medium=email#Hardware-acceleration-in-action). The domain is evolving rapidly and [many approaches remain competitive](https://medium.com/@omershlomovits/revisiting-paradigm-hardware-acceleration-for-zero-knowledge-proofs-16f717a49555). ### GPU-Acceleration for Halo2 In the [Halo2 proof system](https://zcash.github.io/halo2/), bottlenecks can vary depending on the specific circuit being proven. These bottlenecks fall into two main categories: 1. **Commitment Bottlenecks (MSM)**: These are primarily computational bottlenecks and are often parallelizable. In circuits where MSM is the bottleneck, we observe a level of universality. This means that **applying a GPU-accelerated solution can efficiently resolve these bottlenecks** with minimal modifications to the existing codebase. 2. **Constraint Evaluation Bottlenecks (especially in h poly)**: These bottlenecks are more complex as they can be either computational or memory-intensive. They heavily depend on the specifics of the circuit. Addressing these **requires a tailored redesign of the evaluation algorithm**. The focus here is on optimizing the trade-off between memory usage and computation, and deciding whether to store intermediate results or recompute them. ![KZG Aggegation Overview](https://hackmd.io/_uploads/S1CbY9GBp.png) >A prime example is the KZG aggregation circuit. In such circuits, the primary challenge lies in the accumulation of elliptic curve group elements. The constraints in these cases are relatively uniform and of low degree (e.g., incomplete addition formulae with degree 4 constraints as per [Halo2 documentation](https://zcash.github.io/halo2/design/gadgets/ecc/addition.html)). Thus, the bulk of the complexity arises from commitments (MSM), a computational problem effectively solvable with GPU acceleration. For the scope of this integration, we've chosen to **focus on commitment bottlenecks**. It's low hanging fruit, but also an optimization for core component of the engine (KZG aggregation). This is only one step — there remains a lot of work to be done. ### Icicle: CUDA-Enabled GPUs The team at [Ingonyama](https://www.ingonyama.com/) has developed [Icicle](https://github.com/ingonyama-zk/icicle) as an open-source library designed for ZK acceleration using CUDA-enabled GPUs. CUDA, or Compute Unified Device Architecture, is a [parallel computing platform and API model created by Nvidia](https://developer.nvidia.com/cuda-gpus). It allows software to utilize Nvidia GPUs for general-purpose processing. The primary objective of Icicle is to offload a significant portion of the prover code to the GPU and harnesses parallel processing power. Icicle hosts APIs in Rust and Golang, which simplifies integration. The design is also customizable, featuring: - **High-Level API**: For common tasks like committing, evaluating, and interpolating polynomials. - **Low-Level API**: Targeted at specific operations like Multi-Scalar Multiplications (MSM), Number Theoretic Transforms (NTT), and Inverse NTTs (INTT). - **GPU Kernels**: For optimized execution of specific tasks on the GPU. Notably, Icicle supports essential functionalities like: - **Vectorized Field/Group Arithmetic**: Efficient handling of mathematical operations over fields and groups. - **Polynomial Arithmetic**: Critical for many ZK algorithms. - **Hash Functions**: Essential for cryptographic applications. - **Complex Structures**: Like Inverse Elliptic Curve Number Theoretic Transforms (I/ECNTT), Batched MSM, and Merkle trees. ### Integration with EZKL The Icicle library has been seamlessly integrated with the EZKL engine, offering GPU acceleration for users with direct access to NVIDIA GPUs or [simply with access to Colab](https://colab.research.google.com/drive/1ZDsEA4U6m5W8QR6IOHtJ8gt_G-mGWijh?usp=sharing). This integration enhances the performance of the EZKL engine by leveraging the parallel processing capabilities of GPUs. Here's how to enable and manage this feature: - **Enabling GPU Acceleration**: To activate GPU acceleration, build the system with the `icicle` feature and set the environment variable as follows: `export ENABLE_ICICLE_GPU=true` - **Reverting to CPU**: To switch back to CPU processing, simply unset the `ENABLE_ICICLE_GPU` environment variable rather than setting it to false: `unset ENABLE_ICICLE_GPU` - **Customizing Threshold for Small Circuits**: If you wish to modify the threshold for what constitutes a small circuit, you can set the `ICICLE_SMALL_K` environment variable to a desired value. This allows for greater control over when GPU acceleration is employed. ![Screenshot 2023-11-16 at 20.14.29](https://hackmd.io/_uploads/Syh0Y5MSp.png) >Current ICICLE integration overview. This integration targets compute bottlenecks due to MSM, with significant effects visible in the KZG aggregate circuit. ### Key Affordances This integration provides several technical affordances. Most importantly, **the integration supports plug and play MSM operations in the GPU** using the Icicle library. As a target and testing environment, we focused on replacing CPU-based KZG commitments in the [EZKL's aggregation command](https://docs.ezkl.xyz/about_ezkl/commands/#aggregate). This is where multiple proofs are consolidated into a single proof. More specifically, `commit` and `commit_lagrange` for KZG commitments (done on the CPU) with MSM operations (on the GPU) for the BN254 elliptic curve. We have also enabled environment variables and crate features, **allowing developers to toggle between CPU and GPU for different circuits on the same binary/build** of EZKL. In order to optimize GPU toggling, GPU acceleration is only enabled by default for large k circuits (k > 8). ### Benchmarking Results Our benchmarking results demonstrate a substantial improvement in performance with the integration of the Icicle library into the EZKL engine: - **Significant Reduction in MSM Times**: We observed approximately a 98% reduction in Multi-Scalar Multiplication (MSM) times when compared to the baseline CPU run for the aggregate circuit. This indicates a highly efficient offloading of computational tasks to the GPU. - **Dramatic Speed Increase in MSM Operations**: The MSM operations performed by ICICLE are, on average, 50 times faster compared to those in the baseline CPU configuration. This speedup was consistent across most MSMs in the aggregate command. - **Overall Reduction in Proof Times**: The total time required to generate aggregate proofs saw a reduction of about 35% when compared to the baseline CPU prover times. This reflects a significant overall performance enhancement in the proof generation process. These results highlight the effectiveness of GPU acceleration in optimizing ZK proof systems, particularly in computational aspects like MSM operations. For verification, you can view our [continuous integration tests](https://github.com/zkonduit/ezkl/actions/runs/6788144096) here. ### Future Directions Looking ahead, we plan to further optimize and expand the capabilities of EZKL and Icicle integration: - **Expanding GPU Operations**: One key area of focus will be replacing more CPU operations with GPU counterparts. This includes operations involving Number Theoretic Transforms (NTTs), which are currently CPU-based. By offloading these operations to the GPU, we expect to achieve even greater efficiency and speed. - **Introducing Batched Operations**: Another crucial development will be the addition of batched operations. This enhancement is particularly aimed at enabling efficient GPU usage even in smaller and wider circuits. By doing so, we aim to extend the benefits of GPU acceleration to a broader range of circuit types and sizes, ensuring optimal performance across all scenarios. More broadly, we seek to see integration with alternative hardware systems. This will enable functional benchmarking and developer flexibility for the broader domain. Through these future developments, we aim to continue pushing the boundaries of performance in ZK proof systems, making them more efficient and accessible for a wider range of applications. ## Appendix ### Notes for Future Integrations For contributors and developers, we tested this integration with the [aggregate command tutorial](https://docs.ezkl.xyz/about_ezkl/commands/#aggregate) on a custom instance with four proofs. A few notes for future integrations - **Benchmarking Environment**: Tests were conducted using AWS c6a.8xlarge instances with AMD Epyc 7R13 for baseline CPU runs. - **Aggregation Command Tutorial**: The integration's performance was validated using the aggregation command tutorial, including a test instance with 4 proofs for baseline comparison. - **Initial Testing on Single MSM Instances**: Initially, testing focused on single instances of MSM from the EZKL/halo2 crates to verify functionality. - **Issue with GPU Context in Full Proofs**: Upon extending to full proofs, it was discovered that the GPU context was lost after a single operation. A solution was implemented by creating a static reference to maintain the GPU context throughout an entire proof command. - **Focus on Aggregation Circuit/Command**: The integration primarily targeted the aggregation circuit/command, characterized by a large K (number of constraints) and a small number of advice columns. - **Impact on Proof Command**: Modifications in the code affected the proof command as well. It became necessary to ensure that the performance of single proofs was either maintained or improved with these changes. - **Performance Variations Based on Circuit Size and Width**: For large and narrow circuits, the GPU enhancements yielded positive results. However, for smaller (K ≤ 8) and wider circuits, the GPU enhancements led to slower performance. - **Future Improvements for Universal Optimization**: Plans are in place to enhance GPU integration for all circuit types, particularly focusing on batching operations for optimal performance across various circuit dimensions.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully