1
votes

I wish to use local work groups for my kernels, but I'm having some issues passing the 'NULL' parameters to my kernels. I hope to know how to pass these parameters using the methods that I'm using which I will show below, as opposed to setArg which I saw here: How to declare local memory in OpenCL?

I have the following host code for my kernel:

initialized in a .h file:

std::shared_ptr<cl::make_kernel<cl::Buffer, cl::Buffer>> setInputKernel;

in host code:

this->setInputKernel.reset(new cl::make_kernel<cl::Buffer, cl::Buffer>(program, "setInputs"));

enqueue kernel code:

(*setInputKernel)(cl::EnqueueArgs(*queue, cl::NDRange(1000),cl::NDRange(1000)),
            cl::Buffer, cl::Buffer);

kernel code:

kernel void setInputs(global float* restrict inputArr, global float* restrict inputs)

I have already set the appropriate sizes and setting for my local work group parameters. However, I did not successfully pass the data into the kernel.

The kernel with the local work group updates:

kernel void setInputs(global float* restrict inputArr, global float*
                      restrict inputs, local float* inputArrLoc, local float* inputsLoc)

I had tried to change my code accordingly by using NULL or cl::Buffer for the input params of the kernels, but didn't work:

std::shared_ptr<cl::make_kernel<cl::Buffer, cl::Buffer, NULL, NULL>> setInputKernel;
std::shared_ptr<cl::make_kernel<cl::Buffer, cl::Buffer, cl::Buffer, cl::Buffer>> setInputKernel;

with the first attempt giving me compiler issues saying that the function expects a value while I did not give one, and the second attempt returning clSetKernelArg error when I try to run the kernel. In both examples, I had ensured that all the parameters for the headers and host files were consistent.

I also tried to just put NULL behind my cl::Buffers when I enqueue the kernel, but this returns an error telling me that there is no function for call.

How do I pass parameters to my kernel in my example?

1

1 Answers

2
votes

There is a LocalSpaceArg type and Local helper function to do this.

The type of your kernel would be this:

cl::make_kernel<cl::Buffer, cl::Buffer, cl::LocalSpaceArg, cl::LocalSpaceArg>

You would then specify the size of the local memory allocations when you enqueue the kernel by using cl::Local(size) (where size is the number of bytes you wish to allocate).