pub struct DuplexSpongeGpu { /* private fields */ }Expand description
GPU-accelerated duplex sponge that maintains state on both host and device.
The host-side state uses DeviceSpongeState which matches the behavior of
DuplexSponge from openvm_stark_backend (and p3_challenger::DuplexChallenger).
The device-side state is stored in GPU memory for CUDA kernel operations.
§State Synchronization
The host and device states are independent and must be explicitly synchronized:
- Use
sync_h2dto copy host state to device before GPU operations - Use
sync_d2hto copy device state back to host after GPU operations
§Usage Example
let mut sponge = DuplexSpongeGpu::default();
// Do some host operations
sponge.observe(some_value);
let challenge = sponge.sample();
// Sync to device before GPU grinding
sponge.sync_h2d()?;
// ... GPU grinding kernel runs ...
// Sync back after GPU modifies state
sponge.sync_d2h()?;
// Continue with host operations
let next_challenge = sponge.sample();Implementations§
Source§impl DuplexSpongeGpu
impl DuplexSpongeGpu
Sourcepub fn is_device_allocated(&self) -> bool
pub fn is_device_allocated(&self) -> bool
Returns true if the device buffer has been allocated.
Sourcepub fn sync_h2d(
&mut self,
device_ctx: &GpuDeviceCtx,
) -> Result<(), MemCopyError>
pub fn sync_h2d( &mut self, device_ctx: &GpuDeviceCtx, ) -> Result<(), MemCopyError>
Synchronize state from host to device (H2D memcpy).
Call this before running GPU kernels that read/modify the sponge state.
This converts from DuplexChallenger’s representation (with buffered input/output)
to DeviceSpongeState’s representation (with indices pointing into state).
Sourcepub fn device_ptr(&self) -> Option<*const DeviceSpongeState>
pub fn device_ptr(&self) -> Option<*const DeviceSpongeState>
Get a pointer to the device state buffer.
Returns None if the device buffer hasn’t been allocated yet.
Call sync_h2d to allocate and initialize the device buffer.
Sourcepub fn device_ptr_mut(&mut self) -> Option<*mut DeviceSpongeState>
pub fn device_ptr_mut(&mut self) -> Option<*mut DeviceSpongeState>
Get a mutable pointer to the device state buffer.
Returns None if the device buffer hasn’t been allocated yet.
Call sync_h2d to allocate and initialize the device buffer.
Sourcepub fn grind_gpu(
&mut self,
bits: usize,
device_ctx: &GpuDeviceCtx,
) -> Result<F, GrindError>
pub fn grind_gpu( &mut self, bits: usize, device_ctx: &GpuDeviceCtx, ) -> Result<F, GrindError>
Perform GPU-accelerated grinding to find a proof-of-work witness.
This syncs state to device, runs the grinding kernel, and updates the host state with the witness.
§Arguments
bits- Number of bits that must be zero in the sampled value
§Returns
The PoW witness value that satisfies sample_bits(bits) == 0 after observing it.
§Note
After this call, the host state will have observed the witness and sampled,
matching the state after calling check_witness(bits, witness).
Trait Implementations§
Source§impl Clone for DuplexSpongeGpu
impl Clone for DuplexSpongeGpu
Source§impl Debug for DuplexSpongeGpu
impl Debug for DuplexSpongeGpu
Source§impl Default for DuplexSpongeGpu
impl Default for DuplexSpongeGpu
Source§impl FiatShamirTranscript<BabyBearPoseidon2Config> for DuplexSpongeGpu
impl FiatShamirTranscript<BabyBearPoseidon2Config> for DuplexSpongeGpu
fn observe(&mut self, value: F)
fn sample(&mut self) -> F
Source§fn observe_commit(&mut self, digest: Digest)
fn observe_commit(&mut self, digest: Digest)
Digest to array of F is required.fn observe_ext(&mut self, value: <SC as StarkProtocolConfig>::EF)
fn sample_ext(&mut self) -> <SC as StarkProtocolConfig>::EF
Source§fn sample_bits(&mut self, bits: usize) -> u64
fn sample_bits(&mut self, bits: usize) -> u64
Source§fn check_witness(
&mut self,
bits: usize,
witness: <SC as StarkProtocolConfig>::F,
) -> bool
fn check_witness( &mut self, bits: usize, witness: <SC as StarkProtocolConfig>::F, ) -> bool
witness into the transcript and accepts iff the
next Self::sample_bits is zero (probability ≈ 2^{-bits} for a random witness, so
Self::grind tries ≈ 2^bits witnesses to find one). Read moreSource§fn grind(&mut self, bits: usize) -> <SC as StarkProtocolConfig>::F
fn grind(&mut self, bits: usize) -> <SC as StarkProtocolConfig>::F
w such that Self::check_witness(bits, w) holds, by
brute force over the base field.Source§impl GpuFiatShamirTranscript<BabyBearPoseidon2Config> for DuplexSpongeGpu
impl GpuFiatShamirTranscript<BabyBearPoseidon2Config> for DuplexSpongeGpu
Source§fn grind_gpu(
&mut self,
bits: usize,
device_ctx: &GpuDeviceCtx,
) -> Result<F, GrindError>
fn grind_gpu( &mut self, bits: usize, device_ctx: &GpuDeviceCtx, ) -> Result<F, GrindError>
Auto Trait Implementations§
impl Freeze for DuplexSpongeGpu
impl RefUnwindSafe for DuplexSpongeGpu
impl Send for DuplexSpongeGpu
impl Sync for DuplexSpongeGpu
impl Unpin for DuplexSpongeGpu
impl UnsafeUnpin for DuplexSpongeGpu
impl UnwindSafe for DuplexSpongeGpu
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more