Browse Source

Merge branch 'develop' of https://github.com/Genoil/cpp-ethereum into Genoil-develop

Conflicts:
	libethcore/Ethash.cpp
	libethereum/BlockQueue.cpp
cl-refactor
Gav Wood 10 years ago
parent
commit
32071fb12b
  1. 13
      eth/main.cpp
  2. 3
      libdevcore/CommonIO.h
  3. 24
      libethash-cl/ethash_cl_miner.cpp
  4. 4
      libethash-cl/ethash_cl_miner.h
  5. 5
      libethcore/Ethash.cpp
  6. 3
      libethcore/Ethash.h
  7. 4
      libethereum/Client.cpp

13
eth/main.cpp

@ -134,6 +134,7 @@ void help()
<< " -f,--force-mining Mine even when there are no transactions to mine (default: off)" << endl << " -f,--force-mining Mine even when there are no transactions to mine (default: off)" << endl
<< " -C,--cpu When mining, use the CPU." << endl << " -C,--cpu When mining, use the CPU." << endl
<< " -G,--opencl When mining use the GPU via OpenCL." << endl << " -G,--opencl When mining use the GPU via OpenCL." << endl
<< " --opencl-platform <n> When mining using -G/--opencl use OpenCL platform n (default: 0)." << endl
<< " --opencl-device <n> When mining using -G/--opencl use OpenCL device n (default: 0)." << endl << " --opencl-device <n> When mining using -G/--opencl use OpenCL device n (default: 0)." << endl
<< "Client networking:" << endl << "Client networking:" << endl
<< " --client-name <name> Add a name to your client's version string (default: blank)." << endl << " --client-name <name> Add a name to your client's version string (default: blank)." << endl
@ -394,6 +395,7 @@ int main(int argc, char** argv)
/// Mining options /// Mining options
MinerType minerType = MinerType::CPU; MinerType minerType = MinerType::CPU;
unsigned openclPlatform = 0;
unsigned openclDevice = 0; unsigned openclDevice = 0;
/// File name for import/export. /// File name for import/export.
@ -511,6 +513,15 @@ int main(int argc, char** argv)
cerr << "Bad " << arg << " option: " << argv[i] << endl; cerr << "Bad " << arg << " option: " << argv[i] << endl;
return -1; return -1;
} }
else if (arg == "--opencl-platform" && i + 1 < argc)
try {
openclPlatform= stol(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
return -1;
}
else if (arg == "--opencl-device" && i + 1 < argc) else if (arg == "--opencl-device" && i + 1 < argc)
try { try {
openclDevice = stol(argv[++i]); openclDevice = stol(argv[++i]);
@ -809,6 +820,7 @@ int main(int argc, char** argv)
if (sessionSecret) if (sessionSecret)
sigKey = KeyPair(sessionSecret); sigKey = KeyPair(sessionSecret);
ProofOfWork::GPUMiner::setDefaultPlatform(openclPlatform);
ProofOfWork::GPUMiner::setDefaultDevice(openclDevice); ProofOfWork::GPUMiner::setDefaultDevice(openclDevice);
// Two codepaths is necessary since named block require database, but numbered // Two codepaths is necessary since named block require database, but numbered
@ -926,6 +938,7 @@ int main(int argc, char** argv)
{ {
c->setGasPricer(gasPricer); c->setGasPricer(gasPricer);
c->setForceMining(forceMining); c->setForceMining(forceMining);
c->setTurboMining(minerType == MinerType::GPU);
c->setAddress(coinbase); c->setAddress(coinbase);
} }

3
libdevcore/CommonIO.h

@ -45,7 +45,8 @@ namespace dev
/// Retrieve and returns the contents of the given file. If the file doesn't exist or isn't readable, returns an empty bytes. /// Retrieve and returns the contents of the given file. If the file doesn't exist or isn't readable, returns an empty bytes.
bytes contents(std::string const& _file); bytes contents(std::string const& _file);
std::string contentsString(std::string const& _file); std::string contentsString(std::string const& _file);
/// Retrieve and returns the allocated contents of the given file. If the file doesn't exist or isn't readable, returns nullptr. Don't forget to delete [] when finished. /// Retrieve and returns the allocated contents of the given file; if @_dest is given, don't allocate, use it directly.
/// If the file doesn't exist or isn't readable, returns bytesRef(). Don't forget to delete [] the returned value's data when finished.
bytesRef contentsNew(std::string const& _file, bytesRef _dest = bytesRef()); bytesRef contentsNew(std::string const& _file, bytesRef _dest = bytesRef());
/// Write the given binary data into the given file, replacing the file if it pre-exists. /// Write the given binary data into the given file, replacing the file if it pre-exists.

24
libethash-cl/ethash_cl_miner.cpp

@ -57,7 +57,7 @@ ethash_cl_miner::ethash_cl_miner()
{ {
} }
std::string ethash_cl_miner::platform_info() std::string ethash_cl_miner::platform_info(unsigned _platformId, unsigned _deviceId)
{ {
std::vector<cl::Platform> platforms; std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms); cl::Platform::get(&platforms);
@ -67,21 +67,22 @@ std::string ethash_cl_miner::platform_info()
return std::string(); return std::string();
} }
// get GPU device of the default platform // get GPU device of the selected platform
std::vector<cl::Device> devices; std::vector<cl::Device> devices;
platforms[0].getDevices(CL_DEVICE_TYPE_ALL, &devices); unsigned platform_num = std::min<unsigned>(_platformId, platforms.size() - 1);
platforms[platform_num].getDevices(CL_DEVICE_TYPE_ALL, &devices);
if (devices.empty()) if (devices.empty())
{ {
debugf("No OpenCL devices found.\n"); debugf("No OpenCL devices found.\n");
return std::string(); return std::string();
} }
// use default device // use selected default device
unsigned device_num = 0; unsigned device_num = std::min<unsigned>(_deviceId, devices.size() - 1);
cl::Device& device = devices[device_num]; cl::Device& device = devices[device_num];
std::string device_version = device.getInfo<CL_DEVICE_VERSION>(); std::string device_version = device.getInfo<CL_DEVICE_VERSION>();
return "{ \"platform\": \"" + platforms[0].getInfo<CL_PLATFORM_NAME>() + "\", \"device\": \"" + device.getInfo<CL_DEVICE_NAME>() + "\", \"version\": \"" + device_version + "\" }"; return "{ \"platform\": \"" + platforms[platform_num].getInfo<CL_PLATFORM_NAME>() + "\", \"device\": \"" + device.getInfo<CL_DEVICE_NAME>() + "\", \"version\": \"" + device_version + "\" }";
} }
void ethash_cl_miner::finish() void ethash_cl_miner::finish()
@ -92,7 +93,7 @@ void ethash_cl_miner::finish()
} }
} }
bool ethash_cl_miner::init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size, unsigned _deviceId) bool ethash_cl_miner::init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size, unsigned _platformId, unsigned _deviceId)
{ {
// store params // store params
m_params = params; m_params = params;
@ -106,12 +107,15 @@ bool ethash_cl_miner::init(ethash_params const& params, std::function<void(void*
return false; return false;
} }
// use default platform // use selected platform
fprintf(stderr, "Using platform: %s\n", platforms[0].getInfo<CL_PLATFORM_NAME>().c_str());
_platformId = std::min<unsigned>(_platformId, platforms.size() - 1);
fprintf(stderr, "Using platform: %s\n", platforms[_platformId].getInfo<CL_PLATFORM_NAME>().c_str());
// get GPU device of the default platform // get GPU device of the default platform
std::vector<cl::Device> devices; std::vector<cl::Device> devices;
platforms[0].getDevices(CL_DEVICE_TYPE_ALL, &devices); platforms[_platformId].getDevices(CL_DEVICE_TYPE_ALL, &devices);
if (devices.empty()) if (devices.empty())
{ {
debugf("No OpenCL devices found.\n"); debugf("No OpenCL devices found.\n");

4
libethash-cl/ethash_cl_miner.h

@ -31,8 +31,8 @@ public:
public: public:
ethash_cl_miner(); ethash_cl_miner();
bool init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size = 64, unsigned _deviceId = 0); bool init(ethash_params const& params, std::function<void(void*)> _fillDAG, unsigned workgroup_size = 64, unsigned _platformId = 0, unsigned _deviceId = 0);
static std::string platform_info(); static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
void finish(); void finish();
void hash(uint8_t* ret, uint8_t const* header, uint64_t nonce, unsigned count); void hash(uint8_t* ret, uint8_t const* header, uint64_t nonce, unsigned count);

5
libethcore/Ethash.cpp

@ -262,6 +262,7 @@ private:
Ethash::GPUMiner* m_owner = nullptr; Ethash::GPUMiner* m_owner = nullptr;
}; };
unsigned Ethash::GPUMiner::s_platformId = 0;
unsigned Ethash::GPUMiner::s_deviceId = 0; unsigned Ethash::GPUMiner::s_deviceId = 0;
Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci): Ethash::GPUMiner::GPUMiner(ConstructionInfo const& _ci):
@ -307,7 +308,7 @@ void Ethash::GPUMiner::workLoop()
auto p = EthashAux::params(m_minerSeed); auto p = EthashAux::params(m_minerSeed);
auto cb = [&](void* d) { EthashAux::full(m_minerSeed, bytesRef((byte*)d, p.full_size)); }; auto cb = [&](void* d) { EthashAux::full(m_minerSeed, bytesRef((byte*)d, p.full_size)); };
m_miner->init(p, cb, 32, s_deviceId); m_miner->init(p, cb, 32, s_platformId, s_deviceId);
} }
uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192); uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192);
@ -324,7 +325,7 @@ void Ethash::GPUMiner::pause()
std::string Ethash::GPUMiner::platformInfo() std::string Ethash::GPUMiner::platformInfo()
{ {
return ethash_cl_miner::platform_info(); return ethash_cl_miner::platform_info(s_platformId, s_deviceId);
} }
#endif #endif

3
libethcore/Ethash.h

@ -86,6 +86,7 @@ public:
static unsigned instances() { return std::thread::hardware_concurrency(); } static unsigned instances() { return std::thread::hardware_concurrency(); }
static std::string platformInfo(); static std::string platformInfo();
static void setDefaultPlatform(unsigned) {}
static void setDefaultDevice(unsigned) {} static void setDefaultDevice(unsigned) {}
protected: protected:
@ -113,6 +114,7 @@ public:
static unsigned instances() { return 1; } static unsigned instances() { return 1; }
static std::string platformInfo(); static std::string platformInfo();
static void setDefaultPlatform(unsigned _id) { s_platformId = _id; }
static void setDefaultDevice(unsigned _id) { s_deviceId = _id; } static void setDefaultDevice(unsigned _id) { s_deviceId = _id; }
protected: protected:
@ -129,6 +131,7 @@ public:
ethash_cl_miner* m_miner = nullptr; ethash_cl_miner* m_miner = nullptr;
h256 m_minerSeed; ///< Last seed in m_miner h256 m_minerSeed; ///< Last seed in m_miner
static unsigned s_platformId;
static unsigned s_deviceId; static unsigned s_deviceId;
}; };
#else #else

4
libethereum/Client.cpp

@ -352,11 +352,15 @@ void Client::setForceMining(bool _enable)
MiningProgress Client::miningProgress() const MiningProgress Client::miningProgress() const
{ {
if (m_farm.isMining())
return m_farm.miningProgress();
return MiningProgress(); return MiningProgress();
} }
uint64_t Client::hashrate() const uint64_t Client::hashrate() const
{ {
if (m_farm.isMining())
return m_farm.miningProgress().rate();
return 0; return 0;
} }

Loading…
Cancel
Save