mirror of
https://github.com/pseXperiments/cuda-sumcheck.git
synced 2026-01-08 23:18:00 -05:00
Impl From<F: PrimeField> trait for FieldBinding
This commit is contained in:
@@ -4,6 +4,7 @@ use cudarc::driver::{CudaDevice, LaunchConfig, DeviceRepr, DriverError, LaunchAs
|
||||
use cudarc::nvrtc::Ptx;
|
||||
use ff::{Field, PrimeField};
|
||||
use halo2curves::bn256::Fr;
|
||||
use itertools::Itertools;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
@@ -17,6 +18,19 @@ impl Default for FieldBinding {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> From<F> for FieldBinding {
|
||||
fn from(value: F) -> Self {
|
||||
let repr = value.to_repr();
|
||||
let bytes = repr.as_ref();
|
||||
let data = bytes.chunks(8).map(|bytes| {
|
||||
u64::from_le_bytes(bytes.try_into().unwrap())
|
||||
}).collect_vec();
|
||||
FieldBinding {
|
||||
data: data.try_into().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper struct for APIs using GPU
|
||||
#[derive(Default)]
|
||||
pub struct GPUApiWrapper<F: Field>(PhantomData<F>);
|
||||
|
||||
Reference in New Issue
Block a user