cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

Wenju
Elite

Re: Possible memory leak

Confused!  Last time, I told you use while(eventStatus != CL_COMPLETE), and you said it would failed when using different Queues. But I think it would wok if they have the same context. I'm not sure about this. You can have a try.

0 Kudos
Reply
levyfan
Journeyman III

Re: Possible memory leak

hi wenju

you do not get what i meant.

in your code, the host execute a kernel and wait for it, and then execute another and wait again. but in our project, we do not want the host to wait again and again.

so, what you suggest would not help us. your solution just hide the memory leak bug rather than reveal it and fix it.

BTW, what i said "i guess there could be some leaks when different Queues are synced by opencl events.", i meant that the memory leak problem may be related to multiple queues operation in one context.

0 Kudos
Reply
Wenju
Elite

Re: Possible memory leak

I see,

cl_event Q1_evt, Q1_evt_leak;
cl_event Q2_evt;
cl_int eventStatus;
for(;;) {
 

  clEnqueueNDRangeKernel(Q1, memset, 1, NULL, &N, NULL, 0, NULL, &Q1_evt);
 
  clEnqueueNDRangeKernel(Q2, memset, 1, NULL, &N, NULL, 1, &Q1_evt, &Q2_evt);
 
  clEnqueueNDRangeKernel(Q1, memset, 1, NULL, &N, NULL, 1, &Q2_evt, &Q1_evt_leak);
 

   eventStatus = CL_QUEUED;
  while(eventStatus != CL_COMPLETE)
  {
   error = clGetEventInfo(
                        Q1_evt_leak,
                        CL_EVENT_COMMAND_EXECUTION_STATUS,
                        sizeof(cl_int),
                        &eventStatus,
                        NULL);
   if (error != CL_SUCCESS)
   {
    printf("clGetEventInfo failed err = %d\n", error);
    return(error);
   }
  }

  clReleaseEvent(Q1_evt);
  clReleaseEvent(Q2_evt);
  clReleaseEvent(Q1_evt_leak);
  clFinish(Q1);
  clFinish(Q2);
}

no cpu wait, no memory leak, kernels synced by event.

0 Kudos
Reply
levyfan
Journeyman III

Re: Possible memory leak

Hi Wenju

There is a dead-lock/loop in your code. You can detect it by adding printf like this:

for(int i; ; i++) {

     printf("%d\n", i);

     ...

     ...

     ...

     printf("%d\n", i);

}

Because of this dead-lock/loop, you will not see the memory grows up.  But in fact, i suppose that the cl_event is never set to CL_COMPLETE and the host is just looping in your while(eventStatus != CL_COMPLETE).

So, your code above reveals another possible bug.

0 Kudos
Reply
peakitde
Journeyman III

Re: Possible memory leak

Nice Thanx to share this.

0 Kudos
Reply
levyfan
Journeyman III

Re: Possible memory leak

Anyone?

0 Kudos
Reply
bahamut
Journeyman III

Re: Possible memory leak

I think the problem is that you've called clReleaseEvent().

You don't need to call it explicitly in that case, it just messes up the reference counter in the event.

When the work items finish, the reference counter in the event gets decremented automatically.

Your code starts the next iteration before the tasks got finished in the previous one.

0 Kudos
Reply