Can't pass virtual function objects to CUDA kernel is a pain

In my CPU ray tracer, I used polymorphism intensively.

For example, I had a bunch of different light types, point light, area light, etc., all derived from a Light base class.
When rendering, all I need is to loop through an arrary of Light pointers.

Now, without this capability, I have to explicitly store an array for each of the light types, and in order to query all light sources I need to loop through several arrays.
This is really ugly and inelegant to me.

Another alternative is to have a big switch-case clause, and choose different query methods, which also ugly.

I know that we can construct objects locally in the kernel code to call virtual functions too, but that’s not cool to me either and I am afraid it wil hurt performance.

So I am asking is there a good solution to polymorphism in CUDA kernel? Such as a smart way to use template somehow and I can call different implementation of a methods just like in C++?

“…I used polymorphism intensively…”

Polymorphism is a key C++ feature. I use it in a CPU computational fluid dynamics solver. Before i got interested in CUDA programming, i used virtual functions to loop through a vector full of nodes (and do calcs). As for now i use 3 different nodes classes derived from a base class.

To do my calculations on the GPU, im currently designing a new array data structure, which is a real mess, compared to the easy to use polymorphism c++ feature.

I quess you have to write a Kernel for each of your light types :( If theres a better approach, i would be interested to hear any suggestions…