Browse Source

De-template Miner and Farm classes

cl-refactor
Paweł Bylica 8 years ago
parent
commit
bc9ad046e3
No known key found for this signature in database GPG Key ID: 7A0C037434FE77EF
  1. 32
      ethminer/MinerAux.h
  2. 2
      libethcore/EthashCUDAMiner.cpp
  3. 4
      libethcore/EthashCUDAMiner.h
  4. 2
      libethcore/EthashGPUMiner.cpp
  5. 4
      libethcore/EthashGPUMiner.h
  6. 9
      libethcore/Farm.h
  7. 12
      libethcore/Miner.cpp
  8. 23
      libethcore/Miner.h
  9. 2
      libstratum/EthStratumClient.cpp
  10. 4
      libstratum/EthStratumClient.h
  11. 2
      libstratum/EthStratumClientV2.cpp
  12. 4
      libstratum/EthStratumClientV2.h

32
ethminer/MinerAux.h

@ -604,13 +604,13 @@ private:
genesis.setDifficulty(1 << 18); genesis.setDifficulty(1 << 18);
cdebug << genesis.boundary(); cdebug << genesis.boundary();
GenericFarm<EthashProofOfWork> f; GenericFarm f;
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; map<string, GenericFarm::SealerDescriptor> sealers;
#if ETH_ETHASHCL #if ETH_ETHASHCL
sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }};
#endif #endif
#if ETH_ETHASHCUDA #if ETH_ETHASHCUDA
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
#endif #endif
f.setSealers(sealers); f.setSealers(sealers);
f.onSolutionFound([&](EthashProofOfWork::Solution) { return false; }); f.onSolutionFound([&](EthashProofOfWork::Solution) { return false; });
@ -670,13 +670,13 @@ private:
genesis.setDifficulty(1 << 18); genesis.setDifficulty(1 << 18);
cdebug << genesis.boundary(); cdebug << genesis.boundary();
GenericFarm<EthashProofOfWork> f; GenericFarm f;
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; map<string, GenericFarm::SealerDescriptor> sealers;
#if ETH_ETHASHCL #if ETH_ETHASHCL
sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } };
#endif #endif
#if ETH_ETHASHCUDA #if ETH_ETHASHCUDA
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
#endif #endif
f.setSealers(sealers); f.setSealers(sealers);
@ -750,12 +750,12 @@ private:
void doFarm(MinerType _m, string & _remote, unsigned _recheckPeriod) void doFarm(MinerType _m, string & _remote, unsigned _recheckPeriod)
{ {
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; map<string, GenericFarm::SealerDescriptor> sealers;
#if ETH_ETHASHCL #if ETH_ETHASHCL
sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }};
#endif #endif
#if ETH_ETHASHCUDA #if ETH_ETHASHCUDA
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
#endif #endif
(void)_m; (void)_m;
(void)_remote; (void)_remote;
@ -768,7 +768,7 @@ private:
FarmClient * prpc = &rpc; FarmClient * prpc = &rpc;
h256 id = h256::random(); h256 id = h256::random();
GenericFarm<EthashProofOfWork> f; GenericFarm f;
f.setSealers(sealers); f.setSealers(sealers);
if (_m == MinerType::CPU) if (_m == MinerType::CPU)
f.start("cpu", false); f.start("cpu", false);
@ -902,17 +902,17 @@ private:
#if ETH_STRATUM #if ETH_STRATUM
void doStratum() void doStratum()
{ {
map<string, GenericFarm<EthashProofOfWork>::SealerDescriptor> sealers; map<string, GenericFarm::SealerDescriptor> sealers;
#if ETH_ETHASHCL #if ETH_ETHASHCL
sealers["opencl"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashGPUMiner(ci); } }; sealers["opencl"] = GenericFarm::SealerDescriptor{ &EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); } };
#endif #endif
#if ETH_ETHASHCUDA #if ETH_ETHASHCUDA
sealers["cuda"] = GenericFarm<EthashProofOfWork>::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner<EthashProofOfWork>::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } };
#endif #endif
if (!m_farmRecheckSet) if (!m_farmRecheckSet)
m_farmRecheckPeriod = m_defaultStratumFarmRecheckPeriod; m_farmRecheckPeriod = m_defaultStratumFarmRecheckPeriod;
GenericFarm<EthashProofOfWork> f; GenericFarm f;
// this is very ugly, but if Stratum Client V2 tunrs out to be a success, V1 will be completely removed anyway // this is very ugly, but if Stratum Client V2 tunrs out to be a success, V1 will be completely removed anyway
if (m_stratumClientVersion == 1) { if (m_stratumClientVersion == 1) {

2
libethcore/EthashCUDAMiner.cpp

@ -108,7 +108,7 @@ unsigned EthashCUDAMiner::s_numInstances = 0;
int EthashCUDAMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; int EthashCUDAMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) : EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) :
GenericMiner<EthashProofOfWork>(_ci), GenericMiner(_ci),
Worker("cudaminer" + toString(index())), Worker("cudaminer" + toString(index())),
m_hook( new EthashCUDAHook(this)) m_hook( new EthashCUDAHook(this))
{ {

4
libethcore/EthashCUDAMiner.h

@ -36,7 +36,7 @@ namespace eth
{ {
class EthashCUDAHook; class EthashCUDAHook;
class EthashCUDAMiner : public GenericMiner<EthashProofOfWork>, Worker class EthashCUDAMiner : public GenericMiner, Worker
{ {
friend class dev::eth::EthashCUDAHook; friend class dev::eth::EthashCUDAHook;
@ -80,7 +80,7 @@ class EthashCUDAHook;
void workLoop() override; void workLoop() override;
bool report(uint64_t _nonce); bool report(uint64_t _nonce);
using GenericMiner<EthashProofOfWork>::accumulateHashes; using GenericMiner::accumulateHashes;
EthashCUDAHook* m_hook = nullptr; EthashCUDAHook* m_hook = nullptr;
ethash_cuda_miner* m_miner = nullptr; ethash_cuda_miner* m_miner = nullptr;

2
libethcore/EthashGPUMiner.cpp

@ -107,7 +107,7 @@ 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 };
EthashGPUMiner::EthashGPUMiner(ConstructionInfo const& _ci): EthashGPUMiner::EthashGPUMiner(ConstructionInfo const& _ci):
GenericMiner<EthashProofOfWork>(_ci), GenericMiner(_ci),
Worker("openclminer" + toString(index())), Worker("openclminer" + toString(index())),
m_hook(new EthashCLHook(this)) m_hook(new EthashCLHook(this))
{ {

4
libethcore/EthashGPUMiner.h

@ -36,7 +36,7 @@ namespace eth
{ {
class EthashCLHook; class EthashCLHook;
class EthashGPUMiner: public GenericMiner<EthashProofOfWork>, Worker class EthashGPUMiner: public GenericMiner, Worker
{ {
friend class dev::eth::EthashCLHook; friend class dev::eth::EthashCLHook;
@ -76,7 +76,7 @@ private:
void workLoop() override; void workLoop() override;
bool report(uint64_t _nonce); bool report(uint64_t _nonce);
using GenericMiner<EthashProofOfWork>::accumulateHashes; using GenericMiner::accumulateHashes;
EthashCLHook* m_hook = nullptr; EthashCLHook* m_hook = nullptr;
ethash_cl_miner* m_miner = nullptr; ethash_cl_miner* m_miner = nullptr;

9
libethcore/Farm.h

@ -41,13 +41,12 @@ namespace eth
* Miners ask for work, then submit proofs * Miners ask for work, then submit proofs
* @threadsafe * @threadsafe
*/ */
template <class PoW> class GenericFarm: public GenericFarmFace
class GenericFarm: public GenericFarmFace<PoW>
{ {
public: public:
using WorkPackage = typename PoW::WorkPackage; using WorkPackage = EthashProofOfWork::WorkPackage;
using Solution = typename PoW::Solution; using Solution = EthashProofOfWork::Solution;
using Miner = GenericMiner<PoW>; using Miner = GenericMiner;
struct SealerDescriptor struct SealerDescriptor
{ {

12
libethcore/Miner.cpp

@ -4,16 +4,12 @@
using namespace dev; using namespace dev;
using namespace eth; using namespace eth;
template <> unsigned dev::eth::GenericMiner::s_dagLoadMode = 0;
unsigned dev::eth::GenericMiner<dev::eth::EthashProofOfWork>::s_dagLoadMode = 0;
template <> volatile unsigned dev::eth::GenericMiner::s_dagLoadIndex = 0;
volatile unsigned dev::eth::GenericMiner<dev::eth::EthashProofOfWork>::s_dagLoadIndex = 0;
template <> unsigned dev::eth::GenericMiner::s_dagCreateDevice = 0;
unsigned dev::eth::GenericMiner<dev::eth::EthashProofOfWork>::s_dagCreateDevice = 0;
template <> volatile void* dev::eth::GenericMiner::s_dagInHostMemory = NULL;
volatile void* dev::eth::GenericMiner<dev::eth::EthashProofOfWork>::s_dagInHostMemory = NULL;

23
libethcore/Miner.h

@ -30,6 +30,7 @@
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libethcore/Common.h> #include <libethcore/Common.h>
#include "EthashAux.h"
#define MINER_WAIT_STATE_UNKNOWN 0 #define MINER_WAIT_STATE_UNKNOWN 0
#define MINER_WAIT_STATE_WORK 1 #define MINER_WAIT_STATE_WORK 1
@ -67,8 +68,6 @@ enum class MinerType
Mixed Mixed
}; };
struct MineInfo: public WorkingProgress {};
inline std::ostream& operator<<(std::ostream& _out, WorkingProgress _p) inline std::ostream& operator<<(std::ostream& _out, WorkingProgress _p)
{ {
float mh = _p.rate() / 1000000.0f; float mh = _p.rate() / 1000000.0f;
@ -109,7 +108,7 @@ inline std::ostream& operator<<(std::ostream& os, SolutionStats s)
return os << "[A" << s.getAccepts() << "+" << s.getAcceptedStales() << ":R" << s.getRejects() << "+" << s.getRejectedStales() << ":F" << s.getFailures() << "]"; return os << "[A" << s.getAccepts() << "+" << s.getAcceptedStales() << ":R" << s.getRejects() << "+" << s.getRejectedStales() << ":F" << s.getFailures() << "]";
} }
template <class PoW> class GenericMiner; class GenericMiner;
/** /**
@ -117,14 +116,14 @@ template <class PoW> class GenericMiner;
* @warning Must be implemented in a threadsafe manner since it will be called from multiple * @warning Must be implemented in a threadsafe manner since it will be called from multiple
* miner threads. * miner threads.
*/ */
template <class PoW> class GenericFarmFace class GenericFarmFace
{ {
public: public:
using WorkPackage = typename PoW::WorkPackage; using WorkPackage = EthashProofOfWork::WorkPackage;
using Solution = typename PoW::Solution; using Solution = EthashProofOfWork::Solution;
using Miner = GenericMiner<PoW>; using Miner = GenericMiner;
virtual ~GenericFarmFace() {} virtual ~GenericFarmFace() = default;
/** /**
* @brief Called from a Miner to note a WorkPackage has a solution. * @brief Called from a Miner to note a WorkPackage has a solution.
@ -140,12 +139,12 @@ public:
* @brief A miner - a member and adoptee of the Farm. * @brief A miner - a member and adoptee of the Farm.
* @warning Not threadsafe. It is assumed Farm will synchronise calls to/from this class. * @warning Not threadsafe. It is assumed Farm will synchronise calls to/from this class.
*/ */
template <class PoW> class GenericMiner class GenericMiner
{ {
public: public:
using WorkPackage = typename PoW::WorkPackage; using WorkPackage = EthashProofOfWork::WorkPackage;
using Solution = typename PoW::Solution; using Solution = EthashProofOfWork::Solution;
using FarmFace = GenericFarmFace<PoW>; using FarmFace = GenericFarmFace;
using ConstructionInfo = std::pair<FarmFace*, unsigned>; using ConstructionInfo = std::pair<FarmFace*, unsigned>;
GenericMiner(ConstructionInfo const& _ci): GenericMiner(ConstructionInfo const& _ci):

2
libstratum/EthStratumClient.cpp

@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff)
} }
EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) EthStratumClient::EthStratumClient(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email)
: m_socket(m_io_service) : m_socket(m_io_service)
{ {
m_minerType = m; m_minerType = m;

4
libstratum/EthStratumClient.h

@ -21,7 +21,7 @@ using namespace dev::eth;
class EthStratumClient class EthStratumClient
{ {
public: public:
EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); EthStratumClient(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email);
~EthStratumClient(); ~EthStratumClient();
void setFailover(string const & host, string const & port); void setFailover(string const & host, string const & port);
@ -68,7 +68,7 @@ private:
std::mutex x_pending; std::mutex x_pending;
int m_pending; int m_pending;
GenericFarm<EthashProofOfWork> * p_farm; GenericFarm* p_farm;
std::mutex x_current; std::mutex x_current;
EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_current;
EthashProofOfWork::WorkPackage m_previous; EthashProofOfWork::WorkPackage m_previous;

2
libstratum/EthStratumClientV2.cpp

@ -27,7 +27,7 @@ static void diffToTarget(uint32_t *target, double diff)
} }
EthStratumClientV2::EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email) EthStratumClientV2::EthStratumClientV2(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email)
: Worker("stratum"), : Worker("stratum"),
m_socket(m_io_service) m_socket(m_io_service)
{ {

4
libstratum/EthStratumClientV2.h

@ -22,7 +22,7 @@ using namespace dev::eth;
class EthStratumClientV2 : public Worker class EthStratumClientV2 : public Worker
{ {
public: public:
EthStratumClientV2(GenericFarm<EthashProofOfWork> * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); EthStratumClientV2(GenericFarm* f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email);
~EthStratumClientV2(); ~EthStratumClientV2();
void setFailover(string const & host, string const & port); void setFailover(string const & host, string const & port);
@ -64,7 +64,7 @@ private:
string m_response; string m_response;
GenericFarm<EthashProofOfWork> * p_farm; GenericFarm* p_farm;
mutex x_current; mutex x_current;
EthashProofOfWork::WorkPackage m_current; EthashProofOfWork::WorkPackage m_current;
EthashProofOfWork::WorkPackage m_previous; EthashProofOfWork::WorkPackage m_previous;

Loading…
Cancel
Save