Browse Source

Allow device selection.

cl-refactor
Gav Wood 10 years ago
parent
commit
aa6b3c28cc
  1. 24
      eth/main.cpp
  2. 11
      libethash-cl/ethash_cl_miner.cpp
  3. 2
      libethash-cl/ethash_cl_miner.h
  4. 4
      libethcore/Ethash.cpp
  5. 4
      libethcore/Ethash.h

24
eth/main.cpp

@ -38,14 +38,17 @@
#include <libevm/VMFactory.h>
#include <libethereum/All.h>
#include <libwebthree/WebThree.h>
#if ETH_READLINE
#if ETH_READLINE || !ETH_TRUE
#include <readline/readline.h>
#include <readline/history.h>
#endif
#if ETH_JSONRPC
#if ETH_JSONRPC || !ETH_TRUE
#include <libweb3jsonrpc/WebThreeStubServer.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#endif
#if ETH_CURL || !ETH_TRUE
#include <curl/curl.h>
#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 <file> Import file as a concatenated series of blocks and exit." << endl
@ -146,6 +149,7 @@ void help()
<< " -m,--mining <on/off/number> 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 <full/peer> Start a full node or a peer node (Default: full)." << endl
<< " --opencl-device <n> When mining use OpenCL device n (default: 0)." << endl
<< " -p,--port <port> Connect to remote port (default: 30303)." << endl
<< " -P,--priority <0 - 100> Default % priority of a transaction (default: 50)." << endl
<< " --phone-home <on/off> 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();

11
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<void(void*)> _fillDAG, unsigned workgroup_size)
bool ethash_cl_miner::init(ethash_params const& params, std::function<void(void*)> _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<void(void*
}
// use default device
unsigned device_num = 0;
cl::Device& device = devices[device_num];
cl::Device& device = devices[std::min<unsigned>(_deviceId, devices.size() - 1)];
for (unsigned n = 0; n < devices.size(); ++n)
{
auto version = devices[n].getInfo<CL_DEVICE_VERSION>();
auto name = devices[n].getInfo<CL_DEVICE_NAME>();
fprintf(stderr, "%s %d: %s (%s)\n", n == _deviceId ? "USING " : " ", n, name.c_str(), version.c_str());
}
std::string device_version = device.getInfo<CL_DEVICE_VERSION>();
fprintf(stderr, "Using device: %s (%s)\n", device.getInfo<CL_DEVICE_NAME>().c_str(),device_version.c_str());

2
libethash-cl/ethash_cl_miner.h

@ -22,7 +22,7 @@ public:
public:
ethash_cl_miner();
bool init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size = 64);
bool init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size = 64, unsigned _deviceId = 0);
static std::string platform_info();
void finish();

4
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);

4
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;

Loading…
Cancel
Save