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

Pi-GPU.py (revision 71)
44 44
  threads=1
45 45
  for factor in matrix.transpose().ravel():
46 46
    threads=threads*factor
47
    if threads*threads>jobs:
47
    if threads*threads>jobs or threads>512:
48 48
      break
49 49
  return(long(threads))
50 50

  
......
233 233

  
234 234
__kernel void MainLoopGlobal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
235 235
{
236
   uint z=seed_z/(get_global_id(0)+1);
237
   uint w=seed_w/(get_global_id(0)+1);
236
   uint z=seed_z+get_global_id(0);
237
   uint w=seed_w+get_global_id(0);
238 238

  
239 239
   ulong total=0;
240 240

  
......
244 244
      float y=MWCfp ;
245 245

  
246 246
      // Matching test
247
      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
247
      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
248 248
      total+=inside;
249 249
   }
250
   barrier(CLK_GLOBAL_MEM_FENCE);
250 251
   s[get_global_id(0)]=total;
251
   barrier(CLK_GLOBAL_MEM_FENCE);
252 252
      
253 253
}
254 254

  
255 255
__kernel void MainLoopLocal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
256 256
{
257
   uint z=seed_z/(get_local_id(0)+1);
258
   uint w=seed_w/(get_local_id(0)+1);
257
   uint z=seed_z+get_local_id(0);
258
   uint w=seed_w+get_local_id(0);
259 259

  
260 260
   ulong total=0;
261 261

  
......
265 265
      float y=MWCfp ;
266 266

  
267 267
      // Matching test
268
      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
268
      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
269 269
      total+=inside;
270 270
   }
271
   barrier(CLK_LOCAL_MEM_FENCE);
271 272
   s[get_local_id(0)]=total;
272
   barrier(CLK_LOCAL_MEM_FENCE);
273 273
      
274 274
}
275 275

  
276 276
__kernel void MainLoopHybrid(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
277 277
{
278
   uint z=seed_z/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
279
   uint w=seed_w/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
278
   uint z=seed_z+get_global_id(0);
279
   uint w=seed_w+get_global_id(0);
280 280

  
281 281
   ulong total=0;
282 282

  
283 283
   for (uint i=0;i<iterations;i++) {
284 284

  
285 285
      float x=MWCfp ;
286
     float y=MWCfp ;
286
      float y=MWCfp ;
287 287

  
288 288
      // Matching test
289
      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
289
      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
290 290
      total+=inside;
291 291
   }
292
   barrier(CLK_LOCAL_MEM_FENCE);
293
   s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
292
   barrier(CLK_GLOBAL_MEM_FENCE || CLK_GLOBAL_MEM_FENCE);
293
   // s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
294
   s[get_global_id(0)]=total;
294 295
      
295 296
}
296 297

  
297 298
__kernel void MainLoopGlobal64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
298 299
{
299
   uint z=seed_z/(get_global_id(0)+1);
300
   uint w=seed_w/(get_global_id(0)+1);
300
   uint z=seed_z+get_global_id(0);
301
   uint w=seed_w+get_global_id(0);
301 302

  
302 303
   ulong total=0;
303 304

  
......
310 311
      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
311 312
      total+=inside;
312 313
   }
314
   barrier(CLK_GLOBAL_MEM_FENCE);
313 315
   s[get_global_id(0)]=total;
314
   barrier(CLK_GLOBAL_MEM_FENCE);
315 316
      
316 317
}
317 318

  
318 319
__kernel void MainLoopLocal64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
319 320
{
320
   uint z=seed_z/(get_local_id(0)+1);
321
   uint w=seed_w/(get_local_id(0)+1);
321
   uint z=seed_z+get_local_id(0);
322
   uint w=seed_w+get_local_id(0);
322 323

  
323 324
   ulong total=0;
324 325

  
......
331 332
      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
332 333
      total+=inside;
333 334
   }
335
   barrier(CLK_LOCAL_MEM_FENCE);
334 336
   s[get_local_id(0)]=total;
335
   barrier(CLK_LOCAL_MEM_FENCE);
336 337
      
337 338
}
338 339

  
339 340
__kernel void MainLoopHybrid64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
340 341
{
341
   uint z=seed_z/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
342
   uint w=seed_w/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
342
   uint z=seed_z+get_global_id(0);
343
   uint w=seed_w+get_global_id(0);
343 344

  
344 345
   ulong total=0;
345 346

  
......
353 354
      total+=inside;
354 355
   }
355 356
   barrier(CLK_LOCAL_MEM_FENCE);
356
   s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
357
   s[get_global_id(0)]=total;
357 358
      
358 359
}
359 360
"""
......
584 585

  
585 586
    elapsed = 1e-9*(CLLaunch.profile.end - CLLaunch.profile.start)
586 587

  
588
    print circle,numpy.mean(circle),numpy.median(circle),numpy.std(circle)
587 589
    MyDuration[i]=elapsed
588 590
    AllPi=4./numpy.float32(iterationsCL)*circle.astype(numpy.float32)
589 591
    MyPi[i]=numpy.median(AllPi)

Formats disponibles : Unified diff