declaring and defining pointer vetors of vectors in OpenCL Kernel

狂风中的少年 提交于 2019-12-12 03:48:24

问题


I have a variable which is vector of vector, And in c++, I am easily able to define and declare it but in OpenCL Kernel, I am facing the issues. Here is an example of what I am trying to do.

std::vector<vector <double>> filter;
for (int m= 0;m<3;m++)
{
   const auto& w = filters[m];
   -------sum operation using w
}

Now Here, I can easily referencing the values of filters[m] in w, but I am not able to do this OpenCl kernel file. Here is what I have tried,but it is giving me wrong output.

In host code:-

filter_dev = cl::Buffer(context,CL_MEM_READ_ONLY|CL_MEM_USE_HOST_PTR,filter_size,(void*)&filters,&err);

filter_dev_buff = cl::Buffer(context,CL_MEM_READ_WRITE,filter_size,NULL,&err);

kernel.setArg(0, filter_dev);
kernel.setArg(1, filter_dev_buff); 

In kernel code:

 __kernel void forward_shrink(__global double* filters,__global double* weight)
{
 int i = get_global_id[0];   // I have tried to use indiviadual values of i in filters j, just to check the output, but is not giving the same values as in serial c++ implementation
 weight = &filters[i];
 ------ sum operations using weight
 }

Can anyone help me? Where I am wrong or what can be the solution?


回答1:


You are doing multiple things wrong with your vectors.

First of all (void*)&filters doesn't do what you want it to do. &filters doesn't return a pointer to the beginning of the actual data. For that you'll have to use filters.data().

Second you can't use an array of arrays in OpenCL (or vector of vectors even less). You'll have to flatten the array yourself to a 1D array before you pass it to a OpenCL kernel.



来源:https://stackoverflow.com/questions/40593498/declaring-and-defining-pointer-vetors-of-vectors-in-opencl-kernel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!