arkworks-rs / snark

Interfaces for Relations and SNARKs for these relations
https://www.arkworks.rs
Apache License 2.0
770 stars 207 forks source link

CUDA Scalar Mul #302

Closed jon-chuang closed 3 years ago

jon-chuang commented 3 years ago

Exposes single function cpu_gpu_scalar_mul

impl<G: AffineCurve> GPUScalarMulSlice<G> for [G] {
    fn cpu_gpu_scalar_mul(
        &mut self,
        exps_h: &[<<G as AffineCurve>::ScalarField as PrimeField>::BigInt],
        cuda_group_size: usize,
        // size of the batch for cpu scalar mul
        cpu_chunk_size: usize,
    ) {
        if accel::Device::init() && cfg!(feature = "gpu") {
            <G as AffineCurve>::Projective::cpu_gpu_static_partition_run_kernel(
                self,
                exps_h,
                cuda_group_size,
                cpu_chunk_size,
            );
        } else {
            let mut exps_mut = exps_h.to_vec();
            cfg_chunks_mut!(self, cpu_chunk_size)
                .zip(cfg_chunks_mut!(exps_mut, cpu_chunk_size))
                .for_each(|(b, s)| {
                    b[..].batch_scalar_mul_in_place(&mut s[..], 4);
                });
        }
    }
}