diff --git a/eth/main.cpp b/eth/main.cpp index 7da725b6c..bc7d4875c 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -38,14 +38,17 @@ #include #include #include -#if ETH_READLINE +#if ETH_READLINE || !ETH_TRUE #include #include #endif -#if ETH_JSONRPC +#if ETH_JSONRPC || !ETH_TRUE #include #include #endif +#if ETH_CURL || !ETH_TRUE +#include +#endif #include "BuildInfo.h" using namespace std; using namespace dev; @@ -128,7 +131,7 @@ void help() #if ETH_JSONRPC || !ETH_TRUE << " -F,--farm Put into mining farm mode (default GPU with CPU as fallback)." << endl #endif - << " -G,--gpu When miningm use the GPU." << endl + << " -G,--gpu When mining use the GPU." << endl << " -h,--help Show this help message and exit." << endl << " -i,--interactive Enter interactive mode (default: non-interactive)." << endl << " -I,--import Import file as a concatenated series of blocks and exit." << endl @@ -146,6 +149,7 @@ void help() << " -m,--mining Enable mining, optionally for a specified number of blocks (Default: off)" << endl << " -M,--benchmark Benchmark for mining and exit; use with --cpu and --gpu." << endl << " -o,--mode Start a full node or a peer node (Default: full)." << endl + << " --opencl-device When mining use OpenCL device n (default: 0)." << endl << " -p,--port Connect to remote port (default: 30303)." << endl << " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl << " --phone-home When benchmarking, publish results (Default: on)" << endl @@ -302,6 +306,8 @@ void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, u (void)_phoneHome; if (_phoneHome) { + cout << "Phoning home to find world ranking..." << endl; + // TODO: send f.miningInfo() along with f.platformInfo() to Marian. } exit(0); @@ -318,6 +324,7 @@ int main(int argc, char** argv) /// Mining options MinerType minerType = MinerType::CPU; + unsigned openclDevice = 0; /// File name for import/export. string filename; @@ -406,6 +413,15 @@ int main(int argc, char** argv) } else if (arg == "-F" || arg == "--farm") mode = OperationMode::Farm; + else if (arg == "--opencl-device" && i + 1 < argc) + try { + openclDevice = stol(argv[++i]); + } + catch (...) + { + cerr << "Bad " << arg << " option: " << argv[i] << endl; + return -1; + } else if (arg == "--phone-home" && i + 1 < argc) { string m = argv[++i]; @@ -718,6 +734,8 @@ int main(int argc, char** argv) if (mode == OperationMode::DAGInit) doInitDAG(web3.ethereum()->blockChain().number() + (initDAG == PendingBlock ? 30000 : 0)); + ProofOfWork::GPUMiner::setDefaultDevice(openclDevice); + auto toNumber = [&](string const& s) -> unsigned { if (s == "latest") return web3.ethereum()->number(); diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index c9a621e29..56ac44e6b 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -92,7 +92,7 @@ void ethash_cl_miner::finish() } } -bool ethash_cl_miner::init(ethash_params const& params, std::function _fillDAG, unsigned workgroup_size) +bool ethash_cl_miner::init(ethash_params const& params, std::function _fillDAG, unsigned workgroup_size, unsigned _deviceId) { // store params m_params = params; @@ -119,8 +119,13 @@ bool ethash_cl_miner::init(ethash_params const& params, std::function(_deviceId, devices.size() - 1)]; + for (unsigned n = 0; n < devices.size(); ++n) + { + auto version = devices[n].getInfo(); + auto name = devices[n].getInfo(); + fprintf(stderr, "%s %d: %s (%s)\n", n == _deviceId ? "USING " : " ", n, name.c_str(), version.c_str()); + } std::string device_version = device.getInfo(); fprintf(stderr, "Using device: %s (%s)\n", device.getInfo().c_str(),device_version.c_str()); diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index 079000f55..c699a2d83 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/libethash-cl/ethash_cl_miner.h @@ -22,7 +22,7 @@ public: public: ethash_cl_miner(); - bool init(ethash_params const& params, std::function _fillDAG, unsigned workgroup_size = 64); + bool init(ethash_params const& params, std::function _fillDAG, unsigned workgroup_size = 64, unsigned _deviceId = 0); static std::string platform_info(); void finish(); diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 632bc278d..2307da9dc 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -261,6 +261,8 @@ private: Ethash::GPUMiner* m_owner = nullptr; }; +unsigned Ethash::GPUMiner::s_deviceId = 0; + Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci): Miner(_ci), m_hook(new EthashCLHook(this)) @@ -302,7 +304,7 @@ void Ethash::GPUMiner::workLoop() auto p = EthashAux::params(m_minerSeed); auto cb = [&](void* d) { EthashAux::full(m_minerSeed, bytesRef((byte*)d, p.full_size)); }; - m_miner->init(p, cb, 32); + m_miner->init(p, cb, 32, s_deviceId); } uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192); diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 0d33d43a8..077da4460 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -86,6 +86,7 @@ public: static unsigned instances() { return std::thread::hardware_concurrency(); } static std::string platformInfo(); + static void setDefaultDevice(unsigned) {} protected: void kickOff() override @@ -98,6 +99,7 @@ public: private: void workLoop() override; + static unsigned s_deviceId; }; #if ETH_ETHASHCL || !ETH_TRUE @@ -111,6 +113,7 @@ public: static unsigned instances() { return 1; } static std::string platformInfo(); + static void setDefaultDevice(unsigned _id) { s_deviceId = _id; } protected: void kickOff() override; @@ -126,6 +129,7 @@ public: ethash_cl_miner* m_miner = nullptr; h256 m_minerSeed; ///< Last seed in m_miner + static unsigned s_deviceId; }; #else using GPUMiner = CPUMiner;