Skip to content
This repository was archived by the owner on Oct 21, 2019. It is now read-only.

Commit 4f5945b

Browse files
committed
ability to set local and global work per device (OpenCL)
1 parent 3ba069b commit 4f5945b

3 files changed

Lines changed: 39 additions & 16 deletions

File tree

ethminer/MinerAux.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,16 @@ class MinerCLI
281281
std::vector<std::string> strs;
282282
boost::split(strs, argv[++i], boost::is_any_of(","));
283283
int i = 0;
284-
for (std::vector<std::string>::iterator it = strs.begin(); it != strs.end() && i != 16; ++it, ++i)
285-
m_globalWorkSizeMultiplier[i] = stol(*it);
284+
for (std::vector<std::string>::iterator it = strs.begin(); it != strs.end() && i != 16; ++it, ++i) {
285+
unsigned a = stol(*it);
286+
if (a > 0) {
287+
m_globalWorkSizeMultiplier[i] = a;
288+
}
289+
else if (a == 0 && arg == "--cl-global-work") { // cuda set derfault
290+
// set default here
291+
m_globalWorkSizeMultiplier[i] = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier;
292+
}
293+
}
286294
}
287295
catch (...)
288296
{
@@ -294,8 +302,16 @@ class MinerCLI
294302
std::vector<std::string> strs;
295303
boost::split(strs, argv[++i], boost::is_any_of(","));
296304
int i = 0;
297-
for (std::vector<std::string>::iterator it = strs.begin(); it != strs.end() && i != 16; ++it, ++i)
298-
m_localWorkSize[i] = stol(*it);
305+
for (std::vector<std::string>::iterator it = strs.begin(); it != strs.end() && i != 16; ++it, ++i) {
306+
unsigned a = stol(*it);
307+
if (a > 0) {
308+
m_localWorkSize[i] = a;
309+
}
310+
else if (a == 0 && arg == "--cl-local-work") { // cuda set derfault
311+
// set default here
312+
m_localWorkSize[i] = ethash_cl_miner::c_defaultLocalWorkSize;
313+
}
314+
}
299315
}
300316
catch (...)
301317
{

libethash-cl/ethash_cl_miner.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ bool ethash_cl_miner::configureGPU(
201201
uint64_t _currentBlock
202202
)
203203
{
204-
s_workgroupSize = _localWorkSize[0];
205-
s_initialGlobalWorkSize = _globalWorkSize[0];
204+
s_workgroupSize = _localWorkSize;
205+
s_initialGlobalWorkSize = _globalWorkSize;
206206
s_allowCPU = _allowCPU;
207207
s_extraRequiredGPUMem = _extraGPUMemory;
208208

@@ -234,8 +234,10 @@ bool ethash_cl_miner::configureGPU(
234234

235235
bool ethash_cl_miner::s_allowCPU = false;
236236
unsigned ethash_cl_miner::s_extraRequiredGPUMem;
237-
unsigned ethash_cl_miner::s_workgroupSize = ethash_cl_miner::c_defaultLocalWorkSize;
238-
unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier * ethash_cl_miner::c_defaultLocalWorkSize;
237+
//unsigned ethash_cl_miner::s_workgroupSize = ethash_cl_miner::c_defaultLocalWorkSize;
238+
//unsigned ethash_cl_miner::s_initialGlobalWorkSize = ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier * ethash_cl_miner::c_defaultLocalWorkSize;
239+
unsigned *ethash_cl_miner::s_workgroupSize = nullptr;
240+
unsigned *ethash_cl_miner::s_initialGlobalWorkSize = nullptr;
239241

240242
bool ethash_cl_miner::searchForAllDevices(function<bool(cl::Device const&)> _callback)
241243
{
@@ -335,6 +337,7 @@ bool ethash_cl_miner::init(
335337
void** hostDAG
336338
)
337339
{
340+
m_device_id = _deviceId;
338341
// get all platforms
339342
try
340343
{
@@ -399,9 +402,9 @@ bool ethash_cl_miner::init(
399402
m_queue = cl::CommandQueue(m_context, device);
400403

401404
// make sure that global work size is evenly divisible by the local workgroup size
402-
m_globalWorkSize = s_initialGlobalWorkSize;
403-
if (m_globalWorkSize % s_workgroupSize != 0)
404-
m_globalWorkSize = ((m_globalWorkSize / s_workgroupSize) + 1) * s_workgroupSize;
405+
m_globalWorkSize = s_initialGlobalWorkSize[_deviceId];
406+
if (m_globalWorkSize % s_workgroupSize[_deviceId] != 0)
407+
m_globalWorkSize = ((m_globalWorkSize / s_workgroupSize[_deviceId]) + 1) * s_workgroupSize[_deviceId];
405408

406409
uint64_t dagSize = ethash_get_datasize(_light->block_number);
407410
uint32_t dagSize128 = (unsigned)(dagSize / ETHASH_MIX_BYTES);
@@ -411,7 +414,7 @@ bool ethash_cl_miner::init(
411414
// note: ETHASH_CL_MINER_KERNEL is simply ethash_cl_miner_kernel.cl compiled
412415
// into a byte array by bin2h.cmake. There is no need to load the file by hand in runtime
413416
string code(ETHASH_CL_MINER_KERNEL, ETHASH_CL_MINER_KERNEL + ETHASH_CL_MINER_KERNEL_SIZE);
414-
addDefinition(code, "GROUP_SIZE", s_workgroupSize);
417+
addDefinition(code, "GROUP_SIZE", s_workgroupSize[_deviceId]);
415418
addDefinition(code, "DAG_SIZE", dagSize128);
416419
addDefinition(code, "LIGHT_SIZE", lightSize64);
417420
addDefinition(code, "ACCESSES", ETHASH_ACCESSES);
@@ -495,7 +498,7 @@ bool ethash_cl_miner::init(
495498
for (uint32_t i = 0; i < fullRuns; i++)
496499
{
497500
m_dagKernel.setArg(0, i * m_globalWorkSize);
498-
m_queue.enqueueNDRangeKernel(m_dagKernel, cl::NullRange, m_globalWorkSize, s_workgroupSize);
501+
m_queue.enqueueNDRangeKernel(m_dagKernel, cl::NullRange, m_globalWorkSize, s_workgroupSize[_deviceId]);
499502
m_queue.finish();
500503
printf("Generate DAG device OPENCL#%d: %.0f%%\n", _deviceId, 100.0f * (float)i / (float)fullRuns);
501504
}
@@ -573,7 +576,7 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook
573576
m_searchKernel.setArg(3, start_nonce);
574577

575578
// execute it!
576-
m_queue.enqueueNDRangeKernel(m_searchKernel, cl::NullRange, m_globalWorkSize, s_workgroupSize);
579+
m_queue.enqueueNDRangeKernel(m_searchKernel, cl::NullRange, m_globalWorkSize, s_workgroupSize[m_device_id]);
577580

578581
pending.push({ start_nonce, buf });
579582
buf = (buf + 1) % c_bufferCount;

libethash-cl/ethash_cl_miner.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ class ethash_cl_miner
8585
unsigned m_globalWorkSize;
8686
bool m_openclOnePointOne;
8787

88+
unsigned m_device_id;
89+
8890
/// The local work size for the search
89-
static unsigned s_workgroupSize;
91+
// now it is not per group but per device
92+
static unsigned *s_workgroupSize;
9093
/// The initial global work size for the searches
91-
static unsigned s_initialGlobalWorkSize;
94+
// now it is not per group but per device
95+
static unsigned *s_initialGlobalWorkSize;
9296
/// The target milliseconds per batch for the search. If 0, then no adjustment will happen
9397
static unsigned s_msPerBatch;
9498
/// Allow CPU to appear as an OpenCL device or not. Default is false

0 commit comments

Comments
 (0)