Skip to content

Commit

Permalink
chore(fflonk): fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
saitima committed Oct 24, 2024
1 parent 041abd6 commit 7deafa9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 53 deletions.
2 changes: 1 addition & 1 deletion crates/fflonk/src/allocator/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct PoolAllocator;

impl DeviceAllocator for PoolAllocator {
fn allocate(&self, layout: std::alloc::Layout) -> CudaResult<std::ptr::NonNull<[u8]>> {
unimplemented!("Pool allocator can't do static allocation/deallocation")
unimplemented!("Pool allocator can't do static allocation/deallocation")
}

fn deallocate(&self, ptr: std::ptr::NonNull<u8>, layout: std::alloc::Layout) {
Expand Down
6 changes: 1 addition & 5 deletions crates/fflonk/src/relations/copy_perm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ where

// get monomial finally
ntt::bitreverse(&mut grand_prod_bitreversed, stream)?;
ntt::inplace_coset_ifft_for_gen_on(
&mut grand_prod_bitreversed,
&coset_shift_inv,
stream,
)?;
ntt::inplace_coset_ifft_for_gen_on(&mut grand_prod_bitreversed, &coset_shift_inv, stream)?;

Ok(Poly::from_buffer(grand_prod_bitreversed))
}
1 change: 0 additions & 1 deletion crates/gpu-ffi/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ pub fn raw_evaluate(
return Err(GpuError::SchedulingErr);
}


Ok(())
}

Expand Down
36 changes: 14 additions & 22 deletions crates/gpu-ffi/src/bindings_extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ pub fn call_host_fn<F: FnMut()>(stream: bc_stream, cb: &F) -> Result<(), GpuErro
let callback_data = cb as *const _ as *mut ::std::os::raw::c_void;

unsafe {
if bc_launch_host_fn(
stream,
Some(callback_wrapper::<F>),
callback_data,
) != 0
{
if bc_launch_host_fn(stream, Some(callback_wrapper::<F>), callback_data) != 0 {
return Err(GpuError::SchedulingErr);
}
}
Expand All @@ -33,38 +28,28 @@ pub fn malloc_from_pool_async(
Ok(())
}

pub fn device_disable_peer_access(
device_id: usize,
) -> Result<(), GpuError> {
pub fn device_disable_peer_access(device_id: usize) -> Result<(), GpuError> {
if unsafe { bc_device_disable_peer_access(device_id as i32) } != 0 {
return Err(GpuError::DevicePeerAccessErr);
}
Ok(())
}

pub fn device_enable_peer_access(
device_id: i32,
) -> Result<(), GpuError> {
pub fn device_enable_peer_access(device_id: i32) -> Result<(), GpuError> {
if unsafe { bc_device_enable_peer_access(device_id) } != 0 {
return Err(GpuError::DevicePeerAccessErr);
}
Ok(())
}

pub fn mem_pool_disable_peer_access(
pool: bc_mem_pool,
device_id: usize,
) -> Result<(), GpuError> {
pub fn mem_pool_disable_peer_access(pool: bc_mem_pool, device_id: usize) -> Result<(), GpuError> {
if unsafe { bc_mem_pool_disable_peer_access(pool, device_id as i32) } != 0 {
return Err(GpuError::MemPoolPeerAccessErr);
}
Ok(())
}

pub fn mem_pool_enable_peer_access(
pool: bc_mem_pool,
device_id: i32,
) -> Result<(), GpuError> {
pub fn mem_pool_enable_peer_access(pool: bc_mem_pool, device_id: i32) -> Result<(), GpuError> {
if unsafe { bc_mem_pool_enable_peer_access(pool, device_id) } != 0 {
return Err(GpuError::MemPoolPeerAccessErr);
}
Expand Down Expand Up @@ -237,7 +222,7 @@ impl bc_event {
}
}

pub fn sync(self) -> Result<(), GpuError> {
pub fn sync(self) -> Result<(), GpuError> {
if unsafe { bc_event_synchronize(self) } != 0 {
return Err(GpuError::EventSyncErr);
}
Expand All @@ -257,7 +242,14 @@ impl ntt_configuration {
) -> Self {
let log_extension_degree = log_2(lde_factor as usize);
let coset_index = bitreverse(coset_index, log_extension_degree as usize);
let mut this = Self::new(ctx, inputs as *mut c_void, outputs, log_values_count, false, false);
let mut this = Self::new(
ctx,
inputs as *mut c_void,
outputs,
log_values_count,
false,
false,
);
this.coset_index = coset_index as u32;
this.log_extension_degree = log_extension_degree;

Expand Down
4 changes: 2 additions & 2 deletions crates/gpu-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
pub mod error;
pub mod utils;

pub mod other;
pub mod bindings;
pub mod bindings_extra;
pub mod other;
pub mod wrapper;

pub use other::*;
pub use bindings::*;
pub use bindings_extra::*;
pub use other::*;

pub use error::*;
pub use utils::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/gpu-ffi/src/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ pub fn raw_msm(ctx: &GpuContext, d_scalars: *mut c_void, len: usize) -> Result<V
let mut result = vec![0u8; result_buf_len];

copy_and_free(&mut result[..], d_result, ctx.get_d2h_stream())?;

Ok(result)
}
22 changes: 7 additions & 15 deletions crates/gpu-ffi/src/ntt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn ntt(
let d_scalars = alloc_and_copy(ctx, scalars, ctx.get_h2d_stream())?;
ctx.wait_h2d()?;

raw_ntt(ctx, d_scalars, len, bits_reversed, inverse,)
raw_ntt(ctx, d_scalars, len, bits_reversed, inverse)
}

pub fn raw_ntt(
Expand All @@ -20,7 +20,7 @@ pub fn raw_ntt(
bits_reversed: bool,
inverse: bool,
) -> Result<(), GpuError> {
let log_scalars_count = log_2(len/FIELD_ELEMENT_LEN);
let log_scalars_count = log_2(len / FIELD_ELEMENT_LEN);
let cfg = ntt_configuration::new(
ctx,
d_scalars,
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn ifft_then_msm(
h2d_finished.record(ctx.get_h2d_stream())?;
ctx.get_exec_stream().wait(h2d_finished)?;

raw_ntt(ctx, d_scalars, len, bits_reversed, true,)?;
raw_ntt(ctx, d_scalars, len, bits_reversed, true)?;
let result = raw_msm(ctx, d_scalars, len)?;

let exec_finished = bc_event::new()?;
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn raw_coset_ntt(
coset_idx: usize,
inverse: bool,
) -> Result<(), GpuError> {
let log_scalars_count = log_2(len/FIELD_ELEMENT_LEN);
let log_scalars_count = log_2(len / FIELD_ELEMENT_LEN);
let mut cfg = ntt_configuration::new_for_lde(
ctx,
d_scalars,
Expand Down Expand Up @@ -171,11 +171,7 @@ pub fn lde(
Ok(result)
}

pub fn fft(
ctx: &GpuContext,
scalars: &mut [u8],
bits_reversed: bool,
) -> Result<(), GpuError> {
pub fn fft(ctx: &GpuContext, scalars: &mut [u8], bits_reversed: bool) -> Result<(), GpuError> {
ntt(ctx, scalars, bits_reversed, false)
}

Expand Down Expand Up @@ -214,7 +210,7 @@ pub fn multi_ntt(
h2d_finished.record(ctx.get_h2d_stream())?;
ctx.get_exec_stream().wait(h2d_finished)?;

raw_ntt(ctx, d_scalars, len, bits_reversed, inverse)?;
raw_ntt(ctx, d_scalars, len, bits_reversed, inverse)?;

let exec_finished = bc_event::new()?;
exec_finished.record(ctx.get_exec_stream())?;
Expand All @@ -227,10 +223,6 @@ pub fn multi_ntt(
Ok(())
}

pub fn ifft(
ctx: &GpuContext,
scalars: &mut [u8],
bits_reversed: bool,
) -> Result<(), GpuError> {
pub fn ifft(ctx: &GpuContext, scalars: &mut [u8], bits_reversed: bool) -> Result<(), GpuError> {
ntt(ctx, scalars, bits_reversed, true)
}
8 changes: 3 additions & 5 deletions crates/gpu-ffi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn log_2(num: usize) -> u32 {
pow
}


#[inline(always)]
pub fn bitreverse(n: usize, l: usize) -> usize {
let mut r = n.reverse_bits();
Expand All @@ -27,7 +26,6 @@ pub fn bitreverse(n: usize, l: usize) -> usize {
r
}


// pub fn decode_projective_point<E: Engine>(encoding: [Vec<u8>; 3]) -> E::G1 {
// let [encoding_x, encoding_y, encoding_z] = encoding;
// let mut repr = <<E::G1 as CurveProjective>::Base as PrimeField>::Repr::default();
Expand Down Expand Up @@ -64,7 +62,7 @@ pub fn bitreverse(n: usize, l: usize) -> usize {
// for _ in 0..num_chunks {
// let (current_bases, rest) = bases.split_at(chunk_size);
// bases = rest;

// let (mut current_encoding_x, rest) = encoding_x.split_at(chunk_size * 32);
// encoding_x = rest;
// let (mut current_encoding_y, rest) = encoding_y.split_at(chunk_size * 32);
Expand Down Expand Up @@ -95,9 +93,9 @@ pub fn bitreverse(n: usize, l: usize) -> usize {
// [final_encoding_x, final_encoding_y]
// }

// pub fn decode_scalars<E: Engine>(encoding: &[u8]) -> Vec<E::Fr> {
// pub fn decode_scalars<E: Engine>(encoding: &[u8]) -> Vec<E::Fr> {
// let len = encoding.len() / 32;
// let mut result = vec![E::Fr::zero(); len];
// let mut result = vec![E::Fr::zero(); len];
// unsafe{std::ptr::copy(encoding.as_ptr() as *const E::Fr, result.as_mut_ptr(), len)};
// result
// }
Expand Down
2 changes: 1 addition & 1 deletion crates/gpu-ffi/src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl GpuContext {
if unsafe { ntt_set_up() } != 0 {
return Err(GpuError::CreateContextErr);
}

Ok(Self {
device_id: device_id,
mem_pool: mem_pool,
Expand Down

0 comments on commit 7deafa9

Please sign in to comment.