|
|
@ -33,71 +33,69 @@ using namespace eth; |
|
|
|
|
|
|
|
namespace dev |
|
|
|
{ |
|
|
|
namespace eth |
|
|
|
namespace eth |
|
|
|
{ |
|
|
|
class EthashCUHook : public ethash_cu_miner::search_hook |
|
|
|
{ |
|
|
|
public: |
|
|
|
EthashCUHook(EthashCUDAMiner* _owner) : m_owner(_owner) {} |
|
|
|
EthashCUHook(EthashCUHook const&) = delete; |
|
|
|
|
|
|
|
class EthashCUHook : public ethash_cu_miner::search_hook |
|
|
|
void abort() |
|
|
|
{ |
|
|
|
public: |
|
|
|
EthashCUHook(EthashCUDAMiner* _owner) : m_owner(_owner) {} |
|
|
|
EthashCUHook(EthashCUHook const&) = delete; |
|
|
|
|
|
|
|
void abort() |
|
|
|
{ |
|
|
|
{ |
|
|
|
UniqueGuard l(x_all); |
|
|
|
if (m_aborted) |
|
|
|
return; |
|
|
|
// cdebug << "Attempting to abort";
|
|
|
|
|
|
|
|
m_abort = true; |
|
|
|
} |
|
|
|
// m_abort is true so now searched()/found() will return true to abort the search.
|
|
|
|
// 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.
|
|
|
|
m_aborted.wait(true); |
|
|
|
// for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout)
|
|
|
|
// std::this_thread::sleep_for(chrono::milliseconds(30));
|
|
|
|
// if (!m_aborted)
|
|
|
|
// cwarn << "Couldn't abort. Abandoning OpenCL process.";
|
|
|
|
} |
|
|
|
|
|
|
|
void reset() |
|
|
|
{ |
|
|
|
UniqueGuard l(x_all); |
|
|
|
m_aborted = m_abort = false; |
|
|
|
} |
|
|
|
if (m_aborted) |
|
|
|
return; |
|
|
|
// cdebug << "Attempting to abort";
|
|
|
|
|
|
|
|
protected: |
|
|
|
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;
|
|
|
|
for (uint32_t i = 0; i < _count; ++i) |
|
|
|
if (m_owner->report(_nonces[i])) |
|
|
|
return (m_aborted = true); |
|
|
|
return m_owner->shouldStop(); |
|
|
|
m_abort = true; |
|
|
|
} |
|
|
|
// m_abort is true so now searched()/found() will return true to abort the search.
|
|
|
|
// 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.
|
|
|
|
m_aborted.wait(true); |
|
|
|
// for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout)
|
|
|
|
// std::this_thread::sleep_for(chrono::milliseconds(30));
|
|
|
|
// if (!m_aborted)
|
|
|
|
// cwarn << "Couldn't abort. Abandoning OpenCL process.";
|
|
|
|
} |
|
|
|
|
|
|
|
virtual bool searched(uint64_t _startNonce, uint32_t _count) override |
|
|
|
{ |
|
|
|
UniqueGuard l(x_all); |
|
|
|
// std::cerr << "Searched " << _count << " from " << _startNonce << std::endl;
|
|
|
|
m_owner->accumulateHashes(_count); |
|
|
|
m_last = _startNonce + _count; |
|
|
|
if (m_abort || m_owner->shouldStop()) |
|
|
|
void reset() |
|
|
|
{ |
|
|
|
UniqueGuard l(x_all); |
|
|
|
m_aborted = m_abort = false; |
|
|
|
} |
|
|
|
|
|
|
|
protected: |
|
|
|
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;
|
|
|
|
for (uint32_t i = 0; i < _count; ++i) |
|
|
|
if (m_owner->report(_nonces[i])) |
|
|
|
return (m_aborted = true); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return m_owner->shouldStop(); |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
Mutex x_all; |
|
|
|
uint64_t m_last; |
|
|
|
bool m_abort = false; |
|
|
|
Notified<bool> m_aborted = { true }; |
|
|
|
EthashCUDAMiner* m_owner = nullptr; |
|
|
|
}; |
|
|
|
virtual bool searched(uint64_t _startNonce, uint32_t _count) override |
|
|
|
{ |
|
|
|
UniqueGuard l(x_all); |
|
|
|
// std::cerr << "Searched " << _count << " from " << _startNonce << std::endl;
|
|
|
|
m_owner->accumulateHashes(_count); |
|
|
|
m_last = _startNonce + _count; |
|
|
|
if (m_abort || m_owner->shouldStop()) |
|
|
|
return (m_aborted = true); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
private: |
|
|
|
Mutex x_all; |
|
|
|
uint64_t m_last; |
|
|
|
bool m_abort = false; |
|
|
|
Notified<bool> m_aborted = { true }; |
|
|
|
EthashCUDAMiner* m_owner = nullptr; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
unsigned EthashCUDAMiner::s_platformId = 0; |
|
|
@ -105,10 +103,9 @@ unsigned EthashCUDAMiner::s_deviceId = 0; |
|
|
|
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 }; |
|
|
|
|
|
|
|
|
|
|
|
EthashCUDAMiner::EthashCUDAMiner(ConstructionInfo const& _ci) : |
|
|
|
GenericMiner<EthashProofOfWork>(_ci), |
|
|
|
Worker("cudaminer" + toString(index())), |
|
|
|
GenericMiner<EthashProofOfWork>(_ci), |
|
|
|
Worker("cudaminer" + toString(index())), |
|
|
|
m_hook( new EthashCUHook(this)) |
|
|
|
{ |
|
|
|
} |
|
|
@ -207,18 +204,16 @@ bool EthashCUDAMiner::configureGPU( |
|
|
|
unsigned _numStreams, |
|
|
|
unsigned _deviceId, |
|
|
|
unsigned _extraGPUMemory, |
|
|
|
bool _highcpu, |
|
|
|
bool _highcpu, |
|
|
|
uint64_t _currentBlock |
|
|
|
) |
|
|
|
{ |
|
|
|
s_deviceId = _deviceId; |
|
|
|
|
|
|
|
if (_blockSize != 32 && _blockSize != 64 && _blockSize != 128) |
|
|
|
{ |
|
|
|
cout << "Given localWorkSize of " << toString(_blockSize) << "is invalid. Must be either 32,64 or 128" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!ethash_cu_miner::configureGPU( |
|
|
|
_blockSize, |
|
|
|
_gridSize, |
|
|
|