4
votes

I have been working with OpenCL 1.2 and I'm having a trouble with the OpenCL C++ Wrapper API (https://www.khronos.org/registry/OpenCL/specs/opencl-cplusplus-1.2.pdf).

It doesn't tell any restriction about include a class "class MyClass" in the kerenel (cl) file, and I suppose that it is possible since the Platform, Device and Context are "Classes" (If not, what is its objetive then? X_X)

Well, I have the following simple class in a "printer.h" file:

class Printer{

    public:
        void print();
}

And in the cl file I have the following lines:

#include "printer.h"
__kernel void hello()
{
    Printer myPrinter;
    //myPrinter.print();
}

But when I build this kernel file in my cpp program it brings the error: unknown type name 'class'. I have read the post Passing Class to a Kernel in Intel Opencl that suggest use SYCL, but, Is there no other way "easier" according to the standard and the wrapper?

Thanks for your help

1

1 Answers

7
votes

There are really three distinct things here:

  1. The OpenCL C++ Wrapper API is for using C++ on the host side to call the OpenCL API. It has nothing to do with C++ kernels on the device side. It can work with OpenCL 1.2 that you are using.
  2. OpenCL 2.2 brings the OpenCL C++ kernel language into the core specification (optional in OpenCL 2.1).
  3. SYCL is a single-source C++ host and kernel system that allows you to write one block of code that does host API calls behind the scene and calls C++ kernels on the device. It requires a pre-pass by the SYCL compiler.