5 Replies Latest reply on Feb 10, 2011 7:55 AM by nou

    OpenCL Event Callback Usage

      Syntax for OpenCL Event Call-back


      Hello Everyone,  I have a question regarding the usage of the clSetEventCallback. 

      The call as shown below presently segfaults on my system at the 

      clSetEventCallback stage before any real execution happens and the event "device_signal" gets launched

      I am using a 5870 with Stream SDK 2.3 and Catalyst 11.1

      I am not sure of how the syntax should be to set up a callback for when an 

      event is completed.


      //Setting up a callback

      void CL_CALLBACK myCallback( cl_event event,  

                  cl_int cmd_exec_status, void *user_data) {


      // Generates data and moves it to the GPU


      struct ipargs{

      cl_mem ip;  int n;



      //Inside my main()

      cl_event device_signal;

      ipargs x

      //event, status and user data

      cl_int errcode = clSetEventCallback( device_signal, CL_COMPLETE, (void *)&x);

      I would appreciate it if anyone with experience in setting event callbacks can show the right syntax


        • OpenCL Event Callback Usage

          you don't pass a function pointer into a clSetEventCallback(). it should be like this clSetEventCallback( device_signal, CL_COMPLETE, myCallback, (void *)&x);

          • OpenCL Event Callback Usage

            Sorry about that Nou, While copy pasting the text I dropped some text but I am doing the syntax you said. The previous text wouldnt even compile.


            //! Set the callback

            cl_int errcode = clSetEventCallback( device_done_signal, CL_COMPLETE,            myCallback,  (void *)&x);

            I have added the gdb stack frame too



            Program received signal SIGSEGV, Segmentation fault.

            0x00007ffff7bd9d45 in clSetEventCallback () from /usr/local/amd/lib/x86_64/libOpenCL.so

            (gdb) bt

            #0  0x00007ffff7bd9d45 in clSetEventCallback () from /usr/local/amd/lib/x86_64/libOpenCL.so

            #1  0x0000000000407550 in runTest (argc=1, argv=0x7fffffffe0c8)

            I saw on an Nvidia forum that it could happen if you link against a 1.0 version of OpenCL, However the AMD libOpenCL  is 1.1 isnt it ? I have kept any empty function as the callback but it still segfaults


              • OpenCL Event Callback Usage

                it segfault in clSetEventCallback? not when it actualy call that callback function? just try pass NULL as user data.

                  • OpenCL Event Callback Usage

                    Hello Nou, Thanks for the response

                    The segfault was within the clSetEventCallBack, but its my mistake that I was using GCC and it went away when I switched to G++.  I dont know why and it never complained while linking or anything of that sort.

                    However in proceeding with events I have noticed a new problem. If I want to add a callback to a event that is populated by the runtime eg: a enqueuNDRange

                    The code would "intuitively" need to be something like



                    cl_event e;

                    clSetEventCallback(e, CL_COMPLETE, mycallback, (void *)&x) ;

                    enqueuNDRange(____, &e);



                    In the above code, the setEventCallback dies  with CL_INVALID_EVENT which could make sense since cl_event after all is just a pointer till the runtime populates it.

                    So if the kernel was called within a loop, would it be correct to think that the setEventCallBack in this case would  need to be added within the loop so that everytime after  a enqueuNDRange, the callback is set as below 

                    cl_event e;


                    for (){

                       enqueuNDRange(____, &e);

                       clSetEventCallback(e, CL_COMPLETE, mycallback, (void *)&x) ;



                    Is there a better way ?