unique kernel names?

Do the kernel function names have to be unique? Is it ok, if I pass different source code strings to clCreateProgramWithSource but all with the same kernel name? Looks like I will be able to get unique kernel handles with clCreateKernel despite the fact that all kernel functions have the same name. Is it correct?

Within one program all kernel names must be different. However, you can repeat the same kernel names in different programs.

thank you!

what are pro’s and con’s of both approaches?
what was the idea to divide everything into programs?
how will putting one kernel per program impact 1) performance 2) use of resources 3) logic of the code?

what was the idea to divide everything into programs?

Imagine we didn’t have programs. Then a kernel would not be able to call into other auxiliary functions or kernels. That’s perhaps the easiest example of why we need them.

how will putting one kernel per program impact 1) performance 2) use of resources 3) logic of the code?

Performance depends on a lot of factors, including hardware, OpenCL driver and your application. I can imagine examples were putting everything in one program would work best and other examples where one kernel per program would be best. Read your hardware vendor’s (AMD, Intel, Nvidia, etc) programming guides, which should give you some rules of thumb.

I would expect the use of resources will be roughly the same.

If you are asking whether this would have an impact on the complexity of the OpenCL API calls, I don’t think so. At the end of the day what you enqueue are kernels, not programs, so there’s no difference whether they are all in the same program or not.

Generally speaking, if I wanted to get the best performance I would try to maximize locality. If you know that kernel A is always followed by kernel B and that both of them are small, then put A and B in the same program. If you know that kernel A and B do not follow each other very often and/or one of them is large, then put the large one in a separate program.

This advice assumes that all kernels are independent of each other. In reality they will share auxiliary functions which you will need to keep into account when you group kernels into programs.

If performance is less of a concern, then you can group kernels into programs by functionality. I.e. kernels that are naturally related go into the same program. This will make the code easier to read and maintain.

thank you very much for the help!