Browse Source

wip

cl-refactor
Jan Willem Penterman 9 years ago
parent
commit
c4b1f68365
  1. 2
      ethminer/MinerAux.h
  2. 6
      libethash-cu/ethash_cu_miner.cpp
  3. 15
      libethash-cu/ethash_cu_miner.h
  4. 1
      libethcore/BasicAuthority.h
  5. 1
      libethcore/Ethash.cpp
  6. 2
      libethcore/Ethash.h
  7. 90
      libethcore/EthashCUDAMiner.cpp
  8. 58
      libethcore/EthashCUDAMiner.h
  9. 7
      libethcore/EthashSealEngine.cpp

2
ethminer/MinerAux.h

@ -295,6 +295,7 @@ public:
BOOST_THROW_EXCEPTION(BadArgument()); BOOST_THROW_EXCEPTION(BadArgument());
} }
} }
#if ETH_ETHASHCU || !ETH_TRUE
else if (arg == "--cuda-devices") { else if (arg == "--cuda-devices") {
while (m_cudaDeviceCount < 16 && i + 1 < argc) while (m_cudaDeviceCount < 16 && i + 1 < argc)
{ {
@ -310,6 +311,7 @@ public:
else if (arg == "--cuda-high-cpu") { else if (arg == "--cuda-high-cpu") {
m_cudaHighCPULoad = true; m_cudaHighCPULoad = true;
} }
#endif
else else
return false; return false;
return true; return true;

6
libethash-cu/ethash_cu_miner.cpp

@ -65,7 +65,7 @@ std::string ethash_cu_miner::platform_info(unsigned _deviceId)
int runtime_version; int runtime_version;
int device_count; int device_count;
device_count = get_num_devices(); device_count = getNumDevices();
if (device_count == 0) if (device_count == 0)
return std::string(); return std::string();
@ -99,7 +99,7 @@ std::string ethash_cu_miner::platform_info(unsigned _deviceId)
} }
int ethash_cu_miner::get_num_devices() int ethash_cu_miner::getNumDevices()
{ {
int device_count; int device_count;
@ -123,7 +123,7 @@ void ethash_cu_miner::finish()
bool ethash_cu_miner::init(uint8_t const* _dag, uint64_t _dagSize, unsigned num_buffers, unsigned search_batch_size, unsigned workgroup_size, unsigned _deviceId, bool highcpu) bool ethash_cu_miner::init(uint8_t const* _dag, uint64_t _dagSize, unsigned num_buffers, unsigned search_batch_size, unsigned workgroup_size, unsigned _deviceId, bool highcpu)
{ {
int device_count = get_num_devices(); int device_count = getNumDevices();
if (device_count == 0) if (device_count == 0)
return false; return false;

15
libethash-cu/ethash_cu_miner.h

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <cuda_runtime.h> //#include <cuda_runtime.h>
#include <time.h> #include <time.h>
#include <functional> #include <functional>
@ -24,8 +24,17 @@ public:
bool init(uint8_t const* _dag, uint64_t _dagSize, unsigned num_buffers = 2, unsigned search_batch_size = 262144, unsigned workgroup_size = 64, unsigned _deviceId = 0, bool highcpu = false); bool init(uint8_t const* _dag, uint64_t _dagSize, unsigned num_buffers = 2, unsigned search_batch_size = 262144, unsigned workgroup_size = 64, unsigned _deviceId = 0, bool highcpu = false);
static std::string platform_info(unsigned _deviceId = 0); static std::string platform_info(unsigned _deviceId = 0);
static int get_num_devices(); static int getNumDevices();
static void listDevices();
static bool configureGPU(
unsigned _platformId,
unsigned _localWorkSize,
unsigned _globalWorkSize,
unsigned _msPerBatch,
bool _allowCPU,
unsigned _extraGPUMemory,
uint64_t _currentBlock
);
void finish(); void finish();
void hash(uint8_t* ret, uint8_t const* header, uint64_t nonce, unsigned count); void hash(uint8_t* ret, uint8_t const* header, uint64_t nonce, unsigned count);

1
libethcore/BasicAuthority.h

@ -45,6 +45,7 @@ namespace eth
* typename Solution * typename Solution
* typename CPUMiner * typename CPUMiner
* typename GPUMiner * typename GPUMiner
* typename CUDAMiner
* and a few others. TODO * and a few others. TODO
*/ */
class BasicAuthority class BasicAuthority

1
libethcore/Ethash.cpp

@ -45,6 +45,7 @@
#include "EthashSealEngine.h" #include "EthashSealEngine.h"
#include "EthashCPUMiner.h" #include "EthashCPUMiner.h"
#include "EthashGPUMiner.h" #include "EthashGPUMiner.h"
#include "EthashCUDAMiner.h"
using namespace std; using namespace std;
using namespace std::chrono; using namespace std::chrono;

2
libethcore/Ethash.h

@ -33,6 +33,7 @@
#include "Sealer.h" #include "Sealer.h"
class ethash_cl_miner; class ethash_cl_miner;
class ethash_cu_miner;
namespace dev namespace dev
{ {
@ -45,6 +46,7 @@ namespace eth
class BlockInfo; class BlockInfo;
class EthashCLHook; class EthashCLHook;
class EthashCUHook;
class Ethash class Ethash
{ {

90
libethcore/EthashCUDAMiner.cpp

@ -1,25 +1,25 @@
/* /*
This file is part of cpp-ethereum. This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful, cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthashCUDAMiner.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
*
* Determines the PoW algorithm.
*/ */
/** @file EthashGPUMiner.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
*
* Determines the PoW algorithm.
*/
#if ETH_ETHASHCU || !ETH_TRUE #if ETH_ETHASHCU || !ETH_TRUE
@ -33,13 +33,13 @@ using namespace eth;
namespace dev namespace dev
{ {
namespace eth namespace eth
{ {
class EthashCUHook: public ethash_cu_miner::search_hook class EthashCUHook : public ethash_cu_miner::search_hook
{ {
public: public:
EthashCUHook(EthashCUDAMiner* _owner): m_owner(_owner) {} EthashCUHook(EthashCUDAMiner* _owner) : m_owner(_owner) {}
EthashCUHook(EthashCUHook const&) = delete; EthashCUHook(EthashCUHook const&) = delete;
void abort() void abort()
@ -48,7 +48,7 @@ public:
UniqueGuard l(x_all); UniqueGuard l(x_all);
if (m_aborted) if (m_aborted)
return; return;
// cdebug << "Attempting to abort"; // cdebug << "Attempting to abort";
m_abort = true; m_abort = true;
} }
@ -56,10 +56,10 @@ public:
// we hang around on this thread waiting for them to point out that they have aborted since // we hang around on this thread waiting for them to point out that they have aborted since
// otherwise we may end up deleting this object prior to searched()/found() being called. // otherwise we may end up deleting this object prior to searched()/found() being called.
m_aborted.wait(true); m_aborted.wait(true);
// for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout) // for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout)
// std::this_thread::sleep_for(chrono::milliseconds(30)); // std::this_thread::sleep_for(chrono::milliseconds(30));
// if (!m_aborted) // if (!m_aborted)
// cwarn << "Couldn't abort. Abandoning OpenCL process."; // cwarn << "Couldn't abort. Abandoning OpenCL process.";
} }
void reset() void reset()
@ -68,10 +68,10 @@ public:
m_aborted = m_abort = false; m_aborted = m_abort = false;
} }
protected: protected:
virtual bool found(uint64_t const* _nonces, uint32_t _count) override virtual bool found(uint64_t const* _nonces, uint32_t _count) override
{ {
// dev::operator <<(std::cerr << "Found nonces: ", vector<uint64_t>(_nonces, _nonces + _count)) << std::endl; // dev::operator <<(std::cerr << "Found nonces: ", vector<uint64_t>(_nonces, _nonces + _count)) << std::endl;
for (uint32_t i = 0; i < _count; ++i) for (uint32_t i = 0; i < _count; ++i)
if (m_owner->report(_nonces[i])) if (m_owner->report(_nonces[i]))
return (m_aborted = true); return (m_aborted = true);
@ -81,7 +81,7 @@ protected:
virtual bool searched(uint64_t _startNonce, uint32_t _count) override virtual bool searched(uint64_t _startNonce, uint32_t _count) override
{ {
UniqueGuard l(x_all); UniqueGuard l(x_all);
// std::cerr << "Searched " << _count << " from " << _startNonce << std::endl; // std::cerr << "Searched " << _count << " from " << _startNonce << std::endl;
m_owner->accumulateHashes(_count); m_owner->accumulateHashes(_count);
m_last = _startNonce + _count; m_last = _startNonce + _count;
if (m_abort || m_owner->shouldStop()) if (m_abort || m_owner->shouldStop())
@ -89,15 +89,15 @@ protected:
return false; return false;
} }
private: private:
Mutex x_all; Mutex x_all;
uint64_t m_last; uint64_t m_last;
bool m_abort = false; bool m_abort = false;
Notified<bool> m_aborted = {true}; Notified<bool> m_aborted = { true };
EthashCUDAMiner* m_owner = nullptr; EthashCUDAMiner* m_owner = nullptr;
}; };
} }
} }
unsigned EthashCUDAMiner::s_platformId = 0; unsigned EthashCUDAMiner::s_platformId = 0;
@ -105,9 +105,9 @@ unsigned EthashCUDAMiner::s_deviceId = 0;
unsigned EthashCUDAMiner::s_numInstances = 0; unsigned EthashCUDAMiner::s_numInstances = 0;
EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) : EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) :
GenericMiner<EthashProofOfWork>(_ci), GenericMiner<EthashProofOfWork>(_ci),
Worker("cudaminer" + toString(index())), Worker("cudaminer" + toString(index())),
m_hook(new EthashCUDAMiner(this)) m_hook( new EthashCUHook(this))
{ {
} }
@ -123,7 +123,7 @@ bool EthashCUDAMiner::report(uint64_t _nonce)
Nonce n = (Nonce)(u64)_nonce; Nonce n = (Nonce)(u64)_nonce;
EthashProofOfWork::Result r = EthashAux::eval(work().seedHash, work().headerHash, n); EthashProofOfWork::Result r = EthashAux::eval(work().seedHash, work().headerHash, n);
if (r.value < work().boundary) if (r.value < work().boundary)
return submitProof(Solution{n, r.mixHash}); return submitProof(Solution{ n, r.mixHash });
return false; return false;
} }
@ -170,11 +170,11 @@ void EthashCUDAMiner::workLoop()
uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192); uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192);
m_miner->search(w.headerHash.data(), upper64OfBoundary, *m_hook); m_miner->search(w.headerHash.data(), upper64OfBoundary, *m_hook);
} }
catch (cl::Error const& _e) catch (std::runtime_error const& _e)
{ {
delete m_miner; delete m_miner;
m_miner = nullptr; m_miner = nullptr;
cwarn << "Error GPU mining: " << _e.what() << "(" << _e.err() << ")"; cwarn << "Error CUDA mining: " << _e.what();
} }
} }
@ -186,17 +186,17 @@ void EthashCUDAMiner::pause()
std::string EthashCUDAMiner::platformInfo() std::string EthashCUDAMiner::platformInfo()
{ {
return ethash_cl_miner::platform_info(s_platformId, s_deviceId); return ethash_cu_miner::platform_info(s_deviceId);
} }
unsigned EthashCUDAMiner::getNumDevices() unsigned EthashCUDAMiner::getNumDevices()
{ {
return ethash_cl_miner::getNumDevices(s_platformId); return ethash_cu_miner::getNumDevices();
} }
void EthashCUDAMiner::listDevices() void EthashCUDAMiner::listDevices()
{ {
return ethash_cl_miner::listDevices(); return ethash_cu_miner::listDevices();
} }
bool EthashCUDAMiner::configureGPU( bool EthashCUDAMiner::configureGPU(
@ -208,7 +208,7 @@ bool EthashCUDAMiner::configureGPU(
bool _allowCPU, bool _allowCPU,
unsigned _extraGPUMemory, unsigned _extraGPUMemory,
uint64_t _currentBlock uint64_t _currentBlock
) )
{ {
s_platformId = _platformId; s_platformId = _platformId;
s_deviceId = _deviceId; s_deviceId = _deviceId;

58
libethcore/EthashCUDAMiner.h

@ -1,25 +1,25 @@
/* /*
This file is part of cpp-ethereum. This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful, cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthashCUDAMiner.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*
* Determines the PoW algorithm.
*/ */
/** @file EthashGPUMiner.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*
* Determines the PoW algorithm.
*/
#pragma once #pragma once
#if ETH_ETHASHCU || !ETH_TRUE #if ETH_ETHASHCU || !ETH_TRUE
@ -30,14 +30,14 @@
namespace dev namespace dev
{ {
namespace eth namespace eth
{ {
class EthashCUDAMiner: public GenericMiner<EthashProofOfWork>, Worker class EthashCUDAMiner : public GenericMiner<EthashProofOfWork>, Worker
{ {
friend class dev::eth::EthashCLHook; friend class dev::eth::EthashCUHook;
public: public:
EthashCUDAMiner(ConstructionInfo const& _ci); EthashCUDAMiner(ConstructionInfo const& _ci);
~EthashCUDAMiner(); ~EthashCUDAMiner();
@ -57,26 +57,26 @@ public:
); );
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, getNumDevices()); } static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, getNumDevices()); }
protected: protected:
void kickOff() override; void kickOff() override;
void pause() override; void pause() override;
private: private:
void workLoop() override; void workLoop() override;
bool report(uint64_t _nonce); bool report(uint64_t _nonce);
using GenericMiner<EthashProofOfWork>::accumulateHashes; using GenericMiner<EthashProofOfWork>::accumulateHashes;
EthashCLHook* m_hook = nullptr; EthashCUHook* m_hook = nullptr;
ethash_cl_miner* m_miner = nullptr; ethash_cu_miner* m_miner = nullptr;
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_deviceId;
static unsigned s_numInstances; static unsigned s_numInstances;
}; };
} }
} }
#endif #endif

7
libethcore/EthashSealEngine.cpp

@ -24,6 +24,7 @@
#include "EthashSealEngine.h" #include "EthashSealEngine.h"
#include "EthashCPUMiner.h" #include "EthashCPUMiner.h"
#include "EthashGPUMiner.h" #include "EthashGPUMiner.h"
#include "EthashCUDAMiner.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace eth; using namespace eth;
@ -34,6 +35,9 @@ EthashSealEngine::EthashSealEngine()
sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); }}; sealers["cpu"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCPUMiner(ci); }};
#if ETH_ETHASHCL #if ETH_ETHASHCL
sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); }};
#endif
#if ETH_ETHASHCU
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
#endif #endif
m_farm.setSealers(sealers); m_farm.setSealers(sealers);
} }
@ -44,6 +48,9 @@ strings EthashSealEngine::sealers() const
"cpu" "cpu"
#if ETH_ETHASHCL #if ETH_ETHASHCL
, "opencl" , "opencl"
#endif
#if ETH_ETHASHCU
, "cuda"
#endif #endif
}; };
} }

Loading…
Cancel
Save