silx icon indicating copy to clipboard operation
silx copied to clipboard

GPU memory used when devicetype='CPU'

Open chrisroat opened this issue 5 years ago • 1 comments
trafficstars

After running the following code in a notebook (so the process stays alive), a look at nvidia-smi shows there has been memory reserved on the GPU. If that is expected, is there any way to prevent that?

import numpy as np
from silx.opencl import sift

devicetype = 'CPU'
shape = (512, 512)

im1 = np.random.randint(0, 65536, shape, np.uint16)

sift_ocl = sift.SiftPlan(shape=im1.shape, dtype=im1.dtype, devicetype=devicetype)
keypoints1 = sift_ocl.keypoints(im1)

chrisroat avatar Jan 21 '20 07:01 chrisroat

Hi @chrisroat

These contexts are created when silx.opencl.common scans the available platforms/devices with pyopencl.get_platforms(). These contexts are unfortunately not destroyed if the nvidia-persistenced daemon is running.

So regardless if you choose a "CPU" device, importing any silx.opencl module will do this "scanning" step to build the ocl = OpenCL() singleton.

To restrict visible platforms/devices, you can use environment variables, for example:

  • PYOPENCL_CTX="0:" to restrict opencl to platform 0
  • CUDA_VISIBLE_DEVICES="" to ignore all Nvidia GPUs (GPU_DEVICE_ORDINAL for AMD GPUs)

pierrepaleo avatar Jan 21 '20 11:01 pierrepaleo