Révision 46 Pi/GPU/Pi-GPU.py

Pi-GPU.py (revision 46)
304 304
	
305 305
  # Initialisation des variables en les CASTant correctement
306 306
    
307
  # Je detecte un peripherique GPU dans la liste des peripheriques
308
  # for platform in cl.get_platforms():
309
  # 	for device in platform.get_devices():
310
  # 		if cl.device_type.to_string(device.type)=='GPU':
311
  # 			GPU=device
312
  #print "GPU detected: ",device.name
313

  
314
  HasGPU=False
315
  Id=1
316
  # Primary Device selection based on Device Id
317
  for platform in cl.get_platforms():
318
    for device in platform.get_devices():
319
      deviceType=cl.device_type.to_string(device.type)
320
      if Id==Device and not HasGPU:
321
        GPU=device
322
        print "CPU/GPU selected: ",device.name
323
        HasGPU=True
324
      Id=Id+1
325
  # Default Device selection based on ALU Type
326
  for platform in cl.get_platforms():
327
    for device in platform.get_devices():
328
      deviceType=cl.device_type.to_string(device.type)
329
      if deviceType=="GPU" and Alu=="GPU" and not HasGPU:
330
        GPU=device
331
        print "GPU selected: ",device.name
332
        HasGPU=True
333
      if deviceType=="CPU" and Alu=="CPU" and not HasGPU:        
334
        GPU=device
335
        print "CPU selected: ",device.name
336
        HasGPU=True
307
  if Device==0:
308
    print "Enter XPU selector based on ALU type: first selected"
309
    HasXPU=False
310
    # Default Device selection based on ALU Type
311
    for platform in cl.get_platforms():
312
      for device in platform.get_devices():
313
        deviceType=cl.device_type.to_string(device.type)
314
        if deviceType=="GPU" and Alu=="GPU" and not HasXPU:
315
          XPU=device
316
          print "GPU selected: ",device.name
317
          HasXPU=True
318
        if deviceType=="CPU" and Alu=="CPU" and not HasXPU:        
319
          XPU=device
320
          print "CPU selected: ",device.name
321
          HasXPU=True
322
  else:
323
    print "Enter XPU selector based on device number & ALU type"
324
    Id=1
325
    HasXPU=False
326
    # Primary Device selection based on Device Id
327
    for platform in cl.get_platforms():
328
      for device in platform.get_devices():
329
        deviceType=cl.device_type.to_string(device.type)
330
        if Id==Device and Alu==deviceType and HasXPU==False:
331
          XPU=device
332
          print "CPU/GPU selected: ",device.name
333
          HasXPU=True
334
        Id=Id+1
335
    if HasXPU==False:
336
      print "No XPU #%i of type %s found in all of %i devices, sorry..." % \
337
          (Device,Alu,Id-1)
338
      return(0,0,0)
337 339
				
338 340
  # Je cree le contexte et la queue pour son execution
339 341
  #ctx = cl.create_some_context()
340
  ctx = cl.Context([GPU])
342
  ctx = cl.Context([XPU])
341 343
  queue = cl.CommandQueue(ctx,
342 344
                          properties=cl.command_queue_properties.PROFILING_ENABLE)
343 345

  
......
493 495
  # Set defaults values
494 496
  # Alu can be CPU or GPU
495 497
  Alu='CPU'
496
  # Id of GPU : 0 is for first find !
498
  # Id of GPU : 1 is for first find !
497 499
  Device=0
498 500
  # GPU style can be Cuda (Nvidia implementation) or OpenCL
499 501
  GpuStyle='OpenCL'
......
522 524
  for opt, arg in opts:
523 525
    if opt == '-h':
524 526
      print '%s -o (Out of Core Metrology) -c (Print Curves) -a <CPU/GPU> -d <DeviceId> -g <CUDA/OpenCL> -p <Threads/Hybrid/Blocks> -i <Iterations> -s <JobStart> -e <JobEnd> -r <RedoToImproveStats>' % sys.argv[0]
527

  
528
      print "\nInformations about devices detected under OpenCL:"
529
      # For PyOpenCL import
530
      import pyopencl as cl
531
      Id=1
532
      for platform in cl.get_platforms():
533
        for device in platform.get_devices():
534
          deviceType=cl.device_type.to_string(device.type)
535
          print "Device #%i of type %s : %s" % (Id,deviceType,device.name)
536
          Id=Id+1
537

  
525 538
      sys.exit()
526 539
    elif opt == '-o':
527 540
      OutMetrology=True
......
599 612
        start=time.time()
600 613
        if GpuStyle=='CUDA':
601 614
          try:
602
            MetropolisCuda(circle,Iterations,1,Jobs,ParaStyle)
615
            a,m,s=MetropolisCuda(circle,Iterations,1,Jobs,ParaStyle)
603 616
          except:
604 617
            print "Problem with %i // computations on Cuda" % Jobs
605 618
        elif GpuStyle=='OpenCL':
606 619
          try:
607
            MetropolisOpenCL(circle,Iterations,1,Jobs,ParaStyle,Alu,Device)
620
            a,m,s=MetropolisOpenCL(circle,Iterations,1,Jobs,ParaStyle,Alu,Device)
608 621
          except:
609 622
            print "Problem with %i // computations on OpenCL" % Jobs            
610 623
        duration=numpy.append(duration,time.time()-start)
611
      avg=numpy.mean(duration)
612
      med=numpy.median(duration)
613
      std=numpy.std(duration)
624
      if (a,m,s) != (0,0,0):
625
        avg=numpy.mean(duration)
626
        med=numpy.median(duration)
627
        std=numpy.std(duration)
628
      else:
629
        print "Values seem to be wrong..."
614 630
    else:
615 631
      if GpuStyle=='CUDA':
616 632
        try:
......
632 648
    else:
633 649
      print "Values seem to be wrong..."
634 650
    #THREADS*=2
635
    numpy.savez("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
636
    numpy.savetxt("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
651
    if len(average)!=0:
652
      numpy.savez("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
653
      numpy.savetxt("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
637 654
    Jobs+=1
638 655

  
639 656
  FitAndPrint(ExploredJobs,median,Curves)

Formats disponibles : Unified diff