diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index aac68f1a7..2816f637a 100644 --- a/ethminer/MinerAux.h +++ b/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; diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 054985a38..db08d10c3 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/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 _callback) { vector platforms; diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index dc3f7eca0..44ec7eba9 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/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, diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 09ecfe1a3..20ba539d1 100644 --- a/libethcore/Ethash.cpp +++ b/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 diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 91ca5f8fd..ee4c7d008 100644 --- a/libethcore/Ethash.h +++ b/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(_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(_instances, getNumDevices()); } protected: