Memory Leak in OpenCL NVIDIA Driver From clCreateSubBuffer

Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3 x86_64 GNU/Linux
NVIDIA Driver for Linux X64 version 340.32
Tesla K20 and K40

There is a memory leak in the host system (not on the gpu) when calling clCreateSubBuffer, even if the memory object is released. Enough calls exhausts memory and crashes the program.

Steps to reproduce:
Here’s a github repo that will reproduce the leak:

The leak appears from this specific section:

    cl_buffer_region r;
    r.origin = 0*sizeof(float);
    r.size = 100*sizeof(float);
    cl_mem sub = clCreateSubBuffer(mem, CL_MEM_READ_WRITE, CL_BUFFER_CREATE_TYPE_REGION, &r, &info.error);
    info.error = clReleaseMemObject(sub);

I’ve tested this on a machine running the AMD OpenCL drivers and they do not have this leak.

+1, this is very frustrating.

Problem well described here (including code for reproducing):
“However on NVIDIA systems, a final clReleaseMemObject() will not free the memory segment in GPU memory, if not every other OpenCL object has been freed too.”

I fixed my memory leak by adding single missed clReleaseProgram (all others objects were released by appropriate clRelease - including context and buffer, but without this single clReleaseProgram my app was still vRAM leaking)

For me problem exists on Windows (378 driver) and Linux (375 driver).