forked from pscamillo/PSCKangaroo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGpuKang.cpp
More file actions
643 lines (571 loc) · 17.1 KB
/
Copy pathGpuKang.cpp
File metadata and controls
643 lines (571 loc) · 17.1 KB
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
// GpuKang.cpp
// This file is a part of RCKangaroo software
// (c) 2024, RetiredCoder (RC)
// License: GPLv3, see "LICENSE.TXT" file
// https://github.com/RetiredC
#include <iostream>
#include "cuda_runtime.h"
#include "cuda.h"
#include "GpuKang.h"
#include "TameStore.h"
cudaError_t cuSetGpuParams(TKparams Kparams, u64* _jmp2_table);
void CallGpuKernelGen(TKparams Kparams);
void CallGpuKernelABC(TKparams Kparams);
void AddPointsToList(u32* data, int cnt, u64 ops_cnt);
extern bool gGenMode; //tames generation mode
extern TameStore gTameStore;
int RCGpuKang::CalcKangCnt()
{
Kparams.BlockCnt = mpCnt;
Kparams.BlockSize = IsOldGpu ? 512 : 256;
// v45: GroupCnt = PNT_GROUP_CNT (compile-time constant)
if (IsOldGpu) {
Kparams.GroupCnt = 64;
} else {
Kparams.GroupCnt = V45_PNT_GROUP_CNT;
if (GroupCnt > 0 && GroupCnt != V45_PNT_GROUP_CNT) {
printf("Note: -groups %d is compile-time only. Using V45_PNT_GROUP_CNT=%d (defs.h).\n",
GroupCnt, V45_PNT_GROUP_CNT);
printf(" To find the optimal value for your GPU, run: scripts/bench_psck.sh\n");
}
}
return Kparams.BlockSize * Kparams.GroupCnt * Kparams.BlockCnt;
}
//executes in main thread
bool RCGpuKang::Prepare(EcPoint _PntToSolve, int _Range, int _DP, EcJMP* _EcJumps1, EcJMP* _EcJumps2, EcJMP* _EcJumps3)
{
PntToSolve = _PntToSolve;
Range = _Range;
DP = _DP;
EcJumps1 = _EcJumps1;
EcJumps2 = _EcJumps2;
EcJumps3 = _EcJumps3;
StopFlag = false;
Failed = false;
WaveNumber = 0; // Initialize wave counter for smart WILD generation
RndPnts = nullptr; // v38: Initialize to nullptr for ALL-WILD mode check
u64 total_mem = 0;
memset(dbg, 0, sizeof(dbg));
memset(SpeedStats, 0, sizeof(SpeedStats));
cur_stats_ind = 0;
cudaError_t err;
err = cudaSetDevice(CudaIndex);
if (err != cudaSuccess)
return false;
Kparams.BlockCnt = mpCnt; // Original
Kparams.BlockSize = IsOldGpu ? 512 : 256;
// v45: GroupCnt = V45_PNT_GROUP_CNT for maximum loop unrolling
Kparams.GroupCnt = IsOldGpu ? 64 : V45_PNT_GROUP_CNT;
KangCnt = Kparams.BlockSize * Kparams.GroupCnt * Kparams.BlockCnt;
Kparams.KangCnt = KangCnt;
Kparams.DP = DP;
Kparams.KernelA_LDS_Size = 64 * JMP_CNT + 16 * Kparams.BlockSize;
Kparams.KernelB_LDS_Size = 64 * JMP_CNT;
Kparams.KernelC_LDS_Size = 96 * JMP_CNT;
Kparams.IsGenMode = gGenMode;
Kparams.AllWildsMode = false; // Initialize to false, set true during HUNT
//allocate gpu mem
u64 size;
if (!IsOldGpu)
{
//L2
int L2size = Kparams.KangCnt * (3 * 32);
total_mem += L2size;
err = cudaMalloc((void**)&Kparams.L2, L2size);
if (err != cudaSuccess)
{
printf("GPU %d, Allocate L2 memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = L2size;
if (size > persistingL2CacheMaxSize)
size = persistingL2CacheMaxSize;
err = cudaDeviceSetLimit(cudaLimitPersistingL2CacheSize, size); // set max allowed size for L2
//persisting for L2
cudaStreamAttrValue stream_attribute;
stream_attribute.accessPolicyWindow.base_ptr = Kparams.L2;
stream_attribute.accessPolicyWindow.num_bytes = size;
stream_attribute.accessPolicyWindow.hitRatio = 1.0;
stream_attribute.accessPolicyWindow.hitProp = cudaAccessPropertyPersisting;
stream_attribute.accessPolicyWindow.missProp = cudaAccessPropertyStreaming;
err = cudaStreamSetAttribute(NULL, cudaStreamAttributeAccessPolicyWindow, &stream_attribute);
if (err != cudaSuccess)
{
printf("GPU %d, cudaStreamSetAttribute failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
}
size = MAX_DP_CNT * GPU_DP_SIZE + 16;
total_mem += size;
err = cudaMalloc((void**)&Kparams.DPs_out, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate GpuOut memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = KangCnt * 96;
total_mem += size;
err = cudaMalloc((void**)&Kparams.Kangs, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate pKangs memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
total_mem += JMP_CNT * 96;
err = cudaMalloc((void**)&Kparams.Jumps1, JMP_CNT * 96);
if (err != cudaSuccess)
{
printf("GPU %d Allocate Jumps1 memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
total_mem += JMP_CNT * 96;
err = cudaMalloc((void**)&Kparams.Jumps2, JMP_CNT * 96);
if (err != cudaSuccess)
{
printf("GPU %d Allocate Jumps1 memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
total_mem += JMP_CNT * 96;
err = cudaMalloc((void**)&Kparams.Jumps3, JMP_CNT * 96);
if (err != cudaSuccess)
{
printf("GPU %d Allocate Jumps3 memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = 2 * (u64)KangCnt * STEP_CNT;
total_mem += size;
err = cudaMalloc((void**)&Kparams.JumpsList, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate JumpsList memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = (u64)KangCnt * (16 * DPTABLE_MAX_CNT + sizeof(u32)); //we store 16bytes of X
total_mem += size;
err = cudaMalloc((void**)&Kparams.DPTable, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate DPTable memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = mpCnt * Kparams.BlockSize * sizeof(u64);
total_mem += size;
err = cudaMalloc((void**)&Kparams.L1S2, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate L1S2 memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = (u64)KangCnt * MD_LEN * (2 * 32);
total_mem += size;
err = cudaMalloc((void**)&Kparams.LastPnts, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate LastPnts memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = (u64)KangCnt * MD_LEN * sizeof(u64);
total_mem += size;
err = cudaMalloc((void**)&Kparams.LoopTable, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate LastPnts memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
total_mem += 1024;
err = cudaMalloc((void**)&Kparams.dbg_buf, 1024);
if (err != cudaSuccess)
{
printf("GPU %d Allocate dbg_buf memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
size = sizeof(u32) * KangCnt + 8;
total_mem += size;
err = cudaMalloc((void**)&Kparams.LoopedKangs, size);
if (err != cudaSuccess)
{
printf("GPU %d Allocate LoopedKangs memory failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
DPs_out = (u32*)malloc(MAX_DP_CNT * GPU_DP_SIZE);
//jmp1
u64* buf = (u64*)malloc(JMP_CNT * 96);
for (int i = 0; i < JMP_CNT; i++)
{
memcpy(buf + i * 12, EcJumps1[i].p.x.data, 32);
memcpy(buf + i * 12 + 4, EcJumps1[i].p.y.data, 32);
memcpy(buf + i * 12 + 8, EcJumps1[i].dist.data, 32);
}
err = cudaMemcpy(Kparams.Jumps1, buf, JMP_CNT * 96, cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("GPU %d, cudaMemcpy Jumps1 failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
free(buf);
//jmp2
buf = (u64*)malloc(JMP_CNT * 96);
u64* jmp2_table = (u64*)malloc(JMP_CNT * 64);
for (int i = 0; i < JMP_CNT; i++)
{
memcpy(buf + i * 12, EcJumps2[i].p.x.data, 32);
memcpy(jmp2_table + i * 8, EcJumps2[i].p.x.data, 32);
memcpy(buf + i * 12 + 4, EcJumps2[i].p.y.data, 32);
memcpy(jmp2_table + i * 8 + 4, EcJumps2[i].p.y.data, 32);
memcpy(buf + i * 12 + 8, EcJumps2[i].dist.data, 32);
}
err = cudaMemcpy(Kparams.Jumps2, buf, JMP_CNT * 96, cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("GPU %d, cudaMemcpy Jumps2 failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
free(buf);
err = cuSetGpuParams(Kparams, jmp2_table);
if (err != cudaSuccess)
{
free(jmp2_table);
printf("GPU %d, cuSetGpuParams failed: %s!\r\n", CudaIndex, cudaGetErrorString(err));
return false;
}
free(jmp2_table);
//jmp3
buf = (u64*)malloc(JMP_CNT * 96);
for (int i = 0; i < JMP_CNT; i++)
{
memcpy(buf + i * 12, EcJumps3[i].p.x.data, 32);
memcpy(buf + i * 12 + 4, EcJumps3[i].p.y.data, 32);
memcpy(buf + i * 12 + 8, EcJumps3[i].dist.data, 32);
}
err = cudaMemcpy(Kparams.Jumps3, buf, JMP_CNT * 96, cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("GPU %d, cudaMemcpy Jumps3 failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
free(buf);
printf("GPU %d: allocated %llu MB, %d kangaroos. OldGpuMode: %s\r\n", CudaIndex, total_mem / (1024 * 1024), KangCnt, IsOldGpu ? "Yes" : "No");
return true;
}
void RCGpuKang::Release()
{
free(RndPnts);
free(DPs_out);
cudaFree(Kparams.LoopedKangs);
cudaFree(Kparams.dbg_buf);
cudaFree(Kparams.LoopTable);
cudaFree(Kparams.LastPnts);
cudaFree(Kparams.L1S2);
cudaFree(Kparams.DPTable);
cudaFree(Kparams.JumpsList);
cudaFree(Kparams.Jumps3);
cudaFree(Kparams.Jumps2);
cudaFree(Kparams.Jumps1);
cudaFree(Kparams.Kangs);
cudaFree(Kparams.DPs_out);
if (!IsOldGpu)
cudaFree(Kparams.L2);
}
void RCGpuKang::Stop()
{
StopFlag = true;
}
void RCGpuKang::GenerateRndDistances()
{
for (int i = 0; i < KangCnt; i++)
{
EcInt d;
if (i < KangCnt / 3)
d.RndBits(Range - 4); //TAME kangs
else
{
d.RndBits(Range - 1);
d.data[0] &= 0xFFFFFFFFFFFFFFFE; //must be even
}
memcpy(RndPnts[i].priv, d.data, 24);
}
}
// Generate new random WILD positions for a new wave
// Uses fresh random positions each wave (proven to work!)
void RCGpuKang::GenerateSmartWildDistances()
{
// During HUNT phase, ALL kangaroos are WILDs
// Generate random distances in WILD range (Range-1 bits)
// FIXED v37: Previously 1/3 were incorrectly using Range-4 (TAME range)
for (int i = 0; i < KangCnt; i++)
{
EcInt d;
// ALL WILDs - use Range-1 bits for full coverage
d.RndBits(Range - 1);
d.data[0] &= 0xFFFFFFFFFFFFFFFE; // Must be even
memcpy(RndPnts[i].priv, d.data, 24);
}
}
bool RCGpuKang::Start()
{
if (Failed)
return false;
cudaError_t err;
err = cudaSetDevice(CudaIndex);
if (err != cudaSuccess)
return false;
HalfRange.Set(1);
HalfRange.ShiftLeft(Range - 1);
PntHalfRange = ec.MultiplyG(HalfRange);
NegPntHalfRange = PntHalfRange;
NegPntHalfRange.y.NegModP();
PntA = ec.AddPoints(PntToSolve, NegPntHalfRange);
PntB = PntA;
PntB.y.NegModP();
RndPnts = (TPointPriv*)malloc(KangCnt * 96);
GenerateRndDistances();
/*
//we can calc start points on CPU
for (int i = 0; i < KangCnt; i++)
{
EcInt d;
memcpy(d.data, RndPnts[i].priv, 24);
d.data[3] = 0;
d.data[4] = 0;
EcPoint p = ec.MultiplyG(d);
memcpy(RndPnts[i].x, p.x.data, 32);
memcpy(RndPnts[i].y, p.y.data, 32);
}
for (int i = KangCnt / 3; i < 2 * KangCnt / 3; i++)
{
EcPoint p;
p.LoadFromBuffer64((u8*)RndPnts[i].x);
p = ec.AddPoints(p, PntA);
p.SaveToBuffer64((u8*)RndPnts[i].x);
}
for (int i = 2 * KangCnt / 3; i < KangCnt; i++)
{
EcPoint p;
p.LoadFromBuffer64((u8*)RndPnts[i].x);
p = ec.AddPoints(p, PntB);
p.SaveToBuffer64((u8*)RndPnts[i].x);
}
//copy to gpu
err = cudaMemcpy(Kparams.Kangs, RndPnts, KangCnt * 96, cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("GPU %d, cudaMemcpy failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
/**/
//but it's faster to calc then on GPU
u8 buf_PntA[64], buf_PntB[64];
PntA.SaveToBuffer64(buf_PntA);
PntB.SaveToBuffer64(buf_PntB);
for (int i = 0; i < KangCnt; i++)
{
if (i < KangCnt / 3)
memset(RndPnts[i].x, 0, 64);
else
if (i < 2 * KangCnt / 3)
memcpy(RndPnts[i].x, buf_PntA, 64);
else
memcpy(RndPnts[i].x, buf_PntB, 64);
}
//copy to gpu
err = cudaMemcpy(Kparams.Kangs, RndPnts, KangCnt * 96, cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("GPU %d, cudaMemcpy failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
CallGpuKernelGen(Kparams);
err = cudaMemset(Kparams.L1S2, 0, mpCnt * Kparams.BlockSize * 8);
if (err != cudaSuccess)
return false;
cudaMemset(Kparams.dbg_buf, 0, 1024);
cudaMemset(Kparams.LoopTable, 0, KangCnt * MD_LEN * sizeof(u64));
return true;
}
#ifdef DEBUG_MODE
int RCGpuKang::Dbg_CheckKangs()
{
int kang_size = mpCnt * Kparams.BlockSize * Kparams.GroupCnt * 96;
u64* kangs = (u64*)malloc(kang_size);
cudaError_t err = cudaMemcpy(kangs, Kparams.Kangs, kang_size, cudaMemcpyDeviceToHost);
int res = 0;
for (int i = 0; i < KangCnt; i++)
{
EcPoint Pnt, p;
Pnt.LoadFromBuffer64((u8*)&kangs[i * 12 + 0]);
EcInt dist;
dist.Set(0);
memcpy(dist.data, &kangs[i * 12 + 8], 24);
bool neg = false;
if (dist.data[2] >> 63)
{
neg = true;
memset(((u8*)dist.data) + 24, 0xFF, 16);
dist.Neg();
}
p = ec.MultiplyG_Fast(dist);
if (neg)
p.y.NegModP();
if (i < KangCnt / 3)
p = p;
else
if (i < 2 * KangCnt / 3)
p = ec.AddPoints(PntA, p);
else
p = ec.AddPoints(PntB, p);
if (!p.IsEqual(Pnt))
res++;
}
free(kangs);
return res;
}
#endif
extern u32 gTotalErrors;
//executes in separate thread
void RCGpuKang::Execute()
{
cudaSetDevice(CudaIndex);
if (!Start())
{
gTotalErrors++;
return;
}
#ifdef DEBUG_MODE
u64 iter = 1;
#endif
cudaError_t err;
while (!StopFlag)
{
u64 t1 = GetTickCount64();
cudaMemset(Kparams.DPs_out, 0, 4);
cudaMemset(Kparams.DPTable, 0, KangCnt * sizeof(u32));
cudaMemset(Kparams.LoopedKangs, 0, 8);
CallGpuKernelABC(Kparams);
int cnt;
err = cudaMemcpy(&cnt, Kparams.DPs_out, 4, cudaMemcpyDeviceToHost);
if (err != cudaSuccess)
{
printf("GPU %d, CallGpuKernel failed: %s\r\n", CudaIndex, cudaGetErrorString(err));
gTotalErrors++;
break;
}
if (cnt >= MAX_DP_CNT)
{
cnt = MAX_DP_CNT;
printf("GPU %d, gpu DP buffer overflow, some points lost, increase DP value!\r\n", CudaIndex);
}
u64 pnt_cnt = (u64)KangCnt * STEP_CNT;
if (cnt)
{
err = cudaMemcpy(DPs_out, Kparams.DPs_out + 4, cnt * GPU_DP_SIZE, cudaMemcpyDeviceToHost);
if (err != cudaSuccess)
{
gTotalErrors++;
break;
}
AddPointsToList(DPs_out, cnt, (u64)KangCnt * STEP_CNT);
}
//dbg
cudaMemcpy(dbg, Kparams.dbg_buf, 1024, cudaMemcpyDeviceToHost);
u32 lcnt;
cudaMemcpy(&lcnt, Kparams.LoopedKangs, 4, cudaMemcpyDeviceToHost);
//printf("GPU %d, Looped: %d\r\n", CudaIndex, lcnt);
u64 t2 = GetTickCount64();
u64 tm = t2 - t1;
if (!tm)
tm = 1;
int cur_speed = (int)(pnt_cnt / (tm * 1000));
//printf("GPU %d kernel time %d ms, speed %d MH\r\n", CudaIndex, (int)tm, cur_speed);
SpeedStats[cur_stats_ind] = cur_speed;
cur_stats_ind = (cur_stats_ind + 1) % STATS_WND_SIZE;
#ifdef DEBUG_MODE
if ((iter % 300) == 0)
{
int corr_cnt = Dbg_CheckKangs();
if (corr_cnt)
{
printf("DBG: GPU %d, KANGS CORRUPTED: %d\r\n", CudaIndex, corr_cnt);
gTotalErrors++;
}
else
printf("DBG: GPU %d, ALL KANGS OK!\r\n", CudaIndex);
}
iter++;
#endif
}
Release();
}
int RCGpuKang::GetStatsSpeed()
{
int res = SpeedStats[0];
for (int i = 1; i < STATS_WND_SIZE; i++)
res += SpeedStats[i];
return res / STATS_WND_SIZE;
}
void RCGpuKang::SetGenMode(bool mode)
{
Kparams.IsGenMode = mode;
}
bool RCGpuKang::ReinitForHunt()
{
// Reinitialize kangaroos for HUNT phase with ALL WILDs optimization
// 100% of kangaroos will be WILDs (50% more effective than 66%)
cudaError_t err;
err = cudaSetDevice(CudaIndex);
if (err != cudaSuccess)
return false;
// v38: If called before Start() (ALL-WILD mode), initialize required variables
if (RndPnts == nullptr) {
// Allocate host memory for kangaroo data
RndPnts = (TPointPriv*)malloc(KangCnt * 96);
if (!RndPnts) {
printf("GPU %d: Failed to allocate RndPnts in ReinitForHunt\n", CudaIndex);
return false;
}
// Initialize PntA and PntB (WILD start points)
HalfRange.Set(1);
HalfRange.ShiftLeft(Range - 1);
PntHalfRange = ec.MultiplyG(HalfRange);
NegPntHalfRange = PntHalfRange;
NegPntHalfRange.y.NegModP();
PntA = ec.AddPoints(PntToSolve, NegPntHalfRange); // PubKey - HalfRange*G
PntB = PntA;
PntB.y.NegModP(); // PubKey + HalfRange*G
}
// Set mode to HUNT with ALL WILDs
Kparams.IsGenMode = false;
Kparams.AllWildsMode = true; // CRITICAL: Enable 100% WILDs mode!
// Increment wave number for tracking
WaveNumber++;
// Generate distances for ALL kangaroos
GenerateSmartWildDistances();
// Prepare PntA/PntB offset for ALL kangaroos (not just 2/3)
u8 buf_PntA[64], buf_PntB[64];
PntA.SaveToBuffer64(buf_PntA);
PntB.SaveToBuffer64(buf_PntB);
// ALL kangaroos get PntA or PntB based on parity
// v52 FIX: Must match GPU's BuildDP: kang_type = 1 + (kang_ind & 1)
// GPU: Even → WILD1 (type=1), Odd → WILD2 (type=2)
// CPU: Even → PntA (WILD1 start), Odd → PntB (WILD2 start)
for (int i = 0; i < KangCnt; i++)
{
if (i & 1)
memcpy(RndPnts[i].x, buf_PntB, 64); // Odd indices: WILD2 (PntB)
else
memcpy(RndPnts[i].x, buf_PntA, 64); // Even indices: WILD1 (PntA)
}
// Copy to GPU
err = cudaMemcpy(Kparams.Kangs, RndPnts, KangCnt * 96, cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
printf("GPU %d, ReinitForHunt cudaMemcpy failed: %s\n", CudaIndex, cudaGetErrorString(err));
return false;
}
// Regenerate kangaroos - ALL will have PubKey offset now!
CallGpuKernelGen(Kparams);
// Reset DP table and loop detection
cudaMemset(Kparams.DPTable, 0, KangCnt * sizeof(u32));
cudaMemset(Kparams.LoopTable, 0, KangCnt * MD_LEN * sizeof(u64));
cudaMemset(Kparams.LoopedKangs, 0, 8);
return true;
}