Skip to content

Commit

Permalink
refactor pre-compute
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli-Pinchover committed Mar 3, 2024
1 parent 79101e6 commit 417decc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/ingo_msm/msm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MSMInit, MSMParams, MSMInput, MSMResult> for MSMClient {
/// Creates a new [`MSMClient`].
Expand Down
6 changes: 4 additions & 2 deletions src/ingo_msm/msm_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
39 changes: 27 additions & 12 deletions tests/integration_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fn load_msm_binary_test() -> Result<(), Box<dyn std::error::Error>> {
//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())
Expand All @@ -44,6 +45,9 @@ fn load_msm_binary_test() -> Result<(), Box<dyn std::error::Error>> {
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());
Expand Down Expand Up @@ -73,7 +77,7 @@ fn load_msm_binary_test() -> Result<(), Box<dyn std::error::Error>> {

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 {
Expand Down Expand Up @@ -173,7 +177,7 @@ fn msm_bls12_381_test() -> Result<(), Box<dyn std::error::Error>> {
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,
Expand Down Expand Up @@ -298,8 +302,8 @@ impl Display for RunResults {
fn msm_bls12_377_precompute_test() -> Result<(), Box<dyn std::error::Error>> {
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<u8> = Vec::new();
Expand Down Expand Up @@ -333,6 +337,7 @@ fn msm_bls12_377_precompute_test() -> Result<(), Box<dyn std::error::Error>> {
dclient,
);
driver.driver_client.reset()?;
driver.get_api();

log::info!("Checking MSM core is ready: ");
driver.is_msm_engine_ready()?;
Expand Down Expand Up @@ -419,9 +424,11 @@ fn msm_bls12_377_precompute_test() -> Result<(), Box<dyn std::error::Error>> {
fn msm_bls12_377_precompute_max_test() -> Result<(), Box<dyn std::error::Error>> {
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();
Expand All @@ -430,6 +437,7 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box<dyn std::error::Error>>
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(
Expand Down Expand Up @@ -474,13 +482,13 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box<dyn std::error::Error>>
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 = {}",
Expand All @@ -494,7 +502,7 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box<dyn std::error::Error>>
);
}
}

*/
driver.driver_client.firewalls_status();
driver.task_label()?;
driver.nof_elements()?;
Expand All @@ -504,7 +512,8 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box<dyn std::error::Error>>
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();
Expand Down Expand Up @@ -547,6 +556,12 @@ fn msm_bls12_377_precompute_max_test() -> Result<(), Box<dyn std::error::Error>>
sleep(Duration::from_secs(1));
Ok(())
}






/*
#[test]
fn msm_bls12_381_precompute_test() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
3 changes: 2 additions & 1 deletion tests/msm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit 417decc

Please sign in to comment.