Khronos Public Bugzilla
Bug 594 - Clarification for implicit memory allocation of clEvents
Clarification for implicit memory allocation of clEvents
Status: NEW
Product: OpenCL
Classification: Unclassified
Component: Specification
1.2
PC Windows
: P3 normal
: ---
Assigned To: Aaftab Munshi
OpenCL Working Group
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-11 17:47 PST by adam lake
Modified: 2013-05-30 20:19 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description adam lake 2012-02-11 17:47:07 PST
this issue relates to OpenCL clEnqueueXXXX  API functions allocating an event as a side effect if a  cl_event variable is passed by pointer, rather than passing NULL.   

New developers with OpenCL tend to miss that side effect, and assume that they create an event by simply allocating a clEvent variable, or calling clCreateUserEvent to create an event, and that they should then pass that event by pointer to the clEnqueueXXXX functions.   Further, they commonly do not expect that they need to do a clReleaseObject for every event created as a side effect of a clEnqueueXXX call.   The result is that commonly developers create code with an extreme degree of memory leakage.

I would recommend that in section 5.8, the first sentence that ends “…enqueues a command to execute a kernel on the device.” be modified to read “enqueues a command to execute a kernel on the device and allocates a unique new cl_event object (if “event” is non-NULL).”   Possibly even follow that sentence with “The developer must explicitly release each allocated cl_event object when it is no longer needed, to avoid a potential memory leak.”  or words to that effect.

Hopefully with that level of prompting, developers will be sufficiently warned to avoid the issue.
Comment 1 dneto 2012-02-16 06:51:20 PST
(In reply to comment #0)
> 
> I would recommend that in section 5.8, the first sentence that ends “…enqueues
> a command to execute a kernel on the device.” be modified to read “enqueues a
> command to execute a kernel on the device and allocates a unique new cl_event
> object (if “event” is non-NULL).”   Possibly even follow that sentence with
> “The developer must explicitly release each allocated cl_event object when it
> is no longer needed, to avoid a potential memory leak.”  or words to that
> effect.
> 
> Hopefully with that level of prompting, developers will be sufficiently warned
> to avoid the issue.

I like this recommendation.

The issue arises because the cl_event is really a struct wrapping a pointer.
Comment 2 Giuseppe Bilotta 2013-05-30 20:19:49 PDT
I agreee with the proposal. I've come across this issue myself in my early OpenCL programming attempts.