Browse Source

Cleanup OpenCL miner and options

cl-refactor
Paweł Bylica 7 years ago
parent
commit
d7f69051df
No known key found for this signature in database GPG Key ID: 7A0C037434FE77EF
  1. 57
      ethminer/MinerAux.h
  2. 77
      libethash-cl/ethash_cl_miner.cpp
  3. 6
      libethash-cl/ethash_cl_miner.h
  4. 8
      libethcore/EthashGPUMiner.cpp
  5. 3
      libethcore/EthashGPUMiner.h
  6. 1
      libethcore/Miner.h
  7. 4
      libstratum/EthStratumClient.cpp
  8. 4
      libstratum/EthStratumClientV2.cpp

57
ethminer/MinerAux.h

@ -81,7 +81,6 @@ public:
enum class OperationMode
{
None,
DAGInit,
Benchmark,
Simulation,
Farm,
@ -380,8 +379,6 @@ public:
cerr << "Bad " << arg << " option: " << argv[i] << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
else if (arg == "-C" || arg == "--cpu")
m_minerType = MinerType::CPU;
else if (arg == "-G" || arg == "--opencl")
m_minerType = MinerType::CL;
else if (arg == "-U" || arg == "--cuda")
@ -435,18 +432,6 @@ public:
}
}
}
else if ((arg == "-t" || arg == "--mining-threads") && i + 1 < argc)
{
try
{
m_miningThreads = stol(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
}
else
return false;
return true;
@ -464,37 +449,26 @@ public:
if (m_minerType == MinerType::CUDA || m_minerType == MinerType::Mixed)
EthashCUDAMiner::listDevices();
#endif
if (m_minerType == MinerType::CPU)
cout << "--list-devices should be combined with GPU mining flag (-G for OpenCL or -U for CUDA)" << endl;
exit(0);
}
if (m_minerType == MinerType::CPU)
{
cout << "CPU mining is no longer supported in this miner. Use -G (opencl) or -U (cuda) flag to select GPU platform." << endl;
exit(0);
}
else if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
if (m_minerType == MinerType::CL || m_minerType == MinerType::Mixed)
{
#if ETH_ETHASHCL
if (m_openclDeviceCount > 0)
{
EthashGPUMiner::setDevices(m_openclDevices, m_openclDeviceCount);
m_miningThreads = m_openclDeviceCount;
}
if (!EthashGPUMiner::configureGPU(
m_localWorkSize,
m_globalWorkSizeMultiplier,
m_openclPlatform,
m_openclDevice,
m_extraGPUMemory,
0,
m_dagLoadMode,
m_dagCreateDevice
))
exit(1);
EthashGPUMiner::setNumInstances(m_miningThreads);
EthashGPUMiner::setNumInstances(m_openclDeviceCount);
#else
cerr << "Selected GPU mining without having compiled with -DETHASHCL=1" << endl;
exit(1);
@ -504,12 +478,9 @@ public:
{
#if ETH_ETHASHCUDA
if (m_cudaDeviceCount > 0)
{
EthashCUDAMiner::setDevices(m_cudaDevices, m_cudaDeviceCount);
m_miningThreads = m_cudaDeviceCount;
}
EthashCUDAMiner::setNumInstances(m_miningThreads);
EthashCUDAMiner::setNumInstances(m_cudaDeviceCount);
if (!EthashCUDAMiner::configureGPU(
m_localWorkSize,
m_globalWorkSizeMultiplier,
@ -622,12 +593,12 @@ private:
sealers["opencl"] = Farm::SealerDescriptor{&EthashGPUMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }};
#endif
#if ETH_ETHASHCUDA
sealers["cuda"] = Farm::SealerDescriptor{ &EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
sealers["cuda"] = Farm::SealerDescriptor{&EthashCUDAMiner::instances, [](Miner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); }};
#endif
f.setSealers(sealers);
f.onSolutionFound([&](Solution) { return false; });
string platformInfo = _m == MinerType::CPU ? "CPU" : (_m == MinerType::CL ? "CL" : "CUDA");
string platformInfo = _m == MinerType::CL ? "CL" : "CUDA";
cout << "Benchmarking on platform: " << platformInfo << endl;
cout << "Preparing DAG for block #" << m_benchmarkBlock << endl;
@ -635,9 +606,7 @@ private:
genesis.setDifficulty(u256(1) << 63);
f.setWork(genesis);
if (_m == MinerType::CPU)
f.start("cpu", false);
else if (_m == MinerType::CL)
if (_m == MinerType::CL)
f.start("opencl", false);
else if (_m == MinerType::CUDA)
f.start("cuda", false);
@ -692,7 +661,7 @@ private:
#endif
f.setSealers(sealers);
string platformInfo = _m == MinerType::CPU ? "CPU" : (_m == MinerType::CL ? "CL" : "CUDA");
string platformInfo = _m == MinerType::CL ? "CL" : "CUDA";
cout << "Running mining simulation on platform: " << platformInfo << endl;
cout << "Preparing DAG for block #" << m_benchmarkBlock << endl;
@ -701,9 +670,7 @@ private:
genesis.setDifficulty(u256(1) << difficulty);
f.setWork(genesis);
if (_m == MinerType::CPU)
f.start("cpu", false);
else if (_m == MinerType::CL)
if (_m == MinerType::CL)
f.start("opencl", false);
else if (_m == MinerType::CUDA)
f.start("cuda", false);
@ -782,9 +749,7 @@ private:
h256 id = h256::random();
Farm f;
f.setSealers(sealers);
if (_m == MinerType::CPU)
f.start("cpu", false);
else if (_m == MinerType::CL)
if (_m == MinerType::CL)
f.start("opencl", false);
else if (_m == MinerType::CUDA)
f.start("cuda", false);
@ -1019,10 +984,8 @@ private:
/// Mining options
bool m_running = true;
MinerType m_minerType = MinerType::CPU;
MinerType m_minerType = MinerType::Mixed;
unsigned m_openclPlatform = 0;
unsigned m_openclDevice = 0;
unsigned m_miningThreads = UINT_MAX;
bool m_shouldListDevices = false;
#if ETH_ETHASHCL
unsigned m_openclDeviceCount = 0;

77
libethash-cl/ethash_cl_miner.cpp

@ -29,7 +29,7 @@
#include <iostream>
#include <assert.h>
#include <queue>
#include <vector>
#include <memory>
#include <random>
#include <atomic>
#include <sstream>
@ -38,8 +38,6 @@
#include "ethash_cl_miner.h"
#include "ethash_cl_miner_kernel.h"
#define ETHASH_BYTES 32
#define OPENCL_PLATFORM_UNKNOWN 0
#define OPENCL_PLATFORM_NVIDIA 1
#define OPENCL_PLATFORM_AMD 2
@ -123,28 +121,6 @@ std::vector<cl::Platform> ethash_cl_miner::getPlatforms()
return platforms;
}
string ethash_cl_miner::platform_info(unsigned _platformId, unsigned _deviceId)
{
vector<cl::Platform> platforms = getPlatforms();
if (platforms.empty())
return {};
// get GPU device of the selected platform
unsigned platform_num = min<unsigned>(_platformId, platforms.size() - 1);
vector<cl::Device> devices = getDevices(platforms, _platformId);
if (devices.empty())
{
ETHCL_LOG("No OpenCL devices found.");
return {};
}
// use selected default device
unsigned device_num = min<unsigned>(_deviceId, devices.size() - 1);
cl::Device& device = devices[device_num];
string device_version = device.getInfo<CL_DEVICE_VERSION>();
return "{ \"platform\": \"" + platforms[platform_num].getInfo<CL_PLATFORM_NAME>() + "\", \"device\": \"" + device.getInfo<CL_DEVICE_NAME>() + "\", \"version\": \"" + device_version + "\" }";
}
std::vector<cl::Device> ethash_cl_miner::getDevices(std::vector<cl::Platform> const& _platforms, unsigned _platformId)
{
vector<cl::Device> devices;
@ -190,7 +166,6 @@ bool ethash_cl_miner::configureGPU(
{
s_workgroupSize = _localWorkSize;
s_initialGlobalWorkSize = _globalWorkSize;
s_extraRequiredGPUMem = _extraGPUMemory;
// by default let's only consider the DAG of the first epoch
uint64_t dagSize = ethash_get_datasize(_currentBlock);
@ -218,7 +193,6 @@ bool ethash_cl_miner::configureGPU(
);
}
unsigned ethash_cl_miner::s_extraRequiredGPUMem;
unsigned ethash_cl_miner::s_workgroupSize = ethash_cl_miner::c_defaultLocalWorkSize;
unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier * ethash_cl_miner::c_defaultLocalWorkSize;
@ -238,37 +212,28 @@ bool ethash_cl_miner::searchForAllDevices(unsigned _platformId, function<bool(cl
return false;
}
void ethash_cl_miner::doForAllDevices(function<void(cl::Device const&)> _callback)
void ethash_cl_miner::listDevices()
{
vector<cl::Platform> platforms = getPlatforms();
if (platforms.empty())
return;
for (unsigned i = 0; i < platforms.size(); ++i)
doForAllDevices(i, _callback);
}
// cl_uint numPlatforms = 0;
// cl_int r = clGetPlatformIDs(0, nullptr, &numPlatforms);
// assert(r == CL_SUCCESS);
// std::unique_ptr<cl_platform_id[]> platformIds{new cl_platform_id[numPlatforms]};
// r = clGetPlatformIDs(numPlatforms, platformIds.get(), nullptr);
// assert(r == CL_SUCCESS);
void ethash_cl_miner::doForAllDevices(unsigned _platformId, function<void(cl::Device const&)> _callback)
{
string outString ="\nListing OpenCL devices.\nFORMAT: [deviceID] deviceName\n";
vector<cl::Platform> platforms = getPlatforms();
if (platforms.empty())
return;
if (_platformId >= platforms.size())
return;
vector<cl::Device> devices = getDevices(platforms, _platformId);
for (cl::Device const& device: devices)
_callback(device);
}
void ethash_cl_miner::listDevices()
{
string outString ="\nListing OpenCL devices.\nFORMAT: [deviceID] deviceName\n";
unsigned int i = 0;
doForAllDevices([&outString, &i](cl::Device const _device)
int index = 0;
for (unsigned i = 0; i < platforms.size(); ++i)
{
vector<cl::Device> devices = getDevices(platforms, i);
for (cl::Device const& device: devices)
{
outString += "[" + to_string(i) + "] " + _device.getInfo<CL_DEVICE_NAME>() + "\n";
outString += "[" + to_string(index) + "] " + device.getInfo<CL_DEVICE_NAME>() + "\n";
outString += "\tCL_DEVICE_TYPE: ";
switch (_device.getInfo<CL_DEVICE_TYPE>())
switch (device.getInfo<CL_DEVICE_TYPE>())
{
case CL_DEVICE_TYPE_CPU:
outString += "CPU\n";
@ -283,12 +248,12 @@ void ethash_cl_miner::listDevices()
outString += "DEFAULT\n";
break;
}
outString += "\tCL_DEVICE_GLOBAL_MEM_SIZE: " + to_string(_device.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>()) + "\n";
outString += "\tCL_DEVICE_MAX_MEM_ALLOC_SIZE: " + to_string(_device.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()) + "\n";
outString += "\tCL_DEVICE_MAX_WORK_GROUP_SIZE: " + to_string(_device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>()) + "\n";
++i;
outString += "\tCL_DEVICE_GLOBAL_MEM_SIZE: " + to_string(device.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>()) + "\n";
outString += "\tCL_DEVICE_MAX_MEM_ALLOC_SIZE: " + to_string(device.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()) + "\n";
outString += "\tCL_DEVICE_MAX_WORK_GROUP_SIZE: " + to_string(device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>()) + "\n";
++index;
}
);
}
ETHCL_LOG(outString);
}

6
libethash-cl/ethash_cl_miner.h

@ -43,10 +43,7 @@ public:
~ethash_cl_miner();
static bool searchForAllDevices(unsigned _platformId, std::function<bool(cl::Device const&)> _callback);
static void doForAllDevices(unsigned _platformId, std::function<void(cl::Device const&)> _callback);
static void doForAllDevices(std::function<void(cl::Device const&)> _callback);
static unsigned getNumDevices(unsigned _platformId = 0);
static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
static void listDevices();
static bool configureGPU(
unsigned _platformId,
@ -92,7 +89,4 @@ private:
static unsigned s_workgroupSize;
/// The initial global work size for the searches
static unsigned s_initialGlobalWorkSize;
/// GPU memory required for other things, like window rendering e.t.c.
/// User can set it via the --cl-extragpu-mem argument.
static unsigned s_extraRequiredGPUMem;
};

8
libethcore/EthashGPUMiner.cpp

@ -102,7 +102,6 @@ private:
}
unsigned EthashGPUMiner::s_platformId = 0;
unsigned EthashGPUMiner::s_deviceId = 0;
unsigned EthashGPUMiner::s_numInstances = 0;
int EthashGPUMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
@ -186,11 +185,6 @@ void EthashGPUMiner::pause()
stopWorking();
}
std::string EthashGPUMiner::platformInfo()
{
return ethash_cl_miner::platform_info(s_platformId, s_deviceId);
}
unsigned EthashGPUMiner::getNumDevices()
{
return ethash_cl_miner::getNumDevices(s_platformId);
@ -205,7 +199,6 @@ bool EthashGPUMiner::configureGPU(
unsigned _localWorkSize,
unsigned _globalWorkSizeMultiplier,
unsigned _platformId,
unsigned _deviceId,
unsigned _extraGPUMemory,
uint64_t _currentBlock,
unsigned _dagLoadMode,
@ -216,7 +209,6 @@ bool EthashGPUMiner::configureGPU(
s_dagCreateDevice = _dagCreateDevice;
s_platformId = _platformId;
s_deviceId = _deviceId;
_localWorkSize = ((_localWorkSize + 7) / 8) * 8;

3
libethcore/EthashGPUMiner.h

@ -45,14 +45,12 @@ public:
~EthashGPUMiner();
static unsigned instances() { return s_numInstances > 0 ? s_numInstances : 1; }
static std::string platformInfo();
static unsigned getNumDevices();
static void listDevices();
static bool configureGPU(
unsigned _localWorkSize,
unsigned _globalWorkSizeMultiplier,
unsigned _platformId,
unsigned _deviceId,
unsigned _extraGPUMemory,
uint64_t _currentBlock,
unsigned _dagLoadMode,
@ -82,7 +80,6 @@ private:
h256 m_minerSeed; ///< Last seed in m_miner
static unsigned s_platformId;
static unsigned s_deviceId;
static unsigned s_numInstances;
static int s_devices[16];

1
libethcore/Miner.h

@ -61,7 +61,6 @@ namespace eth
enum class MinerType
{
CPU,
CL,
CUDA,
Mixed

4
libstratum/EthStratumClient.cpp

@ -176,9 +176,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp:
if (!p_farm->isMining())
{
cnote << "Starting farm";
if (m_minerType == MinerType::CPU)
p_farm->start("cpu", false);
else if (m_minerType == MinerType::CL)
if (m_minerType == MinerType::CL)
p_farm->start("opencl", false);
else if (m_minerType == MinerType::CUDA)
p_farm->start("cuda", false);

4
libstratum/EthStratumClientV2.cpp

@ -141,9 +141,7 @@ void EthStratumClientV2::connect()
if (!p_farm->isMining())
{
cnote << "Starting farm";
if (m_minerType == MinerType::CPU)
p_farm->start("cpu", false);
else if (m_minerType == MinerType::CL)
if (m_minerType == MinerType::CL)
p_farm->start("opencl", false);
else if (m_minerType == MinerType::CUDA)
p_farm->start("cuda", false);

Loading…
Cancel
Save