Kernel precompilation

Hi,

In OpenCL, to perfom some computations, we have basically to:

  1. create the program from source
  2. compile the program
  3. create the kernel
  4. set the kernel arguments
  5. launch the kernel

At step 2, we can ask OpenCL to give us a char* containing the binary.
We can then replace 1. and 2. by one step consisting in compiling the program from the binary.

Now, imagine we have an inifite loop and at each iteration, we use our kernels.
It is of course not very optimal to do the 5 steps in the loop.
But what is the best save in a variable outside the loop?

  • program binary?
  • program?
  • kernel?

I would say that it’s better to save the kernel and the program so that we can release them properly at the end of the program.
But maybe, if we have a lot of kernels, saving them in variables will use too much memory on the device for nothing.
I don’t know what’s the best. What would you do?

Thanks,

Vincent

If you need to repeat a similar computation many times, you only need to redo steps 4 and 5. All the others can be done “outside of the loop”.

That was my guess too. Thank you!