4

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 Answer 1

7

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.
Sign up to request clarification or add additional context in comments.

4 Comments

Restated in a clearer way: the language used in OpenCL kernels prior to OpenCL 2.2 is based on C99, not C++, so class is not recognised as a keyword.
Thank you both for your responses @Dithermaster and pmdj, mmm, so... I don't find sense to OpenCL C++ Wrapper API ¬¬, I am completily capable to call simple OpenCL API functions inside a C++ application. Then, I know I can send structs from host to device, but these only define properties and not behavior :(. Can not I handle a POO approach on the device side in some way?
SYCL gets you single-source OOP programming model (host and device side). Check if it is supported on your platform.
Oh yeah ... I think I will not be able to work much either under SYCL, there isn't an official implementation of that standard and those ones such ComputeCPP or trySYCL doesn't works well in NVIDIA devices (that's so weird.... or not?), there is only experimental support (codeplay.com/portal/…) . Well, thank you for your responses. I will try to refactor my code to work with structs and other primitive types to communicate my C++ application with a OpenCL kernel. Regards ñ_ñ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.