This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
forked from supranational/pasta-msm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hanting Zhang
committed
Dec 2, 2023
1 parent
c2e1370
commit 8a10540
Showing
5 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright Supranational LLC | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::time::Instant; | ||
|
||
use pasta_curves::group::ff::PrimeField; | ||
use pasta_msm::spmvm::double_pallas; | ||
|
||
pub fn generate_scalars<F: PrimeField>( | ||
len: usize, | ||
) -> Vec<F> { | ||
let mut rng = rand::thread_rng(); | ||
let scalars = (0..len) | ||
.map(|_| F::random(&mut rng)) | ||
.collect::<Vec<_>>(); | ||
|
||
scalars | ||
} | ||
|
||
/// cargo run --release --example spmvm | ||
fn main() { | ||
let npow: usize = std::env::var("NPOW") | ||
.unwrap_or("23".to_string()) | ||
.parse() | ||
.unwrap(); | ||
let n = 1usize << npow; | ||
|
||
let mut scalars = generate_scalars(n); | ||
|
||
let start = Instant::now(); | ||
let double_scalars = scalars.iter().map(|x| x + x).collect::<Vec<_>>(); | ||
println!("cpu took: {:?}", start.elapsed()); | ||
|
||
let start = Instant::now(); | ||
double_pallas(&mut scalars); | ||
println!("gpu took: {:?}", start.elapsed()); | ||
|
||
assert_eq!(double_scalars, scalars); | ||
println!("success!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use pasta_curves::pallas; | ||
|
||
pub fn sparse_matrix_mul_pallas(scalars: &mut [pallas::Scalar]) { | ||
extern "C" { | ||
fn spmvm_pallas( | ||
scalars: *mut pallas::Scalar, | ||
nscalars: usize, | ||
) -> sppark::Error; | ||
} | ||
|
||
let nscalars = scalars.len(); | ||
let err = unsafe { | ||
spmvm_pallas( | ||
scalars.as_mut_ptr(), | ||
nscalars, | ||
) | ||
}; | ||
if err.code != 0 { | ||
panic!("{}", String::from(err)); | ||
} | ||
} |