Skip to content

Commit

Permalink
feat(gpu): env var for disabling gpu validity check (zkcrypto#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank authored and dignifiedquire committed Dec 2, 2019
1 parent 00122ae commit 459a30b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ lazy_static::lazy_static! {
static ref GPU_FFT_SUPPORTED: Mutex<Option<bool>> = { Mutex::new(None) };
}

use std::env;
pub fn gpu_fft_supported<E>(log_d: u32) -> gpu::GPUResult<gpu::FFTKernel<E>>
where
E: Engine,
Expand All @@ -567,6 +568,12 @@ where
let rng = &mut rand::thread_rng();
let mut kern = gpu::FFTKernel::create(1 << log_d)?;

// Checking the correctness of GPU results can be time consuming. User can disable this
// feature using BELLMAN_GPU_NO_CHECK flag.
if env::var("BELLMAN_GPU_NO_CHECK").is_ok() {
return Ok(kern);
}

let res = {
let mut supported = GPU_FFT_SUPPORTED.lock().unwrap();
if let Some(res) = *supported {
Expand Down
8 changes: 8 additions & 0 deletions src/multiexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ lazy_static::lazy_static! {
static ref GPU_MULTIEXP_SUPPORTED: Mutex<Option<bool>> = { Mutex::new(None) };
}

use std::env;
pub fn gpu_multiexp_supported<E>(n: usize) -> gpu::GPUResult<gpu::MultiexpKernel<E>>
where
E: paired::Engine,
Expand All @@ -363,6 +364,13 @@ where
let pool = Worker::new();
let rng = &mut rand::thread_rng();
let mut kern = Some(gpu::MultiexpKernel::<E>::create(chunk_size)?);

// Checking the correctness of GPU results can be time consuming. User can disable this
// feature using BELLMAN_GPU_NO_CHECK flag.
if env::var("BELLMAN_GPU_NO_CHECK").is_ok() {
return Ok(kern.unwrap());
}

let res = {
let mut supported = GPU_MULTIEXP_SUPPORTED.lock().unwrap();
if let Some(res) = *supported {
Expand Down

0 comments on commit 459a30b

Please sign in to comment.