openvm_recursion_circuit/cuda/
vk.rs

1use itertools::Itertools;
2use openvm_cuda_common::{copy::MemCopyH2D, d_buffer::DeviceBuffer, stream::GpuDeviceCtx};
3use openvm_stark_backend::{keygen::types::MultiStarkVerifyingKey, SystemParams};
4use openvm_stark_sdk::config::baby_bear_poseidon2::{BabyBearPoseidon2Config, Digest};
5
6use crate::cuda::types::AirData;
7
8/*
9 * Tracegen information (i.e. records) on a GPU device. Each field should
10 * be computable as soon as the verifier circuit has access to the child
11 * proof's verifying key. Only one of these will be generated per verifier
12 * circuit, i.e. regardless of the number of proofs.
13 */
14pub struct VerifyingKeyGpu {
15    pub cpu: MultiStarkVerifyingKey<BabyBearPoseidon2Config>,
16    pub per_air: DeviceBuffer<AirData>,
17    pub system_params: SystemParams,
18    pub pre_hash: Digest,
19}
20
21impl VerifyingKeyGpu {
22    pub fn new(
23        vk: &MultiStarkVerifyingKey<BabyBearPoseidon2Config>,
24        device_ctx: &GpuDeviceCtx,
25    ) -> Self {
26        let per_air = vk
27            .inner
28            .per_air
29            .iter()
30            .map(|vk| AirData {
31                num_cached: vk.num_cached_mains(),
32                num_interactions_per_row: vk.num_interactions(),
33                total_width: vk.params.width.total_width(),
34                has_preprocessed: vk.preprocessed_data.is_some(),
35            })
36            .collect_vec()
37            .to_device_on(device_ctx)
38            .unwrap();
39        Self {
40            cpu: vk.clone(),
41            per_air,
42            system_params: vk.inner.params.clone(),
43            pre_hash: vk.pre_hash,
44        }
45    }
46}