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

Commit 7d2fd84

Browse files
author
Jean Cyr
committedDec 27, 2017
Clean up and minor optimizations
- Don't waste time formatting output text before sending problem to GPU. - Don't waste time formatting output text before sending solution to pool. - Give more detail in stratum new job log such that we don't have to spit it out for each cards. - Remove uneccessary use of volatile. There are no read/modify/write scenarios that need to be atomic.
1 parent 6fbf438 commit 7d2fd84

File tree

9 files changed

+58
-49
lines changed

9 files changed

+58
-49
lines changed
 

‎ethminer/MinerAux.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -857,19 +857,23 @@ class MinerCLI
857857
}
858858
this_thread::sleep_for(chrono::milliseconds(_recheckPeriod));
859859
}
860-
cnote << "Solution found; Submitting to" << _remote << "...";
861-
cnote << " Nonce:" << solution.nonce;
862-
cnote << " headerHash:" << solution.headerHash.hex();
863-
cnote << " mixHash:" << solution.mixHash.hex();
864860
if (EthashAux::eval(solution.seedHash, solution.headerHash, solution.nonce).value < solution.boundary)
865861
{
866862
bool ok = prpc->eth_submitWork("0x" + toHex(solution.nonce), "0x" + toString(solution.headerHash), "0x" + toString(solution.mixHash));
867863
if (ok) {
868-
cnote << EthLime << "B-) Submitted and accepted." << EthReset;
864+
cnote << "Solution found; Submitted to" << _remote << "...";
865+
cnote << " Nonce:" << solution.nonce;
866+
cnote << " headerHash:" << solution.headerHash.hex();
867+
cnote << " mixHash:" << solution.mixHash.hex();
868+
cnote << EthLime << "Accepted." << EthReset;
869869
f.acceptedSolution(false);
870870
}
871871
else {
872-
cwarn << ":-( Not accepted.";
872+
cwarn << "Solution found; Submitted to" << _remote << "...";
873+
cwarn << " Nonce:" << solution.nonce;
874+
cwarn << " headerHash:" << solution.headerHash.hex();
875+
cwarn << " mixHash:" << solution.mixHash.hex();
876+
cwarn << "Not accepted.";
873877
f.rejectedSolution(false);
874878
}
875879
//exit(0);

‎libethash-cuda/CUDAMiner.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace eth
6060
}
6161

6262
protected:
63-
virtual bool found(uint64_t const* _nonces, uint32_t _count) override
63+
virtual bool found(uint64_t const* _nonces) override
6464
{
6565
m_owner.report(_nonces[0]);
6666
return m_owner.shouldStop();
@@ -124,7 +124,6 @@ void CUDAMiner::workLoop()
124124
if (!w)
125125
return;
126126

127-
cnote << "set work; seed: " << "#" + w.seed.hex().substr(0, 8) + ", target: " << "#" + w.boundary.hex().substr(0, 22);
128127
if (!m_miner || m_minerSeed != w.seed)
129128
{
130129
unsigned device = s_devices[index] > -1 ? s_devices[index] : index;
@@ -162,7 +161,7 @@ void CUDAMiner::workLoop()
162161
//bytesConstRef dagData = dag->data();
163162
bytesConstRef lightData = light->data();
164163

165-
m_miner->init(light->light, lightData.data(), lightData.size(), device, (s_dagLoadMode == DAG_LOAD_MODE_SINGLE), &s_dagInHostMemory);
164+
m_miner->init(light->light, lightData.data(), lightData.size(), device, (s_dagLoadMode == DAG_LOAD_MODE_SINGLE), s_dagInHostMemory);
166165
s_dagLoadIndex++;
167166

168167
if (s_dagLoadMode == DAG_LOAD_MODE_SINGLE)

‎libethash-cuda/ethash_cuda_miner.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <iostream>
2828
#include <queue>
2929
#include <random>
30-
#include <atomic>
3130
#include <sstream>
3231
#include <chrono>
3332
#include <thread>
@@ -201,7 +200,7 @@ void ethash_cuda_miner::finish()
201200
CUDA_SAFE_CALL(cudaDeviceReset());
202201
}
203202

204-
bool ethash_cuda_miner::init(ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, volatile void** hostDAG)
203+
bool ethash_cuda_miner::init(ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, uint8_t* &hostDAG)
205204
{
206205
try
207206
{
@@ -235,7 +234,7 @@ bool ethash_cuda_miner::init(ethash_light_t _light, uint8_t const* _lightData, u
235234
// create buffer for cache
236235
hash64_t * light = NULL;
237236

238-
if (!*hostDAG)
237+
if (!hostDAG)
239238
{
240239
CUDA_SAFE_CALL(cudaMalloc(reinterpret_cast<void**>(&light), _lightSize));
241240
// copy dag cache to CPU.
@@ -260,7 +259,7 @@ bool ethash_cuda_miner::init(ethash_light_t _light, uint8_t const* _lightData, u
260259

261260
m_sharedBytes = device_props.major * 100 < SHUFFLE_MIN_VER ? (64 * s_blockSize) / 8 : 0 ;
262261

263-
if (!*hostDAG)
262+
if (!hostDAG)
264263
{
265264
cudalog << "Generating DAG for GPU #" << m_device_num;
266265
ethash_generate_dag(dagSize, s_gridSize, s_blockSize, m_streams[0], m_device_num);
@@ -271,13 +270,13 @@ bool ethash_cuda_miner::init(ethash_light_t _light, uint8_t const* _lightData, u
271270
cudalog << "Copying DAG from GPU #" << m_device_num << " to host";
272271
CUDA_SAFE_CALL(cudaMemcpy(reinterpret_cast<void*>(memoryDAG), dag, dagSize, cudaMemcpyDeviceToHost));
273272

274-
*hostDAG = (void*)memoryDAG;
273+
hostDAG = memoryDAG;
275274
}
276275
}
277276
else
278277
{
279278
cudalog << "Copying DAG from host to GPU #" << m_device_num;
280-
const void* hdag = (const void*)(*hostDAG);
279+
const void* hdag = (const void*)hostDAG;
281280
CUDA_SAFE_CALL(cudaMemcpy(reinterpret_cast<void*>(dag), hdag, dagSize, cudaMemcpyHostToDevice));
282281
}
283282

@@ -355,7 +354,7 @@ void ethash_cuda_miner::search(uint8_t const* header, uint64_t target, search_ho
355354
run_ethash_search(s_gridSize, s_blockSize, m_sharedBytes, stream, buffer, m_current_nonce, m_parallelHash);
356355
if (m_current_index >= s_numStreams)
357356
{
358-
exit = found_count && hook.found(nonces, found_count);
357+
exit = found_count && hook.found(nonces);
359358
exit |= hook.searched(nonce_base, batch_size);
360359
}
361360
}

‎libethash-cuda/ethash_cuda_miner.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ethash_cuda_miner
1717
virtual ~search_hook(); // always a virtual destructor for a class with virtuals.
1818

1919
// reports progress, return true to abort
20-
virtual bool found(uint64_t const* nonces, uint32_t count) = 0;
20+
virtual bool found(uint64_t const* nonces) = 0;
2121
virtual bool searched(uint64_t start_nonce, uint32_t count) = 0;
2222
};
2323

@@ -37,7 +37,7 @@ class ethash_cuda_miner
3737
);
3838
static void setParallelHash(unsigned _parallelHash);
3939

40-
bool init(ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, volatile void** hostDAG);
40+
bool init(ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, uint8_t * &hostDAG);
4141

4242
void finish();
4343
void search(uint8_t const* header, uint64_t target, search_hook& hook, bool _ethStratum, uint64_t _startN);

‎libethcore/Miner.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ using namespace eth;
66

77
unsigned dev::eth::Miner::s_dagLoadMode = 0;
88

9-
volatile unsigned dev::eth::Miner::s_dagLoadIndex = 0;
9+
unsigned dev::eth::Miner::s_dagLoadIndex = 0;
1010

1111
unsigned dev::eth::Miner::s_dagCreateDevice = 0;
1212

13-
volatile void* dev::eth::Miner::s_dagInHostMemory = NULL;
13+
uint8_t* dev::eth::Miner::s_dagInHostMemory = NULL;
1414

1515

‎libethcore/Miner.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include <thread>
2525
#include <list>
26-
#include <atomic>
2726
#include <string>
2827
#include <boost/timer.hpp>
2928
#include <libdevcore/Common.h>
@@ -209,9 +208,9 @@ class Miner: public Worker
209208
void addHashCount(uint64_t _n) { m_hashCount += _n; }
210209

211210
static unsigned s_dagLoadMode;
212-
static volatile unsigned s_dagLoadIndex;
211+
static unsigned s_dagLoadIndex;
213212
static unsigned s_dagCreateDevice;
214-
static volatile void* s_dagInHostMemory;
213+
static uint8_t* s_dagInHostMemory;
215214

216215
const size_t index = 0;
217216
FarmFace& farm;

‎libhwmon/wrapnvml.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ return NULL;
159159
if (cudaGetDeviceProperties(&props, i) == cudaSuccess) {
160160
int j;
161161
for (j=0; j<nvmlh->nvml_gpucount; j++) {
162-
if ((nvmlh->nvml_pci_domain_id[j] == props.pciDomainID) &&
163-
(nvmlh->nvml_pci_bus_id[j] == props.pciBusID) &&
164-
(nvmlh->nvml_pci_device_id[j] == props.pciDeviceID)) {
162+
if ((nvmlh->nvml_pci_domain_id[j] == (unsigned int)props.pciDomainID) &&
163+
(nvmlh->nvml_pci_bus_id[j] == (unsigned int)props.pciBusID) &&
164+
(nvmlh->nvml_pci_device_id[j] == (unsigned int)props.pciDeviceID)) {
165165
#if 0
166166
printf("CUDA GPU[%d] matches NVML GPU[%d]\n", i, j);
167167
#endif

‎libstratum/EthStratumClient.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
361361
break;
362362
case 4:
363363
if (responseObject.get("result", false).asBool()) {
364-
cnote << EthLime << "B-) Submitted and accepted." << EthReset;
364+
cnote << EthLime << "Accepted." << EthReset;
365365
p_farm->acceptedSolution(m_stale);
366366
}
367367
else {
368-
cwarn << ":-( Not accepted.";
368+
cwarn << "Rejected.";
369369
p_farm->rejectedSolution(m_stale);
370370
}
371371
break;
@@ -399,7 +399,6 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
399399

400400
if (sHeaderHash != "" && sSeedHash != "")
401401
{
402-
cnote << "Received new job #" + job;
403402

404403
h256 seedHash = h256(sSeedHash);
405404

@@ -419,6 +418,9 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
419418
m_job = job;
420419

421420
p_farm->setWork(m_current);
421+
cnote << "Received new job #" + job.substr(0, 8)
422+
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
423+
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);
422424
}
423425
}
424426
else
@@ -435,7 +437,6 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
435437

436438
if (sHeaderHash != "" && sSeedHash != "" && sShareTarget != "")
437439
{
438-
cnote << "Received new job #" + job.substr(0, 8);
439440

440441
h256 seedHash = h256(sSeedHash);
441442
h256 headerHash = h256(sHeaderHash);
@@ -457,6 +458,10 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
457458
m_job = job;
458459

459460
p_farm->setWork(m_current);
461+
cnote << "Received new job #" + job.substr(0, 8)
462+
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
463+
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);
464+
460465
//x_current.unlock();
461466
p_worktimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::seconds(m_worktimeout));
462467
p_worktimer->async_wait(boost::bind(&EthStratumClient::work_timeout_handler, this, boost::asio::placeholders::error));
@@ -521,15 +526,11 @@ bool EthStratumClient::submit(Solution solution) {
521526
string temp_previous_job = m_previousJob;
522527
x_current.unlock();
523528

524-
cnote << "Solution found; Submitting to" << p_active->host << "...";
525-
526529
string minernonce;
527530
string nonceHex = toHex(solution.nonce);
528-
if (m_protocol != STRATUM_PROTOCOL_ETHEREUMSTRATUM)
529-
cnote << " Nonce:" << "0x" + nonceHex;
530-
else
531+
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM) {
531532
minernonce = nonceHex.substr(m_extraNonceHexSize, 16 - m_extraNonceHexSize);
532-
533+
}
533534

534535
if (EthashAux::eval(tempWork.seed, tempWork.header, solution.nonce).value < tempWork.boundary)
535536
{
@@ -553,6 +554,10 @@ bool EthStratumClient::submit(Solution solution) {
553554
async_write(m_socket, m_requestBuffer,
554555
boost::bind(&EthStratumClient::handleResponse, this,
555556
boost::asio::placeholders::error));
557+
cnote << "Solution found; Submitted to" << p_active->host;
558+
if (m_protocol != STRATUM_PROTOCOL_ETHEREUMSTRATUM) {
559+
cnote << "Nonce:" << "0x" + nonceHex;
560+
}
556561
return true;
557562
}
558563
else if (EthashAux::eval(tempPreviousWork.seed, tempPreviousWork.header, solution.nonce).value < tempPreviousWork.boundary)
@@ -574,10 +579,10 @@ bool EthStratumClient::submit(Solution solution) {
574579
std::ostream os(&m_requestBuffer);
575580
os << json;
576581
m_stale = true;
577-
cwarn << "Submitting stale solution.";
578582
async_write(m_socket, m_requestBuffer,
579583
boost::bind(&EthStratumClient::handleResponse, this,
580584
boost::asio::placeholders::error));
585+
cwarn << "Submitted stale solution.";
581586
return true;
582587
}
583588
else {

‎libstratum/EthStratumClientV2.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
305305
break;
306306
case 4:
307307
if (responseObject.get("result", false).asBool()) {
308-
cnote << EthLime << "B-) Submitted and accepted." << EthReset;
308+
cnote << EthLime << "Accepted." << EthReset;
309309
p_farm->acceptedSolution(m_stale);
310310
}
311311
else {
312-
cwarn << ":-( Not accepted.";
312+
cwarn << "Rejected.";
313313
p_farm->rejectedSolution(m_stale);
314314
}
315315
break;
@@ -344,8 +344,6 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
344344

345345
if (sHeaderHash != "" && sSeedHash != "")
346346
{
347-
cnote << "Received new job #" + job;
348-
349347
h256 seedHash = h256(sSeedHash);
350348

351349
m_previous.header = m_current.header;
@@ -364,6 +362,9 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
364362
m_job = job;
365363

366364
p_farm->setWork(m_current);
365+
cnote << "Received new job #" + job.substr(0, 8)
366+
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
367+
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);
367368
}
368369
}
369370
else
@@ -380,7 +381,6 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
380381

381382
if (sHeaderHash != "" && sSeedHash != "" && sShareTarget != "")
382383
{
383-
cnote << "Received new job #" + job.substr(0, 8);
384384

385385
h256 seedHash = h256(sSeedHash);
386386
h256 headerHash = h256(sHeaderHash);
@@ -406,6 +406,9 @@ void EthStratumClientV2::processReponse(Json::Value& responseObject)
406406
//p_worktimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::seconds(m_worktimeout));
407407
//p_worktimer->async_wait(boost::bind(&EthStratumClientV2::work_timeout_handler, this, boost::asio::placeholders::error));
408408
}
409+
cnote << "Received new job #" + job.substr(0, 8)
410+
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
411+
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);
409412
}
410413
}
411414
}
@@ -463,15 +466,11 @@ bool EthStratumClientV2::submit(Solution solution) {
463466
string temp_previous_job = m_previousJob;
464467
x_current.unlock();
465468

466-
cnote << "Solution found; Submitting to" << p_active->host << "...";
467-
468469
string minernonce;
469470
string nonceHex = toHex(solution.nonce);
470-
if (m_protocol != STRATUM_PROTOCOL_ETHEREUMSTRATUM)
471-
cnote << " Nonce:" << "0x" + nonceHex;
472-
else
471+
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM) {
473472
minernonce = nonceHex.substr(m_extraNonceHexSize, 16 - m_extraNonceHexSize);
474-
473+
}
475474

476475
if (EthashAux::eval(tempWork.seed, tempWork.header, solution.nonce).value < tempWork.boundary)
477476
{
@@ -491,6 +490,10 @@ bool EthStratumClientV2::submit(Solution solution) {
491490
os << json;
492491
m_stale = false;
493492
write(m_socket, m_requestBuffer);
493+
cnote << "Solution found; Submitted to" << p_active->host;
494+
if (m_protocol != STRATUM_PROTOCOL_ETHEREUMSTRATUM) {
495+
cnote << "Nonce:" << "0x" + nonceHex;
496+
}
494497
return true;
495498
}
496499
else if (EthashAux::eval(tempPreviousWork.seed, tempPreviousWork.header, solution.nonce).value < tempPreviousWork.boundary)
@@ -509,8 +512,8 @@ bool EthStratumClientV2::submit(Solution solution) {
509512
} std::ostream os(&m_requestBuffer);
510513
os << json;
511514
m_stale = true;
512-
cwarn << "Submitting stale solution.";
513515
write(m_socket, m_requestBuffer);
516+
cwarn << "Submitted stale solution.";
514517
return true;
515518
}
516519
else {

0 commit comments

Comments
 (0)
This repository has been archived.