简体   繁体   English

如何在Opencl内核的本地地址空间中传递数组

[英]How to pass a array in local address space in Opencl kernel

I want to pass an array to the OpenCL kernel in local address space. 我想在本地地址空间中将数组传递给OpenCL内核。 But I get CL_invalid_VALUE . 但是我得到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. 如果我将__local更改为__global ,则一切正常。 Please tell me how to do this. 请告诉我该怎么做。

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. 然后在clSetKernelArg调用上,第三个参数是大小,第四个参数必须为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. 假设您使用的是GPU,则可以将其传递给Constant内存,如果始终不变,则可以在内核中初始化本地内存,或者只是将其传递给全局内存,然后最好使用async_work_group_copy将其加载到内核中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM