7

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Elliot Gorokhovsky
  • 3,610
  • 2
  • 31
  • 56
  • 1
    OpenCL C is a subset of C99. There is also OpenCL C++ which is a subset of C++14 but it's not implemented by any vendor yet. Host code can be written in C,C++,python, etc. Where is your code? – doqtor Jul 07 '16 at 17:43
  • I would accept that as an answer. So let me check my understanding though: OpenCL C++ has been specified, but not implemented on any platform yet? And so I have to write my kernels in OpenCL C? – Elliot Gorokhovsky Jul 07 '16 at 17:49

4 Answers4

10

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.

doqtor
  • 8,414
  • 2
  • 20
  • 36
  • AMD's implementation supports a (limited) number of C++ features since 2012 as an [extension](http://developer.amd.com/community/blog/2012/05/21/opencl-1-2-and-c-static-kernel-language-now-available/). – user703016 Jul 08 '16 at 05:23
  • 2
    @doqtor, can you update your answer with the current state of affairs? – einpoklum Feb 26 '17 at 21:51
4

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.

Rod Burns
  • 2,104
  • 13
  • 24
My Name
  • 151
  • 1
  • 7
  • Just learned that RedHat Developers started working on vendor neutral compute stack. SYCL is the front-end: https://www.phoronix.com/scan.php?page=news_item&px=Red-Hat-Plumbing-Compute-Stack – My Name Jan 11 '19 at 21:42
  • Yet another news that I found this morning posted on LinkedIn that Intel is looking to add SYCL including FPGAs: https://www.phoronix.com/scan.php?page=news_item&px=Intel-SYCL-For-LLVM-Clang – My Name Jan 15 '19 at 15:46
1

For reference, there's also Boost.Compute. It doesn't help you with pyopencl, but it addresses many of the issues that pyopencl does, and has some metaprogramming magic that facilitates writing OpenCL kernels in C++.

This SO question (referenced in the Boost.Compute FAQ) also contains a nice discussion of some of the relevant design constraints that OpenCL poses to devs.

Community
  • 1
  • 1
helmingstay
  • 276
  • 2
  • 7
1

This is an old question, and the work to "solve" it has been ongoing for some time...

There is a community-driven C++ for OpenCL kernel language that is implemented by clang Clang C++ for OpenCL and there is a Khronos extension cl_ext_cxx_for_opencl that adds an online compilation of this language to OpenCL drivers too. Arm has just announced the support for this extension. Although it is also possible to compile kernels in this language offline using upstream tools into machine binary, SPIR-V, or any other IR and then load the precompiled code in OpenCL drivers without any extension.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227