forked from ethereum-mining/ethminer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
1400 lines (1239 loc) · 55.1 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of ethminer.
ethminer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ethminer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ethminer. If not, see <http://www.gnu.org/licenses/>.
*/
#include <CLI/CLI.hpp>
#include <ethminer/buildinfo.h>
#include <condition_variable>
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
#include <libethcore/Farm.h>
#if ETH_ETHASHCL
#include <libethash-cl/CLMiner.h>
#endif
#if ETH_ETHASHCUDA
#include <libethash-cuda/CUDAMiner.h>
#endif
#if ETH_ETHASHCPU
#include <libethash-cpu/CPUMiner.h>
#endif
#include <libpoolprotocols/PoolManager.h>
#if API_CORE
#include <libapicore/ApiServer.h>
#include <regex>
#endif
#if defined(__linux__) || defined(__APPLE__)
#include <execinfo.h>
#elif defined(_WIN32)
#include <Windows.h>
#endif
using namespace std;
using namespace dev;
using namespace dev::eth;
// Global vars
bool g_running = false;
bool g_exitOnError = false; // Whether or not ethminer should exit on mining threads errors
condition_variable g_shouldstop;
boost::asio::io_service g_io_service; // The IO service itself
struct MiningChannel : public LogChannel
{
static const char* name() { return EthGreen " m"; }
static const int verbosity = 2;
};
#define minelog clog(MiningChannel)
#if ETH_DBUS
#include <ethminer/DBusInt.h>
#endif
class MinerCLI
{
public:
enum class OperationMode
{
None,
Simulation,
Mining
};
MinerCLI() : m_cliDisplayTimer(g_io_service), m_io_strand(g_io_service)
{
// Initialize display timer as sleeper
m_cliDisplayTimer.expires_from_now(boost::posix_time::pos_infin);
m_cliDisplayTimer.async_wait(m_io_strand.wrap(boost::bind(
&MinerCLI::cliDisplayInterval_elapsed, this, boost::asio::placeholders::error)));
// Start io_service in it's own thread
m_io_thread = std::thread{boost::bind(&boost::asio::io_service::run, &g_io_service)};
// Io service is now live and running
// All components using io_service should post to reference of g_io_service
// and should not start/stop or even join threads (which heavily time consuming)
}
virtual ~MinerCLI()
{
m_cliDisplayTimer.cancel();
g_io_service.stop();
m_io_thread.join();
}
void cliDisplayInterval_elapsed(const boost::system::error_code& ec)
{
if (!ec && g_running)
{
string logLine =
PoolManager::p().isConnected() ? Farm::f().Telemetry().str() : "Not connected";
minelog << logLine;
#if ETH_DBUS
dbusint.send(Farm::f().Telemetry().str());
#endif
// Resubmit timer
m_cliDisplayTimer.expires_from_now(boost::posix_time::seconds(m_cliDisplayInterval));
m_cliDisplayTimer.async_wait(m_io_strand.wrap(boost::bind(
&MinerCLI::cliDisplayInterval_elapsed, this, boost::asio::placeholders::error)));
}
}
static void signalHandler(int sig)
{
dev::setThreadName("main");
switch (sig)
{
#if defined(__linux__) || defined(__APPLE__)
#define BACKTRACE_MAX_FRAMES 100
case SIGSEGV:
static bool in_handler = false;
if (!in_handler)
{
int j, nptrs;
void* buffer[BACKTRACE_MAX_FRAMES];
char** symbols;
in_handler = true;
dev::setThreadName("main");
cerr << "SIGSEGV encountered ...\n";
cerr << "stack trace:\n";
nptrs = backtrace(buffer, BACKTRACE_MAX_FRAMES);
cerr << "backtrace() returned " << nptrs << " addresses\n";
symbols = backtrace_symbols(buffer, nptrs);
if (symbols == NULL)
{
perror("backtrace_symbols()");
exit(EXIT_FAILURE); // Also exit 128 ??
}
for (j = 0; j < nptrs; j++)
cerr << symbols[j] << "\n";
free(symbols);
in_handler = false;
}
exit(128);
#undef BACKTRACE_MAX_FRAMES
#endif
case (999U):
// Compiler complains about the lack of
// a case statement in Windows
// this makes it happy.
break;
default:
cnote << "Got interrupt ...";
g_running = false;
g_shouldstop.notify_all();
break;
}
}
#if API_CORE
static void ParseBind(
const std::string& inaddr, std::string& outaddr, int& outport, bool advertise_negative_port)
{
std::regex pattern("([\\da-fA-F\\.\\:]*)\\:([\\d\\-]*)");
std::smatch matches;
if (std::regex_match(inaddr, matches, pattern))
{
// Validate Ip address
boost::system::error_code ec;
outaddr = boost::asio::ip::address::from_string(matches[1], ec).to_string();
if (ec)
throw std::invalid_argument("Invalid Ip Address");
// Parse port ( Let exception throw )
outport = std::stoi(matches[2]);
if (advertise_negative_port)
{
if (outport < -65535 || outport > 65535 || outport == 0)
throw std::invalid_argument(
"Invalid port number. Allowed non zero values in range [-65535 .. 65535]");
}
else
{
if (outport < 1 || outport > 65535)
throw std::invalid_argument(
"Invalid port number. Allowed non zero values in range [1 .. 65535]");
}
}
else
{
throw std::invalid_argument("Invalid syntax");
}
}
#endif
bool validateArgs(int argc, char** argv)
{
std::queue<string> warnings;
CLI::App app("Ethminer - GPU Ethash miner");
bool bhelp = false;
string shelpExt;
app.set_help_flag();
app.add_flag("-h,--help", bhelp, "Show help");
app.add_set("-H,--help-ext", shelpExt,
{
"con", "test",
#if ETH_ETHASHCL
"cl",
#endif
#if ETH_ETHASHCUDA
"cu",
#endif
#if ETH_ETHASHCPU
"cp",
#endif
#if API_CORE
"api",
#endif
"misc", "env"
},
"", true);
bool version = false;
app.add_option("--ergodicity", m_FarmSettings.ergodicity, "", true)->check(CLI::Range(0, 2));
app.add_flag("-V,--version", version, "Show program version");
app.add_option("-v,--verbosity", g_logOptions, "", true)->check(CLI::Range(LOG_NEXT - 1));
app.add_option("--farm-recheck", m_PoolSettings.getWorkPollInterval, "", true)->check(CLI::Range(1, 99999));
app.add_option("--farm-retries", m_PoolSettings.connectionMaxRetries, "", true)->check(CLI::Range(0, 99999));
app.add_option("--work-timeout", m_PoolSettings.noWorkTimeout, "", true)
->check(CLI::Range(180, 99999));
app.add_option("--response-timeout", m_PoolSettings.noResponseTimeout, "", true)
->check(CLI::Range(2, 999));
app.add_flag("-R,--report-hashrate,--report-hr", m_PoolSettings.reportHashrate, "");
app.add_option("--display-interval", m_cliDisplayInterval, "", true)
->check(CLI::Range(1, 1800));
app.add_option("--HWMON", m_FarmSettings.hwMon, "", true)->check(CLI::Range(0, 2));
app.add_flag("--exit", g_exitOnError, "");
vector<string> pools;
app.add_option("-P,--pool", pools, "");
app.add_option("--failover-timeout", m_PoolSettings.poolFailoverTimeout, "", true)
->check(CLI::Range(0, 999));
app.add_flag("--nocolor", g_logNoColor, "");
app.add_flag("--syslog", g_logSyslog, "");
app.add_flag("--stdout", g_logStdout, "");
#if API_CORE
app.add_option("--api-bind", m_api_bind, "", true)
->check([this](const string& bind_arg) -> string {
try
{
MinerCLI::ParseBind(bind_arg, this->m_api_address, this->m_api_port, true);
}
catch (const std::exception& ex)
{
throw CLI::ValidationError("--api-bind", ex.what());
}
// not sure what to return, and the documentation doesn't say either.
// https://github.com/CLIUtils/CLI11/issues/144
return string("");
});
app.add_option("--api-port", m_api_port, "", true)->check(CLI::Range(-65535, 65535));
app.add_option("--api-password", m_api_password, "");
#endif
#if ETH_ETHASHCL || ETH_ETHASHCUDA || ETH_ETHASH_CPU
app.add_flag("--list-devices", m_shouldListDevices, "");
#endif
#if ETH_ETHASHCL
app.add_option("--opencl-device,--opencl-devices,--cl-devices", m_CLSettings.devices, "");
app.add_option("--cl-global-work", m_CLSettings.globalWorkSize, "", true);
app.add_set("--cl-local-work", m_CLSettings.localWorkSize, {64, 128, 256}, "", true);
app.add_flag("--cl-nobin", m_CLSettings.noBinary, "");
app.add_flag("--cl-noexit", m_CLSettings.noExit, "");
#endif
#if ETH_ETHASHCUDA
app.add_option("--cuda-devices,--cu-devices", m_CUSettings.devices, "");
app.add_option("--cuda-grid-size,--cu-grid-size", m_CUSettings.gridSize, "", true)
->check(CLI::Range(1, 131072));
app.add_set(
"--cuda-block-size,--cu-block-size", m_CUSettings.blockSize, {32, 64, 128, 256}, "", true);
string sched = "sync";
app.add_set(
"--cuda-schedule,--cu-schedule", sched, {"auto", "spin", "yield", "sync"}, "", true);
app.add_option("--cuda-streams,--cu-streams", m_CUSettings.streams, "", true)
->check(CLI::Range(1, 99));
#endif
#if ETH_ETHASHCPU
app.add_option("--cpu-devices,--cp-devices", m_CPSettings.devices, "");
#endif
app.add_flag("--noeval", m_FarmSettings.noEval, "");
app.add_option("-L,--dag-load-mode", m_FarmSettings.dagLoadMode, "", true)->check(CLI::Range(1));
bool cl_miner = false;
app.add_flag("-G,--opencl", cl_miner, "");
bool cuda_miner = false;
app.add_flag("-U,--cuda", cuda_miner, "");
bool cpu_miner = false;
#if ETH_ETHASHCPU
app.add_flag("--cpu", cpu_miner, "");
#endif
auto sim_opt = app.add_option("-Z,--simulation,-M,--benchmark", m_PoolSettings.benchmarkBlock, "", true);
app.add_option("--tstop", m_FarmSettings.tempStop, "", true)->check(CLI::Range(30, 100));
app.add_option("--tstart", m_FarmSettings.tempStart, "", true)->check(CLI::Range(30, 100));
// Exception handling is held at higher level
app.parse(argc, argv);
if (bhelp)
{
help();
return false;
}
else if (!shelpExt.empty())
{
helpExt(shelpExt);
return false;
}
else if (version)
{
return false;
}
#ifndef DEV_BUILD
if (g_logOptions & LOG_CONNECT)
warnings.push("Socket connections won't be logged. Compile with -DDEVBUILD=ON");
if (g_logOptions & LOG_SWITCH)
warnings.push("Job switch timings won't be logged. Compile with -DDEVBUILD=ON");
if (g_logOptions & LOG_SUBMIT)
warnings.push(
"Solution internal submission timings won't be logged. Compile with -DDEVBUILD=ON");
if (g_logOptions & LOG_PROGRAMFLOW)
warnings.push("Program flow won't be logged. Compile with -DDEVBUILD=ON");
#endif
if (cl_miner)
m_minerType = MinerType::CL;
else if (cuda_miner)
m_minerType = MinerType::CUDA;
else if (cpu_miner)
m_minerType = MinerType::CPU;
else
m_minerType = MinerType::Mixed;
/*
Operation mode Simulation do not require pool definitions
Operation mode Stratum or GetWork do need at least one
*/
if (sim_opt->count())
{
m_mode = OperationMode::Simulation;
pools.clear();
m_PoolSettings.connections.push_back(
std::shared_ptr<URI>(new URI("simulation://localhost:0", true)));
}
else
{
m_mode = OperationMode::Mining;
}
if (!m_shouldListDevices && m_mode != OperationMode::Simulation)
{
if (!pools.size())
throw std::invalid_argument(
"At least one pool definition required. See -P argument.");
for (size_t i = 0; i < pools.size(); i++)
{
std::string url = pools.at(i);
if (url == "exit")
{
if (i == 0)
throw std::invalid_argument(
"'exit' failover directive can't be the first in -P arguments list.");
else
url = "stratum+tcp://-:x@exit:0";
}
try
{
std::shared_ptr<URI> uri = std::shared_ptr<URI>(new URI(url));
if (uri->SecLevel() != dev::SecureLevel::NONE &&
uri->HostNameType() != dev::UriHostNameType::Dns && !getenv("SSL_NOVERIFY"))
{
warnings.push(
"You have specified host " + uri->Host() + " with encryption enabled.");
warnings.push("Certificate validation will likely fail");
}
m_PoolSettings.connections.push_back(uri);
}
catch (const std::exception& _ex)
{
string what = _ex.what();
throw std::runtime_error("Bad URI : " + what);
}
}
}
#if ETH_ETHASHCUDA
if (sched == "auto")
m_CUSettings.schedule = 0;
else if (sched == "spin")
m_CUSettings.schedule = 1;
else if (sched == "yield")
m_CUSettings.schedule = 2;
else if (sched == "sync")
m_CUSettings.schedule = 4;
#endif
if (m_FarmSettings.tempStop)
{
// If temp threshold set HWMON at least to 1
m_FarmSettings.hwMon = std::max((unsigned int)m_FarmSettings.hwMon, 1U);
if (m_FarmSettings.tempStop <= m_FarmSettings.tempStart)
{
std::string what = "-tstop must be greater than -tstart";
throw std::invalid_argument(what);
}
}
// Output warnings if any
if (warnings.size())
{
while (warnings.size())
{
cout << warnings.front() << endl;
warnings.pop();
}
cout << endl;
}
return true;
}
void execute()
{
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
CLMiner::enumDevices(m_DevicesCollection);
#endif
#if ETH_ETHASHCUDA
if (m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed)
CUDAMiner::enumDevices(m_DevicesCollection);
#endif
#if ETH_ETHASHCPU
if (m_minerType == MinerType::CPU)
CPUMiner::enumDevices(m_DevicesCollection);
#endif
// Can't proceed without any GPU
if (!m_DevicesCollection.size())
throw std::runtime_error("No usable mining devices found");
// If requested list detected devices and exit
if (m_shouldListDevices)
{
cout << setw(4) << " Id ";
cout << setiosflags(ios::left) << setw(10) << "Pci Id ";
cout << setw(5) << "Type ";
cout << setw(30) << "Name ";
#if ETH_ETHASHCUDA
if (m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed)
{
cout << setw(5) << "CUDA ";
cout << setw(4) << "SM ";
}
#endif
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
cout << setw(5) << "CL ";
#endif
cout << resetiosflags(ios::left) << setw(13) << "Total Memory"
<< " ";
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
{
cout << resetiosflags(ios::left) << setw(13) << "Cl Max Alloc"
<< " ";
cout << resetiosflags(ios::left) << setw(13) << "Cl Max W.Grp"
<< " ";
}
#endif
cout << resetiosflags(ios::left) << endl;
cout << setw(4) << "--- ";
cout << setiosflags(ios::left) << setw(10) << "--------- ";
cout << setw(5) << "---- ";
cout << setw(30) << "----------------------------- ";
#if ETH_ETHASHCUDA
if (m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed)
{
cout << setw(5) << "---- ";
cout << setw(4) << "--- ";
}
#endif
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
cout << setw(5) << "---- ";
#endif
cout << resetiosflags(ios::left) << setw(13) << "------------"
<< " ";
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
{
cout << resetiosflags(ios::left) << setw(13) << "------------"
<< " ";
cout << resetiosflags(ios::left) << setw(13) << "------------"
<< " ";
}
#endif
cout << resetiosflags(ios::left) << endl;
std::map<string, DeviceDescriptor>::iterator it = m_DevicesCollection.begin();
while (it != m_DevicesCollection.end())
{
auto i = std::distance(m_DevicesCollection.begin(), it);
cout << setw(3) << i << " ";
cout << setiosflags(ios::left) << setw(10) << it->first;
cout << setw(5);
switch (it->second.type)
{
case DeviceTypeEnum::Cpu:
cout << "Cpu";
break;
case DeviceTypeEnum::Gpu:
cout << "Gpu";
break;
case DeviceTypeEnum::Accelerator:
cout << "Acc";
break;
default:
break;
}
cout << setw(30) << (it->second.name).substr(0, 28);
#if ETH_ETHASHCUDA
if (m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed)
{
cout << setw(5) << (it->second.cuDetected ? "Yes" : "");
cout << setw(4) << it->second.cuCompute;
}
#endif
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
cout << setw(5) << (it->second.clDetected ? "Yes" : "");
#endif
cout << resetiosflags(ios::left) << setw(13)
<< getFormattedMemory((double)it->second.totalMemory) << " ";
#if ETH_ETHASHCL
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
{
cout << resetiosflags(ios::left) << setw(13)
<< getFormattedMemory((double)it->second.clMaxMemAlloc) << " ";
cout << resetiosflags(ios::left) << setw(13)
<< getFormattedMemory((double)it->second.clMaxWorkGroup) << " ";
}
#endif
cout << resetiosflags(ios::left) << endl;
it++;
}
return;
}
// Subscribe devices with appropriate Miner Type
// Use CUDA first when available then, as second, OpenCL
// Apply discrete subscriptions (if any)
#if ETH_ETHASHCUDA
if (m_CUSettings.devices.size() &&
(m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed))
{
for (auto index : m_CUSettings.devices)
{
if (index < m_DevicesCollection.size())
{
auto it = m_DevicesCollection.begin();
std::advance(it, index);
if (!it->second.cuDetected)
throw std::runtime_error("Can't CUDA subscribe a non-CUDA device.");
it->second.subscriptionType = DeviceSubscriptionTypeEnum::Cuda;
}
}
}
#endif
#if ETH_ETHASHCL
if (m_CLSettings.devices.size() &&
(m_minerType == MinerType::CL || m_minerType == MinerType::Mixed))
{
for (auto index : m_CLSettings.devices)
{
if (index < m_DevicesCollection.size())
{
auto it = m_DevicesCollection.begin();
std::advance(it, index);
if (!it->second.clDetected)
throw std::runtime_error("Can't OpenCL subscribe a non-OpenCL device.");
if (it->second.subscriptionType != DeviceSubscriptionTypeEnum::None)
throw std::runtime_error(
"Can't OpenCL subscribe a CUDA subscribed device.");
it->second.subscriptionType = DeviceSubscriptionTypeEnum::OpenCL;
}
}
}
#endif
#if ETH_ETHASHCPU
if (m_CPSettings.devices.size() && (m_minerType == MinerType::CPU))
{
for (auto index : m_CPSettings.devices)
{
if (index < m_DevicesCollection.size())
{
auto it = m_DevicesCollection.begin();
std::advance(it, index);
it->second.subscriptionType = DeviceSubscriptionTypeEnum::Cpu;
}
}
}
#endif
// Subscribe all detected devices
#if ETH_ETHASHCUDA
if (!m_CUSettings.devices.size() &&
(m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed))
{
for (auto it = m_DevicesCollection.begin(); it != m_DevicesCollection.end(); it++)
{
if (!it->second.cuDetected ||
it->second.subscriptionType != DeviceSubscriptionTypeEnum::None)
continue;
it->second.subscriptionType = DeviceSubscriptionTypeEnum::Cuda;
}
}
#endif
#if ETH_ETHASHCL
if (!m_CLSettings.devices.size() &&
(m_minerType == MinerType::CL || m_minerType == MinerType::Mixed))
{
for (auto it = m_DevicesCollection.begin(); it != m_DevicesCollection.end(); it++)
{
if (!it->second.clDetected ||
it->second.subscriptionType != DeviceSubscriptionTypeEnum::None)
continue;
it->second.subscriptionType = DeviceSubscriptionTypeEnum::OpenCL;
}
}
#endif
#if ETH_ETHASHCPU
if (!m_CPSettings.devices.size() &&
(m_minerType == MinerType::CPU))
{
for (auto it = m_DevicesCollection.begin(); it != m_DevicesCollection.end(); it++)
{
it->second.subscriptionType = DeviceSubscriptionTypeEnum::Cpu;
}
}
#endif
// Count of subscribed devices
int subscribedDevices = 0;
for (auto it = m_DevicesCollection.begin(); it != m_DevicesCollection.end(); it++)
{
if (it->second.subscriptionType != DeviceSubscriptionTypeEnum::None)
subscribedDevices++;
}
// If no OpenCL and/or CUDA devices subscribed then throw error
if (!subscribedDevices)
throw std::runtime_error("No mining device selected. Aborting ...");
// Enable
g_running = true;
// Signal traps
#if defined(__linux__) || defined(__APPLE__)
signal(SIGSEGV, MinerCLI::signalHandler);
#endif
signal(SIGINT, MinerCLI::signalHandler);
signal(SIGTERM, MinerCLI::signalHandler);
// Initialize Farm
new Farm(m_DevicesCollection, m_FarmSettings, m_CUSettings, m_CLSettings, m_CPSettings);
// Run Miner
doMiner();
}
void help()
{
cout << "Ethminer - GPU ethash miner" << endl
<< "minimal usage : ethminer [DEVICES_TYPE] [OPTIONS] -P... [-P...]" << endl
<< endl
<< "Devices type options :" << endl
<< endl
<< " By default ethminer will try to use all devices types" << endl
<< " it can detect. Optionally you can limit this behavior" << endl
<< " setting either of the following options" << endl
#if ETH_ETHASHCL
<< " -G,--opencl Mine/Benchmark using OpenCL only" << endl
#endif
#if ETH_ETHASHCUDA
<< " -U,--cuda Mine/Benchmark using CUDA only" << endl
#endif
#if ETH_ETHASHCPU
<< " --cpu Development ONLY ! (NO MINING)" << endl
#endif
<< endl
<< "Connection options :" << endl
<< endl
<< " -P,--pool Stratum pool or http (getWork) connection as URL" << endl
<< " "
"scheme://[user[.workername][:password]@]hostname:port[/...]"
<< endl
<< " For an explication and some samples about" << endl
<< " how to fill in this value please use" << endl
<< " ethminer --help-ext con" << endl
<< endl
<< "Common Options :" << endl
<< endl
<< " -h,--help Displays this help text and exits" << endl
<< " -H,--help-ext TEXT {'con','test',"
#if ETH_ETHASHCL
<< "cl,"
#endif
#if ETH_ETHASHCUDA
<< "cu,"
#endif
#if ETH_ETHASHCPU
<< "cp,"
#endif
#if API_CORE
<< "api,"
#endif
<< "'misc','env'}" << endl
<< " Display help text about one of these contexts:" << endl
<< " 'con' Connections and their definitions" << endl
<< " 'test' Benchmark/Simulation options" << endl
#if ETH_ETHASHCL
<< " 'cl' Extended OpenCL options" << endl
#endif
#if ETH_ETHASHCUDA
<< " 'cu' Extended CUDA options" << endl
#endif
#if ETH_ETHASHCPU
<< " 'cp' Extended CPU options" << endl
#endif
#if API_CORE
<< " 'api' API and Http monitoring interface" << endl
#endif
<< " 'misc' Other miscellaneous options" << endl
<< " 'env' Using environment variables" << endl
<< " -V,--version Show program version and exits" << endl
<< endl;
}
void helpExt(std::string ctx)
{
// Help text for benchmarking options
if (ctx == "test")
{
cout << "Benchmarking / Simulation options :" << endl
<< endl
<< " When playing with benchmark or simulation no connection specification "
"is"
<< endl
<< " needed ie. you can omit any -P argument." << endl
<< endl
<< " -M,--benchmark UINT [0 ..] Default not set" << endl
<< " Mining test. Used to test hashing speed." << endl
<< " Specify the block number to test on." << endl
<< endl
<< " -Z,--simulation UINT [0 ..] Default not set" << endl
<< " Mining test. Used to test hashing speed." << endl
<< " Specify the block number to test on." << endl
<< endl;
}
// Help text for API interfaces options
if (ctx == "api")
{
cout << "API Interface Options :" << endl
<< endl
<< " Ethminer provide an interface for monitor and or control" << endl
<< " Please note that information delivered by API interface" << endl
<< " may depend on value of --HWMON" << endl
<< " A single endpoint is used to accept both HTTP or plain tcp" << endl
<< " requests." << endl
<< endl
<< " --api-bind TEXT Default not set" << endl
<< " Set the API address:port the miner should listen "
"on. "
<< endl
<< " Use negative port number for readonly mode" << endl
<< " --api-port INT [1 .. 65535] Default not set" << endl
<< " Set the API port, the miner should listen on all "
"bound"
<< endl
<< " addresses. Use negative numbers for readonly mode"
<< endl
<< " --api-password TEXT Default not set" << endl
<< " Set the password to protect interaction with API "
"server. "
<< endl
<< " If not set, any connection is granted access. " << endl
<< " Be advised passwords are sent unencrypted over "
"plain "
"TCP!!"
<< endl;
}
if (ctx == "cl")
{
cout << "OpenCL Extended Options :" << endl
<< endl
<< " Use this extended OpenCL arguments to fine tune the performance." << endl
<< " Be advised default values are best generic findings by developers" << endl
<< endl
<< " --cl-devices UINT {} Default not set" << endl
<< " Space separated list of device indexes to use" << endl
<< " eg --cl-devices 0 2 3" << endl
<< " If not set all available CL devices will be used"
<< endl
<< " --cl-global-work UINT Default 65536" << endl
<< " Set the global work size multiplier" << endl
<< " Value will be adjusted to nearest power of 2" << endl
<< " --cl-local-work UINT {64,128,256} Default = 128" << endl
<< " Set the local work size multiplier" << endl
<< " --cl-nobin FLAG" << endl
<< " Use openCL kernel. Do not load binary kernel" << endl
<< " --cl-noexit FLAG" << endl
<< " Don't use fast exit algorithm" << endl;
}
if (ctx == "cu")
{
cout << "CUDA Extended Options :" << endl
<< endl
<< " Use this extended CUDA arguments to fine tune the performance." << endl
<< " Be advised default values are best generic findings by developers" << endl
<< endl
<< " --cu-grid-size INT [1 .. 131072] Default = 8192" << endl
<< " Set the grid size" << endl
<< " --cu-block-size UINT {32,64,128,256} Default = 128" << endl
<< " Set the block size" << endl
<< " --cu-devices UINT {} Default not set" << endl
<< " Space separated list of device indexes to use" << endl
<< " eg --cu-devices 0 2 3" << endl
<< " If not set all available CUDA devices will be used"
<< endl
<< " --cu-parallel-hash UINT {1,2,4,8} Default = 4" << endl
<< " Set the number of hashes per kernel" << endl
<< " --cu-streams INT [1 .. 99] Default = 2" << endl
<< " Set the number of streams per GPU" << endl
<< " --cu-schedule TEXT Default = 'sync'" << endl
<< " Set the CUDA scheduler mode. Can be one of" << endl
<< " 'auto' Uses a heuristic based on the number of "
"active "
<< endl
<< " CUDA contexts in the process (C) and the "
"number"
<< endl
<< " of logical processors in the system (P)"
<< endl
<< " If C > P then 'yield' else 'spin'" << endl
<< " 'spin' Instructs CUDA to actively spin when "
"waiting"
<< endl
<< " for results from the device" << endl
<< " 'yield' Instructs CUDA to yield its thread when "
"waiting for"
<< endl
<< " for results from the device" << endl
<< " 'sync' Instructs CUDA to block the CPU thread on "
"a "
<< endl
<< " synchronize primitive when waiting for "
"results"
<< endl
<< " from the device" << endl
<< endl;
}
if (ctx == "cp")
{
cout << "CPU Extended Options :" << endl
<< endl
<< " Use this extended CPU arguments"
<< endl
<< endl
<< " --cp-devices UINT {} Default not set" << endl
<< " Space separated list of device indexes to use" << endl
<< " eg --cp-devices 0 2 3" << endl
<< " If not set all available CPUs will be used" << endl
<< endl;
}
if (ctx == "misc")
{
cout << "Miscellaneous Options :" << endl
<< endl
<< " This set of options is valid for mining mode independently from" << endl
<< " OpenCL or CUDA or Mixed mining mode." << endl
<< endl
<< " --display-interval INT[1 .. 1800] Default = 5" << endl
<< " Statistic display interval in seconds" << endl
<< " --farm-recheck INT[1 .. 99999] Default = 500" << endl
<< " Set polling interval for new work in getWork mode"
<< endl
<< " Value expressed in milliseconds" << endl
<< " It has no meaning in stratum mode" << endl
<< " --farm-retries INT[1 .. 99999] Default = 3" << endl
<< " Set number of reconnection retries to same pool"
<< endl
<< " --failover-timeout INT[0 .. ] Default not set" << endl
<< " Sets the number of minutes ethminer can stay" << endl
<< " connected to a fail-over pool before trying to" << endl
<< " reconnect to the primary (the first) connection."
<< endl
<< " before switching to a fail-over connection" << endl
<< " --work-timeout INT[180 .. 99999] Default = 180" << endl
<< " If no new work received from pool after this" << endl
<< " amount of time the connection is dropped" << endl
<< " Value expressed in seconds." << endl
<< " --response-timeout INT[2 .. 999] Default = 2" << endl
<< " If no response from pool to a stratum message " << endl
<< " after this amount of time the connection is dropped"
<< endl
<< " -R,--report-hr FLAG Notify pool of effective hashing rate" << endl
<< " --HWMON INT[0 .. 2] Default = 0" << endl