4

According to this document page 6 (released by AMD) (and this topics ?), there are some ways to use templates with OpenCL. However, the first document reports this could be done by using some options with clBuildProgramWithSource which doesn't seem to exist... Anyway, assuming it is clBuildProgram rather than the previous one, I attempted to use the so called "-x" option with "clc++", but still, it is not recognized :

warning: ignoring build option: "-x"

In fact, according to the documentation stemming from Khronos, this option is not available! This document may well be deprecated somehow, but are there other ways to use templates inside an OpenCL code?

Community
  • 1
  • 1
Antoine
  • 45
  • 4

2 Answers2

6

The -x option is available only on the latest AMD OpenCL runtimes which support OpenCL 1.2 and the static C++ language extension. You won't find a word about it in the official Khronos docs because this is all an AMD initiative, and, ultimately, a vendor extension.

I assume you have the right runtime, so your kernel needs to be built with these options:

-x clc++

If you are able to build kernels with classes using this, you should then be able to use templates.

If this doesn't work, it means that either your runtime installation is botched, e.g. you're using the wrong compiler somehow, or it means you do not have the right runtime. If so, please give your platform info.

I've messed with the static C++ extension a while ago and I can testify that -x clc++ does work.


Also beware that using this extension will render your code not portable and locked in to AMD-compliant devices, as it is unlikely other vendors will introduce the exact same extension themselves (if ever).

Also, a note on Khronos docs - the ones returned by google are typically the OpenCL 1.0 versions which can be irritating. I recommend downloading the 1.1 or 1.2 standard as well as getting a local copy of the relevant HTML documentation for quick access, if you use OpenCL a lot. It helps.

Thomas
  • 3,321
  • 1
  • 21
  • 44
0

The new SYCL Khronos standard offers native support for template meta programming on top of OpenCL platforms, including AMD OpenCL ones.

Ruyk
  • 775
  • 5
  • 11