simplify sha3 digest handling in qpow kernel

add optional cuda sampler parity logging for debugging false positives
This commit is contained in:
rob thijssen
2025-09-15 08:44:34 +08:00
parent 2480d7828b
commit b108ccefbe
2 changed files with 27 additions and 4 deletions
@@ -688,12 +688,11 @@ for (uint32_t j = 0; j < iters; ++j) {
uint8_t h_le[64];
sha3_512_64bytes_le(y_be, h_le);
// Convert digest to big-endian numeric bytes (preserve lane order; convert each lane LE->BE in-place)
// Use SHA3 output bytes directly to match host pow-core digest semantics
uint8_t digest_be[64];
#pragma unroll
for (int i = 0; i < 8; ++i) {
uint64_t w = load64_le(&h_le[i * 8]);
store64_be(&digest_be[i * 8], w);
for (int i = 0; i < 64; ++i) {
digest_be[i] = h_le[i];
}
// distance = target_be XOR digest_be (bytewise, big-endian order)
+24
View File
@@ -741,6 +741,30 @@ impl CudaEngine {
"CUDA G2(batch): false positive: idx={}, y[0..16]={}, dev_h[0..16]={}, dev_dist[0..16]={}, host_dist[0..16]={}",
k, y_hex, h_hex, dev_dist_hex, host_dist_hex
);
// Optional: if sampler is enabled, log its last parity decision to aid debugging
if std::env::var("MINER_CUDA_SAMPLER")
.map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
.unwrap_or(false)
{
let cidx = std::ffi::CString::new("C_SAMPLER_INDEX").unwrap();
let cdec = std::ffi::CString::new("C_SAMPLER_DECISION").unwrap();
if let (Ok(sym_idx), Ok(sym_dec)) = (
module_ref.get_global::<u32>(cidx.as_c_str()),
module_ref.get_global::<u32>(cdec.as_c_str()),
) {
let mut s_idx: u32 = 0;
let mut s_dec: u32 = 0;
let _ = sym_idx.copy_to(&mut s_idx);
let _ = sym_dec.copy_to(&mut s_dec);
log::warn!(
target: "miner",
"CUDA G2 sampler parity (device): idx={}, dev_ok={}, host_ok=false",
s_idx,
s_dec != 0
);
}
}
}
}
// Optional host-side verify of first W candidates when MINER_CUDA_VERIFY is set