python - How to check if GPU memory is available using PyOpenCL -


i know if there way check how gpu memory available before function uses it. have code uses 1.5 gb of gpu memory or more, , if else using gpu when program wants use it, memoryerror exception or similar.

i implement sort of code can check see if gpu has enough memory available, , if does, go ahead , run, if not, wait until available.

(preferably, check before trying use gpu rather using try-except loop , retrying if fails)

i checked pyopencl documentation see if there relevant under device_info, couldn't find actual descriptions.

this not possible, , limitation of opencl, not pyopencl. see here.

on nvidia devices, can use nvidia-ml-py. can this:

from pynvml import * nvmlinit() in range(nvmldevicegetcount()):     handle = nvmldevicegethandlebyindex(i)     meminfo = nvmldevicegetmemoryinfo(handle)     print("%s: %0.1f mb free, %0.1f mb used, %0.1f mb total" % (         nvmldevicegetname(handle),         meminfo.free/1024.**2, meminfo.used/1024.**2, meminfo.total/1024.**2)) nvmlshutdown() 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -