Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release/0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jan 22, 2018
2 parents c30a119 + 1164588 commit d8d618a
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 196 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: nvidia/cuda:9.0-devel-ubuntu17.04
- image: nvidia/cuda:9.1-devel-ubuntu16.04
steps:
- checkout

Expand Down
9 changes: 2 additions & 7 deletions libethash-cl/CLMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ CLMiner::CLMiner(FarmFace& _farm, unsigned _index):

CLMiner::~CLMiner()
{
pause();
kick_miner();
}

void CLMiner::report(uint64_t _nonce, WorkPackage const& _w)
Expand All @@ -278,9 +278,6 @@ void CLMiner::report(uint64_t _nonce, WorkPackage const& _w)
}
}

void CLMiner::kickOff()
{}

namespace
{
uint64_t randomNonce()
Expand Down Expand Up @@ -404,9 +401,7 @@ void CLMiner::workLoop()
}
}

void CLMiner::pause() {}

void CLMiner::waitPaused() {}
void CLMiner::kick_miner() {}

unsigned CLMiner::getNumDevices()
{
Expand Down
4 changes: 1 addition & 3 deletions libethash-cl/CLMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ class CLMiner: public Miner
static void setCLKernel(unsigned _clKernel) { s_clKernelName = _clKernel == 1 ? CLKernelName::Unstable : CLKernelName::Stable; }
HwMonitor hwmon() override;
protected:
void kickOff() override;
void pause() override;
void waitPaused() override;
void kick_miner() override;

private:
void workLoop() override;
Expand Down
87 changes: 43 additions & 44 deletions libethash-cuda/CUDAMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ using namespace dev;
using namespace eth;

unsigned CUDAMiner::s_numInstances = 0;
int CUDAMiner::s_devices[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

int CUDAMiner::s_devices[16] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};

struct CUDAChannel: public LogChannel
{
static const char* name() { return EthOrange " cu"; }
static const int verbosity = 2;
static const bool debug = false;
};

#define cudalog clog(CUDAChannel)
#define ETHCUDA_LOG(_contents) cudalog << _contents

Expand All @@ -44,26 +48,7 @@ CUDAMiner::CUDAMiner(FarmFace& _farm, unsigned _index) :
CUDAMiner::~CUDAMiner()
{
stopWorking();
pause();
}

void CUDAMiner::report(uint64_t _nonce, const WorkPackage& w)
{
// FIXME: This code is exactly the same as in EthashGPUMiner.
Result r = EthashAux::eval(w.seed, w.header, _nonce);
if (r.value < w.boundary)
farm.submitProof(Solution{_nonce, r.mixHash, w.header, w.seed, w.boundary, w.job, w.job_len, m_abort});
else
{
farm.failedSolution();
cwarn << "FAILURE: GPU gave incorrect result!";
}
}

void CUDAMiner::kickOff()
{
UniqueGuard l(x_all);
m_aborted = m_abort = false;
kick_miner();
}

bool CUDAMiner::init(const h256& seed)
Expand Down Expand Up @@ -148,13 +133,10 @@ void CUDAMiner::workLoop()
}
}

void CUDAMiner::pause()
void CUDAMiner::kick_miner()
{
UniqueGuard l(x_all);
if (m_aborted)
return;

m_abort = true;
if (!m_abort)
m_abort = true;
}

void CUDAMiner::setNumInstances(unsigned _instances)
Expand All @@ -168,14 +150,6 @@ void CUDAMiner::setDevices(const unsigned* _devices, unsigned _selectedDeviceCou
s_devices[i] = _devices[i];
}

void CUDAMiner::waitPaused()
{
// 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);
}

unsigned CUDAMiner::getNumDevices()
{
int deviceCount = -1;
Expand Down Expand Up @@ -323,7 +297,15 @@ unsigned CUDAMiner::s_gridSize = CUDAMiner::c_defaultGridSize;
unsigned CUDAMiner::s_numStreams = CUDAMiner::c_defaultNumStreams;
unsigned CUDAMiner::s_scheduleFlag = 0;

bool CUDAMiner::cuda_init(size_t numDevices, ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, uint8_t* &hostDAG, unsigned dagCreateDevice)
bool CUDAMiner::cuda_init(
size_t numDevices,
ethash_light_t _light,
uint8_t const* _lightData,
uint64_t _lightSize,
unsigned _deviceId,
bool _cpyToHost,
uint8_t* &hostDAG,
unsigned dagCreateDevice)
{
try
{
Expand Down Expand Up @@ -450,7 +432,6 @@ void CUDAMiner::search(
const dev::eth::WorkPackage& w)
{
bool initialize = false;
bool exit = false;
if (memcmp(&m_current_header, header, sizeof(hash32_t)))
{
m_current_header = *reinterpret_cast<hash32_t const *>(header);
Expand Down Expand Up @@ -493,13 +474,15 @@ void CUDAMiner::search(
}
}
uint64_t batch_size = s_gridSize * s_blockSize;
for (; !exit; m_current_index++, m_current_nonce += batch_size)
while (true)
{
m_current_index++;
m_current_nonce += batch_size;
auto stream_index = m_current_index % s_numStreams;
cudaStream_t stream = m_streams[stream_index];
volatile uint32_t* buffer = m_search_buf[stream_index];
uint32_t found_count = 0;
uint64_t nonces[SEARCH_RESULT_BUFFER_SIZE - 1];
uint64_t nonces[SEARCH_RESULT_BUFFER_SIZE];
uint64_t nonce_base = m_current_nonce - s_numStreams * batch_size;
if (m_current_index >= s_numStreams)
{
Expand All @@ -509,17 +492,33 @@ void CUDAMiner::search(
buffer[0] = 0;
if (found_count > (SEARCH_RESULT_BUFFER_SIZE - 1))
found_count = SEARCH_RESULT_BUFFER_SIZE - 1;
for (unsigned int j = 0; j < found_count; j++)
nonces[j] = nonce_base + buffer[j + 1];
for (unsigned int j = 1; j <= found_count; j++)
nonces[j] = nonce_base + buffer[j];
}
}
run_ethash_search(s_gridSize, s_blockSize, m_sharedBytes, stream, buffer, m_current_nonce, m_parallelHash);
if (m_current_index >= s_numStreams)
{
if (found_count)
found(nonces, found_count, w);
searched(batch_size);
exit = cuda_shouldStop();
{
for (uint32_t i = 1; i <= found_count; i++)
{
Result r = EthashAux::eval(w.seed, w.header, nonces[i]);
if (r.value < w.boundary)
farm.submitProof(Solution{nonces[i], r.mixHash, w.header, w.seed, w.boundary, w.job, w.job_len, m_abort});
else
{
farm.failedSolution();
cwarn << "GPU gave incorrect result!";
}
}
}
addHashCount(batch_size);
if (m_abort || shouldStop())
{
m_abort = false;
break;
}
}
}
}
Expand Down
Loading

0 comments on commit d8d618a

Please sign in to comment.