PDA

View Full Version : Asynchrouous call to program build



manish.agarw
08-31-2012, 06:52 AM
Hi,

I want to know if i do non-blocking call to clbuildprogram and then upload data ,enqueue kernel does it work ?
Ex:

create context
creeat queue
buildprogram
...
...
...
upload data

enqueue kernel

clfinish


Thanks
Manish

ofer_rose
09-08-2012, 11:50 PM
Hi Manish,

It might - if enough time had passed between calling to clBuildProgram and clCreateKernel - but I wouldn't count on it.

In order to enqueue the kernel, you need a kernel handler - which means that you need to call clCreateKernel with the program handler. The call to clCreateKernel will fail if the program did not finish building, returning CL_INVALID_PROGRAM_EXECUTABLE (see page 158 in OpenCL 1.2 spec).

If you want call clBuildProgram asynchronously, and ensure that it finished building before calling clCreateKernel, you need to register a callback function. This function will be called when the compilation is done - and inside the typical method is to set a semaphore. The application thread will wait on the semaphore before calling clCreateKernel . of course, you can use other methods (state variable, reference counter, etc...)