-
Notifications
You must be signed in to change notification settings - Fork 10
/
Etarkangaroo3_2_4.pb
11913 lines (11193 loc) · 867 KB
/
Etarkangaroo3_2_4.pb
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
EnableExplicit
IncludeFile "lib\Curve64.pb"
CompilerIf #PB_Compiler_Unicode
Debug" switch to Ascii mode"
End
CompilerEndIf
CompilerIf Not #PB_Compiler_Processor = #PB_Processor_x64
Debug" only x64 processor support"
End
CompilerEndIf
;Do not change this constants
#MB=1048576
#GB=1073741824
#array_dim=64
#line_dim=64
#alignMemoryGpu=256
#LOGFILE=1
#appver="Etarkangaroo3_2_4"
#HEADERSIZE=172
#HEAD="FA6A8002"
#File=777
#File1=778
#File2=779
#FileT=780
#FILEKANG=781
#FILEWIN=782
#FileCheck=783
#TAME =0
#WILD =1
#GPU_GRP_SIZE =128 ; GPU_GRP_SIZE do not change 128
#NumberOfTable=32; NB_JUMP do not change 32
#align_size=128
#HashTablesz=4
#Pointersz=8
#HashTableSizeHash = 8
#HashTableSizeItems = 40
#maximumgpucount = 32
Structure JobSturucture
*arr
*NewPointsArr
beginrangeX$
beginrangeY$
totalpoints.i
pointsperbatch.i
isAlive.i
isError.i
Yoffset.i
beginNumberPoint.i
EndStructure
Structure sortjobStructure
*ptarr
*sortptarray
totallines.i
curpos.i
EndStructure
Structure comparsationStructure
pos.i
direction.i
EndStructure
Structure retTBIStructure
blockIdx.i
threadIdx.i
paramid.i
EndStructure
Structure gpustructure
threadtotal.i
blocktotal.i
hashrate.q
*kangarooArray
isStop.i
Kangaroosaveflag.i
*LastDPArr
*TEMPLastDPArr
List problemsList.i()
resetProblemKangaroo.i
arch.i
EndStructure
Structure mergestructure
filename1$
filename2$
filenameTarget$
EndStructure
Structure CollideStructure
pos1.i
hashhex1.s
distancehex1.s
pos2.i
hashhex2.s
distancehex2.s
EndStructure
Structure SettingsStructure
outputfile$
htfilename$
kangaroofilename$
Defdevice$
Defgrid$
SaveTimeS.i
isSavekangaroo.i
isSaveht.i
isSaveSplit.i
isMerge.i
isMergeFile.i
isLoadkangaroo.i
mergefilename1$
mergefilename2$
mergefilenameT$
rb$
re$
pubcompressed$
pubUncompressed$
DPsize.i
HT_POW.l
totalkangaroo.i
FingerPrint$
maxM.f
EndStructure
Structure HashTableResultStructure
size.l
*contentpointer
EndStructure
Structure CoordPoint
*x
*y
EndStructure
Structure checkerStructure
winset.i
gpuid.i
*ptr
EndStructure
Import "lib\cuda.lib"
cuInit(Flags.i)
cuMemGetInfo_v2(freebytes.i,totalbytes.i)
cuEventCreate(phEvent.i,Flags.i)
cuEventDestroy (hEvent.i)
cuEventQuery (hEvent.i)
cuEventRecord (hEvent.i,Stream.i)
cuEventSynchronize (hEvent.i)
cuDeviceTotalMem(bytes.i,dev.i)
cuDeviceTotalMem_v2(bytes.i,dev.i)
cuDeviceComputeCapability(major.i,minor.i,dev.i)
cuDeviceGetCount(count.i)
cuDeviceGetName(name.s,len.i,dev.i)
cuDeviceGetAttribute(pi.i,attrib.i,dev.i)
cuDeviceGet(device.i, ordinal.i)
cuGetErrorName ( err.i, err_string.s )
cuCtxCreate(pctx.i, flags.i, dev.i)
cuCtxCreate_v2(pctx.i, flags.i, dev.i)
cuMemAlloc(dptr.i, bytesize.i)
cuMemAlloc_v2(dptr.i, bytesize.i)
cuModuleGetGlobal (dptr.i, bytesize.i,hmodule.i,name.i)
cuModuleGetGlobal_v2 (dptr.i, bytesize.i,hmodule.i,name.i)
cuModuleLoadData(hmodule.i, image.i)
cuModuleLoad(hmodule.i, fname.i)
cuModuleGetFunction(hfunc.i, hmod.i, name.s)
cuParamSetSize(hfunc.i, numbytes.i)
cuParamSetv(hfunc.i, offset.i, ptr.i, numbytes.i)
cuParamSeti(hfunc.i, offset.i, value.i)
cuFuncSetBlockShape(hfunc.i, x.i, y.i, z.i)
cuLaunchGridAsync( hfunc.i, x.i, y.i, z.i,hstream.i)
cuLaunchGrid(f.i, grid_width.i, grid_height.i)
cuFuncSetSharedSize(f.i,numbytes.i)
cuFuncSetCacheConfig ( f.i,config.i)
cuLaunch(f.i)
cuFuncGetAttribute (pi.i,attrib.i,f.i)
cuStreamCreate (hStream.i, Flags.i)
cuStreamCreate_v2 (hStream.i, Flags.i)
cuStreamDestroy (hStream.i)
cuStreamSynchronize (hStream)
cuStreamQuery (hStream.i)
cuCtxSynchronize()
cuMemcpyDtoH(dstHost.i, srcDevice.i, ByteCount.i)
cuMemcpyDtoH_v2(dstHost.i, srcDevice.i, ByteCount.i)
cuMemcpyHtoD(dstDevice.i, srcHost.i, ByteCount.i)
cuMemcpyHtoD_v2(dstDevice.i, srcHost.i, ByteCount.i)
cuMemFree(dptr.i)
cuMemFree_v2(dptr.i)
cuCtxDestroy(ctx.i)
cuCtxDestroy_v2(ctx.i)
cuDriverGetVersion (driverVersion.i)
cuFuncSetSharedMemConfig(hfunc.i, config.i)
cuCtxSetSharedMemConfig (config.i)
EndImport
Global Dim cudafuncatrib$(7)
cudafuncatrib$(0)="MAX_THREADS_PER_BLOCK "
cudafuncatrib$(1)="SHARED_SIZE_BYTES "
cudafuncatrib$(2)="CONST_SIZE_BYTES "
cudafuncatrib$(3)="LOCAL_SIZE_BYTES "
cudafuncatrib$(4)="NUM_REGS "
cudafuncatrib$(5)="PTX_VERSION "
cudafuncatrib$(6)="BINARY_VERSION"
Define *CurveP, *CurveGX, *CurveGY, *Curveqn
*CurveP = Curve::m_getCurveValues()
*CurveGX = *CurveP+32
*CurveGY = *CurveP+64
*Curveqn = *CurveP+96
Define NewMap gpu.gpustructure(), NewMap gpulocal.gpustructure()
Define NewMap job.JobSturucture(), thr_quit= #False
Define BitRange, Ntable, Nthreads, NKangaroo, KangarooHerds
Define TableMutex, keyMutex, calcMutex, checkrMutex
Define HT_mask, HT_items=0, HT_total_hashes=0, HT_items_with_collisions=0, HT_max_collisions=0, HT_total_items=0, initHTsize=1, DPmask
Define *Table_unalign, *Table, *PointerTable_unalign, *PointerTable
Define *a, *b, *c, *high, *RangeB, *RangeE, *ShiftedRangeB, *ShiftedRangeE, *JpTable, *DistTable, *KangArrayHelp, *KangArrayDist, *PubshiftedRangeE_X, *PubshiftedRangeE_Y, *PubshiftedRangeE_Y_neg, *ShiftedRangeEhalf
Define *FindPub_X, *FindPub_Y, *ShiftedFindPub_X, *ShiftedFindPub_Y, *PubRangeB_X, *PubRangeB_Y, *PubRangeB_Y_neg, *help_X, *help_Y, *help_Y_neg, *ZeroShiftedFindPub_X, *ZeroShiftedFindPub_Y
Define *randomPRKeytest, *counterBig, *counterBigTemp, *tempor, *hashreminder, *hashbatch, *sBatch
Define *JpTable_unalign, *DistTable_unalign, *KangArrayHelp_unalign, *KangArrayDist_unalign
Define a$, b$, c$, Time1
Define *One, SETTINGS.SettingsStructure
Define *ShiftedRangeB, *ShiftedRangeE, *JpTable_unalign, *JpTable, *DistTable_unalign, *DistTable, Ntable, *PubRangeE_X, PubRangeE_Y, *PubRangeE_Y_neg, BitRange
Define *GTable, isruning=0, isreadyjob=0, warningmessage, *KangarooArrPacked_unalign, *KangarooArrPacked, mergeFlag
Define handle.i, *LastDPdistanceArr_unalign, *LastDPdistanceArr, *TEMPLastDPdistanceArr, *problemArrDist, problemsz, *expophex, *hightest
Define HT_dead
Define HT_date
Define HT_items
Define HT_mask
Define HT_total_items = 0
Define HT_max_collisions = 0
Define HT_items_with_collisions = 0
Define HT_total_hashes = 0
Define initHTsize=1
Define expop.d
Define driverVersion.i, NewList checker.checkerStructure()
checkrMutex = CreateMutex()
TableMutex = CreateMutex()
keyMutex = CreateMutex()
calcMutex = CreateMutex()
;-Default settings
#MaxItemsSave = 65536
#NumberOfRun = 1024
SETTINGS\DPsize = 16
SETTINGS\HT_POW = 25
SETTINGS\SaveTimeS = 600
SETTINGS\Defdevice$="0"
SETTINGS\Defgrid$=""
SETTINGS\htfilename$=""
SETTINGS\kangaroofilename$=""
SETTINGS\outputfile$=""
SETTINGS\Defdevice$=""
SETTINGS\Defgrid$=""
SETTINGS\maxM = 0
;optimal grid size
;GTX 1660s 88,128 ~880Mkeys/s
;RTX 3070 92,256 ~1535Mkeys/s
;puzzle #64
;SETTINGS\rb$ = "8000000000000000"
;SETTINGS\re$ = "ffffffffffffffff"
;SETTINGS\pubcompressed$ = "03100611c54dfef604163b8358f7b7fac13ce478e02cb224ae16d45526b25d9d4d"
;puzzle #70
;SETTINGS\rb$ = "200000000000000000"
;SETTINGS\re$ = "3fffffffffffffffff"
;SETTINGS\pubcompressed$ = "0290e6900a58d33393bc1097b5aed31f2e4e7cbd3e5466af958665bc0121248483"
;puzzle #75
;SETTINGS\rb$ = "4000000000000000000"
;SETTINGS\re$ = "7ffffffffffffffffff"
;SETTINGS\pubcompressed$ = "03726b574f193e374686d8e12bc6e4142adeb06770e0a2856f5e4ad89f66044755"
;puzzle #80
;SETTINGS\rb$ = "80000000000000000000"
;SETTINGS\re$ = "ffffffffffffffffffff"
;SETTINGS\pubcompressed$ = "037e1238f7b1ce757df94faa9a2eb261bf0aeb9f84dbf81212104e78931c2a19dc"
;puzzle #85
;SETTINGS\rb$ = "1000000000000000000000"
;SETTINGS\re$ = "1fffffffffffffffffffff"
;SETTINGS\pubcompressed$ = "0329c4574a4fd8c810b7e42a4b398882b381bcd85e40c6883712912d167c83e73a"
;puzzle #90
;SETTINGS\rb$ = "20000000000000000000000"
;SETTINGS\re$ = "3ffffffffffffffffffffff"
;SETTINGS\pubcompressed$ = "035c38bd9ae4b10e8a250857006f3cfd98ab15a6196d9f4dfd25bc7ecc77d788d5"
;puzzle #125
;SETTINGS\rb$ = "10000000000000000000000000000000"
;SETTINGS\re$ = "1fffffffffffffffffffffffffffffff"
;SETTINGS\pubcompressed$ = "0233709eb11e0d4439a729f21c2c443dedb727528229713f0065721ba8fa46f00e "
;puzzle #130 ( 1Fo65aKq8s8iquMt6weF1rku1moWVEd5Ua )
;SETTINGS\rb$ = "200000000000000000000000000000000"
;SETTINGS\re$ = "3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
;SETTINGS\pubcompressed$ = "03633CBE3EC02B9401C5EFFA144C5B4D22F87940259634858FC7E59B1C09937852"
Declare exit(str.s)
Declare Log2(Quad.q)
Declare HashTableInsert(*hash, *distance, identify)
Declare calculateBitRange(*rb, *re)
Declare randomInRange(*res,*rb, *re)
Declare getprogparam()
OpenConsole()
handle = GetStdHandle_(#STD_OUTPUT_HANDLE)
SetConsoleMode_(handle, 5)
getprogparam()
Macro move16b_1(offset_target_s,offset_target_d)
!movdqa xmm0,[rdx++offset_target_s]
!movdqa [rcx+offset_target_d],xmm0
EndMacro
Macro move32b_(s,d,offset_target_s,offset_target_d)
!mov rdx, [s]
!mov rcx, [d]
move16b_1(0+offset_target_s,0+offset_target_d)
move16b_1(16+offset_target_s,16+offset_target_d)
EndMacro
Procedure toLittleInd32(*a)
!mov rsi,[p.p_a]
!mov eax,[rsi]
!mov ecx,[rsi+4]
!bswap eax
!mov [rsi],eax
!bswap ecx
!mov [rsi+4],ecx
EndProcedure
Procedure toLittleInd32_64(*a)
!mov rsi,[p.p_a]
!mov eax,[rsi]
!mov ecx,[rsi+4]
!bswap eax
!mov [rsi+4],eax
!bswap ecx
!mov [rsi],ecx
EndProcedure
Procedure.s commpressed2uncomressedPub(ha$)
Protected y_parity, ruc$, x$, a$, *a, *res
Shared *CurveP
*a = AllocateMemory(64)
*res=*a + 32
y_parity = Val(Left(ha$,2))-2
x$ = Right(ha$,Len(ha$)-2)
a$=RSet(x$, 64,"0")
Curve::m_sethex32(*a, @a$)
Curve::m_YfromX64(*res,*a, *CurveP)
If PeekB(*res)&1<>y_parity
Curve::m_subModX64(*res,*CurveP,*res,*CurveP)
EndIf
ruc$ = Curve::m_gethex32(*res)
FreeMemory(*a)
ProcedureReturn x$+ruc$
EndProcedure
Procedure.s uncomressed2commpressedPub(ha$)
Protected Str1.s, Str2.s, x$,y$,ru$,rc$
ha$=LCase(ha$)
If Left(ha$,2)="04" And Len(ha$)=130
ha$=Right(ha$,Len(ha$)-2)
EndIf
Str1=Left(ha$,64)
Str2=Right(ha$,64)
Debug Str1
Debug Str2
x$=PeekS(@Str1,-1,#PB_Ascii)
x$=RSet(x$,64,"0")
y$=PeekS(@Str2,-1,#PB_Ascii)
y$=RSet(y$,64,"0")
ru$="04"+x$+y$
If FindString("13579bdf",Right(y$,1))>0
rc$="03"+x$
Else
rc$="02"+x$
EndIf
ProcedureReturn rc$
EndProcedure
Procedure Log2(Quad.q)
Protected Result
While Quad <> 0
Result + 1
Quad>>1
Wend
ProcedureReturn Result-1
EndProcedure
Procedure ValueL(*a)
!mov rbx,[p.p_a]
!mov eax,[rbx]
ProcedureReturn
EndProcedure
Procedure ValuePokeL(*a,vl)
!mov rbx,[p.p_a]
!mov eax,[p.v_vl]
!mov [rbx],eax
EndProcedure
Procedure INCvalue32(*a)
!mov rsi,[p.p_a]
!mov eax,[rsi]
!inc eax
!mov [rsi],eax
EndProcedure
Procedure swap8(*a)
!mov rsi,[p.p_a]
!mov eax,[rsi]
!mov ecx,[rsi+4]
!mov [rsi+4],eax
!mov [rsi],ecx
EndProcedure
Procedure swap32(*a)
!mov rsi,[p.p_a]
!mov eax,[rsi+24]
!mov ecx,[rsi+4]
!mov [rsi+4],eax
!mov [rsi+24],ecx
!mov eax,[rsi+28]
!mov ecx,[rsi]
!mov [rsi],eax
!mov [rsi+28],ecx
!mov eax,[rsi+20]
!mov ecx,[rsi+8]
!mov [rsi+8],eax
!mov [rsi+20],ecx
!mov eax,[rsi+16]
!mov ecx,[rsi+12]
!mov [rsi+12],eax
!mov [rsi+16],ecx
EndProcedure
Procedure m_check_less_more_equilX8(*s,*t); 0 - s = t, 1- s < t, 2- s > t
!mov rsi,[p.p_s]
!mov rdi,[p.p_t]
!xor cx,cx
!llm_check_less_continueQ:
!mov rax,[rsi]
!mov rbx,[rdi]
!cmp rax,rbx
!jb llm_check_less_exit_lessQ
!ja llm_check_less_exit_moreQ
!xor rax,rax
!jmp llm_check_less_exitQ
!llm_check_less_exit_moreQ:
!mov rax,2
!jmp llm_check_less_exitQ
!llm_check_less_exit_lessQ:
!mov rax,1
!llm_check_less_exitQ:
ProcedureReturn
EndProcedure
Procedure check_equil(*s,*t,len=8)
!mov rsi,[p.p_s]
!mov rdi,[p.p_t]
!xor cx,cx
!ll_check_equil_continue:
!mov eax,[rsi]
!mov ebx,[rdi]
!add rsi,4
!add rdi,4
!bswap eax
!bswap ebx
!cmp eax,ebx
!jne ll_check_equil_exit_noteqil
!inc cx
!cmp cx,[p.v_len]
!jb ll_check_equil_continue
!mov eax,1
!jmp ll_check_equil_exit
!ll_check_equil_exit_noteqil:
!mov eax,0
!ll_check_equil_exit:
ProcedureReturn
EndProcedure
Procedure div8(*s,n,*q,*r);8 byte / n> *q, *r
!mov rsi,[p.p_s]
!xor rdx,rdx
!mov rax,[rsi]
!mov rbx,[p.v_n]
!div rbx
!mov rsi,[p.p_r]
!mov [rsi],rdx
!mov rsi,[p.p_q]
!mov [rsi],rax
ProcedureReturn
EndProcedure
Procedure sub8(*a,*b,*c);8 byte a-b> c
!mov rsi,[p.p_a]
!mov rax,[rsi]
!mov rdi,[p.p_b]
!sub rax,[rdi]
!mov rsi,[p.p_c]
!mov [rsi],rax
ProcedureReturn
EndProcedure
Procedure add8(*a,*b,*c);8 byte a+b> c
!mov rsi,[p.p_a]
!mov rax,[rsi]
!mov rdi,[p.p_b]
!add rax,[rdi]
!mov rsi,[p.p_c]
!mov [rsi],rax
ProcedureReturn
EndProcedure
Procedure add8ui(*a,n,*c);8 byte a+b> c
!mov rsi,[p.p_a]
!mov rax,[rsi]
!add rax,[p.v_n]
!mov rsi,[p.p_c]
!mov [rsi],rax
ProcedureReturn
EndProcedure
Procedure mul8ui(*s,n,*q);8 byte * n
!mov rsi,[p.p_s]
!mov rax,[rsi]
!mov rbx,[p.v_n]
!mul rbx
!mov rsi,[p.p_q]
!mov [rsi],rax
ProcedureReturn
EndProcedure
Procedure.s m_gethex8(*bin)
Protected *sertemp=AllocateMemory(16, #PB_Memory_NoClear)
Protected res$
;************************************************************************
;Convert bytes in LITTLE indian format to HEX string in BIG indian format
;************************************************************************
Curve::m_serializeX64(*bin,0,*sertemp,2)
res$=PeekS(*sertemp,16, #PB_Ascii)
FreeMemory(*sertemp)
ProcedureReturn res$
EndProcedure
Procedure deserialize(*a,b,*sptr,counter=32);fron hex
Protected *ptr
*ptr=*a+64*b
!mov rbx,[p.p_ptr] ;ebx > rbx
!mov rdi,[p.p_sptr] ;edi > rdi
!xor cx,cx
!ll_MyLabelf:
!push cx
!mov eax,[rdi]
!mov ecx,eax
!xor edx,edx
!sub al,48
!cmp al,15
!jb ll_MyLabelf1
!sub al,7
!ll_MyLabelf1:
!and al,15 ;1
!or dl,al
!rol edx,4
!ror ecx,8
!mov al,cl
!sub al,48
!cmp al,15
!jb ll_MyLabelf2
!sub al,7
!ll_MyLabelf2:
!and al,15 ;2
!or dl,al
!rol edx,4
!ror ecx,8
!mov al,cl
!sub al,48
!cmp al,15
!jb ll_MyLabelf3
!sub al,7
!ll_MyLabelf3:
!and al,15 ;3
!or dl,al
!rol edx,4
!ror ecx,8
!mov al,cl
!sub al,48
!cmp al,15
!jb ll_MyLabelf4
!sub al,7
!ll_MyLabelf4:
!and al,15 ;4
!or dl,al
!ror dx,8
!mov [rbx],dx
!add rdi,4
!add rbx,2
!pop cx
!inc cx
!cmp cx,[p.v_counter]
!jb ll_MyLabelf
EndProcedure
Procedure serialize(*a,b,*sptr,counter=32);>hex
Protected *ptr
*ptr=*a+#array_dim*b
!mov rbx,[p.p_ptr] ;ebx > rbx
!mov rdi,[p.p_sptr] ;edi > rdi
!xor cx,cx
!ll_MyLabel:
!push cx
!mov ax,[rbx]
!xor edx,edx
!mov cx,ax
!and ax,0fh
!cmp al,10 ;1
!jb ll_MyLabel1
!add al,39
!ll_MyLabel1:
!add al,48
!or dx,ax
!shl edx,8
!ror cx,4
!mov ax,cx
!and ax,0fh
!cmp al,10 ;2
!jb ll_MyLabel2
!add al,39
!ll_MyLabel2:
!add al,48
!or dx,ax
!shl edx,8
!ror cx,4
!mov ax,cx
!and ax,0fh
!cmp al,10 ;3
!jb ll_MyLabel3
!add al,39
!ll_MyLabel3:
!add al,48
!or dx,ax
!shl edx,8
!ror cx,4
!mov ax,cx
!and ax,0fh
!cmp al,10 ;4
!jb ll_MyLabel4
!add al,39
!ll_MyLabel4:
!add al,48
!or dx,ax
!ror edx,16
!mov [rdi],edx
!add rdi,4
!add rbx,2
!pop cx
!inc cx
!cmp cx,[p.v_counter]; words
!jb ll_MyLabel
EndProcedure
Procedure exit(a$)
CloseCryptRandom()
PrintN(a$)
If a$<>""
Input()
EndIf
CloseConsole()
End
EndProcedure
Procedure retGPUcount(i, griddim=0, threaddim=0)
Protected namedev.s=Space(128)
Protected sizebytes.i
Protected piattrib.i
Protected major.i
Protected minor.i
Protected count.i
Protected mp.i
Protected cores.i
Protected pi.i
Protected result.i
Protected CudaDevice.i
Protected freebytes.i
Protected totalbytes.i
Protected CudaContext.i
Shared gpu()
result = cuDeviceGet(@CudaDevice, i)
If result
exit("cuDeviceGet - "+Str(result)+#CRLF$+"Try change -d param")
EndIf
result = cuDeviceGetName(namedev,128,CudaDevice)
If result
exit("cuDeviceGetName - "+Str(result))
EndIf
result = cuDeviceTotalMem_v2(@sizebytes,CudaDevice)
If result
exit("cuDeviceTotalMem - "+Str(result))
EndIf
result = cuCtxCreate_v2(@CudaContext, 4, CudaDevice) ; CU_CTX_BLOCKING_SYNC = 4 -- cuCtxSynchronize()
If result
exit("cuCtxCreate - "+Str(result))
EndIf
result=cuMemGetInfo_v2 (@freebytes,@totalbytes)
If result
exit("error cuMemGetInfo_v2-"+Str(result))
EndIf
cuCtxDestroy_v2(CudaContext)
cuDeviceComputeCapability(@major,@minor,CudaDevice)
cuDeviceGetAttribute(@piattrib,16,CudaDevice)
mp=piattrib
Select major
Case 2 ;Fermi
Debug "Fermi"
If minor=1
cores = mp * 48
Else
cores = mp * 32
EndIf
Case 3; Kepler
Debug "Kepler"
cores = mp * 192
Case 5; Maxwell
Debug "Maxwell"
cores = mp * 128
Case 6; Pascal
Debug "Pascal"
cores = mp * 64
Case 7; Pascal
Debug "Pascal RTX"
cores = mp * 64
Case 8; Ampere
Debug "Ampere RTX"
cores = mp * 128
Default
Debug "Unknown device type"
cores = mp * 128
EndSelect
;PrintN("arch:"+major+minor)
;PrintN("Device have: MP:"+mp+" Cores+"+cores)
gpu(Str(i))\arch = Val(Str(major)+Str(minor))
If griddim=0
gpu(Str(i))\blocktotal = mp * 2
Else
gpu(Str(i))\blocktotal = griddim
EndIf
If threaddim=0
gpu(Str(i))\threadtotal = cores/mp *2
Else
gpu(Str(i))\threadtotal = threaddim
EndIf
PrintN("GPU #"+Str(i)+" "+namedev+" (ARCH"+Str(major)+Str(minor)+") ("+StrD(freebytes/1048576,3)+"/"+Str(sizebytes/1048576)+"MB) ("+Str(mp)+"x"+Str(cores/mp)+")=>("+Str(gpu(Str(i))\blocktotal)+"x"+Str(gpu(Str(i))\threadtotal)+")")
;cuDeviceGetAttribute(@pi,8,CudaDevice)
;PrintN("Shared memory total:"+Str(pi))
;cuDeviceGetAttribute(@pi,9,CudaDevice)
;PrintN("Constant memory total:"+Str(pi))
;PrintN("---------------")
EndProcedure
Procedure.s cutHex(a$)
a$=Trim(UCase(a$))
If Left(a$,2)="0X"
a$=Mid(a$,3,Len(a$)-2)
EndIf
If Len(a$)=1
a$="0"+a$
EndIf
ProcedureReturn LCase(a$)
EndProcedure
Procedure retTBI(idx, *qq.retTBIStructure, threadtotal)
Protected blockIdx, threadIdx, paramid
blockIdx = idx / (threadtotal*#GPU_GRP_SIZE)
threadIdx = (idx -blockIdx * threadtotal*#GPU_GRP_SIZE)/#GPU_GRP_SIZE
paramid = idx - (threadIdx * #GPU_GRP_SIZE + blockIdx*threadtotal*#GPU_GRP_SIZE)
*qq\blockIdx = blockIdx
*qq\threadIdx = threadIdx
*qq\paramid = paramid
EndProcedure
Procedure retIDX(threadIdx, blockIdx, threadDim, paramid)
Protected idx
idx = ( blockIdx * threadDim + threadIdx ) * #GPU_GRP_SIZE + paramid
ProcedureReturn idx
EndProcedure
Procedure GetProblemIDX()
Protected NewMap gpu_local.gpustructure(), i, j, NewList problem_local.i(), problemcounter,a$
Shared gpu(), *problemArrDist, problemsz, calcMutex
CopyMap(gpu(),gpu_local())
ForEach gpu_local()
ClearList(problem_local())
For i = 0 To gpu_local()\threadtotal * gpu_local()\blocktotal * #GPU_GRP_SIZE - 1
For j = 0 To problemsz -1
;compare last dp distanes with every poblem distance
If Curve::m_check_equilX64(gpu_local()\TEMPLastDPArr + i * 32, *problemArrDist + j * 32)
AddElement(problem_local())
problem_local()= i
a$+"["+Str(i)+"]"
EndIf
Next j
Next i
If ListSize(problem_local())
If ListSize(gpu(MapKey(gpu_local()))\problemsList())
While ListSize(gpu(MapKey(gpu_local()))\problemsList())
Delay(1)
Wend
EndIf
CopyList(problem_local(), gpu(MapKey(gpu_local()))\problemsList())
gpu(MapKey(gpu_local()))\resetProblemKangaroo = 1
problemcounter + ListSize(problem_local())
EndIf
Next
If problemcounter
LockMutex(calcMutex)
PrintN("")
PrintN("Found problem kangaroos: "+Str(problemcounter)+" "+a$)
UnlockMutex(calcMutex)
EndIf
FreeMap(gpu_local())
FreeList(problem_local())
EndProcedure
Procedure Writeint(*Aptr, idx.i, blockDim.w, threadDim.w, *targPtr)
Protected *initAptr, threadIdx, blockIdx.i = 0, threadtotal.i, base.i, threadId.i, index.i, threadtotal64.i, temp.i
;PrintN("IDX:"+Str(idx))
*initAptr = *Aptr
blockIdx = idx / (threadDim*#GPU_GRP_SIZE)
threadIdx = (idx -blockIdx * threadDim*#GPU_GRP_SIZE)/#GPU_GRP_SIZE
idx = idx - (threadIdx * #GPU_GRP_SIZE + blockIdx*threadDim*#GPU_GRP_SIZE)
;PrintN( "TID>"+Str(threadIdx) + " BID>"+Str(blockIdx)+"P>"+Str(idx)+" "+Curve::m_gethex32(*targPtr))
;PrintN("idx local for thread>"+Str(idx))
threadtotal.i = threadDim * blockDim
base.i = idx * threadtotal * 4
threadId.i = blockIdx * threadDim + threadIdx
index.i = base + threadId
;Debug "index: "+Str(index)
threadtotal64.i = index*8
*Aptr = *Aptr + threadtotal64
threadtotal64.i = threadtotal * 8
CopyMemory(*targPtr, *Aptr, 8)
;Debug "[0] offest:"+Str(*Aptr-*initAptr)+" "+Hex(PeekL(*Aptr))
*Aptr = *Aptr + threadtotal64
CopyMemory(*targPtr+8, *Aptr, 8)
;Debug "[1] offest:"+Str(*Aptr-*initAptr)+" "+Hex(PeekL(*Aptr))
*Aptr = *Aptr + threadtotal64
CopyMemory(*targPtr+16, *Aptr, 8)
;Debug "[2] offest:"+Str(*Aptr-*initAptr)+" "+Hex(PeekL(*Aptr))
*Aptr = *Aptr + threadtotal64
CopyMemory(*targPtr+24, *Aptr, 8)
;Debug "[3] offest:"+Str(*Aptr-*initAptr)+" "+Hex(PeekL(*Aptr))
EndProcedure
Procedure Readint(*Aptr, idx.i, blockDim.w, threadDim.w, *targPtr)
Protected *initAptr, threadIdx, blockIdx.i = 0, threadtotal.i, base.i, threadId.i, index.i, threadtotal64.i, temp.i
;PrintN("IDX:"+Str(idx))
*initAptr = *Aptr
blockIdx = idx / (threadDim*#GPU_GRP_SIZE)
threadIdx = (idx -blockIdx * threadDim*#GPU_GRP_SIZE)/#GPU_GRP_SIZE
idx = idx - (threadIdx * #GPU_GRP_SIZE + blockIdx*threadDim*#GPU_GRP_SIZE)
;PrintN( "TID>"+Str(threadIdx) + " BID>"+Str(blockIdx)+"P>"+Str(idx)+" "+Curve::m_gethex32(*targPtr))
;PrintN("idx local for thread>"+Str(idx))
threadtotal.i = threadDim * blockDim
base.i = idx * threadtotal * 4