pyopencl
pyopencl copied to clipboard
Memory deallocation issue
Hi,
I noticed memory deallocation issues when compiling and running OpenCL kernels many times within a loop. Consider the following simple example code:
import pyopencl as cl
import psutil
import os
import gc
n = 5000
ctx = cl.create_some_context()
proc = psutil.Process(os.getpid())
gc.collect()
mem0 = proc.memory_info().rss / 1024**2
for _ in range(n):
prg = cl.Program(ctx, """
__kernel void sum(
__global const float *a_g, __global const float *b_g, __global float *res_g)
{
int gid = get_global_id(0);
res_g[gid] = a_g[gid] + b_g[gid];
}
""").build()
kernel = prg.sum
del kernel
gc.collect()
mem1 = proc.memory_info().rss / 1024**2
print(mem0)
print(mem1)
It creates a number of kernels within a loop and then prints out the memory consumption. With the POCL driver it gives me (in megabytes): 130 621 as output, a significant increase. However, if I move 'del kernel' into the loop behind 'kernel = prg.sum' then I obtain 129 141 as output. The order of deletion seems to matter. If I first delete prg with 'del prg' and then delete the kernel in the loop the memory consumption increases strongly. Deleting first kernel and then prg keeps the memory under control.
I only observe this problem with POCL. However, given that the deletion order seems crucial I wonder if some clean-up issues in PyOpenCL due to dependencies between prg and kernel might be involved in this problem.
We've observed memory leaks in our solver as well: https://gitlab.tiker.net/inducer/pytential/issues/131. We're working on it, but I'd certainly be grateful for help in debugging. Michal mentioned on the pocl list that he tracked down some memory leaks in the 1.4rc---what version of pocl are you running?
Hi,
I use pocl 1.3. If you tell me how I can debug it I am happy to help.
Timo
On Thu, 26 Sep 2019, 01:55 Andreas Klöckner, [email protected] wrote:
We've observed memory leaks in our solver as well: https://gitlab.tiker.net/inducer/pytential/issues/131. We're working on it, but I'd certainly be grateful for help in debugging. Michal mentioned on the pocl list that he tracked down some memory leaks in the 1.4rc---what version of pocl are you running?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/inducer/pyopencl/issues/300?email_source=notifications&email_token=AAA42KEA3QNPJAEIDDQV7XDQLQB7ZA5CNFSM4I2TP4CKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7T4EXI#issuecomment-535282269, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA42KE4XMIU7UT3MPJGXLDQLQB7ZANCNFSM4I2TP4CA .
A good start might be to build PyOpenCL with tracing (./configure.py --cl-trace=1
) and look for clCreate*
/clRetain*
and clRelease*
counts that don't add up to zero.
Thanks. Will do so over the next days and report back.
Timo
On Thu, 26 Sep 2019 at 03:57, Andreas Klöckner [email protected] wrote:
A good start might be to build PyOpenCL with tracing (./configure.py --cl-trace=1) and look for clCreate*/clRetain* and clRelease* counts that don't add up to zero.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/inducer/pyopencl/issues/300?email_source=notifications&email_token=AAA42KCXRFHKKBFZHWWTBMDQLQQKRA5CNFSM4I2TP4CKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7UC74Y#issuecomment-535310323, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA42KB3GYWXFDELWXZS4FTQLQQKRANCNFSM4I2TP4CA .
-- Timo Betcke Professor of Computational Mathematics University College London Department of Mathematics E-Mail: [email protected] Tel.: +44 (0) 20-3108-4068