Browse Source

Quick discovery of optimal global work size

Use a dichotomic algo to discover optimal m_globalWorkSize:
- m_wayWorkSizeAdjust is the direction steps are done (-1 or +1)
- m_stepWorkSizeAdjust is the steps of adjustment (added or substracted
  to m_globalWorkSize)
- when a change of direction is needed, step is divided by 2
cl-refactor
bargst 10 years ago
parent
commit
7450b8a0bc
  1. 22
      libethash-cl/ethash_cl_miner.cpp
  2. 5
      libethash-cl/ethash_cl_miner.h

22
libethash-cl/ethash_cl_miner.cpp

@ -315,6 +315,8 @@ bool ethash_cl_miner::init(
m_globalWorkSize = ((m_globalWorkSize / s_workgroupSize) + 1) * s_workgroupSize; m_globalWorkSize = ((m_globalWorkSize / s_workgroupSize) + 1) * s_workgroupSize;
// remember the device's address bits // remember the device's address bits
m_deviceBits = device.getInfo<CL_DEVICE_ADDRESS_BITS>(); m_deviceBits = device.getInfo<CL_DEVICE_ADDRESS_BITS>();
// make sure first step of global work size adjustment is large enough
m_stepWorkSizeAdjust = pow(2, m_deviceBits/2+1);
// patch source code // patch source code
// note: ETHASH_CL_MINER_KERNEL is simply ethash_cl_miner_kernel.cl compiled // note: ETHASH_CL_MINER_KERNEL is simply ethash_cl_miner_kernel.cl compiled
@ -520,14 +522,26 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook
{ {
if (d > chrono::milliseconds(s_msPerBatch * 10 / 9)) if (d > chrono::milliseconds(s_msPerBatch * 10 / 9))
{ {
// cerr << "Batch of " << m_globalWorkSize << " took " << chrono::duration_cast<chrono::milliseconds>(d).count() << " ms, >> " << _msPerBatch << " ms." << endl; // Divide the step by 2 when adjustment way change
m_globalWorkSize = max<unsigned>(128, m_globalWorkSize - s_workgroupSize); if (m_wayWorkSizeAdjust > -1 )
m_stepWorkSizeAdjust = max<unsigned>(1, m_stepWorkSizeAdjust / 2);
m_wayWorkSizeAdjust = -1;
// cerr << "m_stepWorkSizeAdjust: " << m_stepWorkSizeAdjust << ", m_wayWorkSizeAdjust: " << m_wayWorkSizeAdjust << endl;
// cerr << "Batch of " << m_globalWorkSize << " took " << chrono::duration_cast<chrono::milliseconds>(d).count() << " ms, >> " << s_msPerBatch << " ms." << endl;
m_globalWorkSize = max<unsigned>(128, m_globalWorkSize - m_stepWorkSizeAdjust);
// cerr << "New global work size" << m_globalWorkSize << endl; // cerr << "New global work size" << m_globalWorkSize << endl;
} }
else if (d < chrono::milliseconds(s_msPerBatch * 9 / 10)) else if (d < chrono::milliseconds(s_msPerBatch * 9 / 10))
{ {
// cerr << "Batch of " << m_globalWorkSize << " took " << chrono::duration_cast<chrono::milliseconds>(d).count() << " ms, << " << _msPerBatch << " ms." << endl; // Divide the step by 2 when adjustment way change
m_globalWorkSize = min<unsigned>(pow(2, m_deviceBits) - 1, m_globalWorkSize + s_workgroupSize); if (m_wayWorkSizeAdjust < 1 )
m_stepWorkSizeAdjust = max<unsigned>(1, m_stepWorkSizeAdjust / 2);
m_wayWorkSizeAdjust = 1;
// cerr << "m_stepWorkSizeAdjust: " << m_stepWorkSizeAdjust << ", m_wayWorkSizeAdjust: " << m_wayWorkSizeAdjust << endl;
// cerr << "Batch of " << m_globalWorkSize << " took " << chrono::duration_cast<chrono::milliseconds>(d).count() << " ms, << " << s_msPerBatch << " ms." << endl;
m_globalWorkSize = min<unsigned>(pow(2, m_deviceBits) - 1, m_globalWorkSize + m_stepWorkSizeAdjust);
// Global work size should never be less than the workgroup size // Global work size should never be less than the workgroup size
m_globalWorkSize = max<unsigned>(s_workgroupSize, m_globalWorkSize); m_globalWorkSize = max<unsigned>(s_workgroupSize, m_globalWorkSize);
// cerr << "New global work size" << m_globalWorkSize << endl; // cerr << "New global work size" << m_globalWorkSize << endl;

5
libethash-cl/ethash_cl_miner.h

@ -82,6 +82,11 @@ private:
bool m_openclOnePointOne; bool m_openclOnePointOne;
unsigned m_deviceBits; unsigned m_deviceBits;
/// The step used in the work size adjustment
unsigned int m_stepWorkSizeAdjust;
/// The Work Size way of adjustment, > 0 when previously increased, < 0 when previously decreased
int m_wayWorkSizeAdjust = 0;
/// The local work size for the search /// The local work size for the search
static unsigned s_workgroupSize; static unsigned s_workgroupSize;
/// The initial global work size for the searches /// The initial global work size for the searches

Loading…
Cancel
Save