diff --git a/jolt-core/src/msm/icicle/adapter.rs b/jolt-core/src/msm/icicle/adapter.rs index 0feb4bcf0..65a96b87d 100644 --- a/jolt-core/src/msm/icicle/adapter.rs +++ b/jolt-core/src/msm/icicle/adapter.rs @@ -1,7 +1,9 @@ use crate::msm::VariableBaseMSM; -use ark_ec::{ScalarMul, CurveGroup}; +use ark_bn254::G1Projective; +use ark_ec::{CurveGroup, ScalarMul}; use ark_ff::{BigInteger, Field, PrimeField}; -use icicle_bn254::curve::{CurveCfg as IcicleBn254}; +use icicle_bn254::curve::CurveCfg as IcicleBn254; +use icicle_core::curve::{Affine, Curve, Projective}; use icicle_core::{ msm::{msm, MSMConfig, MSM}, traits::FieldImpl, @@ -11,8 +13,6 @@ use icicle_runtime::{ memory::{DeviceVec, HostSlice}, stream::IcicleStream, }; -use ark_bn254::G1Projective; -use icicle_core::curve::{Affine, Curve, Projective}; impl Icicle for G1Projective { type C = IcicleBn254; @@ -99,7 +99,7 @@ pub fn icicle_msm( &cfg, &mut msm_result[..], ) - .unwrap(); + .unwrap(); drop(_guard); drop(span); @@ -146,7 +146,7 @@ pub fn icicle_batch_msm( DeviceVec::<<::C as Curve>::ScalarField>::device_malloc_async( len, &stream, ) - .unwrap(); + .unwrap(); let scalars_mont = unsafe { &*(&scalars[..] as *const _ as *const [<::C as Curve>::ScalarField]) }; @@ -167,7 +167,7 @@ pub fn icicle_batch_msm( &cfg, &mut msm_result[..], ) - .unwrap(); + .unwrap(); msm_result .copy_to_host_async( @@ -212,7 +212,7 @@ pub fn icicle_variable_batch_msm( scalars.len(), &stream, ) - .unwrap(); + .unwrap(); let scalars_mont = unsafe { &*(&scalars[..] as *const _ as *const [<::C as Curve>::ScalarField]) }; @@ -233,7 +233,7 @@ pub fn icicle_variable_batch_msm( &cfg, &mut msm_result[..], ) - .unwrap(); + .unwrap(); msm_result .copy_to_host_async( @@ -276,13 +276,13 @@ where #[cfg(test)] mod tests { use super::*; + use crate::msm::total_memory_bits; use ark_bn254::{Fr, G1Affine, G1Projective}; use ark_ec::VariableBaseMSM as ark_VariableBaseMSM; use ark_std::UniformRand; use icicle_bn254::curve::ScalarField as GPUScalar; use rand_core::SeedableRng; use rayon::prelude::*; - use crate::msm::total_memory_bits; // Note due to contention for the gpu device testing using multiple threads leads to unit tests that intermittently fail. // To avoid this run `cargo t --features icicle -- --test-threads=1` @@ -330,4 +330,4 @@ mod tests { let total = total_memory_bits(); assert!(total > 0); } -} \ No newline at end of file +} diff --git a/jolt-core/src/msm/icicle/mod.rs b/jolt-core/src/msm/icicle/mod.rs index d02ee8506..d4cf32489 100644 --- a/jolt-core/src/msm/icicle/mod.rs +++ b/jolt-core/src/msm/icicle/mod.rs @@ -1,9 +1,8 @@ +#[cfg(not(feature = "icicle"))] +use ark_bn254::G1Projective; #[allow(dead_code)] - use ark_ec::{CurveGroup, ScalarMul}; use std::sync::Once; -#[cfg(not(feature = "icicle"))] -use ark_bn254::G1Projective; #[cfg(feature = "icicle")] pub(crate) mod adapter; @@ -86,9 +85,17 @@ pub fn total_memory_bits() -> usize { // Fallback to system memory if icicle is unavailable or not enabled. #[cfg(not(target_arch = "wasm32"))] if let Ok(mem_info) = sys_info::mem_info() { - return (mem_info.total as usize * BYTES_PER_KB).checked_mul(BITS_PER_BYTE).unwrap_or(usize::MAX); + return (mem_info.total as usize * BYTES_PER_KB) + .checked_mul(BITS_PER_BYTE) + .unwrap_or(usize::MAX); } // Fallback to "default" memory if system memory retrieval fails. - DEFAULT_MEM_GB.checked_mul(BYTES_PER_GB.checked_mul(BITS_PER_BYTE).unwrap_or(usize::MAX)).unwrap_or(usize::MAX) + DEFAULT_MEM_GB + .checked_mul( + BYTES_PER_GB + .checked_mul(BITS_PER_BYTE) + .unwrap_or(usize::MAX), + ) + .unwrap_or(usize::MAX) } diff --git a/jolt-core/src/msm/mod.rs b/jolt-core/src/msm/mod.rs index f139c195b..c5110f409 100644 --- a/jolt-core/src/msm/mod.rs +++ b/jolt-core/src/msm/mod.rs @@ -44,7 +44,9 @@ pub trait VariableBaseMSM: ScalarMul + Icicle { } #[cfg(not(feature = "icicle"))] { - unreachable!("icicle_init must not return true without the icicle feature"); + unreachable!( + "icicle_init must not return true without the icicle feature" + ); } } @@ -67,7 +69,9 @@ pub trait VariableBaseMSM: ScalarMul + Icicle { } #[cfg(not(feature = "icicle"))] { - unreachable!("icicle_init must not return true without the icicle feature"); + unreachable!( + "icicle_init must not return true without the icicle feature" + ); } } @@ -167,7 +171,9 @@ pub trait VariableBaseMSM: ScalarMul + Icicle { } #[cfg(not(feature = "icicle"))] { - unreachable!("icicle_init must not return true without the icicle feature"); + unreachable!( + "icicle_init must not return true without the icicle feature" + ); } } else { indices @@ -198,7 +204,9 @@ pub trait VariableBaseMSM: ScalarMul + Icicle { } #[cfg(not(feature = "icicle"))] { - unreachable!("icicle_init must not return true without the icicle feature"); + unreachable!( + "icicle_init must not return true without the icicle feature" + ); } } else { indices @@ -234,7 +242,9 @@ pub trait VariableBaseMSM: ScalarMul + Icicle { } #[cfg(not(feature = "icicle"))] { - unreachable!("icicle_init must not return true without the icicle feature"); + unreachable!( + "icicle_init must not return true without the icicle feature" + ); } } else { indices