0

I want to pass an array to the OpenCL kernel in local address space. But I get CL_invalid_VALUE.

int a[]={1,2,3,4,5};

We don't need to create a buffer to pass data in Local address space. So:

clSetKernelArg(kernel, 21, sizeof(int)*5,a);

In Kernel

__kernel void abc(__local int *a)
{} 

If i change the __local to __global, everything works fine. Please tell me how to do this.

2
  • 1
    For start, replace sizeof(int)*5 to sizeof(a) Commented Apr 21, 2017 at 12:45
  • 1
    I'm not up to speed on opencl, but if the nature and location of the pointed-to memory is indeed relevant, then you haven't provided enough information to determine that. As always, we expect a minimal reproducible example, and your chances of getting a useful answer are greatly improved if you provide one. Commented Apr 21, 2017 at 13:15

1 Answer 1

1

You cannot pass anything to local memory from host.

The purpose of spesifying a local pointer in kernel parameters is to spesify the size of the local buffer at the runtime. Then on the clSetKernelArg call the 3rd parameter is the size and the 4th parameter must be NULL.Documentation

Assuming you are using GPU you can either pass it to Constant memory, initialize the local memory in the kernel if it's always the same or just pass it to global memory and then load it in the kernel to local memory preferably using async_work_group_copy.

Sign up to request clarification or add additional context in comments.

2 Comments

But we can pass data to private memory from host. And there is one book called "Opencl Programming guide" by "[Aaftab Munshi, Benedict Gaster, Timothy Mattson" , on page no. - 134 , they show it is possible to pass the elements to local memory from host.
I've edited the answer to hopefully clear any confusion you have.

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.