-
Notifications
You must be signed in to change notification settings - Fork 41
/
xpmclient.h
225 lines (131 loc) · 3.01 KB
/
xpmclient.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* xpmclient.h
*
* Created on: 01.05.2014
* Author: mad
*/
#ifndef XPMCLIENT_H_
#define XPMCLIENT_H_
#include <gmp.h>
#include <gmpxx.h>
#include "baseclient.h"
#include "opencl.h"
#include "uint256.h"
#include "sha256.h"
extern unsigned gPrimes[96*1024];
extern std::vector<unsigned> gPrimes2;
extern cl_program gProgram;
struct stats_t {
unsigned id;
unsigned errors;
unsigned fps;
double primeprob;
double cpd;
stats_t(){
id = 0;
errors = 0;
fps = 0;
primeprob = 0;
cpd = 0;
}
};
struct config_t {
cl_uint N;
cl_uint SIZE;
cl_uint STRIPES;
cl_uint WIDTH;
cl_uint PCOUNT;
cl_uint TARGET;
};
class PrimeMiner {
public:
struct block_t {
static const int CURRENT_VERSION = 2;
int version;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
unsigned int time;
unsigned int bits;
unsigned int nonce;
};
struct search_t {
clBuffer<cl_uint> midstate;
clBuffer<cl_uint> found;
clBuffer<cl_uint> count;
};
struct hash_t {
unsigned iter;
unsigned nonce;
unsigned time;
uint256 hash;
mpz_class shash;
};
struct fermat_t {
cl_uint index;
cl_uchar origin;
cl_uchar chainpos;
cl_uchar type;
cl_uchar hashid;
};
struct info_t {
clBuffer<fermat_t> info;
clBuffer<cl_uint> count;
};
struct pipeline_t {
unsigned bsize;
clBuffer<cl_uint> input;
clBuffer<cl_uchar> output;
info_t buffer[2];
info_t final;
};
PrimeMiner(unsigned id, unsigned threads, unsigned hashprim, unsigned prim, unsigned depth);
~PrimeMiner();
bool Initialize(cl_device_id dev);
static void InvokeMining(void *args, zctx_t *ctx, void *pipe);
bool MakeExit;
private:
void Mining(zctx_t *ctx, void *pipe);
unsigned mID;
unsigned mThreads;
config_t mConfig;
unsigned mPrimorial;
unsigned mHashPrimorial;
unsigned mBlockSize;
unsigned mDepth;
cl_command_queue mSmall;
cl_command_queue mBig;
cl_kernel mHashMod;
cl_kernel mSieveSetup;
cl_kernel mSieve;
cl_kernel mSieveSearch;
cl_kernel mFermatSetup;
cl_kernel mFermatKernel;
cl_kernel mFermatCheck;
};
class XPMClient {
public:
XPMClient(zctx_t* ctx);
~XPMClient();
bool Initialize(Configuration* cfg);
void NotifyBlock(const proto::Block& block);
void TakeWork(const proto::Work& work);
int GetStats(proto::ClientStats& stats);
void Toggle();
void setup_adl();
private:
zctx_t* mCtx;
std::vector<std::pair<PrimeMiner*, void*> > mWorkers;
std::map<int,int> mDeviceMap;
std::map<int,int> mDeviceMapRev;
void* mBlockPub;
void* mWorkPub;
void* mStatsPull;
unsigned mNumDevices;
unsigned mStatCounter;
bool mPaused;
std::vector<int> mCoreFreq;
std::vector<int> mMemFreq;
std::vector<int> mPowertune;
};
extern XPMClient* gClient;
#endif /* XPMCLIENT_H_ */