From 417decc5d0897d7d3677ad8bd01afeab75dc3220 Mon Sep 17 00:00:00 2001 From: administrator Date: Sun, 3 Mar 2024 19:07:36 +0200 Subject: [PATCH] refactor pre-compute --- src/ingo_msm/msm_api.rs | 4 ++-- src/ingo_msm/msm_cfg.rs | 6 ++++-- tests/integration_msm.rs | 39 +++++++++++++++++++++++++++------------ tests/msm/mod.rs | 3 ++- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/ingo_msm/msm_api.rs b/src/ingo_msm/msm_api.rs index dcdaeee..6f3001c 100755 --- a/src/ingo_msm/msm_api.rs +++ b/src/ingo_msm/msm_api.rs @@ -33,8 +33,8 @@ pub struct MSMResult { pub result_label: u32, } -//pub const PRECOMPUTE_FACTOR_BASE: u32 = 1; -//pub const PRECOMPUTE_FACTOR: u32 = 8; +pub const PRECOMPUTE_FACTOR_BASE: u32 = 1; +pub const PRECOMPUTE_FACTOR: u32 = 7; impl DriverPrimitive for MSMClient { /// Creates a new [`MSMClient`]. diff --git a/src/ingo_msm/msm_cfg.rs b/src/ingo_msm/msm_cfg.rs index f8be774..e16f6b7 100644 --- a/src/ingo_msm/msm_cfg.rs +++ b/src/ingo_msm/msm_cfg.rs @@ -56,8 +56,10 @@ fn msm_bls377_dma_cfg() -> MSMConfig { result_point_size: 144, point_size: Some(96), scalar_size: 32, - dma_scalars_addr: Some(0x0000010000000000), //dma_scalars_addr: Some(0x0000010000000000), - dma_points_addr: Some(0x0000000000000000), // dma_points_addr: Some(0x0000000000000000), + dma_scalars_addr: Some(0x0000_0200_0000_0000), + dma_points_addr: Some(0x0000_0100_0000_0000), + // dma_scalars_addr: Some(0x0000_0100_0000_0000), + // dma_points_addr: Some(0x0000_0000_0000_0000), } } diff --git a/tests/integration_msm.rs b/tests/integration_msm.rs index 1b4425e..ab1aec8 100644 --- a/tests/integration_msm.rs +++ b/tests/integration_msm.rs @@ -24,7 +24,8 @@ fn load_msm_binary_test() -> Result<(), Box> { //let id = env::var("ID").unwrap_or_else(|_| 1.to_string()); let id = 0.to_string(); // let bin_file = env::var("FILENAME").unwrap(); - let bin_file = "/home/administrator/users/eli/fpga-bin/msm-bls377/user.bin"; + //let bin_file = "/home/administrator/users/eli/fpga-bin/msm-bls377/user.bin"; + let bin_file = "/home/administrator/users/eli/fpga-bin/msm-bls377/msmfeb20.bin"; let msm_size = env::var("MSM_SIZE") .unwrap_or_else(|_| 8192.to_string()) @@ -44,6 +45,9 @@ fn load_msm_binary_test() -> Result<(), Box> { dclient, ); + let precompute_factor: u32 = driver.get_precompute_factor().into(); + println!("precompute_factor = {}", precompute_factor); + log::info!("Start to loading binary file..."); let buf = read_binary_file(&bin_file)?; log::info!("Buffer size: {:?}", buf.len()); @@ -73,7 +77,7 @@ fn load_msm_binary_test() -> Result<(), Box> { let (points, scalars, msm_result, results) = //msm::input_generator_bls12_381(msm_size as usize, PRECOMPUTE_FACTOR_BASE); - msm::input_generator_bls12_377(msm_size as usize, driver.get_precompute_factor().into()); + msm::input_generator_bls12_377(msm_size as usize, precompute_factor); log::info!("Starting to initialize task and set number of elements: "); let msm_params = MSMParams { @@ -173,7 +177,7 @@ fn msm_bls12_381_test() -> Result<(), Box> { let dclient = DriverClient::new(&id, DriverConfig::driver_client_cfg(CardType::C1100)); let driver = MSMClient::new( MSMInit { - mem_type: PointMemoryType::DMA, + mem_type: PointMemoryType::DMA, curve: Curve::BLS381, }, dclient, @@ -298,8 +302,8 @@ impl Display for RunResults { fn msm_bls12_377_precompute_test() -> Result<(), Box> { env_logger::try_init().expect("Invalid logger initialisation"); let id = env::var("ID").unwrap_or_else(|_| 0.to_string()); - let low_exp: u32 = 1; - let max_exp: u32 = 1; + let low_exp: u32 = 10; + let max_exp: u32 = 10; let base = 2; let mut points: Vec = Vec::new(); @@ -333,6 +337,7 @@ fn msm_bls12_377_precompute_test() -> Result<(), Box> { dclient, ); driver.driver_client.reset()?; + driver.get_api(); log::info!("Checking MSM core is ready: "); driver.is_msm_engine_ready()?; @@ -419,9 +424,11 @@ fn msm_bls12_377_precompute_test() -> Result<(), Box> { fn msm_bls12_377_precompute_max_test() -> Result<(), Box> { env_logger::try_init().expect("Invalid logger initialisation"); let id = env::var("ID").unwrap_or_else(|_| 0.to_string()); - let msm_size = 67108864; //8388608; // 1048576; //67108864; //67108864; // 2**26 + let msm_size = 1024; //67108864; //8388608; // 1048576; //67108864; //67108864; // 2**26 - let bin_file = "/home/administrator/users/eli/fpga-bin/msm-bls377/user.bin"; + //let bin_file = "/home/administrator/users/eli/fpga-bin/msm-bls377/user.bin"; + let bin_file = "/home/administrator/users/eli/fpga-bin/msm-bls377/msmfeb20.bin"; + /* log::debug!("Timer start to generate test data"); let start_gen = Instant::now(); @@ -430,6 +437,7 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box> let duration_gen = start_gen.elapsed(); log::debug!("Time elapsed in generate test data is: {:?}", duration_gen); */ + log::info!("Create Driver API instance"); let dclient = DriverClient::new(&id, DriverConfig::driver_client_cfg(CardType::C1100)); let driver = MSMClient::new( @@ -474,13 +482,13 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box> driver.initialize(msm_params)?; println!("is_msm_engine_ready = {}", driver.is_msm_engine_ready()?); - // driver.start_process(None)?; - driver.start_process(Some(1))?; + driver.start_process(None)?; + //driver.start_process(Some(1))?; println!( "nof_pending_tasks_in_queue = {}", driver.nof_pending_tasks_in_queue()? ); - for i in 1..25 { + /* for i in 1..25 { driver.start_process(Some(1))?; println!( "{} - is_msm_engine_ready = {}", @@ -494,7 +502,7 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box> ); } } - + */ driver.driver_client.firewalls_status(); driver.task_label()?; driver.nof_elements()?; @@ -504,7 +512,8 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box> let start_set_data = Instant::now(); let start_full = Instant::now(); - let precompute_factor: u32 = driver.get_precompute_factor().into(); + let precompute_factor: u32 = driver.get_precompute_factor().into(); + println!("precompute_factor = {}", precompute_factor); log::debug!("Timer start to generate test data"); let start_gen = Instant::now(); @@ -547,6 +556,12 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box> sleep(Duration::from_secs(1)); Ok(()) } + + + + + + /* #[test] fn msm_bls12_381_precompute_test() -> Result<(), Box> { diff --git a/tests/msm/mod.rs b/tests/msm/mod.rs index 5e3061b..40095ff 100755 --- a/tests/msm/mod.rs +++ b/tests/msm/mod.rs @@ -14,7 +14,7 @@ use ark_std::UniformRand; use ::std::ops::{Add, Mul}; use std::{fmt::Display, time::Duration}; -const SCALAR_SIZE_BLS377: u32 = 32; // TBD 256 / precompue +const SCALAR_SIZE_BLS377: u32 = 37; // TBD 256 / precompue const SCALAR_SIZE_BLS381: u32 = 32; const SCALAR_SIZE_BN254: u32 = 32; @@ -167,6 +167,7 @@ pub fn result_check_bls12_377( ) } else { log::debug!("Expected MSM result: {:}\n", msm_res.into_affine()); + println!("{} {}",point.to_string(), msm_res.into_affine().to_string()); ( point.is_on_curve(), point.to_string() == msm_res.into_affine().to_string(),