Révision 61
| Splutter/GPU/SplutterGPU.py (revision 61) | ||
|---|---|---|
| 336 | 336 |
|
| 337 | 337 |
# Initialisation des variables en les CASTant correctement |
| 338 | 338 |
|
| 339 |
MaxMemoryXPU=0 |
|
| 340 |
MinMemoryXPU=0 |
|
| 341 |
|
|
| 339 | 342 |
if Device==0: |
| 340 | 343 |
print "Enter XPU selector based on ALU type: first selected" |
| 341 | 344 |
HasXPU=False |
| ... | ... | |
| 344 | 347 |
for device in platform.get_devices(): |
| 345 | 348 |
deviceType=cl.device_type.to_string(device.type) |
| 346 | 349 |
deviceMemory=device.max_mem_alloc_size |
| 350 |
if deviceMemory>MaxMemoryXPU: |
|
| 351 |
MaxMemoryXPU=deviceMemory |
|
| 352 |
if deviceMemory<MinMemoryXPU or MinMemoryXPU==0: |
|
| 353 |
MinMemoryXPU=deviceMemory |
|
| 347 | 354 |
if deviceType=="GPU" and Alu=="GPU" and not HasXPU: |
| 348 | 355 |
XPU=device |
| 349 |
print "GPU selected: ",device.name
|
|
| 356 |
print "GPU selected with Allocable Memory %i: %s" % (deviceMemory,device.name)
|
|
| 350 | 357 |
HasXPU=True |
| 351 | 358 |
MemoryXPU=deviceMemory |
| 352 | 359 |
if deviceType=="CPU" and Alu=="CPU" and not HasXPU: |
| 353 | 360 |
XPU=device |
| 354 |
print "CPU selected: ",device.name
|
|
| 361 |
print "CPU selected with Allocable Memory %i: %s" % (deviceMemory,device.name)
|
|
| 355 | 362 |
HasXPU=True |
| 356 | 363 |
MemoryXPU=deviceMemory |
| 364 |
|
|
| 357 | 365 |
else: |
| 358 | 366 |
print "Enter XPU selector based on device number & ALU type" |
| 359 | 367 |
Id=1 |
| ... | ... | |
| 363 | 371 |
for device in platform.get_devices(): |
| 364 | 372 |
deviceType=cl.device_type.to_string(device.type) |
| 365 | 373 |
deviceMemory=device.max_mem_alloc_size |
| 374 |
if deviceMemory>MaxMemoryXPU: |
|
| 375 |
MaxMemoryXPU=deviceMemory |
|
| 376 |
if deviceMemory<MinMemoryXPU or MinMemoryXPU==0: |
|
| 377 |
MinMemoryXPU=deviceMemory |
|
| 366 | 378 |
if Id==Device and Alu==deviceType and HasXPU==False: |
| 367 | 379 |
XPU=device |
| 368 |
print "CPU/GPU selected: ",device.name
|
|
| 380 |
print "CPU/GPU selected with Allocable Memory %i: %s" % (deviceMemory,device.name)
|
|
| 369 | 381 |
HasXPU=True |
| 370 | 382 |
MemoryXPU=deviceMemory |
| 371 | 383 |
Id=Id+1 |
| ... | ... | |
| 374 | 386 |
(Device,Alu,Id-1) |
| 375 | 387 |
return(0,0,0) |
| 376 | 388 |
|
| 389 |
print "Allocable Memory is %i, between %i and %i " % (MemoryXPU,MinMemoryXPU,MaxMemoryXPU) |
|
| 390 |
|
|
| 377 | 391 |
# Je cree le contexte et la queue pour son execution |
| 378 | 392 |
ctx = cl.Context([XPU]) |
| 379 | 393 |
queue = cl.CommandQueue(ctx, |
| ... | ... | |
| 383 | 397 |
mf = cl.mem_flags |
| 384 | 398 |
|
| 385 | 399 |
MetropolisCL = cl.Program(ctx,KERNEL_CODE_OPENCL).build(options = "-cl-mad-enable -cl-fast-relaxed-math") |
| 386 |
#MetropolisCL = cl.Program(ctx,KERNEL_CODE_OPENCL).build() |
|
| 387 | 400 |
|
| 388 | 401 |
MyDuration=numpy.zeros(steps) |
| 389 | 402 |
|
| ... | ... | |
| 394 | 407 |
|
| 395 | 408 |
iterationsNew=numpy.uint64(iterationsCL*jobs) |
| 396 | 409 |
|
| 397 |
print iterations,iterationsCL,iterationsNew |
|
| 398 |
|
|
| 399 | 410 |
MySplutter=numpy.zeros(steps) |
| 400 | 411 |
|
| 401 |
MaxWorks=2**(int)(numpy.log2(MemoryXPU/4))/8
|
|
| 402 |
print MaxWorks,2**(int)(numpy.log2(MemoryXPU/4))
|
|
| 412 |
MaxWorks=2**(int)(numpy.log2(MinMemoryXPU/4))
|
|
| 413 |
print MaxWorks,2**(int)(numpy.log2(MemoryXPU)) |
|
| 403 | 414 |
|
| 415 |
|
|
| 416 |
Splutter=numpy.zeros((MaxWorks/jobs)*jobs).astype(numpy.uint32) |
|
| 417 |
|
|
| 404 | 418 |
for i in range(steps): |
| 405 | 419 |
|
| 406 | 420 |
#Splutter=numpy.zeros(2**(int)(numpy.log2(MemoryXPU/4))).astype(numpy.uint32) |
| 407 | 421 |
#Splutter=numpy.zeros(1024).astype(numpy.uint32) |
| 408 | 422 |
|
| 409 | 423 |
#Splutter=numpy.zeros(jobs).astype(numpy.uint32) |
| 410 |
Splutter=numpy.zeros((MaxWorks/jobs)*jobs).astype(numpy.uint32) |
|
| 411 | 424 |
|
| 412 | 425 |
print Splutter,len(Splutter) |
| 413 | 426 |
|
| 427 |
Splutter[:]=0 |
|
| 428 |
|
|
| 414 | 429 |
SplutterCL = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=Splutter) |
| 415 | 430 |
|
| 416 | 431 |
if ParaStyle=='Blocks': |
| ... | ... | |
| 463 | 478 |
elapsed = 1e-9*(CLLaunch.profile.end - CLLaunch.profile.start) |
| 464 | 479 |
|
| 465 | 480 |
MyDuration[i]=elapsed |
| 466 |
print Splutter,sum(Splutter) |
|
| 467 |
MySplutter[i]=numpy.median(Splutter) |
|
| 468 |
print numpy.mean(Splutter)*len(Splutter),MySplutter[i]*len(Splutter),numpy.std(Splutter) |
|
| 481 |
#print Splutter,sum(Splutter)
|
|
| 482 |
#MySplutter[i]=numpy.median(Splutter)
|
|
| 483 |
#print numpy.mean(Splutter)*len(Splutter),MySplutter[i]*len(Splutter),numpy.std(Splutter)
|
|
| 469 | 484 |
|
| 470 | 485 |
SplutterCL.release() |
| 471 | 486 |
|
Formats disponibles : Unified diff