Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I embed C++ Classes in OpenCL Kernels?

Tags:

c++

object

opencl

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!

like image 250
cl_progger Avatar asked Dec 13 '22 15:12

cl_progger


1 Answers

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.

like image 179
Vite Falcon Avatar answered Jan 02 '23 16:01

Vite Falcon