| 22 |
22 |
import sys
|
| 23 |
23 |
import getopt
|
| 24 |
24 |
import time
|
| 25 |
|
import math
|
| 26 |
25 |
import itertools
|
| 27 |
26 |
from socket import gethostname
|
| 28 |
27 |
|
| ... | ... | |
| 383 |
382 |
s[get_global_id(0)]=total;
|
| 384 |
383 |
}
|
| 385 |
384 |
|
| 386 |
|
|
| 387 |
385 |
__kernel void MainLoopLocal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
|
| 388 |
386 |
{
|
| 389 |
387 |
ulong total=MainLoop(iterations,seed_z,seed_w,get_local_id(0));
|
| ... | ... | |
| 418 |
416 |
try:
|
| 419 |
417 |
# For PyCUDA import
|
| 420 |
418 |
import pycuda.driver as cuda
|
| 421 |
|
import pycuda.tools
|
| 422 |
419 |
from pycuda.compiler import SourceModule
|
| 423 |
420 |
|
| 424 |
421 |
cuda.init()
|
| ... | ... | |
| 428 |
425 |
print "GPU selected %s" % (XPU.name())
|
| 429 |
426 |
print
|
| 430 |
427 |
|
|
428 |
# import pycuda.driver as cuda
|
|
429 |
# from pycuda.compiler import SourceModule
|
|
430 |
# import pycuda.autoinit
|
|
431 |
|
| 431 |
432 |
except ImportError:
|
| 432 |
433 |
print "Platform does not seem to support CUDA"
|
| 433 |
|
|
|
434 |
|
| 434 |
435 |
Context=XPU.make_context()
|
| 435 |
436 |
circle=numpy.zeros(blocks*threads).astype(numpy.uint64)
|
| 436 |
437 |
circleCU = cuda.InOut(circle)
|
|
438 |
#circleCU = cuda.mem_alloc(circle.size*circle.dtype.itemize)
|
|
439 |
#cuda.memcpy_htod(circleCU, circle)
|
| 437 |
440 |
|
| 438 |
441 |
try:
|
| 439 |
|
mod = SourceModule(KernelCodeCuda(),options=['--compiler-options','-Wall -DTRNG=%i -DTYPE=%s' % (Marsaglia[RNG],Computing[ValueType])])
|
|
442 |
mod = SourceModule(KernelCodeCuda(),options=['--compiler-options','-DTRNG=%i -DTYPE=%s' % (Marsaglia[RNG],Computing[ValueType])])
|
| 440 |
443 |
except:
|
| 441 |
|
print "Compilation seems to brake"
|
|
444 |
print "Compilation seems to broke"
|
| 442 |
445 |
|
| 443 |
446 |
MetropolisBlocksCU=mod.get_function("MainLoopBlocks")
|
| 444 |
|
MetropolisJobsCU=mod.get_function("MainLoopThreads")
|
|
447 |
MetropolisThreadsCU=mod.get_function("MainLoopThreads")
|
| 445 |
448 |
MetropolisHybridCU=mod.get_function("MainLoopHybrid")
|
| 446 |
|
|
|
449 |
|
| 447 |
450 |
MyDuration=numpy.zeros(steps)
|
| 448 |
451 |
|
| 449 |
452 |
jobs=blocks*threads;
|
| 450 |
453 |
|
| 451 |
454 |
iterationsCU=numpy.uint64(iterations/jobs)
|
| 452 |
455 |
if iterations%jobs!=0:
|
| 453 |
|
iterationsCU+=1
|
|
456 |
iterationsCU+=numpy.uint64(1)
|
| 454 |
457 |
|
| 455 |
458 |
for i in range(steps):
|
| 456 |
459 |
start_time=time.time()
|
| 457 |
460 |
|
| 458 |
|
MetropolisHybridCU(circleCU,
|
| 459 |
|
numpy.uint64(iterationsCU),
|
| 460 |
|
numpy.uint32(nprnd(2**32)),
|
| 461 |
|
numpy.uint32(nprnd(2**32)),
|
| 462 |
|
grid=(blocks,1),
|
| 463 |
|
block=(threads,1,1))
|
|
461 |
try:
|
|
462 |
MetropolisHybridCU(circleCU,
|
|
463 |
numpy.uint64(iterationsCU),
|
|
464 |
numpy.uint32(nprnd(2**32)),
|
|
465 |
numpy.uint32(nprnd(2**32)),
|
|
466 |
grid=(blocks,1),block=(threads,1,1))
|
|
467 |
except:
|
|
468 |
print "Crash during CUDA call"
|
| 464 |
469 |
|
| 465 |
470 |
elapsed = time.time()-start_time
|
| 466 |
471 |
print "(Blocks/Threads)=(%i,%i) method done in %.2f s..." % (blocks,threads,elapsed)
|
| ... | ... | |
| 519 |
524 |
|
| 520 |
525 |
MetropolisCL = cl.Program(ctx,KernelCodeOpenCL()).build( options = "-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%s" % (Marsaglia[RNG],Computing[ValueType]))
|
| 521 |
526 |
|
| 522 |
|
MyPi=numpy.zeros(steps)
|
| 523 |
527 |
MyDuration=numpy.zeros(steps)
|
| 524 |
528 |
|
| 525 |
529 |
jobs=blocks*threads;
|
| ... | ... | |
| 703 |
707 |
print "Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip(),deviceType,device.name.lstrip())
|
| 704 |
708 |
Id=Id+1
|
| 705 |
709 |
|
| 706 |
|
except ImportError:
|
|
710 |
except:
|
| 707 |
711 |
print "Your platform does not seem to support OpenCL"
|
| 708 |
712 |
|
| 709 |
713 |
print "\nInformations about devices detected under CUDA API:"
|
| ... | ... | |
| 715 |
719 |
device=cuda.Device(Id)
|
| 716 |
720 |
print "Device #%i of type GPU : %s" % (Id,device.name())
|
| 717 |
721 |
print
|
| 718 |
|
except ImportError:
|
|
722 |
except:
|
| 719 |
723 |
print "Your platform does not seem to support CUDA"
|
| 720 |
724 |
|
| 721 |
725 |
sys.exit()
|