Moven Tsai
    • 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
    • Note Insights
    • 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 Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Grant Summary on Accelerating MSM on Mobile with GPUs Improving the efficiency of zero-knowledge proofs (ZKPs) is crucial for enhancing privacy and scalability in privacy-preserving applications. [Mopro-22 Grant](https://hackmd.io/@moven0831/mopro-22-improving-msm) focuses on leveraging GPU acceleration to boost the performance of multi-scalar multiplication (MSM) on mobile devices. This blog post summarizes the progress and future plans to enhance proving speed using GPUs on mobile phones, aimed at enthusiasts and professionals interested in cryptographic optimizations. ## Background and Context ### Understanding MSM and Its Importance Multi-Scalar Multiplication (MSM) is a fundamental operation in various cryptographic protocols, particularly pairing-based zk-SNARKs like Groth16. Efficient MSM performance is essential for the scalability and responsiveness of these systems. However, executing MSM on mobile devices presents significant challenges due to the limited computational power of mobile CPUs. ### GPU Acceleration Graphics Processing Units (GPUs) offer parallel processing capabilities that can handle multiple computations simultaneously. Leveraging GPUs for MSM operations presents a promising solution to overcome the performance limitations of mobile CPUs. ### Related Work Our approach builds upon existing efforts such as the [Zprize 2022 MSM on Mobile Acceleration](https://github.com/z-prize/2022-entries/tree/main/open-division/prize7-msm-mobile), [Lambdaworks Metal MSM](https://github.com/lambdaclass/lambdaworks), and utilizes [Arkworks](https://github.com/arkworks-rs) for cryptographic primitives. ## Project Overview ### Objectives - **Integrate MSM Algorithms:** Incorporate various MSM implementations into the Mopro framework. - **Benchmark Performance:** Compare MSM performance against existing solutions using Arkworks as a baseline. - **Optimize for Mobile GPUs:** Utilize Apple's Metal API to tailor MSM algorithms for mobile GPU architectures. - **Documentation:** Provide comprehensive guides for enabling GPU acceleration in the proving process on mobile devices. ### Methodology Our approach involves integrating MSM algorithms into Mopro, conducting extensive benchmarks on both simulators and real devices, optimizing these algorithms using the Metal API, and iteratively addressing performance bottlenecks. <figure align="center"> <a href="https://hackmd.io/_uploads/S1mEaZuRC.png"> <img src="https://hackmd.io/_uploads/S1mEaZuRC.png" alt="High Latency"/> <br> </a> <center><em>GPU Channels of Metal MSM</em></center> </figure> ## Milestone Progress Reports ### [Milestone 1: Integration and Benchmarking](#Associated-Reports-to-This-Grant) **Objectives:** Integrate Zprize MSM works into Mopro and establish Arkworks Pippenger MSM as a baseline. **Achievements:** - Successfully integrated TrapdoorTech’s MSM. - Adapted benchmarking methods and conducted initial performance comparisons. ### [Milestone 2: GPU Acceleration with Metal API](#Associated-Reports-to-This-Grant) **Objectives:** Explore GPU acceleration using Metal, integrate Halo2curve MSM, and build GPU exploration examples. **Achievements:** - Implemented Metal shaders and benchmarked different curves (BN254 vs BLS12-377). - Migrated Lambdaworks’ Metal shaders. - Identified performance bottlenecks in the accumulation phase and optimized parallel computation strategies. **Challenges:** - Faced GPU hang errors on larger MSM instances. - Compatibility issues with Metal-rs, resolved by switching to the updated `metal` crate. **Next Steps:** Refine Metal implementations and address GPU stability on mobile devices. ### [Milestone 3: Advanced Optimization and Parallelism](#Associated-Reports-to-This-Grant) **Objectives:** Enhance parallelism in MSM algorithms, implement bucket-wise MSM, and leverage precomputation techniques. **Achievements:** - Transitioned to bucket-wise MSM to maximize GPU parallelism. - Conducted extensive benchmarking on Apple M3 chips, extracting more parallelism suitable for GPU computation. **Challenges:** - GPU hang errors persisted for larger instances. - Incompatibility with Metal’s built-in sort functions, leading to the use of CPU-based sorting. **Next Steps:** Continue optimizing accumulation phases and explore alternative sorting mechanisms. ### [Milestone 4: Final Benchmarking and Integration](#Associated-Reports-to-This-Grant) **Objectives:** Benchmark all MSM implementations on real iOS devices, refactor MSM into a standalone crate, and prepare for integration into proving systems. **Achievements:** - Completed extensive benchmarks showing similar trends to simulators and laptops. - Isolated MSM code into a standalone crate for easier integration. - Identified GPU accumulation as the primary performance bottleneck. **Challenges:** - GPU hang errors on real devices and limitations in Metal’s built-in sort functions. - Precompute MSM scalability issues for larger instances. **Next Steps:** Integrate GPU-acceleration crate into proving systems, support curve-specific MSM algorithms, and continue mobile GPU optimization. ## Benchmarking MSM Algorithms on iOS Devices Detailed information for the testing device. <figure align="center"> <a href="https://hackmd.io/_uploads/ryqXX-OKC.jpg"> <img src="https://hackmd.io/_uploads/ryqXX-OKC.jpg" alt="Testing Device Info"/> <br> </a> <center><em>Testing Device Info</em></center> </figure> > [hardware reference](https://www.gsmarena.com/apple_iphone_14_pro-11860.php) * Phone type: IPhone 14 pro * ChipSet: Apple A16 Bionic (4nm) * CPU: Hexa-core (2x3.46 GHz Everest + 4x2.02 GHz Sawtooth) * GPU: Apple GPU (5-core graphics) * Memory: 6GB RAM ### Methodology <!-- e.g. Device Setup, Benchmarking Process, Metrics --> The unit for all column is ms. | Instance Size | arkwork (baseline) | Metal (GPU) | Bucket Wise Msm | Precompute Msm | result(screen shot) | | ------------- | ------------------ | ---------------- | ------------------ | ------------------ | ---------------------------------------- | | 2^10 | 11.29 | 21.31 (-88.66%) | 80.54 (-613.07%) | 25.57 (-126.41%) | [![](https://imgur.com/tzjjEgQ.png)](https://imgur.com/tzjjEgQ.png)<br> | | 2^12 | 19.34 | 62.85 (-225.00%) | 331.15 (-1612.43%) | 82.93(-328.85%) | [![](https://imgur.com/ShdhJaS.png)](https://imgur.com/ShdhJaS.png)<br> | | 2^14 | 53.11 | - | 221.17 (-316.43%) | 265.68 (-400.24%) | [![](https://imgur.com/6cx0LwH.png)](https://imgur.com/6cx0LwH.png)<br> | | 2^16 | 198.11 | - | 759.87 (-283.57%) | 888.23 (-348.36) | [![](https://imgur.com/LRARN41.png)](https://imgur.com/LRARN41.png) | | 2^18 | 707.95 | - | 2938.61 (-315.09%) | 1429.06 (-101.86%) | [![](https://imgur.com/XE3BVFV.png)](https://imgur.com/XE3BVFV.png)<br> | | 2^20 | 1902.76 | - | 7341.82 (-285.85%) | - | [![](https://imgur.com/oJY6O0T.png)](https://imgur.com/oJY6O0T.png)<br> | ### Footnote When the instance size is larger than $2^{14}$, `MetalMsm` encounters a GPU Hang error. For sizes above $2^{18}$, `precomputeMsm` takes an excessive amount of time generating extended points, which might cause the process of generating the proving key and verification key to be too slow, as indicated in the log below. Additionally, deserialization takes even longer than in `arkwork (baseline)`. Therefore, `precomputeMsm` is not compared for instance sizes $2^{20}$ and $2^{22}$. **Key Insights:** - **Memory Management Needs Improvement:** The current Metal MSM implementation encounters GPU hang errors with larger instances, limiting scalability. - **Bottlenecks:** The accumulation phase in bucket-wise Metal MSM remains the primary performance bottleneck. - **Precompute MSM:** While offering speedups, precompute MSM introduces substantial I/O overhead, making it unsuitable for larger instances. ## Future Work and Next Steps > Please refer to [the profiling report](#Associated-Reports-to-This-Grant) for detailed GPU activities of Metal MSM. To address the critical challenges identified, we will prioritize the following tasks: 1. **Reduce CPU-GPU Latency and Improve Synchronization** - **Streamline Data Transfers:** Implement batching and asynchronous methods to minimize latency. - **Enable Concurrent Processing:** Optimize synchronization to allow simultaneous CPU and GPU workloads, enhancing overall throughput. 2. **Resolve GPU Stability Issues for Larger MSM Instances** - **Fix GPU Hang Errors:** Investigate and eliminate the causes of GPU hangs when handling larger MSM instances. - **Refine Metal Shaders:** Update and optimize Metal shader code to ensure compatibility and stability across various mobile devices. 3. **Optimize EC Point Conversion Efficiency** - **Accelerate Encoding:** Develop faster algorithms or alternative data representations to significantly reduce the time spent on converting EC points from 64-bit to 32-bit. 4. **Enhance Parallelism in the Accumulation Phase** - **Improve Bucket-wise MSM:** Refine parallel computation strategies to speed up the accumulation process. - **Implement GPU-based Sorting:** Replace CPU-based sorting with GPU-optimized solutions to decrease latency and boost performance. ## Conclusion **Project Mopro-22** has made substantial strides in accelerating MSM operations on mobile GPUs, laying the groundwork for more efficient cryptographic proofs on the go. While challenges like GPU stability and accumulation optimization remain, our progress opens new avenues for research and development in mobile cryptography. We invite the community to join us in this exciting journey towards faster, more efficient proving systems. ## References and Further Reading - #### **Associated Reports to This Grant** - [General Grant Proposal - Mopro-22](/ZL-PmVl7SGq0IBt6mAGC8A) - [Milestone 1 Report](/ZCxFpQ8AROyYGTl5GLqAGQ) - [Milestone 2 Report](/YtTVJUArRmWrdvaTza2LGg) - [Milestone 3 Report](/v8WPAG8-RsCANrbv_seSXw) - [Milestone 4 Report](/6aYxLgNZTaGG4gbXkZUlCw) - [Profiling on Metal MSM](https://hackmd.io/@moven0831/profiling-metal-msm) - [Guide for Extending Custom Functions Through Mopro](https://github.com/zkmopro/gpu-acceleration/blob/main/guide-for-extending-ffi.md) - #### **GitHub Repositories:** - [zkmopro/mopro](https://github.com/zkmopro/mopro) - [zkmopro/gpu-acceleration](https://github.com/zkmopro/gpu-acceleration) - [Zprize 2022 MSM on Mobile Acceleration](https://github.com/z-prize/2022-entries/tree/main/open-division/prize7-msm-mobile) - [Ingonyama - Icicle](https://github.com/ingonyama-zk/icicle/blob/main/wrappers/rust/icicle-curves/icicle-bn254/src/msm/mod.rs) - #### **Technical Articles and Papers:** - [BeH22: Multi-Scalar Multiplication for SNARKs](https://hackmd.io/@moven0831/BeH22) - [Optimization Strategies for MSM](https://hackmd.io/@drouyang/msm) - [Performance Optimization | Metal by Tutorials](https://www.kodeco.com/books/metal-by-tutorials/v2.0/chapters/24-performance-optimization) - #### **Tools and Frameworks:** - [Arkworks](https://github.com/arkworks-rs) - [Metal-rs](https://github.com/gfx-rs/metal-rs) - [Lambdaworks](https://github.com/lambdaclass/lambdaworks) - [Halo2curve](https://github.com/privacy-scaling-explorations/halo2curves) ## Acknowledgments We extend our gratitude to our advisors Oskar and Vivian, and the open-source community for their invaluable support to Mopro-22 Grant.

    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