Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar-a16z committed Nov 15, 2024
1 parent b6201b7 commit adf16c9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
22 changes: 11 additions & 11 deletions jolt-core/src/msm/icicle/adapter.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn icicle_msm<V: VariableBaseMSM + Icicle>(
&cfg,
&mut msm_result[..],
)
.unwrap();
.unwrap();

drop(_guard);
drop(span);
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn icicle_batch_msm<V: VariableBaseMSM + Icicle>(
DeviceVec::<<<V as Icicle>::C as Curve>::ScalarField>::device_malloc_async(
len, &stream,
)
.unwrap();
.unwrap();
let scalars_mont = unsafe {
&*(&scalars[..] as *const _ as *const [<<V as Icicle>::C as Curve>::ScalarField])
};
Expand All @@ -167,7 +167,7 @@ pub fn icicle_batch_msm<V: VariableBaseMSM + Icicle>(
&cfg,
&mut msm_result[..],
)
.unwrap();
.unwrap();

msm_result
.copy_to_host_async(
Expand Down Expand Up @@ -212,7 +212,7 @@ pub fn icicle_variable_batch_msm<V: VariableBaseMSM + Icicle>(
scalars.len(),
&stream,
)
.unwrap();
.unwrap();
let scalars_mont = unsafe {
&*(&scalars[..] as *const _ as *const [<<V as Icicle>::C as Curve>::ScalarField])
};
Expand All @@ -233,7 +233,7 @@ pub fn icicle_variable_batch_msm<V: VariableBaseMSM + Icicle>(
&cfg,
&mut msm_result[..],
)
.unwrap();
.unwrap();

msm_result
.copy_to_host_async(
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -330,4 +330,4 @@ mod tests {
let total = total_memory_bits();
assert!(total > 0);
}
}
}
17 changes: 12 additions & 5 deletions jolt-core/src/msm/icicle/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
}
20 changes: 15 additions & 5 deletions jolt-core/src/msm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}

Expand All @@ -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"
);
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit adf16c9

Please sign in to comment.