cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

edwen
Journeyman III

Seems OpenCL doesn't support Polymorphism?

In my Kernel file .cl, I define several functions with the same name, but have different numbers and types of parameters. The excecution always failed until I named those functions differently. Doesn't anyone have the same experience?

I wonder if OpenCL support "class" and "derived class", which are very popular in C++.

 

0 Likes
6 Replies
mihzaha
Journeyman III

OpenCL is based on C, not C++. It doesn't support polymorphism or classes, it's not object oriented.

0 Likes
Raistmer
Adept II

Originally posted by: edwen

In my Kernel file .cl, I define several functions with the same name, but have different numbers and types of parameters. The excecution always failed until I named those functions differently. Doesn't anyone have the same experience?




I wonder if OpenCL support "class" and "derived class", which are very popular in C++.




 



when you will bound OpenCL kernel with cl_kernel object in your C++ code you will provide only kernel name, not kernel name decorated with its parameters and return type.
From this fact it's obvious that same kernel names will not go.
0 Likes

Btw, I tried a custom mechanism ( ala GObject ) using C function pointers, but it neither supports them so it's impossible to get polymorphism, sorry.

 

On the other hand, I think you are referring to function parameter's overriding which is a completely different thing... but C does not support it, you must change the function's name.

 

Those things together with templates reminds me each day why C is really awful and why OpenCL 2.0 should support C++.

0 Likes
edwen
Journeyman III

That's right. It's actually overriding, instead of polymorphism. If OpenCL doesn't support Classes, it shouldn't support that, either. Is OpenCL going to support C++ in the near future?

0 Likes

Originally posted by: bubu

 

Those things together with templates reminds me each day why C is really awful and why OpenCL 2.0 should support C++.

 

<Rant>

Funny that. After trying everything from Assembler to .NET and back, I've rediscovered the beauty and simplicity of C. And guess what's occupying the other end of my preference list. It's that overgrown, one-language-to-rule-them-all (and then some), Mess++ we all love so much.

The last thing, I'd like to see, is GPUs burried in layers and layers of templates, inheritance, polymorphism, constructor chains and virtual function tables.

What a joy...

</Rant>

0 Likes

OpenCl can support many c++ features using c++ bindings.

http://www.khronos.org/registry/cl/

0 Likes