0

I am trying to build an OpenCL kernel using OpenCL2.0. I am calling the cl::Program build function and passing the flag -cl-std=CL2.0. The g++ compiler finishes and links with no errors. However, when I run the program, the build function throws an exception (see below). Wanted to see if anyone has seen this before and has a solution. Thank you.

I tried other flags such as -cl-std=c++11, -cl-std=CL2.2, but none of these worked.

[20:03:47.768768][info][Demosaic] CL_FLAGS = -cl-std=CL2.0 -D IMAGE_MAD_INDEXING -D AMD_GPU_ARCH -D DEVICE_WAVEFRONT_SIZE=64 -D WG_SIZE_MAX=256
terminate called after throwing an instance of 'cl::BuildError'
[20:03:47.788335][error][Demosaic] Build failed: In file included from /tmp/OCL21460T1.cl:244:
/usr/include/CL/cl2.hpp:495:2: error: Visual studio 2013 or another C++11-supporting compiler required
#error Visual studio 2013 or another C++11-supporting compiler required
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

1

Is cl2.hpp not a file that should be #included in host code rather than OpenCL kernel code?

I assume it checks the value of __cplusplus which, if I'm reading the relevant section of the OpenCL C++ specification correctly, is not defined in the C++ dialect used for OpenCL kernels.

pmdj
  • 22,018
  • 3
  • 52
  • 103
  • Thanks. I took out cl2.hpp from the kernel files. But now it still seems that the runtime compiler is not supporting c++. I get errors such as: `20:12:03.103065][error][Response] Build failed: /tmp/OCL31577T3.cl:419:1: error: unknown type name 'template' template` So really my question is: How do I get OpenCL2.0 to work with kernel source that has c++ code. In the past I was using the clc++ extension in OpenCL1.2, that extension is not supported in OpenCL2.0. Thanks again. – user2556975 May 31 '19 at 03:12
  • I think that for kernel language, C++ was only included in core since OpenCL 2.2. If you have a 2.2 implementation, you can use `-cl-std=C++`, at least that's what the docs say. Otherwise, for older implementations, you'll have to use whatever the vendor provides (like AMD had `-x clc++`). In general C++ support is immature, so i'd only recommend if you're writing something for a very specific hardware. – mogu May 31 '19 at 10:02