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

Commit

Permalink
Merge pull request #506 from EoD/restore_old_cl_kernel
Browse files Browse the repository at this point in the history
Restore old cl kernel v4
  • Loading branch information
chfast authored Jan 7, 2018
2 parents 99d8674 + 3935f35 commit f6de7ad
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 10 deletions.
22 changes: 22 additions & 0 deletions ethminer/MinerAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ class MinerCLI
BOOST_THROW_EXCEPTION(BadArgument());
}
}
else if (arg == "--cl-kernel" && i + 1 < argc)
{
try
{
m_openclSelectedKernel = stol(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
BOOST_THROW_EXCEPTION(BadArgument());
}
}
#endif
#if ETH_ETHASHCL || ETH_ETHASHCUDA
else if ((arg == "--cl-global-work" || arg == "--cuda-grid-size") && i + 1 < argc)
Expand Down Expand Up @@ -501,7 +513,9 @@ class MinerCLI
m_miningThreads = m_openclDeviceCount;
}

CLMiner::setCLKernel(m_openclSelectedKernel);
CLMiner::setThreadsPerHash(m_openclThreadsPerHash);

if (!CLMiner::configureGPU(
m_localWorkSize,
m_globalWorkSizeMultiplier,
Expand Down Expand Up @@ -601,11 +615,17 @@ class MinerCLI
<< " sequential - load DAG on GPUs one after another. Use this when the miner crashes during DAG generation" << endl
<< " single <n> - generate DAG on device n, then copy to other devices" << endl
#if ETH_ETHASHCL
<< " OpenCL configuration:" << endl
<< " --cl-kernel <n> Use a different OpenCL kernel (default: use stable kernel)" << endl
<< " 0: stable kernel" << endl
<< " 1: unstable kernel" << endl
// << " 2: experimental kernel" << endl
<< " --cl-local-work Set the OpenCL local work size. Default is " << CLMiner::c_defaultLocalWorkSize << endl
<< " --cl-global-work Set the OpenCL global work size as a multiple of the local work size. Default is " << CLMiner::c_defaultGlobalWorkSizeMultiplier << " * " << CLMiner::c_defaultLocalWorkSize << endl
<< " --cl-parallel-hash <1 2 ..8> Define how many threads to associate per hash. Default=8" << endl
#endif
#if ETH_ETHASHCUDA
<< " CUDA configuration:" << endl
<< " --cuda-block-size Set the CUDA block work size. Default is " << toString(ethash_cuda_miner::c_defaultBlockSize) << endl
<< " --cuda-grid-size Set the CUDA grid size. Default is " << toString(ethash_cuda_miner::c_defaultGridSize) << endl
<< " --cuda-streams Set the number of CUDA streams. Default is " << toString(ethash_cuda_miner::c_defaultNumStreams) << endl
Expand All @@ -618,6 +638,7 @@ class MinerCLI
<< " --cuda-parallel-hash <1 2 ..8> Define how many hashes to calculate in a kernel, can be scaled to achieve better performance. Default=4" << endl
#endif
#if API_CORE
<< " API core configuration:" << endl
<< " --api-port Set the api port, the miner should listen to. Use 0 to disable. Default=0, use negative numbers to run in readonly mode. for example -3333." << endl
#endif
;
Expand Down Expand Up @@ -1048,6 +1069,7 @@ class MinerCLI
unsigned m_miningThreads = UINT_MAX;
bool m_shouldListDevices = false;
#if ETH_ETHASHCL
unsigned m_openclSelectedKernel = 0; ///< A numeric value for the selected OpenCL kernel
unsigned m_openclDeviceCount = 0;
unsigned m_openclDevices[16];
unsigned m_openclThreadsPerHash = 8;
Expand Down
24 changes: 21 additions & 3 deletions libethash-cl/CLMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include "CLMiner.h"
#include <libethash/internal.h>
#include "CLMiner_kernel.h"
#include "CLMiner_kernel_stable.h"
#include "CLMiner_kernel_unstable.h"

using namespace dev;
using namespace eth;
Expand All @@ -18,6 +19,7 @@ namespace eth
unsigned CLMiner::s_workgroupSize = CLMiner::c_defaultLocalWorkSize;
unsigned CLMiner::s_initialGlobalWorkSize = CLMiner::c_defaultGlobalWorkSizeMultiplier * CLMiner::c_defaultLocalWorkSize;
unsigned CLMiner::s_threadsPerHash = 8;
CLKernelName CLMiner::s_clKernelName = CLMiner::c_defaultKernelName;

constexpr size_t c_maxSearchResults = 1;

Expand Down Expand Up @@ -632,10 +634,26 @@ bool CLMiner::init(const h256& seed)
uint32_t lightSize64 = (unsigned)(light->data().size() / sizeof(node));

// patch source code
// note: CLMiner_kernel is simply ethash_cl_miner_kernel.cl compiled
// 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()
// TODO: Just use C++ raw string literal.
string code(CLMiner_kernel, CLMiner_kernel + sizeof(CLMiner_kernel));
string code;

if ( s_clKernelName == CLKernelName::Unstable ) {
cllog << "OpenCL kernel: Unstable kernel";
code = string(CLMiner_kernel_unstable, CLMiner_kernel_unstable + sizeof(CLMiner_kernel_unstable));
}
else { //if(s_clKernelName == CLKernelName::Stable)
cllog << "OpenCL kernel: Stable kernel";

//CLMiner_kernel_stable.cl will do a #undef THREADS_PER_HASH
if(s_threadsPerHash != 8) {
cwarn << "The current stable OpenCL kernel only supports exactly 8 threads. Thread parameter will be ignored.";
}

code = string(CLMiner_kernel_stable, CLMiner_kernel_stable + sizeof(CLMiner_kernel_stable));
}
addDefinition(code, "GROUP_SIZE", m_workgroupSize);
addDefinition(code, "DAG_SIZE", dagSize128);
addDefinition(code, "LIGHT_SIZE", lightSize64);
Expand Down
10 changes: 10 additions & 0 deletions libethash-cl/CLMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ namespace dev
namespace eth
{

enum CLKernelName {
Stable,
Unstable,
};

class CLMiner: public Miner
{
public:
Expand All @@ -50,6 +55,9 @@ class CLMiner: public Miner
/// Default value of the global work size as a multiplier of the local work size
static const unsigned c_defaultGlobalWorkSizeMultiplier = 8192;

/// Default value of the kernel is the original one
static const CLKernelName c_defaultKernelName = CLKernelName::Stable;

CLMiner(FarmFace& _farm, unsigned _index);
~CLMiner();

Expand All @@ -73,6 +81,7 @@ class CLMiner: public Miner
s_devices[i] = _devices[i];
}
}
static void setCLKernel(unsigned _clKernel) { s_clKernelName = _clKernel == 1 ? CLKernelName::Unstable : CLKernelName::Stable; }
HwMonitor hwmon() override;
protected:
void kickOff() override;
Expand All @@ -98,6 +107,7 @@ class CLMiner: public Miner
static unsigned s_platformId;
static unsigned s_numInstances;
static unsigned s_threadsPerHash;
static CLKernelName s_clKernelName;
static int s_devices[16];

/// The local work size for the search
Expand Down
Loading

0 comments on commit f6de7ad

Please sign in to comment.