Skip to content

Commit

Permalink
CLI support for selecting certain OpenCL devices and reference CPU miner
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralvarez committed Oct 24, 2016
1 parent 4ae4d28 commit 834807a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
48 changes: 48 additions & 0 deletions src/libzogminer/gpusolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,54 @@ GPUSolver::GPUSolver() {

}

GPUSolver::GPUSolver(int64_t selGPU) {

/* Notes
I've added some extra parameters in this interface to assist with dev, such as
a kernel string to specify which kernel to run and local/global work sizes.
The following are private members of the class, but I have them here to specify the
global work size for now. This will probably be hard-coded later
*/
unsigned int z_n = 200;
unsigned int z_k = 9;
size_t z_collision_bit_length = z_n / (z_k + 1);
eh_index z_N = 1 << (z_collision_bit_length + 1);
//uint32_t global_work_size = z_N;

//TODO This looks like IND_PER_BUCKET, enough for GPU?
size_t global_work_size = 1 << 17;
size_t local_work_size = 32;

miner = new cl_zogminer();
miner->listDevices();

//Generic Things
std::cout << "Number of Platforms:" << miner->getNumPlatforms << "\n";

/* Checks each device for memory requirements and sets local/global sizes
TODO: Implement device logic for equihash kernel
@params: unsigned platformId
@params: unsigned localWorkSizes
@params: unsigned globalWorkSizes
*/
GPU = miner->configureGPU(0, local_work_size, global_work_size);
if(!GPU)
std::cout << "ERROR: No suitable GPU found! No work will be performed!" << std::endl;

/*Initialize the kernel, compile it and create buffers
Currently runs for the gpu-list-gen.c kernel DATA_SIZE=100 times
TODO: pass base state and nonce's to kernel.
@params: unsigned _platformId
@params: unsigned _deviceId
@params: string& _kernel - The name of the kernel for dev purposes
*/
std::vector<std::string> kernels {"initial_bucket_hashing", "bucket_collide_and_hash", "produce_solutions"};
if(GPU)
initOK = miner->init(0, selGPU, kernels);

}

GPUSolver::~GPUSolver() {

if(GPU)
Expand Down
1 change: 1 addition & 0 deletions src/libzogminer/gpusolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class GPUSolver {

public:
GPUSolver();
GPUSolver(int64_t selGPU);
~GPUSolver();
bool run(unsigned int n, unsigned int k, const eh_HashState& base_state,
const std::function<bool(std::vector<unsigned char>)> validBlock,
Expand Down
30 changes: 24 additions & 6 deletions src/standaloneminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ std::string HelpMessageMiner()
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be "
"solved instantly. This is intended for regression testing tools and app development."));
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
strUsage += HelpMessageOpt("-G", _("GPU mine"));
strUsage += HelpMessageOpt("-S=<deviceid>", _("Select GPU device (default: 0)"));

return strUsage;
}
Expand All @@ -95,12 +97,14 @@ std::string LicenseInfo()
"\n";
}

void test_mine(int n, int k, uint32_t d)
void test_mine(int n, int k, uint32_t d, bool GPU, int64_t selGPU)
{
CBlock pblock;
pblock.nBits = d;
arith_uint256 hashTarget = arith_uint256().SetCompact(d);
GPUSolver solver;
GPUSolver * solver;
if(GPU)
solver = new GPUSolver(selGPU);

while (true) {
// Hash state
Expand Down Expand Up @@ -152,14 +156,21 @@ void test_mine(int n, int k, uint32_t d)

return true;
};
std::function<bool(GPUSolverCancelCheck)> cancelled =
std::function<bool(GPUSolverCancelCheck)> cancelledGPU =
[](GPUSolverCancelCheck pos) {
return false;
};
std::function<bool(EhSolverCancelCheck)> cancelled =
[](EhSolverCancelCheck pos) {
return false;
};
try {
uint64_t solve_start = rdtsc();
//bool foundBlock = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
bool foundBlock = solver.run(n, k, curr_state, validBlock, cancelled);
bool foundBlock;
if(!GPU)
foundBlock = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
else
foundBlock = solver->run(n, k, curr_state, validBlock, cancelledGPU);
uint64_t solve_end = rdtsc();
LogPrint("cycles", "Solver took %2.2f Mcycles\n\n",
(double)(solve_end - solve_start) / (1UL << 20));
Expand All @@ -179,6 +190,10 @@ void test_mine(int n, int k, uint32_t d)

pblock.hashPrevBlock = pblock.GetHash();
}

if(GPU)
delete solver;

}

static ZcashStratumClient* scSig;
Expand Down Expand Up @@ -227,6 +242,9 @@ int main(int argc, char* argv[])
LogPrintf("Zcash Miner version %s (%s)\n", FormatFullVersion(), CLIENT_DATE);

// Start the mining operation
bool GPU = GetBoolArg("-G", false);
int64_t selGPU = GetArg("-S", 0);
//std::cout << GPU << " " << selGPU << std::endl;
std::string stratum = GetArg("-stratum", "");
if (!stratum.empty() || GetBoolArg("-stratum", false)) {
if (stratum.compare(0, 14, "stratum+tcp://") != 0) {
Expand Down Expand Up @@ -270,7 +288,7 @@ int main(int argc, char* argv[])
test_mine(
Params().EquihashN(),
Params().EquihashK(),
0x200f0f0f);
0x200f0f0f, GPU, selGPU);
}

return 0;
Expand Down

0 comments on commit 834807a

Please sign in to comment.