Akash
Akash

Reputation: 103

declaring and defining pointer vetors of vectors in OpenCL Kernel

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?

Upvotes: 1

Views: 550

Answers (1)

Jovasa
Jovasa

Reputation: 445

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.

Upvotes: 1

Related Questions