Skip to content

Commit

Permalink
Report statistics every second and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralvarez committed Oct 26, 2016
1 parent ab39288 commit dbcd27c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
60 changes: 27 additions & 33 deletions src/libzogminer/cl_zogminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace std;
unsigned const cl_zogminer::c_defaultLocalWorkSize = 32;
unsigned const cl_zogminer::c_defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE
unsigned const cl_zogminer::c_defaultMSPerBatch = 0;
bool cl_zogminer::s_allowCPU = false;
bool cl_zogminer::s_allowCPU = true;
unsigned cl_zogminer::s_extraRequiredGPUMem;
unsigned cl_zogminer::s_msPerBatch = cl_zogminer::c_defaultMSPerBatch;
unsigned cl_zogminer::s_workgroupSize = cl_zogminer::c_defaultLocalWorkSize;
Expand Down Expand Up @@ -374,24 +374,19 @@ bool cl_zogminer::init(

// TODO create buffer kernel inputs (private variables)
m_digests[0] = cl::Buffer(m_context, CL_MEM_READ_WRITE, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), NULL, NULL);
m_queue.enqueueFillBuffer(m_digests[0], &zero, 1, 0, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), 0);
m_digests[1] = cl::Buffer(m_context, CL_MEM_READ_WRITE, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), NULL, NULL);
m_queue.enqueueFillBuffer(m_digests[1], &zero, 1, 0, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), 0);

m_buckets = cl::Buffer(m_context, CL_MEM_READ_WRITE, NUM_BUCKETS * sizeof(bucket_t) * EQUIHASH_K, NULL, NULL);
m_queue.enqueueFillBuffer(m_buckets, &zero, 1, 0, NUM_BUCKETS * sizeof(bucket_t) * EQUIHASH_K, 0);

m_new_digest_index = cl::Buffer(m_context, CL_MEM_READ_WRITE, sizeof(uint32_t), NULL, NULL);
m_queue.enqueueFillBuffer(m_new_digest_index, &zero, 1, 0, sizeof(uint32_t), 0);

m_blake2b_digest = cl::Buffer(m_context, CL_MEM_READ_WRITE, sizeof(crypto_generichash_blake2b_state), NULL, NULL);
m_queue.enqueueFillBuffer(m_blake2b_digest, &zero, 1, 0, sizeof(crypto_generichash_blake2b_state), 0);

m_dst_solutions = cl::Buffer(m_context, CL_MEM_READ_WRITE, 20*NUM_INDICES*sizeof(uint32_t), NULL, NULL);
m_queue.enqueueFillBuffer(m_dst_solutions, &zero, 1, 0, 20*NUM_INDICES*sizeof(uint32_t), 0);

m_n_solutions = cl::Buffer(m_context, CL_MEM_READ_WRITE, sizeof(uint32_t), NULL, NULL);
m_queue.enqueueFillBuffer(m_n_solutions, &zero, 1, 0, sizeof(uint32_t), 0);

m_queue.finish();

}
catch (cl::Error const& err)
Expand All @@ -408,10 +403,20 @@ void cl_zogminer::run(crypto_generichash_blake2b_state base_state, uint32_t * so
try
{

m_queue.enqueueFillBuffer(m_digests[0], &zero, 1, 0, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), 0);
m_queue.enqueueFillBuffer(m_digests[1], &zero, 1, 0, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), 0);
m_queue.enqueueFillBuffer(m_buckets, &zero, 1, 0, NUM_BUCKETS * sizeof(bucket_t) * EQUIHASH_K, 0);
m_queue.enqueueFillBuffer(m_new_digest_index, &zero, 1, 0, sizeof(uint32_t), 0);
m_queue.enqueueFillBuffer(m_blake2b_digest, &zero, 1, 0, sizeof(crypto_generichash_blake2b_state), 0);
m_queue.enqueueFillBuffer(m_dst_solutions, &zero, 1, 0, 20*NUM_INDICES*sizeof(uint32_t), 0);
m_queue.enqueueFillBuffer(m_n_solutions, &zero, 1, 0, sizeof(uint32_t), 0);

m_queue.finish();

// update buffer
m_queue.enqueueWriteBuffer(m_blake2b_digest, true, 0, sizeof(crypto_generichash_blake2b_state), &base_state);

m_queue.enqueueBarrier();
m_queue.finish();

// TODO: Check zcashd for methods for choosing nonces

Expand All @@ -423,7 +428,7 @@ void cl_zogminer::run(crypto_generichash_blake2b_state base_state, uint32_t * so
auto t = chrono::high_resolution_clock::now();
*/

CL_LOG("Running Solver...");
//CL_LOG("Running Solver...");
// Just send it numbers for now

//TODO find out why it is segfaulting
Expand All @@ -434,26 +439,28 @@ void cl_zogminer::run(crypto_generichash_blake2b_state base_state, uint32_t * so

// execute it!
// Here we assume an 1-Dimensional problem split into local worksizes
m_queue.enqueueNDRangeKernel(m_zogKernels[0], cl::NullRange, 1048576, 32);
m_queue.enqueueNDRangeKernel(m_zogKernels[0], cl::NullRange, cl::NDRange(1 << 20), cl::NullRange);

m_queue.enqueueBarrier();
m_queue.finish();

uint32_t i = 1;
for(i = 1; i < EQUIHASH_K; ++i) {
for(i = 1; i < EQUIHASH_K; ++i) {

m_queue.enqueueFillBuffer(m_new_digest_index, &zero, 1, 0, sizeof(uint32_t), 0);

std::cout << "Step: " << i << "..." << std::endl;
m_queue.finish();

//std::cout << "Step: " << i << "..." << std::endl;

m_zogKernels[1].setArg(0, m_digests[i % 2]);
m_zogKernels[1].setArg(1, m_digests[(i - 1) % 2]);
m_zogKernels[1].setArg(2, m_buckets);
m_zogKernels[1].setArg(3, i);
m_zogKernels[1].setArg(4, m_new_digest_index);

m_queue.enqueueNDRangeKernel(m_zogKernels[1], cl::NullRange, 1048576, 32);
m_queue.enqueueNDRangeKernel(m_zogKernels[1], cl::NullRange, cl::NDRange(1 << 20), cl::NDRange(32));

m_queue.enqueueBarrier();
m_queue.finish();

}

Expand All @@ -469,9 +476,9 @@ void cl_zogminer::run(crypto_generichash_blake2b_state base_state, uint32_t * so
m_zogKernels[2].setArg(3, m_digests[0]);
m_zogKernels[2].setArg(4, m_blake2b_digest);

m_queue.enqueueNDRangeKernel(m_zogKernels[2], cl::NullRange, 1048576, 32);
m_queue.enqueueNDRangeKernel(m_zogKernels[2], cl::NullRange, cl::NDRange(1 << 16), cl::NDRange(32));

m_queue.enqueueBarrier();
m_queue.finish();

//pending.push({ start_nonce, buf });
//buf = (buf + 1) % c_bufferCount;
Expand All @@ -496,21 +503,11 @@ void cl_zogminer::run(crypto_generichash_blake2b_state base_state, uint32_t * so
normalize_indices(dst_solutions + (NUM_INDICES*i));
}

std::cout << "Solutions: " << solutions << std::endl;
//std::cout << "Solutions: " << solutions << std::endl;

memcpy(sols, dst_solutions, 20*512*sizeof(uint32_t));
*n_sol = solutions;

m_queue.enqueueFillBuffer(m_digests[0], &zero, 1, 0, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), 0);
m_queue.enqueueFillBuffer(m_digests[1], &zero, 1, 0, (NUM_VALUES + NUM_VALUES / 2) * sizeof(digest_t), 0);
m_queue.enqueueFillBuffer(m_buckets, &zero, 1, 0, NUM_BUCKETS * sizeof(bucket_t) * EQUIHASH_K, 0);
m_queue.enqueueFillBuffer(m_new_digest_index, &zero, 1, 0, sizeof(uint32_t), 0);
m_queue.enqueueFillBuffer(m_blake2b_digest, &zero, 1, 0, sizeof(crypto_generichash_blake2b_state), 0);
m_queue.enqueueFillBuffer(m_dst_solutions, &zero, 1, 0, 20*NUM_INDICES*sizeof(uint32_t), 0);
m_queue.enqueueFillBuffer(m_n_solutions, &zero, 1, 0, sizeof(uint32_t), 0);

m_queue.finish();

/*if (i % 10 == 0){
CL_LOG("Iteration: " << i << " Result: " << *results);
}*/
Expand Down Expand Up @@ -559,10 +556,7 @@ void cl_zogminer::run(crypto_generichash_blake2b_state base_state, uint32_t * so
//}

// not safe to return until this is ready
#if CL_VERSION_1_2 && 0
if (!m_opencl_1_1)
pre_return_event.wait();
#endif

}
catch (cl::Error const& err)
{
Expand Down
9 changes: 5 additions & 4 deletions src/libzogminer/gpusolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "gpusolver.h"

//#define DEBUG
#define DEBUG

GPUSolver::GPUSolver() {

Expand Down Expand Up @@ -172,12 +172,13 @@ bool GPUSolver::GPUSolve200_9(const eh_HashState& base_state,

avg = sum/++counter;

std::cout << "Kernel run took " << milis << " ms. (" << avg << " H/s)" << std::endl;
if(!(counter % 10))
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) {
++checkedSols;
std::cout << "Checking solution " << checkedSols << std::endl;
//std::cout << "Checking solution " << checkedSols << std::endl;
std::vector<eh_index> index_vector(PROOFSIZE);
for (size_t i = 0; i < PROOFSIZE; i++) {
index_vector[i] = indices[s * PROOFSIZE + i];
Expand All @@ -198,7 +199,7 @@ bool GPUSolver::GPUSolve200_9(const eh_HashState& base_state,
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.
std::cout << "Valid block found!" << std::endl;
//std::cout << "Valid block found!" << std::endl;
return true;
}
}
Expand Down

0 comments on commit dbcd27c

Please sign in to comment.