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

feat: msm metal gpu acceleration #20

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ serde_derive = { version = "1", optional = true}
bincode = { version = "1.3.3", default_features = false }
serde = { version = "1.0.126", features = ["derive"] }
instant = { version = "0.1" }

mopro-msm = { git = "https://github.com/zkonduit/metal-msm-gpu-acceleration.git", optional = true, features = ["h2c"], default-features = false }

# Developer tooling dependencies
plotters = { version = "0.3.0", default-features = false, optional = true }
Expand Down Expand Up @@ -114,6 +114,9 @@ batch = ["rand_core/getrandom"]
circuit-params = []
counter = []
icicle_gpu = ["icicle-cuda-runtime", "icicle-core", "icicle-bn254"]
metal = ["mopro-msm"]
macos = ["mopro-msm/macos", "metal"]
ios = ["mopro-msm/ios", "metal"]
mv-lookup = []
cost-estimator = ["serde_derive"]
derive_serde = ["halo2curves/derive_serde"]
Expand Down
32 changes: 25 additions & 7 deletions halo2_proofs/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,38 @@ where
}

/// Best MSM
pub fn best_multiexp<C: CurveAffine>(
coeffs: &[C::Scalar], bases: &[C]
) -> C::Curve {
pub fn best_multiexp<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C]) -> C::Curve {
#[cfg(feature = "icicle_gpu")]
if env::var("ENABLE_ICICLE_GPU").is_ok()
&& !icicle::should_use_cpu_msm(coeffs.len())
&& icicle::is_gpu_supported_field(&coeffs[0])
{
best_multiexp_gpu(coeffs, bases)
} else {
best_multiexp_cpu(coeffs, bases)
return best_multiexp_gpu(coeffs, bases);
}

#[cfg(not(feature = "icicle_gpu"))]
#[cfg(feature = "metal")]
{
use mopro_msm::metal::abstraction::limbs_conversion::h2c::{H2Fr, H2GAffine, H2G};
use std::sync::Once;

// Static mutex to block concurrent Metal acceleration calls
static PRINT_ONCE: Once = Once::new();

// Print the warning message only once
PRINT_ONCE.call_once(|| {
log::warn!(
"WARNING: Using Experimental Metal Acceleration for MSM. \
Best performance improvements are observed with log row size >= 20. \
Current log size: {}",
coeffs.len().ilog2()
);
});

// Perform MSM using Metal acceleration
return mopro_msm::metal::msm_best::<C, H2GAffine, H2G, H2Fr>(coeffs, bases);
}

#[allow(unreachable_code)]
best_multiexp_cpu(coeffs, bases)
}

Expand Down
Loading