Skip to content

Commit

Permalink
rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nonam3e committed Jul 28, 2024
1 parent 98dbcee commit cbb4620
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 78 deletions.
44 changes: 19 additions & 25 deletions wrappers/rust_v3/icicle-core/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ pub trait Curve: Debug + PartialEq + Copy + Clone {
#[doc(hidden)]
fn generate_random_affine_points(size: usize) -> Vec<Affine<Self>>;
#[doc(hidden)]
fn convert_affine_montgomery(points: *mut Affine<Self>, len: usize, is_into: bool, stream: &IcicleStream) -> eIcicleError;
fn convert_affine_montgomery(
points: *mut Affine<Self>,
len: usize,
is_into: bool,
stream: &IcicleStream,
) -> eIcicleError;
#[doc(hidden)]
fn convert_projective_montgomery(points: *mut Projective<Self>, len: usize, is_into: bool, stream: &IcicleStream) -> eIcicleError;
fn convert_projective_montgomery(
points: *mut Projective<Self>,
len: usize,
is_into: bool,
stream: &IcicleStream,
) -> eIcicleError;
}

/// A [projective](https://hyperelliptic.org/EFD/g1p/auto-shortw-projective.html) elliptic curve point.
Expand Down Expand Up @@ -118,14 +128,14 @@ impl<C: Curve> From<Projective<C>> for Affine<C> {

impl<C: Curve> MontgomeryConvertible for Affine<C> {
fn to_mont(values: &mut DeviceSlice<Self>, stream: &IcicleStream) -> eIcicleError {
if !values.is_on_active_device(){
if !values.is_on_active_device() {
panic!("values not allocated on an inactive device");
}
C::convert_affine_montgomery(unsafe { values.as_mut_ptr() }, values.len(), true, stream)
}

fn from_mont(values: &mut DeviceSlice<Self>, stream: &IcicleStream) -> eIcicleError {
if !values.is_on_active_device(){
if !values.is_on_active_device() {
panic!("values not allocated on an inactive device");
}
C::convert_affine_montgomery(unsafe { values.as_mut_ptr() }, values.len(), false, stream)
Expand All @@ -134,14 +144,14 @@ impl<C: Curve> MontgomeryConvertible for Affine<C> {

impl<C: Curve> MontgomeryConvertible for Projective<C> {
fn to_mont(values: &mut DeviceSlice<Self>, stream: &IcicleStream) -> eIcicleError {
if !values.is_on_active_device(){
if !values.is_on_active_device() {
panic!("values not allocated on an inactive device");
}
C::convert_projective_montgomery(unsafe { values.as_mut_ptr() }, values.len(), true, stream)
}

fn from_mont(values: &mut DeviceSlice<Self>, stream: &IcicleStream) -> eIcicleError {
if !values.is_on_active_device(){
if !values.is_on_active_device() {
panic!("values not allocated on an inactive device");
}
C::convert_projective_montgomery(unsafe { values.as_mut_ptr() }, values.len(), false, stream)
Expand Down Expand Up @@ -238,15 +248,7 @@ macro_rules! impl_curve {
config.is_result_on_device = true;
config.is_async = false;
config.stream_handle = (&*stream).into();
unsafe {
$curve_prefix_ident::_convert_affine_montgomery(
points,
len,
is_into,
&config,
points
)
}
unsafe { $curve_prefix_ident::_convert_affine_montgomery(points, len, is_into, &config, points) }
}

fn convert_projective_montgomery(
Expand All @@ -260,15 +262,7 @@ macro_rules! impl_curve {
config.is_result_on_device = true;
config.is_async = false;
config.stream_handle = (&*stream).into();
unsafe {
$curve_prefix_ident::_convert_projective_montgomery(
points,
len,
is_into,
&config,
points
)
}
unsafe { $curve_prefix_ident::_convert_projective_montgomery(points, len, is_into, &config, points) }
}
}
};
Expand Down Expand Up @@ -306,4 +300,4 @@ macro_rules! impl_curve_tests {
}
}
};
}
}
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ macro_rules! impl_scalar_field {
}

impl MontgomeryConvertibleField<$field_name> for $field_cfg {
fn to_mont(values: &mut DeviceSlice<$field_name>, stream: &IcicleStream) -> eIcicleError {
fn to_mont(values: &mut DeviceSlice<$field_name>, stream: &IcicleStream) -> eIcicleError {
// check device slice is on active device
if !values.is_on_active_device() {
panic!("input not allocated on an inactive device");
Expand Down
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pub mod ecntt;
pub mod field;
pub mod msm;
pub mod ntt;
pub mod vec_ops;
pub mod polynomials;
pub mod vec_ops;

#[doc(hidden)]
pub mod test_utilities;
Expand Down
5 changes: 3 additions & 2 deletions wrappers/rust_v3/icicle-core/src/msm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub struct MSMConfig {
pub bitsize: i32,

pub batch_size: i32,
pub are_bases_shared: bool, /// MSMs in batch share the bases. If false, expecting #bases==#scalars
pub are_bases_shared: bool,
/// MSMs in batch share the bases. If false, expecting #bases==#scalars
are_scalars_on_device: bool,
pub are_scalars_montgomery_form: bool,
are_bases_on_device: bool,
Expand All @@ -54,7 +55,7 @@ pub const IS_BIG_TRIANGLE: &str = "is_big_triangle";
impl Default for MSMConfig {
fn default() -> Self {
Self {
stream_handle: std::ptr::null_mut(),
stream_handle: std::ptr::null_mut(),
precompute_factor: 1,
c: 0,
bitsize: 0,
Expand Down
18 changes: 9 additions & 9 deletions wrappers/rust_v3/icicle-core/src/msm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::curve::{Affine, Curve, Projective};
use crate::msm::{msm, precompute_bases, MSMConfig, LARGE_BUCKET_FACTOR, MSM};
use crate::test_utilities;
use crate::traits::{FieldImpl, GenerateRandom, MontgomeryConvertible};
use icicle_runtime::memory::HostOrDeviceSlice;
use icicle_runtime::{
memory::{DeviceVec, HostSlice},
runtime,
stream::IcicleStream,
};
use icicle_runtime::memory::HostOrDeviceSlice;
use rayon::iter::{IntoParallelIterator, ParallelIterator};

use rand::thread_rng;
Expand Down Expand Up @@ -101,7 +101,7 @@ where
<C::ScalarField as FieldImpl>::Config: GenerateRandom<C::ScalarField>,
{
// let test_sizes = [1000, 1 << 16]; //TODO - uncomment this line after implementing fast msm
let test_sizes = [100];
let test_sizes = [100];
// let batch_sizes = [1, 3, 1 << 4];
let batch_sizes = [1, 3]; //TODO - uncomment this line after implementing fast msm
let mut stream = IcicleStream::create().unwrap();
Expand Down Expand Up @@ -181,10 +181,10 @@ where

pub fn check_msm_batch_shared<C: Curve + MSM<C>>()
where
<C::ScalarField as FieldImpl>::Config: GenerateRandom<C::ScalarField>,
<C::ScalarField as FieldImpl>::Config: GenerateRandom<C::ScalarField>,
{
// let test_sizes = [1000, 1 << 16]; //TODO - uncomment this line after implementing fast msm
let test_sizes = [100];
let test_sizes = [100];
// let batch_sizes = [1, 3, 1 << 4];
let batch_sizes = [1, 3]; //TODO - uncomment this line after implementing fast msm
let mut stream = IcicleStream::create().unwrap();
Expand Down Expand Up @@ -264,10 +264,10 @@ where

pub fn check_msm_batch_not_shared<C: Curve + MSM<C>>()
where
<C::ScalarField as FieldImpl>::Config: GenerateRandom<C::ScalarField>,
<C::ScalarField as FieldImpl>::Config: GenerateRandom<C::ScalarField>,
{
// let test_sizes = [1000, 1 << 16]; //TODO - uncomment this line after implementing fast msm
let test_sizes = [100];
let test_sizes = [100];
// let batch_sizes = [1, 3, 1 << 4];
let batch_sizes = [3, 5]; //TODO - uncomment this line after implementing fast msm
let mut stream = IcicleStream::create().unwrap();
Expand Down Expand Up @@ -351,12 +351,12 @@ where
{
// let test_sizes = [1 << 10, 10000]; // TODO - uncomment this line after implementing fast msm
let test_sizes = [1 << 10]; // TODO - remove this line after implementing fast msm
// let test_threshold = 1 << 11; // TODO - uncomment this line after implementing fast msm
// let batch_sizes = [1, 3, 1 << 4]; // TODO - uncomment this line after implementing fast msm
// let test_threshold = 1 << 11; // TODO - uncomment this line after implementing fast msm
// let batch_sizes = [1, 3, 1 << 4]; // TODO - uncomment this line after implementing fast msm
let batch_sizes = [1, 3]; // TODO - remove this line after implementing fast msm
let rng = &mut thread_rng();
for test_size in test_sizes {
let test_threshold = test_size>>2; // TODO - remove this line after implementing fast msm
let test_threshold = test_size >> 2; // TODO - remove this line after implementing fast msm
for batch_size in batch_sizes {
let points = generate_random_affine_points_with_zeroes::<C>(test_size * batch_size, 100);
let mut scalars = vec![C::ScalarField::zero(); test_size * batch_size];
Expand Down
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-core/src/ntt/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ where
let coset_generators = [
F::Config::generate_random(1)[0],
get_root_of_unity::<F>(test_size as u64),
F::one(),
F::one(),
];
for coset_gen in coset_generators {
let mut scalars = F::Config::generate_random(test_size);
Expand Down
11 changes: 7 additions & 4 deletions wrappers/rust_v3/icicle-core/src/polynomials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ macro_rules! impl_univariate_polynomial_api {

pub fn coeffs_mut_slice(&mut self) -> &mut DeviceSlice<$field> {
unsafe {
let mut len: u64 = 0;
let mut len: u64 = 0;
let mut coeffs_mut = get_coeffs_ptr(self.handle, &mut len);
let s = slice::from_raw_parts_mut(coeffs_mut, len as usize);
DeviceSlice::from_mut_slice(s)
Expand Down Expand Up @@ -413,9 +413,12 @@ macro_rules! impl_polynomial_tests {
$field:ident
) => {
use super::*;
use icicle_core::ntt::{get_root_of_unity, initialize_domain, release_domain, NTTDomain, NTTInitDomainConfig, CUDA_NTT_FAST_TWIDDLES_MODE};
use icicle_core::vec_ops::{add_scalars, mul_scalars, sub_scalars, VecOps, VecOpsConfig};
use icicle_core::ntt::{
get_root_of_unity, initialize_domain, release_domain, NTTDomain, NTTInitDomainConfig,
CUDA_NTT_FAST_TWIDDLES_MODE,
};
use icicle_core::test_utilities;
use icicle_core::vec_ops::{add_scalars, mul_scalars, sub_scalars, VecOps, VecOpsConfig};
use icicle_runtime::memory::{DeviceVec, HostSlice};
use std::sync::Once;

Expand Down Expand Up @@ -497,7 +500,7 @@ macro_rules! impl_polynomial_tests {

fn randomize_poly(size: usize) -> Poly {
let coeffs = randomize_coeffs::<$field>(size);
Poly::from_coeffs(HostSlice::from_slice(&coeffs), size)
Poly::from_coeffs(HostSlice::from_slice(&coeffs), size)
}

static INIT: Once = Once::new();
Expand Down
8 changes: 4 additions & 4 deletions wrappers/rust_v3/icicle-core/src/vec_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ fn check_vec_ops_args<'a, F>(
}

// check device slices are on active device
if a.is_on_device() && !a.is_on_active_device(){
if a.is_on_device() && !a.is_on_active_device() {
panic!("input a is allocated on an inactive device");
}
if b.is_on_device() && !b.is_on_active_device(){
if b.is_on_device() && !b.is_on_active_device() {
panic!("input b is allocated on an inactive device");
}
if result.is_on_device() && !result.is_on_active_device(){
if result.is_on_device() && !result.is_on_active_device() {
panic!("output is allocated on an inactive device");
}

Expand Down Expand Up @@ -196,7 +196,7 @@ macro_rules! impl_vec_ops_field {
) => {
mod $field_prefix_ident {

use crate::vec_ops::{$field, HostOrDeviceSlice};
use crate::vec_ops::{$field, HostOrDeviceSlice};
use icicle_core::vec_ops::VecOpsConfig;
use icicle_runtime::errors::eIcicleError;

Expand Down
7 changes: 5 additions & 2 deletions wrappers/rust_v3/icicle-core/src/vec_ops/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![allow(unused_imports)]
use crate::test_utilities;
use crate::traits::GenerateRandom;
use crate::vec_ops::{add_scalars, mul_scalars, sub_scalars, bit_reverse, bit_reverse_inplace, transpose_matrix, FieldImpl, VecOps, VecOpsConfig};
use crate::vec_ops::{
add_scalars, bit_reverse, bit_reverse_inplace, mul_scalars, sub_scalars, transpose_matrix, FieldImpl, VecOps,
VecOpsConfig,
};
use icicle_runtime::device::Device;
use icicle_runtime::memory::{DeviceVec, HostSlice};
use icicle_runtime::{runtime, stream::IcicleStream};
Expand Down Expand Up @@ -108,7 +111,7 @@ where
<F as FieldImpl>::Config: VecOps<F> + GenerateRandom<F>,
{
test_utilities::test_set_main_device();

const LOG_SIZE: u32 = 20;
const TEST_SIZE: usize = 1 << LOG_SIZE;
let input_vec = F::Config::generate_random(TEST_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) mod tests {
use crate::curve::{CurveCfg, ScalarField};

use icicle_core::ecntt::tests::*;
use icicle_core::impl_ecntt_tests;
use icicle_core::impl_ecntt_tests;

impl_ecntt_tests!(ScalarField, CurveCfg);
}
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pub mod curve;
pub mod ecntt;
pub mod msm;
pub mod ntt;
pub mod polynomials;
pub mod vec_ops;
pub mod polynomials;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ pub(crate) mod tests {
use icicle_core::impl_ntt_tests;
use icicle_core::ntt::tests::*;
use serial_test::{parallel, serial};

impl_ntt_tests!(ScalarField);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) mod tests {
use crate::curve::{CurveCfg, ScalarField};

use icicle_core::ecntt::tests::*;
use icicle_core::impl_ecntt_tests;
use icicle_core::impl_ecntt_tests;

impl_ecntt_tests!(ScalarField, CurveCfg);
}
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pub mod curve;
pub mod ecntt;
pub mod msm;
pub mod ntt;
pub mod vec_ops;
pub mod polynomials;
pub mod vec_ops;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) mod tests {
use crate::curve::{CurveCfg, ScalarField};

use icicle_core::ecntt::tests::*;
use icicle_core::impl_ecntt_tests;
use icicle_core::impl_ecntt_tests;

impl_ecntt_tests!(ScalarField, CurveCfg);
}
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-curves/icicle-bn254/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pub mod curve;
pub mod ecntt;
pub mod msm;
pub mod ntt;
pub mod vec_ops;
pub mod polynomials;
pub mod vec_ops;
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-fields/icicle-babybear/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod field;
pub mod ntt;
pub mod vec_ops;
pub mod polynomials;
pub mod vec_ops;
8 changes: 4 additions & 4 deletions wrappers/rust_v3/icicle-fields/icicle-babybear/src/ntt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ pub(crate) mod tests {
impl_ntt_tests!(ScalarField);

// Tests against risc0 and plonky3
use super::{ExtensionField};
use super::ExtensionField;
use icicle_core::{
ntt::{initialize_domain, ntt_inplace, release_domain, NTTConfig, NTTInitDomainConfig, NTTDir},
traits::{FieldImpl, GenerateRandom}
ntt::{initialize_domain, ntt_inplace, release_domain, NTTConfig, NTTDir, NTTInitDomainConfig},
traits::{FieldImpl, GenerateRandom},
};
use icicle_runtime::{memory::HostSlice};
use icicle_runtime::memory::HostSlice;
use risc0_core::field::{
baby_bear::{Elem, ExtElem},
Elem as FieldElem, RootsOfUnity,
Expand Down
2 changes: 1 addition & 1 deletion wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod field;
pub mod ntt;
pub mod vec_ops;
pub mod polynomials;
pub mod vec_ops;
Loading

0 comments on commit cbb4620

Please sign in to comment.