Asynchrouous call to program build


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

create context
creeat queue

upload data

enqueue kernel



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…)