This package provides GPU-accelerated Multi-Scalar Multiplication (MSM) for the halo2curves library, optimized for Apple M-series chips and iPhones. It supports both halo2curves and arkworks curve implementations, with a primary focus on the BN254 curve.
-
Curve Support:
halo2curves(use theh2cfeature)arkworks(use thearkfeature)- Only BN254 is supported at the moment.
-
Platform-Specific Shader Compilation:
- For macOS, use the
macosfeature. - For iOS, use the
iosfeature. - Note: These features are mutually exclusive as Metal shaders are compiled during the build process (
build.rs).
- For macOS, use the
To run all tests:
cargo test --features "h2c ark macos" --no-default-features --release
Some arkworks MSM tests are ignored by default due to concurrency issues. Run these separately with:
cargo test --features "h2c ark macos" --no-default-features --release -- --test-threads=1 --ignored
-
General Benchmarking:
cargo run --release --features "gpu-profiler" --bin gpu-profiler -- --log-instance-size 20 --num-instances 1 --retries 1This benchmarks:
- The
halo2curvesimplementation - The GPU-accelerated implementation
- For log size 20 and 5 instances by default.
To benchmark the
arkworksimplementation, use thearkfeature:cargo bench --features "ark" -- benchmark_msm - The
-
Custom Benchmarking: Use the
gpu_profilerbinary for fine-grained control:RUST_LOG=info cargo run --release --bin gpu_profiler 20 5 gpu_cpu 10- Arguments:
- First: MSM log size
- Second: Number of instances
- Third: Algorithm to use (refer to
gpu_profilersource for options) - Fourth: Number of reruns for consistent results.
- Note: You can also change the logging level to
debugfor more detailed output on the GPU implementation.
- Arguments:
-
iOS Benchmarking: The
ios-metal-benchmarkerproject allows performance measurement on iPhones:- Generate iOS bindings:
cargo run --release --bin gen_ios_bindings - Follow the Mopro iOS setup guide for integrating the bindings: iOS Setup Tutorial
- Generate iOS bindings:
Ensure you have a macOS machine with an M-series chip (or an iPhone for iOS benchmarks). Compilation for iOS still requires a macOS environment.
Contributions are welcome! Please open issues for feature requests or bug reports.
This project is licensed under the MIT License. See the LICENSE file for details.