Browse Source

Refactor in OpenCL argument passing

- No need for many different functions to set each single option for the
miner. First we set all options and then we execute them. This way
--list-devices will give different results with --alow-opencl-cpu and
without it as it should.

- If the user has no GPU with sufficient memory we no longer default to
  CPU. It's better to throw an error and let the user remove the
  argument. It's easy to miss the defaulting to CPU log message.
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
eaee35dd0b
  1. 36
      ethminer/MinerAux.h
  2. 8
      libethash-cl/ethash_cl_miner.cpp
  3. 3
      libethash-cl/ethash_cl_miner.h
  4. 11
      libethcore/Ethash.cpp
  5. 11
      libethcore/Ethash.h

36
ethminer/MinerAux.h

@ -128,12 +128,9 @@ public:
throw BadArgument();
}
else if (arg == "--list-devices")
{
ProofOfWork::GPUMiner::listDevices();
exit(0);
}
shouldListDevices = true;
else if (arg == "--allow-opencl-cpu")
ProofOfWork::GPUMiner::allowCPU();
clAllowCPU = true;
else if (arg == "--phone-home" && i + 1 < argc)
{
string m = argv[++i];
@ -177,18 +174,7 @@ public:
else if (arg == "-C" || arg == "--cpu")
m_minerType = MinerType::CPU;
else if (arg == "-G" || arg == "--opencl")
{
if (!ProofOfWork::GPUMiner::configureGPU())
{
cout << "No GPU device with sufficient memory was found. Defaulting to CPU" << endl;
m_minerType = MinerType::CPU;
}
else
{
m_minerType = MinerType::GPU;
miningThreads = 1;
}
}
m_minerType = MinerType::GPU;
else if (arg == "--no-precompute")
{
precompute = false;
@ -264,13 +250,22 @@ public:
void execute()
{
if (shouldListDevices)
{
ProofOfWork::GPUMiner::listDevices();
exit(0);
}
if (m_minerType == MinerType::CPU)
ProofOfWork::CPUMiner::setNumInstances(miningThreads);
else if (m_minerType == MinerType::GPU)
{
ProofOfWork::GPUMiner::setDefaultPlatform(openclPlatform);
ProofOfWork::GPUMiner::setDefaultDevice(openclDevice);
ProofOfWork::GPUMiner::setNumInstances(miningThreads);
if (!ProofOfWork::GPUMiner::configureGPU(openclPlatform, openclDevice, clAllowCPU))
{
cout << "No GPU device with sufficient memory was found. Can't GPU mine. Remove the -G argument" << endl;
exit(1);
}
}
if (mode == OperationMode::DAGInit)
doInitDAG(initDAG);
@ -495,7 +490,8 @@ private:
unsigned openclPlatform = 0;
unsigned openclDevice = 0;
unsigned miningThreads = UINT_MAX;
unsigned dagChunks = 1;
bool shouldListDevices = false;
bool clAllowCPU = false;
/// DAG initialisation param.
unsigned initDAG = 0;

8
libethash-cl/ethash_cl_miner.cpp

@ -137,8 +137,9 @@ unsigned ethash_cl_miner::getNumDevices(unsigned _platformId)
return devices.size();
}
bool ethash_cl_miner::configureGPU()
bool ethash_cl_miner::configureGPU(bool _allowCPU)
{
s_allowCPU = _allowCPU;
return searchForAllDevices([](cl::Device const _device) -> bool
{
cl_ulong result;
@ -164,11 +165,6 @@ bool ethash_cl_miner::configureGPU()
bool ethash_cl_miner::s_allowCPU = false;
void ethash_cl_miner::allowCPU()
{
s_allowCPU = true;
}
bool ethash_cl_miner::searchForAllDevices(function<bool(cl::Device const&)> _callback)
{
vector<cl::Platform> platforms;

3
libethash-cl/ethash_cl_miner.h

@ -40,8 +40,7 @@ public:
static unsigned getNumDevices(unsigned _platformId = 0);
static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
static void listDevices();
static bool configureGPU();
static void allowCPU();
static bool configureGPU(bool _allowCPU);
bool init(
uint8_t const* _dag,

11
libethcore/Ethash.cpp

@ -366,11 +366,6 @@ void Ethash::GPUMiner::pause()
stopWorking();
}
void Ethash::GPUMiner::allowCPU()
{
return ethash_cl_miner::allowCPU();
}
std::string Ethash::GPUMiner::platformInfo()
{
return ethash_cl_miner::platform_info(s_platformId, s_deviceId);
@ -386,9 +381,11 @@ void Ethash::GPUMiner::listDevices()
return ethash_cl_miner::listDevices();
}
bool Ethash::GPUMiner::configureGPU()
bool Ethash::GPUMiner::configureGPU(unsigned _platformId, unsigned _deviceId, bool _allowCPU)
{
return ethash_cl_miner::configureGPU();
s_platformId = _platformId;
s_deviceId = _deviceId;
return ethash_cl_miner::configureGPU(_allowCPU);
}
#endif

11
libethcore/Ethash.h

@ -87,12 +87,8 @@ public:
static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); }
static std::string platformInfo();
static void setDefaultPlatform(unsigned) {}
static void setDagChunks(unsigned) {}
static void setDefaultDevice(unsigned) {}
static void listDevices() {}
static bool configureGPU() { return false; }
static void allowCPU() {}
static bool configureGPU(unsigned, unsigned, bool) { return false; }
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, std::thread::hardware_concurrency()); }
protected:
void kickOff() override
@ -121,10 +117,7 @@ public:
static std::string platformInfo();
static unsigned getNumDevices();
static void listDevices();
static bool configureGPU();
static void allowCPU();
static void setDefaultPlatform(unsigned _id) { s_platformId = _id; }
static void setDefaultDevice(unsigned _id) { s_deviceId = _id; }
static bool configureGPU(unsigned _platformId, unsigned _deviceId, bool _allowCPU);
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, getNumDevices()); }
protected:

Loading…
Cancel
Save