- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm working on a project where I'm using OpenCL 2.1 NEO and I want to know if I can use C++ inside the kernel code. I see AMD has that feature and also OpenCL 2.1 it has C++ specs. But I'm not able to use the C++ code inside the kernel.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi SujayS,
Thanks for the interest and the question. I think your question can help a lot of users, so I'm linking some useful resources for users who want to develop with OpenCL-C++ and Intel Graphics Compute Runtime for OpenCL Driver (NEO).
At this time, NEO can ingest SPIR-V. Exploring compilation of OpenCL-C++ to SPIR-V may help you. Here are some overview references and examples:
- NEO Reference on ingesting OpenCL-C++ through SPIR-V
- Khronos Announcement for how SPIR-V ingestion works.
- IWOCL 2019 Keynote (see page 20)
- Godbolt (CLANG-LLVM) toolchain example from IWOCL 2019 Keynote
- Note: it looks like for more recent versions of the clang environment the toggle has changed to -cl-std=clc++ from -cl-std=c++ used in the prepopulated godbolt example.
- Khronos SPIR repo guidance for targeting with the SPIR-V enabled CLANG build toolchain.
- Clang cli document
- Clang Users Manual OpenCL section
- Some context for ingesting SPIR-V with 2019 Update 5 and earlier versions of the Intel® SDK for OpenCL Applications.
- Note: ioc64 build command won't work for OpenCL-C++, but seeing the OpenCL-C -> SPIR-V -> clCreateProgramWithIL flow can be useful. The ingestion part should be similar.
Some spellings for toggles may have been updated between clang version so picking a toolchain to fit your needs may not be so trivial. The Khronos SPIR repo looks like a good place to start to keep it simple.
Hopefully, browsing the above guidance can help you get there. Please let us know how your exploration goes.
-MichaelC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SujayS,
Also noteworthy, the ioc64 tool, can compile SPIR-V to both Intel CPU and Intel Graphics Technology (NEO enabled) targets. You may wish to use it to check offline compilation for targets of interest. The ioc64 tool comes with Intel® SDK for OpenCL™ Applications and the Intel® oneAPI beta Data Parallel C++ Base Toolkit.
ioc64 maintainers monitor these forums so if you have SPIR-V usage feedback for Intel platforms this would be a good thread to speak to your experience.
-MichaelC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd like to add a few additional links to Michael's excellent list above:
- Here is an updated link demonstrating an OpenCL C++ kernel and command line that compiles through standard Clang (at least, as of this writing): https://godbolt.org/z/mZ22WE
- Here is the open source SPIR-V LLVM translator that can convert the LLVM IR bitcode emitted by Clang to SPIR-V: https://github.com/khronosgroup/spirv-llvm-translator
- Here is an example demonstrating how to create a kernel from a file containing SPIR-V (works on Windows and Linux): https://github.com/bashbaug/SimpleOpenCLSamples/tree/master/samples/05_spirvkernelfromfile
Finally, if you are interested in a more complete end-to-end C++ experience, I'd encourage you to take a look at SYCL and Intel oneAPI Data Parallel C++. More information about Data Parallel C++ can be found here: https://software.intel.com/en-us/oneapi/dpc-compiler
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any way to do compilation of C++ code (for use within an OpenCL kernel) at runtime with Intel OpenCL?
All avenues suggest that code must be compiled to SPIRV first (at application build/compile time), without allowing arbitrary C++ source to be created, compiled and executed all at runtime.
Examples of existing toolsets that allow for runtime compilation:
- NVRTC (nvidias runtime compiler)
- OpenGL/GLSL
- OpenCL (using standard C)
- OpenCL on AMD (via their "opencl static c++ kernel language" extension)
- etc...
the use-case is executing shader graphs.
So imagine the user at runtime can construct an arbitrary node-graph representing a large computation.
I would like to translate that node-graph into C++ sourcecode at runtime, and then execute on the device.
If such a system were possible with Intel OpenCL, what would need to be installed on the users machine to make this work?
thanks very much
Brian Sharpe

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page