How to use templates with OpenCL?

According to this document, page 6 (released by AMD) (and these topics?) , There are several ways to use templates with OpenCL. However, the first document says that this can be done using some parameters with clBuildProgramWithSource, which does not seem to exist ... In any case, assuming it is clBuildProgram and not the previous one, I tried to use the so-called "- x "option with" cl ++ ", but still it is not recognized:

warning: ignoring build option: "-x" 

In fact, according to the documentation received from Khronos, this option is not available! This document may very well be outdated in some way, but are there other ways to use patterns inside OpenCL code?

+4
source share
2 answers

The -x option is available only in the latest versions of AMD OpenCL, which support OpenCL 1.2 and the static C ++ language extension. You will not find a word about this in the official Khronos documents, because this is all AMD's initiative and, ultimately, a supplier extension.

I assume that you have the correct runtime, so your kernel should be built with these parameters:

 -x clc++ 

If you can create kernels with classes using this, you should be able to use templates.

If this does not work, it means that either your runtime setting is corrupt, for example. you are somehow using the wrong compiler, or that means you don't have the right runtime. If yes, provide your platform information.

I came across a static C ++ extension for some time, and I can testify that -x clc++ works.


You should also remember that using this extension will make your code not portable and not connected to devices compatible with AMD, as it is unlikely that other manufacturers will introduce the same extension (if ever).

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

+6
source

The new SYCL Khronos Standard offers built-in support for meta-programming of templates on top of OpenCL platforms, including AMD OpenCL.

0
source

All Articles