From ef91e9d3a9d429c77f40caed62d99344828ba528 Mon Sep 17 00:00:00 2001 From: Hanh Date: Sun, 14 Aug 2022 10:56:42 +0800 Subject: [PATCH] Detect CUDA --- Cargo.toml | 3 --- binding.h | 4 ++-- src/api/dart_ffi.rs | 8 +++++++- src/chain.rs | 2 +- src/cuda/processor.rs | 1 - src/lib.rs | 11 +++++++++++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8dc82b7..9ec7ef9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,8 +88,6 @@ node-bindgen = { version = "4.0", optional = true } rustacuda = { version = "0.1.3", optional = true } rustacuda_core = { version = "0.1.2", optional = true } -# ash-warp = { path = "../../../ash-warp", optional = true } - [features] ledger = ["ledger-apdu", "hmac", "ed25519-bip32", "ledger-transport-hid"] ledger_sapling = ["ledger"] @@ -97,7 +95,6 @@ dart_ffi = ["allo-isolate", "once_cell", "android_logger"] rpc = ["rocket", "dotenv"] nodejs = ["node-bindgen"] cuda = ["rustacuda", "rustacuda_core"] -# vulkan = ["ash-warp"] # librustzcash synced to 35023ed8ca2fb1061e78fd740b640d4eefcc5edd diff --git a/binding.h b/binding.h index c1e1be9..775e1d9 100644 --- a/binding.h +++ b/binding.h @@ -13,8 +13,6 @@ typedef void *DartPostCObjectFnType; #define QR_DATA_SIZE 256 -#define MAX_OUTPUTS_PER_CHUNK 200000 - void dummy_export(void); void dart_post_cobject(DartPostCObjectFnType ptr); @@ -128,3 +126,5 @@ char *derive_zip32(uint8_t coin, uint32_t external, bool has_address, uint32_t address); + +bool has_cuda(void); diff --git a/src/api/dart_ffi.rs b/src/api/dart_ffi.rs index aa1b0ff..2ca6ba3 100644 --- a/src/api/dart_ffi.rs +++ b/src/api/dart_ffi.rs @@ -43,6 +43,7 @@ pub unsafe extern "C" fn deallocate_str(s: *mut c_char) { } fn try_init_logger() { + let _ = env_logger::try_init(); android_logger::init_once( Config::default() // .format(|buf, record| { @@ -61,7 +62,7 @@ fn try_init_logger() { fn log_result(result: anyhow::Result) -> T { match result { Err(err) => { - log::error!("{}", err); + log::error!("ERROR: {}", err); let last_error = LAST_ERROR.lock().unwrap(); last_error.replace(err.to_string()); IS_ERROR.store(true, Ordering::Release); @@ -642,3 +643,8 @@ pub unsafe extern "C" fn derive_zip32( }; to_c_str(log_string(res())) } + +#[no_mangle] +pub unsafe extern "C" fn has_cuda() -> bool { + crate::has_cuda() +} diff --git a/src/chain.rs b/src/chain.rs index 07b38c7..4d61c8e 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -101,7 +101,7 @@ pub enum ChainError { fn get_mem_per_output() -> usize { if cfg!(feature = "cuda") { - 1000 + 250 } else { 5 } diff --git a/src/cuda/processor.rs b/src/cuda/processor.rs index b243eba..f52f2e4 100644 --- a/src/cuda/processor.rs +++ b/src/cuda/processor.rs @@ -12,7 +12,6 @@ use std::ffi::CString; use zcash_note_encryption::Domain; use zcash_primitives::consensus::{BlockHeight, Network}; use zcash_primitives::sapling::note_encryption::SaplingDomain; -use zcash_primitives::zip32::ExtendedFullViewingKey; use crate::db::AccountViewKey; const THREADS_PER_BLOCK: usize = 256usize; diff --git a/src/lib.rs b/src/lib.rs index daeedce..61296d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,3 +97,14 @@ pub mod nodejs; #[cfg(feature = "cuda")] mod cuda; + +#[cfg(feature = "cuda")] +pub fn has_cuda() -> bool { + let cuda = cuda::CUDA_PROCESSOR.lock().unwrap(); + return cuda.is_some(); +} + +#[cfg(not(feature = "cuda"))] +pub fn has_cuda() -> bool { + false +}