cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

levyfan
Journeyman III

when to call clReleaseEvent()

cl_event event;

clEnqueueNDRangeKernel(secondaryQueue, ..., 0, NULL, &event);   //kernel1

clEnqueueNDRangeKernel(queue, ..., 1, &event, NULL);                   //kernel2

clReleaseEvent(event);

is the code above right?

or we need to release event after kernel2 is completed?

0 Likes
1 Solution
LeeHowes
Staff

Yes, that's correct. It's a retain/release reference counting API. When you call clEnqueueNDRangeKernel it takes a reference to the event. When you release it you decrease the reference. So in that code if you watched the reference count you'd see it go 1, 2, 3, 1 (unless the kernel completes in the meantime in which case it may drop faster). Or, possibly, as the first enqueue actually creates the event you start at 2. In any case both the host API and the runtime itself have references to objects.

View solution in original post

0 Likes
4 Replies
Wenju
Elite

You'd better add

while(eventStatus != CL_COMPLETE)

    {

        status = clGetEventInfo(

                        event,

                        CL_EVENT_COMMAND_EXECUTION_STATUS,

                        sizeof(cl_int),

                        &eventStatus,

                        NULL);

        CHECK_OPENCL_ERROR(status, "clGetEventInfo failed.");

    }

after kernel1, then release it. Define event2, release it.

0 Likes

so you mean:

cl_event event;

clEnqueueNDRangeKernel(secondaryQueue, ..., 0, NULL, &event);   //kernel1

clEnqueueNDRangeKernel(queue, ..., 1, &event, NULL);                   //kernel2

while(eventStatus != CL_COMPLETE) {

    status = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int),&eventStatus,NULL);

    CHECK_OPENCL_ERROR(status, "clGetEventInfo failed.");

}

clReleaseEvent(event);

right?

0 Likes
LeeHowes
Staff

Yes, that's correct. It's a retain/release reference counting API. When you call clEnqueueNDRangeKernel it takes a reference to the event. When you release it you decrease the reference. So in that code if you watched the reference count you'd see it go 1, 2, 3, 1 (unless the kernel completes in the meantime in which case it may drop faster). Or, possibly, as the first enqueue actually creates the event you start at 2. In any case both the host API and the runtime itself have references to objects.

0 Likes

we encounter memory leak problems with clReleaseEvent()

a new thread is created at here: http://devgurus.amd.com/thread/159738

0 Likes