Révision 181
| Pi/XPU/PiXPU.py (revision 181) | ||
|---|---|---|
| 71 | 71 |
def DictionariesAPI(): |
| 72 | 72 |
Marsaglia={'CONG':0,'SHR3':1,'MWC':2,'KISS':3}
|
| 73 | 73 |
Computing={'INT32':0,'INT64':1,'FP32':2,'FP64':3}
|
| 74 |
return(Marsaglia,Computing) |
|
| 74 |
Test={True:1,False:0}
|
|
| 75 |
return(Marsaglia,Computing,Test) |
|
| 75 | 76 |
|
| 76 | 77 |
# find prime factors of a number |
| 77 | 78 |
# Get for WWW : |
| ... | ... | |
| 128 | 129 |
#define TFP32 2 |
| 129 | 130 |
#define TFP64 3 |
| 130 | 131 |
|
| 132 |
#define IFTHEN 1 |
|
| 133 |
|
|
| 131 | 134 |
// Marsaglia RNG very simple implementation |
| 132 | 135 |
|
| 133 | 136 |
#define znew ((z=36969*(z&65535)+(z>>16))<<16) |
| ... | ... | |
| 225 | 228 |
#endif |
| 226 | 229 |
#endif |
| 227 | 230 |
|
| 231 |
#if TEST == IFTHEN |
|
| 232 |
if ((x*x+y*y) <=THEONE) {
|
|
| 233 |
total+=1; |
|
| 234 |
} |
|
| 235 |
#else |
|
| 228 | 236 |
ulong inside=((x*x+y*y) <= THEONE) ? 1:0; |
| 229 | 237 |
total+=inside; |
| 238 |
#endif |
|
| 230 | 239 |
} |
| 231 | 240 |
|
| 232 | 241 |
return(total); |
| ... | ... | |
| 270 | 279 |
#define TFP32 2 |
| 271 | 280 |
#define TFP64 3 |
| 272 | 281 |
|
| 282 |
#define IFTHEN 1 |
|
| 283 |
|
|
| 273 | 284 |
// Marsaglia RNG very simple implementation |
| 274 | 285 |
#define znew ((z=36969*(z&65535)+(z>>16))<<16) |
| 275 | 286 |
#define wnew ((w=18000*(w&65535)+(w>>16))&65535) |
| ... | ... | |
| 368 | 379 |
#endif |
| 369 | 380 |
#endif |
| 370 | 381 |
|
| 382 |
#if TEST == IFTHEN |
|
| 383 |
if ((x*x+y*y) <= THEONE) {
|
|
| 384 |
total+=1; |
|
| 385 |
} |
|
| 386 |
#else |
|
| 371 | 387 |
ulong inside=((x*x+y*y) <= THEONE) ? 1:0; |
| 372 | 388 |
total+=inside; |
| 389 |
#endif |
|
| 373 | 390 |
} |
| 374 | 391 |
|
| 375 | 392 |
return(total); |
| ... | ... | |
| 410 | 427 |
Device=InputCU['Device'] |
| 411 | 428 |
RNG=InputCU['RNG'] |
| 412 | 429 |
ValueType=InputCU['ValueType'] |
| 430 |
TestType=InputCU['IfThen'] |
|
| 413 | 431 |
|
| 414 |
Marsaglia,Computing=DictionariesAPI() |
|
| 432 |
Marsaglia,Computing,Test=DictionariesAPI()
|
|
| 415 | 433 |
|
| 416 | 434 |
try: |
| 417 | 435 |
# For PyCUDA import |
| ... | ... | |
| 439 | 457 |
#mod = SourceModule(KernelCodeCuda(),options=['--compiler-options','-DTRNG=%i -DTYPE=%s' % (Marsaglia[RNG],Computing[ValueType])]) |
| 440 | 458 |
#mod = SourceModule(KernelCodeCuda(),nvcc='nvcc',keep=True) |
| 441 | 459 |
# Needed to set the compiler via ccbin for CUDA9 implementation |
| 442 |
mod = SourceModule(KernelCodeCuda(),options=['-ccbin','clang-3.8','--compiler-options','-DTRNG=%i' % Marsaglia[RNG],'-DTYPE=%s' % Computing[ValueType]],keep=True) |
|
| 460 |
mod = SourceModule(KernelCodeCuda(),options=['-ccbin','clang-3.8','--compiler-options','-DTRNG=%i' % Marsaglia[RNG],'-DTYPE=%s' % Computing[ValueType],'-DTEST=%s' % Test[TestType]],keep=True)
|
|
| 443 | 461 |
except: |
| 444 | 462 |
print("Compilation seems to break")
|
| 445 | 463 |
|
| ... | ... | |
| 490 | 508 |
blocks=InputCL['Blocks'] |
| 491 | 509 |
threads=InputCL['Threads'] |
| 492 | 510 |
Device=InputCL['Device'] |
| 493 |
RNG=InputCL['RNG'] |
|
| 511 |
RNG=InputCL['RNG']
|
|
| 494 | 512 |
ValueType=InputCL['ValueType'] |
| 513 |
TestType=InputCL['IfThen'] |
|
| 514 |
|
|
| 515 |
Marsaglia,Computing,Test=DictionariesAPI() |
|
| 495 | 516 |
|
| 496 |
Marsaglia,Computing=DictionariesAPI() |
|
| 497 |
|
|
| 498 | 517 |
# Initialisation des variables en les CASTant correctement |
| 499 | 518 |
Id=0 |
| 500 | 519 |
HasXPU=False |
| ... | ... | |
| 523 | 542 |
circle=numpy.zeros(blocks*threads).astype(numpy.uint64) |
| 524 | 543 |
circleCL = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=circle) |
| 525 | 544 |
|
| 526 |
MetropolisCL = cl.Program(ctx,KernelCodeOpenCL()).build( options = "-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%s" % (Marsaglia[RNG],Computing[ValueType]))
|
|
| 545 |
MetropolisCL = cl.Program(ctx,KernelCodeOpenCL()).build( options = "-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%s -DTEST=%s" % (Marsaglia[RNG],Computing[ValueType],Test[TestType]))
|
|
| 527 | 546 |
|
| 528 | 547 |
MyDuration=numpy.zeros(steps) |
| 529 | 548 |
|
| ... | ... | |
| 671 | 690 |
Curves=False |
| 672 | 691 |
# Fit is True to print the curves |
| 673 | 692 |
Fit=False |
| 693 |
# Inside based on If |
|
| 694 |
IfThen=False |
|
| 674 | 695 |
# Marsaglia RNG |
| 675 | 696 |
RNG='MWC' |
| 676 | 697 |
# Value type : INT32, INT64, FP32, FP64 |
| 677 | 698 |
ValueType='FP32' |
| 678 | 699 |
|
| 679 |
HowToUse='%s -o (Out of Core Metrology) -c (Print Curves) -d <DeviceId> -g <CUDA/OpenCL> -i <Iterations> -b <BlocksBegin> -e <BlocksEnd> -s <BlocksStep> -f <ThreadsFirst> -l <ThreadsLast> -t <ThreadssTep> -r <RedoToImproveStats> -m <SHR3/CONG/MWC/KISS> -v <INT32/INT64/FP32/FP64>' |
|
| 700 |
HowToUse='%s -o (Out of Core Metrology) -c (Print Curves) -k (Case On IfThen) -d <DeviceId> -g <CUDA/OpenCL> -i <Iterations> -b <BlocksBegin> -e <BlocksEnd> -s <BlocksStep> -f <ThreadsFirst> -l <ThreadsLast> -t <ThreadssTep> -r <RedoToImproveStats> -m <SHR3/CONG/MWC/KISS> -v <INT32/INT64/FP32/FP64>'
|
|
| 680 | 701 |
|
| 681 | 702 |
try: |
| 682 |
opts, args = getopt.getopt(sys.argv[1:],"hocg:i:b:e:s:f:l:t:r:d:m:v:",["gpustyle=","iterations=","blocksBegin=","blocksEnd=","blocksStep=","threadsFirst=","threadsLast=","threadssTep=","redo=","device=","marsaglia=","valuetype="]) |
|
| 703 |
opts, args = getopt.getopt(sys.argv[1:],"hockg:i:b:e:s:f:l:t:r:d:m:v:",["gpustyle=","iterations=","blocksBegin=","blocksEnd=","blocksStep=","threadsFirst=","threadsLast=","threadssTep=","redo=","device=","marsaglia=","valuetype="])
|
|
| 683 | 704 |
except getopt.GetoptError: |
| 684 | 705 |
print(HowToUse % sys.argv[0]) |
| 685 | 706 |
sys.exit(2) |
| ... | ... | |
| 727 | 748 |
Metrology='OutMetro' |
| 728 | 749 |
elif opt == '-c': |
| 729 | 750 |
Curves=True |
| 751 |
elif opt == '-k': |
|
| 752 |
IfThen=True |
|
| 730 | 753 |
elif opt in ("-d", "--device"):
|
| 731 | 754 |
Devices.append(int(arg)) |
| 732 | 755 |
elif opt in ("-g", "--gpustyle"):
|
| ... | ... | |
| 842 | 865 |
InputCU['Device']=Devices[0] |
| 843 | 866 |
InputCU['RNG']=RNG |
| 844 | 867 |
InputCU['ValueType']=ValueType |
| 868 |
InputCU['IfThen']=IfThen |
|
| 845 | 869 |
OutputCU=MetropolisCuda(InputCU) |
| 846 | 870 |
Inside=OutputCU['Circle'] |
| 847 | 871 |
NewIterations=OutputCU['NewIterations'] |
| ... | ... | |
| 857 | 881 |
InputCL['Threads']=Threads |
| 858 | 882 |
InputCL['Device']=Devices[0] |
| 859 | 883 |
InputCL['RNG']=RNG |
| 860 |
InputCL['ValueType']=ValueType |
|
| 884 |
InputCL['ValueType']=ValueType |
|
| 885 |
InputCL['IfThen']=IfThen |
|
| 861 | 886 |
OutputCL=MetropolisOpenCL(InputCL) |
| 862 | 887 |
Inside=OutputCL['Circle'] |
| 863 | 888 |
NewIterations=OutputCL['NewIterations'] |
| ... | ... | |
| 877 | 902 |
InputCU['Device']=Devices[0] |
| 878 | 903 |
InputCU['RNG']=RNG |
| 879 | 904 |
InputCU['ValueType']=ValueType |
| 905 |
InputCU['IfThen']=IfThen |
|
| 880 | 906 |
OutputCU=MetropolisCuda(InputCU) |
| 881 | 907 |
Inside=OutputCU['Inside'] |
| 882 | 908 |
NewIterations=OutputCU['NewIterations'] |
| ... | ... | |
| 897 | 923 |
InputCL['Device']=Devices[0] |
| 898 | 924 |
InputCL['RNG']=RNG |
| 899 | 925 |
InputCL['ValueType']=ValueType |
| 926 |
InputCL['IfThen']=IfThen |
|
| 900 | 927 |
OutputCL=MetropolisOpenCL(InputCL) |
| 901 | 928 |
Inside=OutputCL['Inside'] |
| 902 | 929 |
NewIterations=OutputCL['NewIterations'] |
Formats disponibles : Unified diff