Skip to content

Commit

Permalink
update rust msm example
Browse files Browse the repository at this point in the history
  • Loading branch information
ChickenLover committed Dec 12, 2024
1 parent 307f24b commit 674f2e5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
5 changes: 0 additions & 5 deletions examples/rust/msm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ edition = "2018"
icicle-runtime = { path = "../../../wrappers/rust/icicle-runtime" }
icicle-core = { path = "../../../wrappers/rust/icicle-core" }
icicle-bn254 = { path = "../../../wrappers/rust/icicle-curves/icicle-bn254" }
icicle-bls12-377 = { path = "../../../wrappers/rust/icicle-curves/icicle-bls12-377" }
clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bls12-377/cuda_backend",
"icicle-bls12-377/no_ecntt"
]

metal = ["icicle-runtime/metal_backend",
"icicle-bn254/metal_backend",
"icicle-bn254/no_ecntt",
"icicle-bls12-377/metal_backend",
"icicle-bls12-377/no_ecntt"
]
41 changes: 0 additions & 41 deletions examples/rust/msm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ use icicle_runtime::{
stream::IcicleStream,
};

// Using both bn254 and bls12-377 curves
use icicle_bls12_377::curve::{
CurveCfg as BLS12377CurveCfg, G1Projective as BLS12377G1Projective, ScalarCfg as BLS12377ScalarCfg,
};
use icicle_bn254::curve::{CurveCfg, G1Projective, G2CurveCfg, G2Projective, ScalarCfg};

use clap::Parser;
Expand Down Expand Up @@ -53,10 +49,6 @@ fn main() {
let g2_upper_points = G2CurveCfg::generate_random_affine_points(upper_size);
let upper_scalars = ScalarCfg::generate_random(upper_size);

println!("Generating random inputs on host for bls12377...");
let upper_points_bls12377 = BLS12377CurveCfg::generate_random_affine_points(upper_size);
let upper_scalars_bls12377 = BLS12377ScalarCfg::generate_random(upper_size);

for i in lower_bound..=upper_bound {
let log_size = i;
let size = 1 << log_size;
Expand All @@ -70,10 +62,6 @@ fn main() {
let g2_points = HostSlice::from_slice(&g2_upper_points[..size]);
let scalars = HostSlice::from_slice(&upper_scalars[..size]);

// Setting bls12377 points and scalars
let points_bls12377 = HostSlice::from_slice(&upper_points_bls12377[..size]);
let scalars_bls12377 = HostSlice::from_slice(&upper_scalars_bls12377[..size]);

println!("Configuring bn254 MSM...");
let mut msm_results = DeviceVec::<G1Projective>::device_malloc(1).unwrap();
let mut g2_msm_results = DeviceVec::<G2Projective>::device_malloc(1).unwrap();
Expand All @@ -86,30 +74,13 @@ fn main() {
g2_cfg.stream_handle = *g2_stream;
g2_cfg.is_async = true;

println!("Configuring bls12377 MSM...");
let mut msm_results_bls12377 = DeviceVec::<BLS12377G1Projective>::device_malloc(1).unwrap();
let mut stream_bls12377 = IcicleStream::create().unwrap();
let mut cfg_bls12377 = msm::MSMConfig::default();
cfg_bls12377.stream_handle = *stream_bls12377;
cfg_bls12377.is_async = true;

println!("Executing bn254 MSM on device...");
msm::msm(scalars, points, &cfg, &mut msm_results[..]).unwrap();
msm::msm(scalars, g2_points, &g2_cfg, &mut g2_msm_results[..]).unwrap();

println!("Executing bls12377 MSM on device...");
msm::msm(
scalars_bls12377,
points_bls12377,
&cfg_bls12377,
&mut msm_results_bls12377[..],
)
.unwrap();

println!("Moving results to host...");
let mut msm_host_result = vec![G1Projective::zero(); 1];
let mut g2_msm_host_result = vec![G2Projective::zero(); 1];
let mut msm_host_result_bls12377 = vec![BLS12377G1Projective::zero(); 1];

stream
.synchronize()
Expand All @@ -127,14 +98,6 @@ fn main() {
.unwrap();
println!("G2 bn254 result: {:#?}", g2_msm_host_result);

stream_bls12377
.synchronize()
.unwrap();
msm_results_bls12377
.copy_to_host(HostSlice::from_mut_slice(&mut msm_host_result_bls12377[..]))
.unwrap();
println!("bls12377 result: {:#?}", msm_host_result_bls12377);

println!("Cleaning up bn254...");
stream
.destroy()
Expand All @@ -143,10 +106,6 @@ fn main() {
.destroy()
.unwrap();

println!("Cleaning up bls12377...");
stream_bls12377
.destroy()
.unwrap();
println!("");
}
}

0 comments on commit 674f2e5

Please sign in to comment.