Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit 485b5c0

Browse files
committedMay 1, 2018
No eval for OpenCL - One last thing on my ethminer todo list.
- Rename -cuda-noeval option to --noeval since it can now apply to both Cuda and OpenCl. - Add support for using GPU mix hash result when noeval is set in CLIMiner. - Modify experimental opencl kernel to return mix hash on solution found. - Modify stable opencl kernel to return mix hash on solution found. - Move global s_noval bool to common miner.cpp - Fix eval check to include equality.
1 parent 0df6360 commit 485b5c0

File tree

9 files changed

+80
-34
lines changed

9 files changed

+80
-34
lines changed
 

‎ethminer/MinerAux.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@ class MinerCLI
536536
}
537537
else if (arg == "--cuda-streams" && i + 1 < argc)
538538
m_numStreams = stol(argv[++i]);
539-
else if (arg == "--cuda-noeval")
540-
m_cudaNoEval = true;
541539
#endif
540+
else if (arg == "--noeval")
541+
m_noEval = true;
542542
else if ((arg == "-L" || arg == "--dag-load-mode") && i + 1 < argc)
543543
{
544544
string mode = argv[++i];
@@ -696,6 +696,7 @@ class MinerCLI
696696
0,
697697
m_dagLoadMode,
698698
m_dagCreateDevice,
699+
m_noEval,
699700
m_exit
700701
))
701702
exit(1);
@@ -722,7 +723,7 @@ class MinerCLI
722723
m_cudaSchedule,
723724
m_dagLoadMode,
724725
m_dagCreateDevice,
725-
m_cudaNoEval,
726+
m_noEval,
726727
m_exit
727728
))
728729
exit(1);
@@ -821,7 +822,7 @@ class MinerCLI
821822
<< " sync - Instruct CUDA to block the CPU thread on a synchronization primitive when waiting for the results from the device." << endl
822823
<< " --cuda-devices <0 1 ..n> Select which CUDA GPUs to mine on. Default is to use all" << endl
823824
<< " --cuda-parallel-hash <1 2 ..8> Define how many hashes to calculate in a kernel, can be scaled to achieve better performance. Default=4" << endl
824-
<< " --cuda-noeval bypass host software re-evaluation of GPU solutions." << endl
825+
<< " --noeval bypass host software re-evaluation of GPU solutions." << endl
825826
<< " This will trim some milliseconds off the time it takes to send a result to the pool." << endl
826827
<< " Use at your own risk! If GPU generates errored results they WILL be forwarded to the pool" << endl
827828
<< " Not recommended at high overclock." << endl
@@ -1009,9 +1010,9 @@ class MinerCLI
10091010
unsigned m_cudaSchedule = 4; // sync
10101011
unsigned m_cudaGridSize = CUDAMiner::c_defaultGridSize;
10111012
unsigned m_cudaBlockSize = CUDAMiner::c_defaultBlockSize;
1012-
bool m_cudaNoEval = false;
10131013
unsigned m_parallelHash = 4;
10141014
#endif
1015+
bool m_noEval = false;
10151016
unsigned m_dagLoadMode = 0; // parallel
10161017
unsigned m_dagCreateDevice = 0;
10171018
bool m_exit = false;

‎libethash-cl/CLMiner.cpp

+28-15
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ CLMiner::~CLMiner()
274274
kick_miner();
275275
}
276276

277+
278+
typedef struct {
279+
unsigned count;
280+
unsigned gid;
281+
unsigned mix[8];
282+
} search_results;
283+
277284
void CLMiner::workLoop()
278285
{
279286
// Memory for zero-ing buffers. Cannot be static because crashes on macOS.
@@ -341,15 +348,12 @@ void CLMiner::workLoop()
341348
}
342349

343350
// Read results.
344-
// TODO: could use pinned host pointer instead.
345-
uint32_t results[c_maxSearchResults + 1];
351+
search_results results;
352+
346353
m_queue.enqueueReadBuffer(m_searchBuffer, CL_TRUE, 0, sizeof(results), &results);
347354

348-
uint64_t nonce = 0;
349-
if (results[0] > 0)
355+
if (results.count)
350356
{
351-
// Ignore results except the first one.
352-
nonce = current.startNonce + results[1];
353357
// Reset search buffer if any solution found.
354358
m_queue.enqueueWriteBuffer(m_searchBuffer, CL_FALSE, 0, sizeof(c_zero), &c_zero);
355359
}
@@ -359,14 +363,21 @@ void CLMiner::workLoop()
359363
m_queue.enqueueNDRangeKernel(m_searchKernel, cl::NullRange, m_globalWorkSize, m_workgroupSize);
360364

361365
// Report results while the kernel is running.
362-
// It takes some time because ethash must be re-evaluated on CPU.
363-
if (nonce != 0) {
364-
Result r = EthashAux::eval(current.epoch, current.header, nonce);
365-
if (r.value < current.boundary)
366-
farm.submitProof(Solution{nonce, r.mixHash, current, current.header != w.header});
366+
if (results.count) {
367+
uint64_t nonce = current.startNonce + results.gid;
368+
if (!s_noeval) {
369+
Result r = EthashAux::eval(current.epoch, current.header, nonce);
370+
if (r.value <= current.boundary)
371+
farm.submitProof(Solution{nonce, r.mixHash, current, current.header != w.header});
372+
else {
373+
farm.failedSolution();
374+
cwarn << "GPU gave incorrect result!";
375+
}
376+
}
367377
else {
368-
farm.failedSolution();
369-
cwarn << "FAILURE: GPU gave incorrect result!";
378+
h256 mix;
379+
memcpy(mix.data(), results.mix, sizeof(results.mix));
380+
farm.submitProof(Solution{nonce, mix, current, current.header != w.header});
370381
}
371382
}
372383

@@ -450,8 +461,10 @@ void CLMiner::listDevices()
450461
}
451462

452463
bool CLMiner::configureGPU(unsigned _localWorkSize, unsigned _globalWorkSizeMultiplier,
453-
unsigned _platformId, int epoch, unsigned _dagLoadMode, unsigned _dagCreateDevice, bool _exit)
464+
unsigned _platformId, int epoch, unsigned _dagLoadMode, unsigned _dagCreateDevice,
465+
bool _noeval, bool _exit)
454466
{
467+
s_noeval = _noeval;
455468
s_dagLoadMode = _dagLoadMode;
456469
s_dagCreateDevice = _dagCreateDevice;
457470
s_exit = _exit;
@@ -677,7 +690,7 @@ bool CLMiner::init(int epoch)
677690

678691
// create mining buffers
679692
ETHCL_LOG("Creating mining buffer");
680-
m_searchBuffer = cl::Buffer(m_context, CL_MEM_WRITE_ONLY, (c_maxSearchResults + 1) * sizeof(uint32_t));
693+
m_searchBuffer = cl::Buffer(m_context, CL_MEM_WRITE_ONLY, sizeof(search_results));
681694

682695
const auto workItems = dagNumItems * 2; // GPU computes partial 512-bit DAG items.
683696
uint32_t fullRuns = workItems / m_globalWorkSize;

‎libethash-cl/CLMiner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CLMiner: public Miner
6161
static void listDevices();
6262
static bool configureGPU(unsigned _localWorkSize, unsigned _globalWorkSizeMultiplier,
6363
unsigned _platformId, int epoch, unsigned _dagLoadMode, unsigned _dagCreateDevice,
64-
bool _exit);
64+
bool _noeval, bool _exit);
6565
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, getNumDevices()); }
6666
static void setThreadsPerHash(unsigned _threadsPerHash){s_threadsPerHash = _threadsPerHash; }
6767
static void setDevices(const vector<unsigned>& _devices, unsigned _selectedDeviceCount)

‎libethash-cl/CLMiner_kernel_experimental.cl

+19-3
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,17 @@ typedef union {
266266
uint16 uint16s[200 / sizeof(uint16)];
267267
} hash200_t;
268268

269+
typedef struct {
270+
unsigned count;
271+
unsigned gid;
272+
ulong mix[4];
273+
} search_results;
269274

270275
#if PLATFORM != OPENCL_PLATFORM_NVIDIA // use maxrregs on nv
271276
__attribute__((reqd_work_group_size(GROUP_SIZE, 1, 1)))
272277
#endif
273278
__kernel void ethash_search(
274-
__global volatile uint* restrict g_output,
279+
__global volatile search_results* restrict g_output,
275280
__constant hash32_t const* g_header,
276281
__global hash128_t const* g_dag,
277282
ulong start_nonce,
@@ -400,6 +405,12 @@ __kernel void ethash_search(
400405
}
401406
#endif
402407

408+
ulong mixhash[4];
409+
mixhash[0] = state[8];
410+
mixhash[1] = state[9];
411+
mixhash[2] = state[10];
412+
mixhash[3] = state[11];
413+
403414
for (uint i = 13; i != 25; ++i) {
404415
state[i] = 0;
405416
}
@@ -411,8 +422,13 @@ __kernel void ethash_search(
411422

412423
if (as_ulong(as_uchar8(state[0]).s76543210) > target)
413424
return;
414-
uint slot = min(MAX_OUTPUTS, atomic_inc(&g_output[0]) + 1);
415-
g_output[slot] = gid;
425+
if (atomic_inc(&g_output->count))
426+
return;
427+
g_output->gid = gid;
428+
g_output->mix[0] = mixhash[0];
429+
g_output->mix[1] = mixhash[1];
430+
g_output->mix[2] = mixhash[2];
431+
g_output->mix[3] = mixhash[3];
416432
}
417433

418434
__kernel void ethash_calculate_dag_item(uint start, __global hash64_t const* g_light, __global hash64_t * g_dag, uint isolate)

‎libethash-cl/CLMiner_kernel_stable.cl

+22-5
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,17 @@ typedef union {
284284
uint uints[16];
285285
} compute_hash_share;
286286

287+
typedef struct {
288+
unsigned count;
289+
unsigned gid;
290+
ulong mix[4];
291+
} search_results;
292+
287293
#if PLATFORM != OPENCL_PLATFORM_NVIDIA // use maxrregs on nv
288294
__attribute__((reqd_work_group_size(GROUP_SIZE, 1, 1)))
289295
#endif
290296
__kernel void ethash_search(
291-
__global volatile uint* restrict g_output,
297+
__global volatile search_results* restrict g_output,
292298
__constant hash32_t const* g_header,
293299
__global hash128_t const* g_dag,
294300
ulong start_nonce,
@@ -364,6 +370,12 @@ __kernel void ethash_search(
364370
barrier(CLK_LOCAL_MEM_FENCE);
365371
}
366372

373+
ulong mixhash[4];
374+
mixhash[0] = state[8];
375+
mixhash[1] = state[9];
376+
mixhash[2] = state[10];
377+
mixhash[3] = state[11];
378+
367379
for (uint i = 13; i != 25; ++i)
368380
{
369381
state[i] = 0;
@@ -374,10 +386,15 @@ __kernel void ethash_search(
374386
// keccak_256(keccak_512(header..nonce) .. mix);
375387
keccak_f1600_no_absorb((uint2*)state, 1, isolate);
376388

377-
if (as_ulong(as_uchar8(state[0]).s76543210) > target)
378-
return;
379-
uint slot = min(MAX_OUTPUTS, atomic_inc(&g_output[0]) + 1);
380-
g_output[slot] = gid;
389+
if (as_ulong(as_uchar8(state[0]).s76543210) > target)
390+
return;
391+
if (atomic_inc(&g_output->count))
392+
return;
393+
g_output->gid = gid;
394+
g_output->mix[0] = mixhash[0];
395+
g_output->mix[1] = mixhash[1];
396+
g_output->mix[2] = mixhash[2];
397+
g_output->mix[3] = mixhash[3];
381398
}
382399

383400
static void SHA3_512(uint2* s, uint isolate)

‎libethash-cuda/CUDAMiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ unsigned CUDAMiner::s_blockSize = CUDAMiner::c_defaultBlockSize;
299299
unsigned CUDAMiner::s_gridSize = CUDAMiner::c_defaultGridSize;
300300
unsigned CUDAMiner::s_numStreams = CUDAMiner::c_defaultNumStreams;
301301
unsigned CUDAMiner::s_scheduleFlag = 0;
302-
bool CUDAMiner::s_noeval = false;
303302

304303
bool CUDAMiner::cuda_init(
305304
size_t numDevices,
@@ -514,7 +513,7 @@ void CUDAMiner::search(
514513
else
515514
{
516515
Result r = EthashAux::eval(w.epoch, w.header, nonces[i]);
517-
if (r.value < w.boundary)
516+
if (r.value <= w.boundary)
518517
farm.submitProof(Solution{nonces[i], r.mixHash, w, m_new_work});
519518
else
520519
{

‎libethash-cuda/CUDAMiner.h

-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ class CUDAMiner: public Miner
127127

128128
static unsigned s_numInstances;
129129
static vector<int> s_devices;
130-
131-
static bool s_noeval;
132-
133130
};
134131

135132

‎libethcore/Miner.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ uint8_t* dev::eth::Miner::s_dagInHostMemory = NULL;
1414

1515
bool dev::eth::Miner::s_exit = false;
1616

17+
bool dev::eth::Miner::s_noeval = false;
18+

‎libethcore/Miner.h

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class Miner: public Worker
234234
static unsigned s_dagCreateDevice;
235235
static uint8_t* s_dagInHostMemory;
236236
static bool s_exit;
237+
static bool s_noeval;
237238

238239
const size_t index = 0;
239240
FarmFace& farm;

0 commit comments

Comments
 (0)
This repository has been archived.