File: fill_gpu_with_nans.py

package info (click to toggle)
pycuda 2016.1.2%2Bgit20161024-1
  • links: PTS, VCS
  • area: contrib
  • in suites: stretch
  • size: 1,560 kB
  • ctags: 2,268
  • sloc: python: 11,951; cpp: 9,839; makefile: 139; sh: 1
file content (26 lines) | stat: -rw-r--r-- 639 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ import print_function
from __future__ import absolute_import
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import numpy

free_bytes, total_bytes = cuda.mem_get_info()
exp = 10
while True:
    fill_floats = free_bytes / 4 - (1<<exp)
    if fill_floats < 0:
        raise RuntimeError("couldn't find allocatable size")
    try:
        print("alloc", fill_floats)
        ary = gpuarray.empty((fill_floats,), dtype=numpy.float32)
        break
    except:
        pass

    exp += 1

ary.fill(float("nan"))

print("filled %d out of %d bytes with NaNs" % (fill_floats*4, free_bytes))