Use GPU flag
This commit is contained in:
parent
4d1d4a9d59
commit
de506ba074
|
@ -144,3 +144,7 @@ void disable_wal(char *db_path);
|
||||||
bool has_cuda(void);
|
bool has_cuda(void);
|
||||||
|
|
||||||
bool has_metal(void);
|
bool has_metal(void);
|
||||||
|
|
||||||
|
bool has_gpu(void);
|
||||||
|
|
||||||
|
void use_gpu(bool v);
|
||||||
|
|
|
@ -671,3 +671,13 @@ pub unsafe extern "C" fn has_cuda() -> bool {
|
||||||
pub unsafe extern "C" fn has_metal() -> bool {
|
pub unsafe extern "C" fn has_metal() -> bool {
|
||||||
crate::has_metal()
|
crate::has_metal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn has_gpu() -> bool {
|
||||||
|
crate::has_gpu()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn use_gpu(v: bool) {
|
||||||
|
crate::use_gpu(v)
|
||||||
|
}
|
||||||
|
|
20
src/chain.rs
20
src/chain.rs
|
@ -34,7 +34,7 @@ use zcash_primitives::zip32::ExtendedFullViewingKey;
|
||||||
use crate::gpu::cuda::{CudaProcessor, CUDA_CONTEXT};
|
use crate::gpu::cuda::{CudaProcessor, CUDA_CONTEXT};
|
||||||
#[cfg(feature = "apple_metal")]
|
#[cfg(feature = "apple_metal")]
|
||||||
use crate::gpu::metal::MetalProcessor;
|
use crate::gpu::metal::MetalProcessor;
|
||||||
use crate::gpu::trial_decrypt;
|
use crate::gpu::{trial_decrypt, USE_GPU};
|
||||||
|
|
||||||
pub static DOWNLOADED_BYTES: AtomicUsize = AtomicUsize::new(0);
|
pub static DOWNLOADED_BYTES: AtomicUsize = AtomicUsize::new(0);
|
||||||
pub static TRIAL_DECRYPTIONS: AtomicUsize = AtomicUsize::new(0);
|
pub static TRIAL_DECRYPTIONS: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
@ -417,14 +417,20 @@ impl DecryptNode {
|
||||||
network: &Network,
|
network: &Network,
|
||||||
blocks: Vec<CompactBlock>,
|
blocks: Vec<CompactBlock>,
|
||||||
) -> Vec<DecryptedBlock> {
|
) -> Vec<DecryptedBlock> {
|
||||||
#[cfg(feature = "cuda")]
|
let use_gpu = USE_GPU.load(Ordering::Acquire);
|
||||||
return self.cuda_decrypt_blocks(network, blocks);
|
log::info!("use gpu = {}", use_gpu);
|
||||||
|
if use_gpu {
|
||||||
|
#[cfg(feature = "cuda")]
|
||||||
|
return self.cuda_decrypt_blocks(network, blocks);
|
||||||
|
|
||||||
#[cfg(feature = "apple_metal")]
|
#[cfg(feature = "apple_metal")]
|
||||||
return self.metal_decrypt_blocks(network, blocks);
|
return self.metal_decrypt_blocks(network, blocks);
|
||||||
|
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
self.decrypt_blocks_soft(network, blocks)
|
self.decrypt_blocks_soft(network, blocks)
|
||||||
|
} else {
|
||||||
|
self.decrypt_blocks_soft(network, blocks)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decrypt_blocks_soft(
|
pub fn decrypt_blocks_soft(
|
||||||
|
|
29
src/gpu.rs
29
src/gpu.rs
|
@ -2,12 +2,41 @@ use crate::chain::{DecryptedBlock, DecryptedNote, Nf};
|
||||||
use crate::db::AccountViewKey;
|
use crate::db::AccountViewKey;
|
||||||
use crate::CompactBlock;
|
use crate::CompactBlock;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use zcash_note_encryption::Domain;
|
use zcash_note_encryption::Domain;
|
||||||
use zcash_primitives::consensus::{BlockHeight, Network};
|
use zcash_primitives::consensus::{BlockHeight, Network};
|
||||||
use zcash_primitives::sapling::note_encryption::SaplingDomain;
|
use zcash_primitives::sapling::note_encryption::SaplingDomain;
|
||||||
use zcash_primitives::sapling::SaplingIvk;
|
use zcash_primitives::sapling::SaplingIvk;
|
||||||
use zcash_primitives::zip32::ExtendedFullViewingKey;
|
use zcash_primitives::zip32::ExtendedFullViewingKey;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref USE_GPU: AtomicBool = AtomicBool::new(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "cuda")]
|
||||||
|
pub fn has_cuda() -> bool {
|
||||||
|
let cuda = cuda::CUDA_CONTEXT.lock().unwrap();
|
||||||
|
return cuda.is_some();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "cuda"))]
|
||||||
|
pub fn has_cuda() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_metal() -> bool {
|
||||||
|
cfg!(feature = "apple_metal")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_gpu() -> bool {
|
||||||
|
cfg!(any(feature = "cuda", feature = "apple_metal"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn use_gpu(v: bool) {
|
||||||
|
USE_GPU.store(v, Ordering::Release);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cuda")]
|
#[cfg(feature = "cuda")]
|
||||||
pub mod cuda;
|
pub mod cuda;
|
||||||
|
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -3,6 +3,7 @@
|
||||||
#[path = "generated/cash.z.wallet.sdk.rpc.rs"]
|
#[path = "generated/cash.z.wallet.sdk.rpc.rs"]
|
||||||
pub mod lw_rpc;
|
pub mod lw_rpc;
|
||||||
|
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
pub use zcash_params::coin::{get_branch, get_coin_type, CoinType};
|
pub use zcash_params::coin::{get_branch, get_coin_type, CoinType};
|
||||||
|
|
||||||
// Mainnet
|
// Mainnet
|
||||||
|
@ -98,17 +99,4 @@ pub mod nodejs;
|
||||||
|
|
||||||
mod gpu;
|
mod gpu;
|
||||||
|
|
||||||
#[cfg(feature = "cuda")]
|
pub use gpu::{has_cuda, has_gpu, has_metal, use_gpu};
|
||||||
pub fn has_cuda() -> bool {
|
|
||||||
let cuda = gpu::cuda::CUDA_CONTEXT.lock().unwrap();
|
|
||||||
return cuda.is_some();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "cuda"))]
|
|
||||||
pub fn has_cuda() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_metal() -> bool {
|
|
||||||
cfg!(feature = "apple_metal")
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue