cl_progger cl_progger - 5 months ago 44
C++ Question

Can I embed C++ Classes in OpenCL Kernels?

is there a possibility to use self-defined C++ - classes in an OpenCL kernel?
It should work like this:

#include "element.cpp"
__kernel void do_something(__global element* input, __global element* output);
int index = get_global_id(0);
output[index] = input[index].update(index);

This is interesting, because you can specify the work that must be done in element::update(int no) afterwards.

I did not get it to work. This is what the OpenCL-Compiler tells me:

unknown type name 'class'

In CUDA this works. Are there any other ideas, if the approach with objects in the OpenCL kernel does not work?

Thanks for your hints in advance!


I believe OpenCL follows C99 language specification and not C++. The specifications for C++ version of OpenCL is going on. I believe AMD APP has implemented the C++ version of OpenCL. Coming back to your question, I think it's best to have a struct as the interface between C++ and C. The C++ version should be a wrapper around the C implementation, IF you direly need to do so.

EDIT: I couldn't place this in comments, hence putting it here. AMD's C++ libraries around OpenCL include a static C++ library and Bolt.