How to use C++ templates in kernel?

I’m a novice in OpenCL.

I have an algorithm which uses templates and now I need to rewrite it to use OpenCL.
Is there any way to use C++ templates in kernel?

Is it possible to somehow expand templates by C++ compiler or some tool and after that use so changed kernel function?

It will depend on how templates are being used. You may be able to replace some simple uses with preprocessor #defines. Long ago there used to be a tool called CFront that was the C++ compiler and it translated to C rather than compiling directly to an ISA… I’ve never gone looking for whether somebody has been keeping it alive. Other than that, you’re facing doing the task by hand, I’m afraid.