@@ -25,14 +25,18 @@ using namespace dev;
25
25
using namespace eth ;
26
26
27
27
unsigned CUDAMiner::s_numInstances = 0 ;
28
- int CUDAMiner::s_devices[16 ] = { -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 };
28
+
29
+ int CUDAMiner::s_devices[16 ] = {
30
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1
31
+ };
29
32
30
33
struct CUDAChannel : public LogChannel
31
34
{
32
35
static const char * name () { return EthOrange " cu" ; }
33
36
static const int verbosity = 2 ;
34
37
static const bool debug = false ;
35
38
};
39
+
36
40
#define cudalog clog (CUDAChannel)
37
41
#define ETHCUDA_LOG (_contents ) cudalog << _contents
38
42
@@ -44,26 +48,7 @@ CUDAMiner::CUDAMiner(FarmFace& _farm, unsigned _index) :
44
48
CUDAMiner::~CUDAMiner ()
45
49
{
46
50
stopWorking ();
47
- pause ();
48
- }
49
-
50
- void CUDAMiner::report (uint64_t _nonce, const WorkPackage& w)
51
- {
52
- // FIXME: This code is exactly the same as in EthashGPUMiner.
53
- Result r = EthashAux::eval (w.seed , w.header , _nonce);
54
- if (r.value < w.boundary )
55
- farm.submitProof (Solution{_nonce, r.mixHash , w.header , w.seed , w.boundary , w.job , w.job_len , m_abort});
56
- else
57
- {
58
- farm.failedSolution ();
59
- cwarn << " FAILURE: GPU gave incorrect result!" ;
60
- }
61
- }
62
-
63
- void CUDAMiner::kickOff ()
64
- {
65
- UniqueGuard l (x_all);
66
- m_aborted = m_abort = false ;
51
+ kick_miner ();
67
52
}
68
53
69
54
bool CUDAMiner::init (const h256& seed)
@@ -148,13 +133,10 @@ void CUDAMiner::workLoop()
148
133
}
149
134
}
150
135
151
- void CUDAMiner::pause ()
136
+ void CUDAMiner::kick_miner ()
152
137
{
153
- UniqueGuard l (x_all);
154
- if (m_aborted)
155
- return ;
156
-
157
- m_abort = true ;
138
+ if (!m_abort)
139
+ m_abort = true ;
158
140
}
159
141
160
142
void CUDAMiner::setNumInstances (unsigned _instances)
@@ -168,14 +150,6 @@ void CUDAMiner::setDevices(const unsigned* _devices, unsigned _selectedDeviceCou
168
150
s_devices[i] = _devices[i];
169
151
}
170
152
171
- void CUDAMiner::waitPaused ()
172
- {
173
- // m_abort is true so now searched()/found() will return true to abort the search.
174
- // we hang around on this thread waiting for them to point out that they have aborted since
175
- // otherwise we may end up deleting this object prior to searched()/found() being called.
176
- m_aborted.wait (true );
177
- }
178
-
179
153
unsigned CUDAMiner::getNumDevices ()
180
154
{
181
155
int deviceCount = -1 ;
@@ -323,7 +297,15 @@ unsigned CUDAMiner::s_gridSize = CUDAMiner::c_defaultGridSize;
323
297
unsigned CUDAMiner::s_numStreams = CUDAMiner::c_defaultNumStreams;
324
298
unsigned CUDAMiner::s_scheduleFlag = 0 ;
325
299
326
- bool CUDAMiner::cuda_init (size_t numDevices, ethash_light_t _light, uint8_t const * _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, uint8_t * &hostDAG, unsigned dagCreateDevice)
300
+ bool CUDAMiner::cuda_init (
301
+ size_t numDevices,
302
+ ethash_light_t _light,
303
+ uint8_t const * _lightData,
304
+ uint64_t _lightSize,
305
+ unsigned _deviceId,
306
+ bool _cpyToHost,
307
+ uint8_t * &hostDAG,
308
+ unsigned dagCreateDevice)
327
309
{
328
310
try
329
311
{
@@ -450,7 +432,6 @@ void CUDAMiner::search(
450
432
const dev::eth::WorkPackage& w)
451
433
{
452
434
bool initialize = false ;
453
- bool exit = false ;
454
435
if (memcmp (&m_current_header, header, sizeof (hash32_t )))
455
436
{
456
437
m_current_header = *reinterpret_cast <hash32_t const *>(header);
@@ -493,13 +474,15 @@ void CUDAMiner::search(
493
474
}
494
475
}
495
476
uint64_t batch_size = s_gridSize * s_blockSize;
496
- for (; !exit; m_current_index++, m_current_nonce += batch_size )
477
+ while ( true )
497
478
{
479
+ m_current_index++;
480
+ m_current_nonce += batch_size;
498
481
auto stream_index = m_current_index % s_numStreams;
499
482
cudaStream_t stream = m_streams[stream_index];
500
483
volatile uint32_t * buffer = m_search_buf[stream_index];
501
484
uint32_t found_count = 0 ;
502
- uint64_t nonces[SEARCH_RESULT_BUFFER_SIZE - 1 ];
485
+ uint64_t nonces[SEARCH_RESULT_BUFFER_SIZE];
503
486
uint64_t nonce_base = m_current_nonce - s_numStreams * batch_size;
504
487
if (m_current_index >= s_numStreams)
505
488
{
@@ -509,17 +492,33 @@ void CUDAMiner::search(
509
492
buffer[0 ] = 0 ;
510
493
if (found_count > (SEARCH_RESULT_BUFFER_SIZE - 1 ))
511
494
found_count = SEARCH_RESULT_BUFFER_SIZE - 1 ;
512
- for (unsigned int j = 0 ; j < found_count; j++)
513
- nonces[j] = nonce_base + buffer[j + 1 ];
495
+ for (unsigned int j = 1 ; j <= found_count; j++)
496
+ nonces[j] = nonce_base + buffer[j];
514
497
}
515
498
}
516
499
run_ethash_search (s_gridSize, s_blockSize, m_sharedBytes, stream, buffer, m_current_nonce, m_parallelHash);
517
500
if (m_current_index >= s_numStreams)
518
501
{
519
502
if (found_count)
520
- found (nonces, found_count, w);
521
- searched (batch_size);
522
- exit = cuda_shouldStop ();
503
+ {
504
+ for (uint32_t i = 1 ; i <= found_count; i++)
505
+ {
506
+ Result r = EthashAux::eval (w.seed , w.header , nonces[i]);
507
+ if (r.value < w.boundary )
508
+ farm.submitProof (Solution{nonces[i], r.mixHash , w.header , w.seed , w.boundary , w.job , w.job_len , m_abort});
509
+ else
510
+ {
511
+ farm.failedSolution ();
512
+ cwarn << " GPU gave incorrect result!" ;
513
+ }
514
+ }
515
+ }
516
+ addHashCount (batch_size);
517
+ if (m_abort || shouldStop ())
518
+ {
519
+ m_abort = false ;
520
+ break ;
521
+ }
523
522
}
524
523
}
525
524
}
0 commit comments