OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1663 Discussions

clSetMemObjectDestructorCallback calls callback with invalid mem_obj

Matthias_H_4
Beginner
209 Views

Hi everyone,

I wrote a little wrapper for clMemoryObjects in which I set a callback for buffer/memory destruction via clSetMemObjectDestructorCallback (actually it's the C++ wrapper equivalent).

When the callback is called, however, and I want to query the cl_mem, which is passed to the callback by the API, I sometimes get an error code Of "-38" -> CL_INVALID_MEM_OBJECT. The application is basically single threaded, so I don't see, where the object should have been destroyed elswhere.

I am also using other OpenCL platforms, in which the code workd properly, so I'm wondering where to look next for my bug.

Best regards

Matthias 

0 Kudos
3 Replies
Rami_J_Intel
Employee
209 Views

Please see end of chapter 5.4.1 at OpenCL 1.2 specification; it says:

" The user callback function may not call OpenCL APIs with the memory object for which the callback function is invoked and for such cases the behavior of OpenCL APIs is considered to be undefined."

So i conclude that the behaviour your are getting is expected. Callback registration is mainly for releasing resources that have been used for the memory object creation and been provided to the OpenCL framework; and this callback hints that it's fine now to release them.

Hope this helps.

Dmitry_K_Intel
Employee
209 Views

chapter 5.4.1 OpenCL 1.2:

"memobj is the memory object being deleted. When the user callback is called by the implementation, this memory object is not longer valid.memobj is only provided for reference purposes."

Implementation calls the callback AFTER releasing all internal resources in order to allow user to free the memory used for data. The memobj handle is provided solely for easing lookup process in user data structure in case user used this handle as a key.

 

Matthias_H_4
Beginner
209 Views

Classical case of "Read first - then ask" ...

Thank you for the quick and profound answers!

 

Reply