Browse Source

Cleanup OpenCL miner and options

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

77
libethash-cl/ethash_cl_miner.cpp

@ -29,7 +29,7 @@
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include <queue> #include <queue>
#include <vector> #include <memory>
#include <random> #include <random>
#include <atomic> #include <atomic>
#include <sstream> #include <sstream>
@ -38,8 +38,6 @@
#include "ethash_cl_miner.h" #include "ethash_cl_miner.h"
#include "ethash_cl_miner_kernel.h" #include "ethash_cl_miner_kernel.h"
#define ETHASH_BYTES 32
#define OPENCL_PLATFORM_UNKNOWN 0 #define OPENCL_PLATFORM_UNKNOWN 0
#define OPENCL_PLATFORM_NVIDIA 1 #define OPENCL_PLATFORM_NVIDIA 1
#define OPENCL_PLATFORM_AMD 2 #define OPENCL_PLATFORM_AMD 2
@ -123,28 +121,6 @@ std::vector<cl::Platform> ethash_cl_miner::getPlatforms()
return platforms; 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) std::vector<cl::Device> ethash_cl_miner::getDevices(std::vector<cl::Platform> const& _platforms, unsigned _platformId)
{ {
vector<cl::Device> devices; vector<cl::Device> devices;
@ -190,7 +166,6 @@ bool ethash_cl_miner::configureGPU(
{ {
s_workgroupSize = _localWorkSize; s_workgroupSize = _localWorkSize;
s_initialGlobalWorkSize = _globalWorkSize; s_initialGlobalWorkSize = _globalWorkSize;
s_extraRequiredGPUMem = _extraGPUMemory;
// by default let's only consider the DAG of the first epoch // by default let's only consider the DAG of the first epoch
uint64_t dagSize = ethash_get_datasize(_currentBlock); 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_workgroupSize = ethash_cl_miner::c_defaultLocalWorkSize;
unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier * 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; return false;
} }
void ethash_cl_miner::doForAllDevices(function<void(cl::Device const&)> _callback) void ethash_cl_miner::listDevices()
{ {
vector<cl::Platform> platforms = getPlatforms(); // cl_uint numPlatforms = 0;
if (platforms.empty()) // cl_int r = clGetPlatformIDs(0, nullptr, &numPlatforms);
return; // assert(r == CL_SUCCESS);
for (unsigned i = 0; i < platforms.size(); ++i) // std::unique_ptr<cl_platform_id[]> platformIds{new cl_platform_id[numPlatforms]};
doForAllDevices(i, _callback); // 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(); vector<cl::Platform> platforms = getPlatforms();
if (platforms.empty()) if (platforms.empty())
return; return;
if (_platformId >= platforms.size()) int index = 0;
return; for (unsigned i = 0; i < platforms.size(); ++i)
{
vector<cl::Device> devices = getDevices(platforms, _platformId); vector<cl::Device> devices = getDevices(platforms, i);
for (cl::Device const& device: devices) 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)
{ {
outString += "[" + to_string(i) + "] " + _device.getInfo<CL_DEVICE_NAME>() + "\n"; outString += "[" + to_string(index) + "] " + device.getInfo<CL_DEVICE_NAME>() + "\n";
outString += "\tCL_DEVICE_TYPE: "; outString += "\tCL_DEVICE_TYPE: ";
switch (_device.getInfo<CL_DEVICE_TYPE>()) switch (device.getInfo<CL_DEVICE_TYPE>())
{ {
case CL_DEVICE_TYPE_CPU: case CL_DEVICE_TYPE_CPU:
outString += "CPU\n"; outString += "CPU\n";
@ -283,12 +248,12 @@ void ethash_cl_miner::listDevices()
outString += "DEFAULT\n"; outString += "DEFAULT\n";
break; break;
} }
outString += "\tCL_DEVICE_GLOBAL_MEM_SIZE: " + to_string(_device.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>()) + "\n"; 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_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"; outString += "\tCL_DEVICE_MAX_WORK_GROUP_SIZE: " + to_string(device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>()) + "\n";
++i; ++index;
} }
); }
ETHCL_LOG(outString); ETHCL_LOG(outString);
} }

6
libethash-cl/ethash_cl_miner.h

@ -43,10 +43,7 @@ public:
~ethash_cl_miner(); ~ethash_cl_miner();
static bool searchForAllDevices(unsigned _platformId, std::function<bool(cl::Device const&)> _callback); 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 unsigned getNumDevices(unsigned _platformId = 0);
static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
static void listDevices(); static void listDevices();
static bool configureGPU( static bool configureGPU(
unsigned _platformId, unsigned _platformId,
@ -92,7 +89,4 @@ private:
static unsigned s_workgroupSize; static unsigned s_workgroupSize;
/// The initial global work size for the searches /// The initial global work size for the searches
static unsigned s_initialGlobalWorkSize; 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_platformId = 0;
unsigned EthashGPUMiner::s_deviceId = 0;
unsigned EthashGPUMiner::s_numInstances = 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 }; 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(); stopWorking();
} }
std::string EthashGPUMiner::platformInfo()
{
return ethash_cl_miner::platform_info(s_platformId, s_deviceId);
}
unsigned EthashGPUMiner::getNumDevices() unsigned EthashGPUMiner::getNumDevices()
{ {
return ethash_cl_miner::getNumDevices(s_platformId); return ethash_cl_miner::getNumDevices(s_platformId);
@ -205,7 +199,6 @@ bool EthashGPUMiner::configureGPU(
unsigned _localWorkSize, unsigned _localWorkSize,
unsigned _globalWorkSizeMultiplier, unsigned _globalWorkSizeMultiplier,
unsigned _platformId, unsigned _platformId,
unsigned _deviceId,
unsigned _extraGPUMemory, unsigned _extraGPUMemory,
uint64_t _currentBlock, uint64_t _currentBlock,
unsigned _dagLoadMode, unsigned _dagLoadMode,
@ -216,7 +209,6 @@ bool EthashGPUMiner::configureGPU(
s_dagCreateDevice = _dagCreateDevice; s_dagCreateDevice = _dagCreateDevice;
s_platformId = _platformId; s_platformId = _platformId;
s_deviceId = _deviceId;
_localWorkSize = ((_localWorkSize + 7) / 8) * 8; _localWorkSize = ((_localWorkSize + 7) / 8) * 8;

3
libethcore/EthashGPUMiner.h

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

1
libethcore/Miner.h

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

4
libstratum/EthStratumClient.cpp

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

4
libstratum/EthStratumClientV2.cpp

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

Loading…
Cancel
Save