Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile OpenCL kernels for correct ProgPoW period seed #44

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions libethash-cl/CLMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,15 @@ void CLMiner::workLoop()
// The work package currently processed by GPU.
WorkPackage current;
current.header = h256{1u};
uint64_t old_period_seed = -1;

try {
while (!shouldStop())
{
const WorkPackage w = work();
uint64_t period_seed = w.height / PROGPOW_PERIOD;

if (current.header != w.header)
if (current.header != w.header || current.epoch != w.epoch || old_period_seed != period_seed)
{
// New work received. Update GPU data.
if (!w)
Expand All @@ -302,7 +304,7 @@ void CLMiner::workLoop()

//cllog << "New work: header" << w.header << "target" << w.boundary.hex();

if (current.epoch != w.epoch)
if (current.epoch != w.epoch || old_period_seed != period_seed)
{
if (s_dagLoadMode == DAG_LOAD_MODE_SEQUENTIAL)
{
Expand All @@ -311,8 +313,8 @@ void CLMiner::workLoop()
++s_dagLoadIndex;
}

cllog << "New epoch: " << w.epoch;
init(w.epoch);
cllog << "New epoch " << w.epoch << "/ period " << period_seed;
init(w.epoch, w.height, current.epoch != w.epoch, old_period_seed != period_seed);
}

// Upper 64 bits of the boundary.
Expand Down Expand Up @@ -370,6 +372,8 @@ void CLMiner::workLoop()
}
}

old_period_seed = period_seed;

current = w; // kernel now processing newest work
current.startNonce = startNonce;
// Increase start nonce for following kernel execution.
Expand Down Expand Up @@ -500,8 +504,10 @@ bool CLMiner::configureGPU(
return false;
}

bool CLMiner::init(int epoch)
bool CLMiner::init(int epoch, uint64_t block_number, bool new_epoch, bool new_period)
{
assert(new_epoch || new_period);

EthashAux::LightType light = EthashAux::light(epoch);

// get all platforms
Expand Down Expand Up @@ -604,7 +610,7 @@ bool CLMiner::init(int epoch)
// note: The kernels here are simply compiled version of the respective .cl kernels
// into a byte array by bin2h.cmake. There is no need to load the file by hand in runtime
// See libethash-cl/CMakeLists.txt: add_custom_command()
std::string code = ProgPow::getKern(light->light->block_number, ProgPow::KERNEL_CL);
std::string code = ProgPow::getKern(block_number, ProgPow::KERNEL_CL);
code += string(CLMiner_kernel, sizeof(CLMiner_kernel));

addDefinition(code, "GROUP_SIZE", m_workgroupSize);
Expand Down Expand Up @@ -672,6 +678,9 @@ bool CLMiner::init(int epoch)
m_searchKernel.setArg(2, m_dag);
m_searchKernel.setArg(5, 0);

if (!new_epoch)
return true;

// create mining buffers
ETHCL_LOG("Creating mining buffer");
m_searchBuffer = cl::Buffer(m_context, CL_MEM_WRITE_ONLY, (c_maxSearchResults + 1) * sizeof(uint32_t));
Expand Down
2 changes: 1 addition & 1 deletion libethash-cl/CLMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CLMiner: public Miner
private:
void workLoop() override;

bool init(int epoch);
bool init(int epoch, uint64_t block_number, bool new_epoch, bool new_period);

cl::Context m_context;
cl::CommandQueue m_queue;
Expand Down