Memory deallocation issue
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 247
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 6
Description
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.