Skip to content

Instantly share code, notes, and snippets.

@brandondube
Created October 25, 2021 17:09
Show Gist options
  • Save brandondube/0fcae87071ef4b448d1b8c0f89628e33 to your computer and use it in GitHub Desktop.
Save brandondube/0fcae87071ef4b448d1b8c0f89628e33 to your computer and use it in GitHub Desktop.
cupy 9.5.0 memory leak and setDevice not working
from io import BytesIO
import requests
from imageio import imread
if __name__ == '__main__':
url = 'http://localhost:5000/wrong-gpu-and-memory-leak'
while True:
resp = requests.get(url)
b = BytesIO(resp.content)
b.seek(0)
im = imread(b, format='tiff')
"""LOWFSC server -- simulation server for PACE."""
from io import BytesIO
from imageio import imwrite
from flask import Flask, send_file
try:
import cupy as cp
from cupyx.scipy import fft as cpfft
cp.cuda.runtime.setDevice(1) # use the second GPU, "private"
# cp.cuda.Device(1).use()
# print('Using GPU', cp.cuda.runtime.getDevice())
mempool = cp.get_default_memory_pool()
pinned_mempool = cp.get_default_pinned_memory_pool()
except ImportError:
pass
app = Flask('cupy-dev1-memleak-mwe')
@app.route('/wrong-gpu-and-memory-leak', methods=['GET'])
def foobar():
a = cp.random.rand(512,512)
b = cpfft.fftshift(cpfft.fft2(cpfft.ifftshift(a)))
c = b.get()
buf = BytesIO()
imwrite(buf, c, format='tiff')
buf.seek(0)
return send_file(buf, mimetype='image/tiff')
cupy 9.5.0
numpy 1.20.3
python 3.9.6
CUDA 10.2
GPU: Nvidia Titan XP (2x)
CPU: Intel(R) Xeon(R) Gold 6154 (2x)
... more as needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment