forked from ethereum-mining/ethminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLMiner.h
106 lines (87 loc) · 2.66 KB
/
CLMiner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/// OpenCL miner implementation.
///
/// @file
/// @copyright GNU General Public License
#pragma once
#include <libdevcore/Worker.h>
#include <libethcore/EthashAux.h>
#include <libethcore/Miner.h>
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS true
#define CL_HPP_ENABLE_EXCEPTIONS true
#define CL_HPP_CL_1_2_DEFAULT_BUILD true
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include "CL/cl2.hpp"
// macOS OpenCL fix:
#ifndef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000
#endif
#ifndef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001
#endif
#define OPENCL_PLATFORM_UNKNOWN 0
#define OPENCL_PLATFORM_NVIDIA 1
#define OPENCL_PLATFORM_AMD 2
#define OPENCL_PLATFORM_CLOVER 3
namespace dev
{
namespace eth
{
class CLMiner: public Miner
{
public:
/* -- default values -- */
/// Default value of the local work size. Also known as workgroup size.
static const unsigned c_defaultLocalWorkSize = 128;
/// Default value of the global work size as a multiplier of the local work size
static const unsigned c_defaultGlobalWorkSizeMultiplier = 8192;
CLMiner(FarmFace& _farm, unsigned _index);
~CLMiner();
static unsigned instances() { return s_numInstances > 0 ? s_numInstances : 1; }
static unsigned getNumDevices();
static void listDevices();
static bool configureGPU(
unsigned _localWorkSize,
unsigned _globalWorkSizeMultiplier,
unsigned _platformId,
uint64_t _currentBlock,
unsigned _dagLoadMode,
unsigned _dagCreateDevice
);
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, getNumDevices()); }
static void setThreadsPerHash(unsigned _threadsPerHash){s_threadsPerHash = _threadsPerHash; }
static void setDevices(unsigned * _devices, unsigned _selectedDeviceCount)
{
for (unsigned i = 0; i < _selectedDeviceCount; i++)
{
s_devices[i] = _devices[i];
}
}
protected:
void kickOff() override;
void pause() override;
private:
void workLoop() override;
void report(uint64_t _nonce, WorkPackage const& _w);
bool init(const h256& seed);
cl::Context m_context;
cl::CommandQueue m_queue;
cl::Kernel m_searchKernel;
cl::Kernel m_dagKernel;
cl::Buffer m_dag;
cl::Buffer m_light;
cl::Buffer m_header;
cl::Buffer m_searchBuffer;
unsigned m_globalWorkSize = 0;
unsigned m_workgroupSize = 0;
static unsigned s_platformId;
static unsigned s_numInstances;
static unsigned s_threadsPerHash;
static int s_devices[16];
/// The local work size for the search
static unsigned s_workgroupSize;
/// The initial global work size for the searches
static unsigned s_initialGlobalWorkSize;
};
}
}