From 4ae4d2881ede22a83c73802e8396a244b0d5266e Mon Sep 17 00:00:00 2001 From: Omar Alvarez Date: Mon, 24 Oct 2016 11:52:22 +0200 Subject: [PATCH] Debug option for solution validation and avg hashrate stats --- src/libzogminer/gpusolver.cpp | 25 +++++++++++++++++-------- src/libzogminer/gpusolver.h | 4 ++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/libzogminer/gpusolver.cpp b/src/libzogminer/gpusolver.cpp index de26bfd..ff92bcd 100644 --- a/src/libzogminer/gpusolver.cpp +++ b/src/libzogminer/gpusolver.cpp @@ -25,6 +25,8 @@ #include "gpusolver.h" +#define DEBUG + GPUSolver::GPUSolver() { /* Notes @@ -112,7 +114,15 @@ bool GPUSolver::GPUSolve200_9(const eh_HashState& base_state, auto d = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - t); auto milis = std::chrono::duration_cast(d).count(); - std::cout << "Kernel run took " << milis << " ms. (" << 1000.f*n_sol/milis << " H/s)" << std::endl; + if(!counter) { + sum = 1000.f*n_sol/milis; + } else { + sum += 1000.f*n_sol/milis; + } + + avg = sum/++counter; + + std::cout << "Kernel run took " << milis << " ms. (" << avg << " H/s)" << std::endl; size_t checkedSols = 0; for (size_t s = 0; s < n_sol; ++s) { @@ -123,17 +133,16 @@ bool GPUSolver::GPUSolve200_9(const eh_HashState& base_state, index_vector[i] = indices[s * PROOFSIZE + i]; } std::vector sol_char = GetMinimalFromIndices(index_vector, DIGITBITS); - +#ifdef DEBUG bool isValid; EhIsValidSolution(200, 9, base_state, sol_char, isValid); std::cout << "is valid: " << isValid << '\n'; - if (isValid) { - // If we find a POW solution, do not try other solutions - // because they become invalid as we created a new block in blockchain. - std::cout << "Valid solution found!" << std::endl; - return true; + if (!isValid) { + //If we find invalid solution bail, it cannot be a valid POW + std::cout << "Invalid solution found!" << std::endl; + return false; } - +#endif if (validBlock(sol_char)) { // If we find a POW solution, do not try other solutions // because they become invalid as we created a new block in blockchain. diff --git a/src/libzogminer/gpusolver.h b/src/libzogminer/gpusolver.h index 165d973..135eb60 100644 --- a/src/libzogminer/gpusolver.h +++ b/src/libzogminer/gpusolver.h @@ -73,6 +73,10 @@ class GPUSolver { static const uint32_t PROOFSIZE = 1 << EK; //TODO 20? uint32_t indices[20*PROOFSIZE]; + //Avg + uint32_t counter = 0; + float sum = 0.f; + float avg = 0.f; bool GPUSolve200_9(const eh_HashState& base_state, const std::function)> validBlock,