What should I use instead of cl::KernelFunctor?
Asked Answered
S

4

14

I'm following some tutorials on OpenCL and they mention a type called cl::KernelFunctor. However, that type isn't found and when I looked at the headers of the AMD APP SDK, I saw that the declaration of the cl::KernelFunctor class is commented out.

What am I supposed to use in place of this code to run a kernel?

//run the kernel
cl::KernelFunctor simple_add(cl::Kernel(program, "simple_add"), queue, cl::NullRange, cl::NDRange(10), cl::NullRange);
simple_add(buffer_A, buffer_B, buffer_C);
Spica answered 2/6, 2014 at 10:27 Comment(0)
C
27
cl::Kernel simple_add(program, "simple_add");
simple_add.setArg(0, buffer_A);
simple_add.setArg(1, buffer_B);
simple_add.setArg(2, buffer_C);
queue.enqueueNDRangeKernel(simple_add,cl::NullRange,cl::NDRange(10),cl::NullRange);
queue.finish();
Chism answered 2/6, 2014 at 10:35 Comment(0)
E
6

You are probably following this tutorial just as I do. I figured out based on this, that files CL/cl.hpp for OpenCL 1.1 and CL/cl.hpp for OpenCL 1.2 differ in that cl::KernelFunctor is removed in the later.

The solution is to use the function cl::make_kernel that takes as template arguments types of your functor. In that particular case the template parameter is thus cl::Buffer. The code that compiles for me using OpenCL 1.2 header is:

cl::make_kernel<cl::Buffer, cl::Buffer, cl::Buffer> simple_add(cl::Kernel(program, "simple_add"));
cl::EnqueueArgs eargs(queue, cl::NullRange, cl::NDRange(10), cl::NullRange);
simple_add(eargs, buffer_A, buffer_B, buffer_C).wait();
Erl answered 24/1, 2019 at 10:55 Comment(1)
This is now under cl::compatibility.Bogie
S
4

As @Michael Dorner said, you can replace the code by a step by step approach. Create the kernel, set the args, and then queue it.


The KernelFunctor is to funct-ify the kernel code so you can call it as a function. Since usually that is not the case, is rarely used in real applications, but it may be useful for some cases.

With this code you are saying:

cl::KernelFunctor simple_add(cl::Kernel(program, "simple_add"), queue, cl::NullRange, cl::NDRange(10), cl::NullRange);
  • Create a functor of kernel "simple_add".
  • Launching in the queue "queue"
  • With these NDRanges.

Then when you call the functor you pass the only remaining things, the arguments:

simple_add(buffer_A, buffer_B, buffer_C);

The good thing is that you can later on launch it with different arguments in an easy way, by just:

simple_add(buffer_B, buffer_C, buffer_D);
Sherwood answered 2/6, 2014 at 11:42 Comment(0)
H
-2
cl::KernelFunctor<cl::Buffer, cl::Buffer, cl::Buffer> simple_add(program, simple_add);
cl::EnqueueArgs eargs(queue, cl::NullRange, cl::NDRange(10), cl::NullRange);
// call func
simple_add(eargs, buffer_A, buffer_B, buffer_C);
Herisau answered 12/6, 2023 at 17:38 Comment(2)
You should add explanation.Kilpatrick
Redefinition of simple_add in the first line. Even with changed name No matching constructor for initialization of 'cl::KernelFunctor<cl::Buffer, cl::Buffer, cl::Buffer>' [ovl_no_viable_function_in_init]. Does not work.Drucilladrucy

© 2022 - 2024 — McMap. All rights reserved.