AnsweredAssumed Answered

Kernel memory leak using openCL ?

Question asked by Philippe De Muyter on Dec 8, 2016
Latest reply on Dec 15, 2016 by Philippe De Muyter

Hi all,

 

I have a simple openCL kernel called repeatedly on a image stream.  The repeated  part is :

 

cl_int err;

/* Create memory buffers */
input_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, input_size, src, &err);
opencl_check(err, "Could not create the input buffer.");
output_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, output_size, dest, &err);
opencl_check(err, "Could not create the output buffer.");

/* Set OpenCL kernel arguments */
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &input_buffer);
err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &output_buffer);
opencl_check(err, "Could not set the kernel arguments.");

/* Execute OpenCL kernel */
size_t global_work_size[2];
global_work_size[0] = width;
global_work_size[1] = height;

err = clEnqueueNDRangeKernel(command_queue, kernel, 2, NULL, global_work_size, NULL, 0, NULL, NULL);
opencl_check(err, "Could not enqueue the kernel execution command.");

/* Transfer result from output buffer */
err = clEnqueueReadBuffer(command_queue, output_buffer, CL_TRUE, 0, output_size, dest, 0, NULL, NULL);
opencl_check(err, "Could not read the output buffer.");

err = clReleaseMemObject(input_buffer);
opencl_check(err, "Could not release input buffer.");
err = clReleaseMemObject(output_buffer);
opencl_check(err, "Could not release output buffer.");

 

The image transformation works perfectly, but this program is plagued by a kernel memory leak, that I cannot spot.

I work with the g3-4.1.15_1.2.0_ga kernel and the 5.0.11.p8.6+hfp vivante libraries.  Is there an obvious mistake in the above code that could lead to a kernel memory leak ?

 

Alternatively, is there a way to track memory leaks in galcore driver ?

 

I must add that valgrind does not indicate any user memory leak.

 

I must also add that the kernel memory leaked is not even freed when the program terminates.

 

It seems that the memory is freed when I unload (rmmod) and reload (modprobe) the galcore module.

 

I have estimated the leak rate, by disabling as many processes as I could, and logging 'free' answers.  My estimate is 2300 bytes leaked per iteration (= frame, = kernel call).  This is not the size of my frames (neither input_size, nor output_size)

 

Thanks in advance

Outcomes