Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16593 Discussions

clSetEventCallback substitute

Altera_Forum
Honored Contributor II
1,099 Views

Hi, 

 

I am trying to write a program where I get an asynchronous callback once a kernel has finished and I am stuck. May be a trivial thing (or not?) but I am running out of ideas. 

 

In OpenCL 1.1 and higher, one can call clSetEventCallback(), passing it an event and a user function that gets called once the associated kernel is done. However, Altera's OpenCL api is 1.0 and this function apparently doesn't exist. 

 

A second way I thought of is to call clEnqueueNativeKernel(), passing it a command ququeue and a user "kernel" function. As I understood it, a native kernel is just a normal C/C++ function that should get executed on the CPU. So what I had expected is that once it's the enqueued native kernel's time in the Queue, the driver would just call the function. However, this seems to be the wrong assumption because I get a "CL_INVALID_OPERATION" error and clGetDeviceInfo tells me that the FPGA cannot execute a native kernel (the CL_EXEC_NATIVE_KERNEL flag is 0 when asking for the execution capabilities). 

 

So one workaround would be to install the intel opencl sdk and open a second platform/device, create a queue there and order the kernels cross-platform through their event objects. But a) this really seems overkill and b) I am not even sure if that is supposed to work. 

 

So my question: is there any straight forward way how I can tell the OpenCL driver to call a C/C++ callback function on the host once some (non native) kernel finished? 

 

Thanks, 

Christoph
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
413 Views

Did you attempt to use clSetEventCallback() and the compilation failed because the API was missing or did you assume it would be missing? If it was the latter you might want to try it out, even though the supported API is 1.0 there are features from newer revisions mixed into it. I'm not sure myself if that API is present or not since I have never tried to use it before. 

 

The Altera SDK doesn't support ICD which makes using a mix of SDKs very difficult. There is another post in this forum about that particular topic and I don't think it's worth exploring that method since it overcomplicates the host application assuming the workaround I posted actually works (not sure). 

 

I did a search through the 1.0 spec and I don't see any way to create a callback mechanism triggered by the completion of the kernel execution.
0 Kudos
Altera_Forum
Honored Contributor II
413 Views
0 Kudos
Altera_Forum
Honored Contributor II
413 Views

Thanks for your answers.  

 

I did try to compile it and it failed using the altera 13.1 version. And yes, clSetEventCallback was added in OpenCL 1.1. 

 

I was able to rewrite my code such that the host has an opportunity to wait for kernel completion which made my code less straight forward than using a callback (because it has to "inline" the interleaved execution of multiple kernels); but at least it works for now. 

 

Thanks!
0 Kudos
Reply