Reputation: 8692
This question derives from my desire to have an OpenCL program constructed at runtime from various kernels. So, imagine I have various kernels that I want to execute in a given context with the same set of memory objects.
If I knew ahead of time all the kernels I wanted to combine into a program, I'd have no problem - simply create a program with all the kernel sources or binaries.
However, given that I don't know ahead of time which kernels I want to combine I was considering creating one program for each kernel source. Is this equivalent to the original case (assuming the compile time options are all the same)? Is there a performance penalty in calling kernels that reside in different programs?
The problem is possibly that I don't understand the abstraction of a "program". What is it? Is it more than just a collection of kernels and some compile time options?
Upvotes: 3
Views: 909
Reputation: 8036
There are a couple of benefits of grouping OpenCL kernels into a single program:
The (slight) overhead of invoking the compiler multiple times through multiple clBuildProgram()
calls. This can be avoided by compiling a single source string into a single program and then creating multiple kernels from it. However, after you get a kernel object there should be no difference in performance based on the program it came from.
The more significant benefit: Grouping kernels together in programs allows them to reference and use each-other and/or other associated helper functions.
Example: A program might define a function to convert between spherical and Cartesian coordinates which could then be used by multiple kernels without its source needing to be duplicated.
Upvotes: 4