From 25270123d057fcf4273e1dfb03a82024f051c017 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 8 Jun 2015 17:16:53 +0200 Subject: [PATCH] Argument to list available opencl devices and platforms - Additionally some small refactoring in how some query functions are processed for GPU mining. --- ethminer/MinerAux.h | 7 ++++- libethash-cl/ethash_cl_miner.cpp | 51 +++++++++++++++++++++++++++++--- libethash-cl/ethash_cl_miner.h | 5 +++- libethcore/Ethash.cpp | 15 ++++++---- libethcore/Ethash.h | 6 ++-- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 6a42dd774..245b97ceb 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -127,6 +127,11 @@ public: cerr << "Bad " << arg << " option: " << argv[i] << endl; throw BadArgument(); } + else if (arg == "--list-devices") + { + ProofOfWork::GPUMiner::listDevices(); + exit(0); + } else if (arg == "--use-chunks") { dagChunks = 4; @@ -175,7 +180,7 @@ public: m_minerType = MinerType::CPU; else if (arg == "-G" || arg == "--opencl") { - if (!ProofOfWork::GPUMiner::haveSufficientGPUMemory()) + if (!ProofOfWork::GPUMiner::haveSufficientMemory()) { cout << "No GPU device with sufficient memory was found. Defaulting to CPU" << endl; m_minerType = MinerType::CPU; diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index f501d9642..2bdcfcd9a 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -127,7 +127,7 @@ unsigned ethash_cl_miner::get_num_devices(unsigned _platformId) return devices.size(); } -bool ethash_cl_miner::haveSufficientGPUMemory(unsigned _platformId) +bool ethash_cl_miner::haveSufficientGPUMemory() { std::vector platforms; cl::Platform::get(&platforms); @@ -136,15 +136,25 @@ bool ethash_cl_miner::haveSufficientGPUMemory(unsigned _platformId) ETHCL_LOG("No OpenCL platforms found."); return false; } + for (unsigned i = 0; i < platforms.size(); ++i) + if (haveSufficientGPUMemory(i)) + return true; + + return false; +} + +bool ethash_cl_miner::haveSufficientGPUMemory(unsigned _platformId) +{ + std::vector platforms; + cl::Platform::get(&platforms); + if (_platformId >= platforms.size()) + return false; std::vector devices; unsigned platform_num = std::min(_platformId, platforms.size() - 1); platforms[platform_num].getDevices(CL_DEVICE_TYPE_ALL, &devices); if (devices.empty()) - { - ETHCL_LOG("No OpenCL devices found."); return false; - } for (cl::Device const& device: devices) { @@ -168,6 +178,39 @@ bool ethash_cl_miner::haveSufficientGPUMemory(unsigned _platformId) return false; } +void ethash_cl_miner::listDevices() +{ + std::vector platforms; + cl::Platform::get(&platforms); + if (platforms.empty()) + { + ETHCL_LOG("No OpenCL platforms found."); + return; + } + for (unsigned i = 0; i < platforms.size(); ++i) + listDevices(i); +} + +void ethash_cl_miner::listDevices(unsigned _platformId) +{ + std::vector platforms; + cl::Platform::get(&platforms); + if (_platformId >= platforms.size()) + return; + + std::string outString ="Listing OpenCL devices for platform " + to_string(_platformId) + "\n[deviceID] deviceName\n"; + std::vector devices; + platforms[_platformId].getDevices(CL_DEVICE_TYPE_ALL, &devices); + unsigned i = 0; + std::string deviceString; + for (cl::Device const& device: devices) + { + outString += "[" + to_string(i) + "] " + device.getInfo() + "\n"; + ++i; + } + ETHCL_LOG(outString); +} + void ethash_cl_miner::finish() { if (m_queue()) diff --git a/libethash-cl/ethash_cl_miner.h b/libethash-cl/ethash_cl_miner.h index cdc4cf07f..4d5317186 100644 --- a/libethash-cl/ethash_cl_miner.h +++ b/libethash-cl/ethash_cl_miner.h @@ -35,7 +35,10 @@ public: static unsigned get_num_platforms(); static unsigned get_num_devices(unsigned _platformId = 0); static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0); - static bool haveSufficientGPUMemory(unsigned _platformId = 0); + static bool haveSufficientGPUMemory(); + static bool haveSufficientGPUMemory(unsigned _platformId); + static void listDevices(); + static void listDevices(unsigned _platformId); bool init( uint8_t const* _dag, diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 0ea09a5bc..f715d6912 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -364,11 +364,6 @@ void Ethash::GPUMiner::pause() stopWorking(); } -bool Ethash::GPUMiner::haveSufficientGPUMemory() -{ - return ethash_cl_miner::haveSufficientGPUMemory(s_platformId); -} - std::string Ethash::GPUMiner::platformInfo() { return ethash_cl_miner::platform_info(s_platformId, s_deviceId); @@ -379,6 +374,16 @@ unsigned Ethash::GPUMiner::getNumDevices() return ethash_cl_miner::get_num_devices(s_platformId); } +void Ethash::GPUMiner::listDevices() +{ + return ethash_cl_miner::listDevices(); +} + +bool Ethash::GPUMiner::haveSufficientMemory() +{ + return ethash_cl_miner::haveSufficientGPUMemory(); +} + #endif } diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 68c21c609..99df1dc71 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -87,10 +87,11 @@ public: static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); } static std::string platformInfo(); - static bool haveSufficientGPUMemory() { return false; } static void setDefaultPlatform(unsigned) {} static void setDagChunks(unsigned) {} static void setDefaultDevice(unsigned) {} + static void listDevices() {} + static bool haveSufficientMemory() { return false; } static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, std::thread::hardware_concurrency()); } protected: void kickOff() override @@ -117,8 +118,9 @@ public: static unsigned instances() { return s_numInstances > 0 ? s_numInstances : 1; } static std::string platformInfo(); - static bool haveSufficientGPUMemory(); static unsigned getNumDevices(); + static void listDevices(); + static bool haveSufficientMemory(); static void setDefaultPlatform(unsigned _id) { s_platformId = _id; } static void setDefaultDevice(unsigned _id) { s_deviceId = _id; } static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, getNumDevices()); }