Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write OpenCL kernels in C++ rather than C?

I understand there's an openCL C++ API, but I'm having trouble compiling my kernels... do the kernels have to be written in C? And then it's just the host code that's allowed to be written in C++? Or is there some way to write the kernels in C++ that I'm not finding? Specifically, I'm trying to compile my kernels using pyopencl, and it seems to be failing because it's compiling them as C code.

like image 669
Elliot Gorokhovsky Avatar asked Jul 07 '16 17:07

Elliot Gorokhovsky


2 Answers

OpenCL C is a subset of C99.

There is also OpenCL C++ (OpenCL 2.1 and OpenCL 2.2 specs) which is a subset of C++14 but it's not implemented by any vendor yet (OpenCL 2.1 partially implemented by Intel but not C++ kernels).

Host code can be written in C,C++,python, etc.

In short you can read about OpenCL on wikipedia. There is a description about each OpenCL version. In pyopencl you can use OpenCL1.2 (as far as I'm aware there isn't support for OpenCL2.0 yet). More details about OpenCL on Khronos website.

like image 91
doqtor Avatar answered Nov 15 '22 06:11

doqtor


I would add SYCL on ComputeCpp from Codeplay. They have been very active at IWOCL.org promoting the use of single source C++ host and kernel code. SYCL has OpenCL execution model "under the hood". https://en.wikipedia.org/wiki/SYCL. Though Wikipedia has this statement about SYCL: "The open standards SYCL and OpenCL are similar to vendor-specific CUDA from Nvidia." Which cannot be any further from the intent of portable code (not performance portable) of SYCL and OpenCL.

You can find information, news, blogs, videos and resourcs on SYCL on the sycl.tech website.

like image 29
My Name Avatar answered Nov 15 '22 06:11

My Name