/
mean.cu
616 lines (541 loc) · 19.8 KB
/
mean.cu
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
// Cuckaroom Cycle, a memory-hard proof-of-work by John Tromp
// Copyright (c) 2018-2020 Jiri Vadura (photon) and John Tromp
// This software is covered by the FAIR MINING license
#include <stdio.h>
#include <string.h>
#include <vector>
#include <assert.h>
#include "cuckaroom.hpp"
#include "graph.hpp"
#include "../crypto/blake2.h"
// Number of Parts of BufferB, all but one of which will overlap BufferA
#ifndef NA
#define NA 4
#endif
#define NA2 (NA * NA)
#define NODE1MASK NODEMASK
#include "../crypto/siphash.cuh"
#include "kernel.cuh"
typedef uint8_t u8;
typedef uint16_t u16;
#ifndef IDXSHIFT
// number of bits of compression of surviving edge endpoints
// reduces space used in cycle finding, but too high a value
// results in NODE OVERFLOW warnings and fake cycles
#define IDXSHIFT 12
#endif
const u32 MAXEDGES = NEDGES >> IDXSHIFT;
#ifndef NEPS_A
#define NEPS_A 135
#endif
#ifndef NEPS_B
#define NEPS_B 88
#endif
#ifndef NEPS_C
#define NEPS_C 55
#endif
#define NEPS 128
const u32 EDGES_A = NZ * NEPS_A / NEPS;
const u32 EDGES_B = NZ * NEPS_B / NEPS;
const u32 EDGES_C = NZ * NEPS_C / NEPS;
const u32 ROW_EDGES_A = EDGES_A * NY;
const u32 ROW_EDGES_B = EDGES_B * NY;
#define checkCudaErrors_V(ans) ({if (gpuAssert((ans), __FILE__, __LINE__) != cudaSuccess) return;})
#define checkCudaErrors_N(ans) ({if (gpuAssert((ans), __FILE__, __LINE__) != cudaSuccess) return NULL;})
#define checkCudaErrors(ans) ({int retval = gpuAssert((ans), __FILE__, __LINE__); if (retval != cudaSuccess) return retval;})
inline int gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) {
int device_id;
cudaGetDevice(&device_id);
if (code != cudaSuccess) {
snprintf(LAST_ERROR_REASON, MAX_NAME_LEN, "Device %d GPUassert: %s %s %d", device_id, cudaGetErrorString(code), file, line);
cudaDeviceReset();
if (abort) return code;
}
return code;
}
struct blockstpb {
u16 blocks;
u16 tpb;
};
#ifndef SEED_TPB
#define SEED_TPB 256
#endif
#ifndef TRIM0_TPB
#define TRIM0_TPB 1024
#endif
#ifndef TRIM1_TPB
#define TRIM1_TPB 512
#endif
#ifndef TRIM_TPB
#define TRIM_TPB 512
#endif
#ifndef RELAY_TPB
#define RELAY_TPB 512
#endif
#ifndef TAIL_TPB
#define TAIL_TPB SEED_TPB
#endif
struct trimparams {
u16 ntrims;
blockstpb seed;
blockstpb trim0;
blockstpb trim1;
blockstpb trim;
blockstpb tail;
blockstpb recover;
trimparams() {
ntrims = 399;
seed.blocks = 1024;
seed.tpb = SEED_TPB;
trim0.blocks = NX2/NA;
trim0.tpb = TRIM0_TPB;
trim1.blocks = NX2/NA;
trim1.tpb = TRIM1_TPB;
trim.blocks = NX2;
trim.tpb = TRIM_TPB;
tail.blocks = NX2;
tail.tpb = TAIL_TPB;;
recover.blocks = 2048;
recover.tpb = 256;
}
};
typedef u32 proof[PROOFSIZE];
// maintains set of trimmable edges
struct edgetrimmer {
trimparams tp;
edgetrimmer *dt;
const size_t sizeA = ROW_EDGES_A * NX * sizeof(uint2);
const size_t sizeB = ROW_EDGES_B * NX * sizeof(uint2);
const size_t bufferSize = sizeB / NA + sizeA;
const size_t indexesSize = NX2 * sizeof(u32);
const size_t indexesSizeNA = NA * indexesSize;
const size_t nodemapSize = NNODES / 8; // 8 bits per byte
u8 *bufferA;
u8 *bufferB;
u8 *bufferA1;
u32 *indexesA;
u32 *indexesB;
u32 *nodemap;
u32 nedges;
siphash_keys sipkeys;
bool abort;
bool initsuccess = false;
edgetrimmer(const trimparams _tp) : tp(_tp) {
checkCudaErrors_V(cudaMalloc((void**)&dt, sizeof(edgetrimmer)));
checkCudaErrors_V(cudaMalloc((void**)&indexesA, indexesSizeNA));
checkCudaErrors_V(cudaMalloc((void**)&indexesB, indexesSizeNA));
checkCudaErrors_V(cudaMalloc((void**)&nodemap, nodemapSize));
checkCudaErrors_V(cudaMalloc((void**)&bufferB, bufferSize));
bufferA = bufferB + sizeB / NA;
bufferA1 = bufferB + sizeB;
cudaMemcpy(dt, this, sizeof(edgetrimmer), cudaMemcpyHostToDevice);
initsuccess = true;
}
u64 globalbytes() const {
return bufferSize + 2 * indexesSizeNA + nodemapSize + sizeof(siphash_keys) + sizeof(edgetrimmer);
}
~edgetrimmer() {
checkCudaErrors_V(cudaFree(bufferB));
checkCudaErrors_V(cudaFree(indexesA));
checkCudaErrors_V(cudaFree(indexesB));
checkCudaErrors_V(cudaFree(nodemap));
checkCudaErrors_V(cudaFree(dt));
cudaDeviceReset();
}
void indexcount(u32 round, const u32 *indexes) {
#ifdef VERBOSE
u32 nedges[NX2];
cudaMemcpy(nedges, indexes, NX2 * sizeof(u32), cudaMemcpyDeviceToHost);
cudaDeviceSynchronize();
u32 sum, max;
for (int i = sum = max = 0; i < NX2; i++) {
sum += nedges[i];
if (nedges[i] > max)
max = nedges[i];
}
print_log("round %d edges avg %d max %d\n", round, sum/NX2, max);
#endif
}
u32 trim() {
cudaEvent_t start, stop;
checkCudaErrors(cudaEventCreate(&start)); checkCudaErrors(cudaEventCreate(&stop));
cudaMemcpyToSymbol(dipkeys, &sipkeys, sizeof(sipkeys));
cudaDeviceSynchronize();
float durationA, durationB, durationY;
cudaEventRecord(start, NULL);
const u32 qI = NX2 / NA;
#if 1
cudaMemset(indexesA, 0, indexesSizeNA);
for (u32 i=0; i < NA; i++) {
YSeed<SEED_TPB, EDGES_A/NA><<<tp.seed.blocks, SEED_TPB>>>((uint2*)bufferA, indexesA+i*NX2, i);
if (abort) return false;
}
cudaDeviceSynchronize();
#ifdef VERBOSE
print_log("%d x YSeed<<<%d,%d>>>\n", NA, tp.seed.blocks, tp.seed.tpb); // 1024x256
indexcount(0, indexesA);
#endif
cudaMemset(nodemap, 0, nodemapSize);
NodemapRound<TRIM0_TPB, EDGES_A/NA><<<NX2, TRIM0_TPB>>>((u32*)bufferA, indexesA, nodemap);
if (abort) return false;
checkCudaErrors(cudaDeviceSynchronize()); cudaEventRecord(stop, NULL);
cudaEventSynchronize(stop); cudaEventElapsedTime(&durationY, start, stop);
cudaEventRecord(start, NULL);
#ifdef VERBOSE
print_log("NodemapRound<<<%d,%d>>>\n", NX2/NA, TRIM0_TPB); // 1024x1024
print_log("YSeeding completed in %.0f ms\n", durationY);
#endif
#endif
cudaMemset(indexesA, 0, indexesSizeNA);
for (u32 i=0; i < NA; i++) {
FluffySeed<SEED_TPB, EDGES_A/NA><<<tp.seed.blocks, SEED_TPB>>>((uint4*)(bufferA+i*(sizeA/NA2)), indexesA+i*NX2, i*(NEDGES/NA));
if (abort) return false;
}
#ifdef VERBOSE
print_log("%d x Seed<<<%d,%d>>>\n", NA, tp.seed.blocks, tp.seed.tpb); // 1024x512
indexcount(0, indexesA);
#endif
checkCudaErrors(cudaDeviceSynchronize()); cudaEventRecord(stop, NULL);
cudaEventSynchronize(stop); cudaEventElapsedTime(&durationA, start, stop);
cudaEventRecord(start, NULL);
#ifdef VERBOSE
print_log("Seeding completed in %.0f ms\n", durationA);
print_log("Round_A1<<<%d,%d>>>\n", NX2/NA, TRIM0_TPB); // 1024x1024
#endif
cudaMemset(indexesB, 0, indexesSizeNA);
const u32 qB = sizeB/NA;
for (u32 i=0; i < NA; i++) {
FluffyRound_A1<TRIM0_TPB, EDGES_A/NA, EDGES_B/NA><<<NX2/NA, TRIM0_TPB>>>((uint2*)bufferA, (uint4*)(bufferB+i*qB), indexesA, indexesB, nodemap, i*qI); // .632
if (abort) return false;
}
checkCudaErrors(cudaDeviceSynchronize()); cudaEventRecord(stop, NULL);
cudaEventSynchronize(stop); cudaEventElapsedTime(&durationB, start, stop);
checkCudaErrors(cudaEventDestroy(start)); checkCudaErrors(cudaEventDestroy(stop));
#ifdef VERBOSE
indexcount(1, indexesB);
print_log("Round A1 completed in %.0f ms\n", durationB);
print_log("Round_A3<<<%d,%d>>>\n", NX2/NA, TRIM1_TPB); // 4096x1024
#endif
cudaMemset(indexesA, 0, indexesSize);
FluffyRound_A3<TRIM1_TPB, EDGES_B/NA, EDGES_C><<<NX2, TRIM1_TPB>>>((uint2*)bufferB, (uint2*)bufferA1, indexesB, indexesA, nodemap);
indexcount(2, indexesA); // .400
if (abort) return false;
#ifdef VERBOSE
print_log("Round_A2<><<<%d,%d>>>\n", NX2, TRIM_TPB); // 4096x512
#endif
cudaMemset(indexesB, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_C, EDGES_B/2><<<NX2, TRIM_TPB>>>((uint2*)bufferA1, (uint2*)bufferB, indexesA, indexesB, nodemap);
indexcount(3, indexesB);
if (abort) return false;
cudaMemset(indexesA, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_B/2, EDGES_A/4><<<NX2, TRIM_TPB>>>((uint2*)bufferB, (uint2*)bufferA1, indexesB, indexesA, nodemap);
indexcount(4, indexesA);
if (abort) return false;
cudaMemset(indexesB, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_A/4, EDGES_A/4><<<NX2, TRIM_TPB>>>((uint2*)bufferA1, (uint2*)bufferB, indexesA, indexesB, nodemap);
indexcount(5, indexesB);
if (abort) return false;
cudaMemset(indexesA, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_A/4, EDGES_B/4><<<NX2, TRIM_TPB>>>((uint2*)bufferB, (uint2*)bufferA1, indexesB, indexesA, nodemap);
indexcount(6, indexesA);
if (abort) return false;
cudaMemset(indexesB, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_B/4, EDGES_B/4><<<NX2, TRIM_TPB>>>((uint2*)bufferA1, (uint2*)bufferB, indexesA, indexesB, nodemap);
indexcount(7, indexesB);
if (abort) return false;
cudaMemset(indexesA, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_B/4, EDGES_A/8><<<NX2, TRIM_TPB>>>((uint2*)bufferB, (uint2*)bufferA1, indexesB, indexesA, nodemap);
indexcount(8, indexesA);
if (abort) return false;
for (int round = 9; round < tp.ntrims; round += 2) {
cudaMemset(indexesB, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_A/8, EDGES_A/8><<<NX2, TRIM_TPB>>>((uint2*)bufferA1, (uint2*)bufferB, indexesA, indexesB, nodemap);
indexcount(round, indexesB);
if (abort) return false;
cudaMemset(indexesA, 0, indexesSize);
FluffyRound_A2<TRIM_TPB, EDGES_A/8, EDGES_A/8><<<NX2, TRIM_TPB>>>((uint2*)bufferB, (uint2*)bufferA1, indexesB, indexesA, nodemap);
indexcount(round+1, indexesA);
if (abort) return false;
}
cudaMemset(indexesB, 0, indexesSize);
#ifdef VERBOSE
print_log("Tail<><<<%d,%d>>>\n", NX2, TAIL_TPB);
#endif
FluffyTail<TAIL_TPB, EDGES_A/8><<<NX2, TAIL_TPB>>>((uint2*)bufferA1, (uint2*)bufferB, indexesA, indexesB);
cudaMemcpy(&nedges, indexesB, sizeof(u32), cudaMemcpyDeviceToHost);
cudaDeviceSynchronize();
print_log("%d rounds %d edges\n", tp.ntrims, nedges);
return nedges;
}
};
struct solver_ctx {
edgetrimmer trimmer;
bool mutatenonce;
uint2 *edges;
graph<word_t> cg;
uint2 soledges[PROOFSIZE];
std::vector<u32> sols; // concatenation of all proof's indices
solver_ctx(const trimparams tp, bool mutate_nonce) : trimmer(tp), cg(MAXEDGES, MAXEDGES, MAX_SOLS, IDXSHIFT) {
edges = new uint2[MAXEDGES];
mutatenonce = mutate_nonce;
}
void setheadernonce(char * const headernonce, const u32 len, const u32 nonce) {
if (mutatenonce)
((u32 *)headernonce)[len/sizeof(u32)-1] = htole32(nonce); // place nonce at end
setheader(headernonce, len, &trimmer.sipkeys);
sols.clear();
}
~solver_ctx() {
delete[] edges;
}
int findcycles(uint2 *edges, u32 nedges) {
cg.reset();
for (u32 i = 0; i < nedges; i++) {
cg.add_compress_edge(edges[i].x, edges[i].y);
}
for (u32 s = 0 ;s < cg.nsols; s++) {
#ifdef VERBOSE
print_log("Solution");
#endif
for (u32 j = 0; j < PROOFSIZE; j++) {
soledges[j] = edges[cg.sols[s][j]];
#ifdef VERBOSE
print_log(" (%x, %x)", soledges[j].x, soledges[j].y);
#endif
}
#ifdef VERBOSE
print_log("\n");
#endif
sols.resize(sols.size() + PROOFSIZE);
cudaMemcpyToSymbol(recovery, soledges, sizeof(soledges));
cudaMemset(trimmer.indexesA, 0, trimmer.indexesSize);
#ifdef VERBOSE
print_log("Recovery<><<<%d,%d>>>\n", trimmer.tp.recover.blocks, trimmer.tp.recover.tpb);
#endif
FluffyRecovery<<<trimmer.tp.recover.blocks, trimmer.tp.recover.tpb>>>((u32 *)trimmer.bufferA1);
cudaMemcpy(&sols[sols.size()-PROOFSIZE], trimmer.bufferA1, PROOFSIZE * sizeof(u32), cudaMemcpyDeviceToHost);
checkCudaErrors(cudaDeviceSynchronize());
qsort(&sols[sols.size()-PROOFSIZE], PROOFSIZE, sizeof(u32), cg.nonce_cmp);
}
return 0;
}
int solve() {
u64 time0, time1;
u32 timems,timems2;
trimmer.abort = false;
time0 = timestamp();
u32 nedges = trimmer.trim();
if (!nedges)
return 0;
if (nedges > MAXEDGES) {
print_log("OOPS; losing %d edges beyond MAXEDGES=%d\n", nedges-MAXEDGES, MAXEDGES);
nedges = MAXEDGES;
}
cudaMemcpy(edges, trimmer.bufferB, sizeof(uint2[nedges]), cudaMemcpyDeviceToHost);
time1 = timestamp(); timems = (time1 - time0) / 1000000;
time0 = timestamp();
findcycles(edges, nedges);
time1 = timestamp(); timems2 = (time1 - time0) / 1000000;
print_log("trim time %d ms findcycles edges %d time %d ms total %d ms\n", timems, nedges, timems2, timems+timems2);
return sols.size() / PROOFSIZE;
}
void abort() {
trimmer.abort = true;
}
};
#include <unistd.h>
// arbitrary length of header hashed into siphash key
#define HEADERLEN 80
typedef solver_ctx SolverCtx;
CALL_CONVENTION int run_solver(SolverCtx* ctx,
char* header,
int header_length,
u32 nonce,
u32 range,
SolverSolutions *solutions,
SolverStats *stats
)
{
u64 time0, time1;
u32 timems;
u32 sumnsols = 0;
int device_id;
if (stats != NULL) {
cudaGetDevice(&device_id);
cudaDeviceProp props;
cudaGetDeviceProperties(&props, stats->device_id);
stats->device_id = device_id;
stats->edge_bits = EDGEBITS;
strncpy(stats->device_name, props.name, MAX_NAME_LEN);
}
if (ctx == NULL || !ctx->trimmer.initsuccess){
print_log("Error initialising trimmer. Aborting.\n");
print_log("Reason: %s\n", LAST_ERROR_REASON);
if (stats != NULL) {
stats->has_errored = true;
strncpy(stats->error_reason, LAST_ERROR_REASON, MAX_NAME_LEN);
}
return 0;
}
for (u32 r = 0; r < range; r++) {
time0 = timestamp();
ctx->setheadernonce(header, header_length, nonce + r);
print_log("nonce %d k0 k1 k2 k3 %llx %llx %llx %llx\n", nonce+r, ctx->trimmer.sipkeys.k0, ctx->trimmer.sipkeys.k1, ctx->trimmer.sipkeys.k2, ctx->trimmer.sipkeys.k3);
u32 nsols = ctx->solve();
time1 = timestamp();
timems = (time1 - time0) / 1000000;
print_log("Time: %d ms\n", timems);
for (unsigned s = 0; s < nsols; s++) {
print_log("Solution");
u32* prf = &ctx->sols[s * PROOFSIZE];
for (u32 i = 0; i < PROOFSIZE; i++)
print_log(" %jx", (uintmax_t)prf[i]);
print_log("\n");
if (solutions != NULL){
solutions->edge_bits = EDGEBITS;
solutions->num_sols++;
solutions->sols[sumnsols+s].nonce = nonce + r;
for (u32 i = 0; i < PROOFSIZE; i++)
solutions->sols[sumnsols+s].proof[i] = (u64) prf[i];
}
int pow_rc = verify(prf, ctx->trimmer.sipkeys);
if (pow_rc == POW_OK) {
print_log("Verified with cyclehash ");
unsigned char cyclehash[32];
blake2b((void *)cyclehash, sizeof(cyclehash), (const void *)prf, sizeof(proof), 0, 0);
for (int i=0; i<32; i++)
print_log("%02x", cyclehash[i]);
print_log("\n");
} else {
print_log("FAILED due to %s\n", errstr[pow_rc]);
}
}
sumnsols += nsols;
if (stats != NULL) {
stats->last_start_time = time0;
stats->last_end_time = time1;
stats->last_solution_time = time1 - time0;
}
}
print_log("%d total solutions\n", sumnsols);
return sumnsols > 0;
}
CALL_CONVENTION SolverCtx* create_solver_ctx(SolverParams* params) {
trimparams tp;
tp.ntrims = params->ntrims;
tp.seed.blocks = params->genablocks;
tp.seed.tpb = params->genatpb;
tp.trim0.tpb = params->genbtpb;
tp.trim.tpb = params->trimtpb;
tp.tail.tpb = params->tailtpb;
tp.recover.blocks = params->recoverblocks;
tp.recover.tpb = params->recovertpb;
cudaDeviceProp prop;
checkCudaErrors_N(cudaGetDeviceProperties(&prop, params->device));
assert(tp.seed.tpb <= prop.maxThreadsPerBlock);
assert(tp.trim0.tpb <= prop.maxThreadsPerBlock);
assert(tp.trim.tpb <= prop.maxThreadsPerBlock);
// assert(tp.tailblocks <= prop.threadDims[0]);
assert(tp.tail.tpb <= prop.maxThreadsPerBlock);
assert(tp.recover.tpb <= prop.maxThreadsPerBlock);
cudaSetDevice(params->device);
if (!params->cpuload)
checkCudaErrors_N(cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync));
return new SolverCtx(tp, params->mutate_nonce);
}
CALL_CONVENTION void destroy_solver_ctx(SolverCtx* ctx) {
delete ctx;
}
CALL_CONVENTION void stop_solver(SolverCtx* ctx) {
ctx->abort();
}
CALL_CONVENTION void fill_default_params(SolverParams* params) {
trimparams tp;
params->device = 0;
params->ntrims = tp.ntrims;
params->genablocks = tp.seed.blocks;
params->genatpb = tp.seed.tpb;
params->genbtpb = tp.trim0.tpb;
params->trimtpb = tp.trim.tpb;
params->tailtpb = tp.tail.tpb;
params->recoverblocks = tp.recover.blocks;
params->recovertpb = tp.recover.tpb;
params->cpuload = false;
}
static_assert(NLISTS % (RELAY_TPB) == 0, "RELAY_TPB must be of NLISTS"); // for Tag_Edges lists init
static_assert(NZ % (32 * TRIM0_TPB) == 0, "TRIM0_TPB must be divisor of NZ/32"); // for Round_A1 ecounters init
static_assert(NZ % (32 * TRIM1_TPB) == 0, "TRIM1_TPB must be divisor of NZ/32"); // for Round_A3 ecounters init
static_assert(NZ % (32 * TRIM_TPB) == 0, "TRIM_TPB must be divisor of NZ/32"); // for Round_A2 ecounters init
int main(int argc, char **argv) {
trimparams tp;
u32 nonce = 0;
u32 range = 1;
u32 device = 0;
char header[HEADERLEN];
u32 len;
int c;
// set defaults
SolverParams params;
fill_default_params(¶ms);
memset(header, 0, sizeof(header));
while ((c = getopt(argc, argv, "scd:h:m:n:r:U:Z:z:")) != -1) {
switch (c) {
case 's':
print_log("SYNOPSIS\n cuda%d [-s] [-c] [-d device] [-h hexheader] [-m trims] [-n nonce] [-r range] [-U seedblocks] [-Z recoverblocks] [-z recoverthreads]\n", EDGEBITS);
print_log("DEFAULTS\n cuda%d -d %d -h \"\" -m %d -n %d -r %d -U %d -Z %d -z %d\n", EDGEBITS, device, tp.ntrims, nonce, range, tp.seed.blocks, tp.recover.blocks, tp.recover.tpb);
exit(0);
case 'c':
params.cpuload = false;
break;
case 'd':
device = params.device = atoi(optarg);
break;
case 'h':
len = strlen(optarg)/2;
assert(len <= sizeof(header));
for (u32 i=0; i<len; i++)
sscanf(optarg+2*i, "%2hhx", header+i); // hh specifies storage of a single byte
break;
case 'm': // ntrims = 458;
params.ntrims = atoi(optarg);
break;
case 'n':
nonce = atoi(optarg);
break;
case 'r':
range = atoi(optarg);
break;
case 'U': // seed.blocks = 1024;
params.genablocks = atoi(optarg);
break;
case 'Z': // recover.blocks = 2048;
params.recoverblocks = atoi(optarg);
break;
case 'z': // recover.tpb = 256;
params.recovertpb = atoi(optarg);
break;
}
}
int nDevices;
checkCudaErrors(cudaGetDeviceCount(&nDevices));
assert(device < nDevices);
cudaDeviceProp prop;
checkCudaErrors(cudaGetDeviceProperties(&prop, device));
u64 dbytes = prop.totalGlobalMem;
int dunit;
for (dunit=0; dbytes >= 102040; dbytes>>=10,dunit++) ;
print_log("%s with %d%cB @ %d bits x %dMHz\n", prop.name, (u32)dbytes, " KMGT"[dunit], prop.memoryBusWidth, prop.memoryClockRate/1000);
// cudaSetDevice(device);
print_log("Looking for %d-cycle on cuckaroom%d(\"%s\",%d", PROOFSIZE, EDGEBITS, header, nonce);
if (range > 1)
print_log("-%d", nonce+range-1);
print_log(") with 50%% edges, %d*%d buckets, %d trims, and %d thread blocks.\n", NX, NY, params.ntrims, NX);
assert(params.recovertpb >= PROOFSIZE);
SolverCtx* ctx = create_solver_ctx(¶ms);
u64 bytes = ctx->trimmer.globalbytes();
int unit;
for (unit=0; bytes >= 102400; bytes>>=10,unit++) ;
print_log("Using %d%cB of global memory.\n", (u32)bytes, " KMGT"[unit]);
run_solver(ctx, header, sizeof(header), nonce, range, NULL, NULL);
return 0;
}