1 import pycuda.autoinit
2 import pycuda.gpuarray as gpuarray
3 import pycuda.driver as cuda
4 import numpy
5
6 free_bytes, total_bytes = cuda.mem_get_info()
7 exp = 10
8 while True:
9 fill_floats = free_bytes / 4 - (1<<exp)
10 try:
11 ary = gpuarray.empty((fill_floats), dtype=numpy.float32)
12 break
13 except MemoryError:
14 pass
15
16 exp += 1
17
18 ary.fill(float("nan"))
19
20 print "filled %d out of %d bytes with NaNs" % (fill_floats*4, free_bytes)
PyCuda/Examples/FillGpuWithNans (last edited 2012-05-25 09:21:29 by 46)