0
votes

I need to pass a C++ vector of vectors to OpenCL kernel, for exemple, I have the follow data:

3 1 9 1 3 8 5 1 3 8 4

3 9 4 0 7 4 3

1 0 4 8 2 8 3 1 2

1 9 3 2

8 3 9 4

4 9 3 9 5 4 3

My structure of data in C++ is a vector of vectors:

  • std::vector < std::vector < int > >

So, my structure is a vector of vectos with size 6 and the size of the vector 'i' is dynamic.

How can I pass the data to OpenCL kernel?

Any idea?

Thank you.

1
What's the signature of the OpenCL kernel function you need the data to pass to?πάντα ῥεῖ
When you add 3 to first vector's vector, it re-allocates whole vectors and their vectors to be contiguous in memory? That would be very low performance. Maybe works only for static sized inner objects.huseyin tugrul buyukisik
Is a new kernel function, I have to define it. I have to migrate a code to OpenCL and I have this problem. The only idea that I have had is change the 2D array to 1D array with function "vector.insert(...)" but in this case I need to iterate the first dimension of the array and I would like to avoid it... The sequential code is a hybrid code with MPI and OpenMP, and there is a part that is necessary convert to OpenCL. The data are coming from the one point in the algorithm that can not modify.Albert Herrero
Another information that I have is the number of elements of the array 2D. In the case of the exmple is 42 elements.Albert Herrero

1 Answers

1
votes

In case you are still interested:

Create your vector on the host side:

std::vector<std::vector <float> > yourVector;

Then on your host, pass your vector to the kernel as

std::vector<std::vector <float>& >& yourVector

In the input arguments of your kernel, use

__global float (*yourVector)[6]

You can now access the elements in the kernel with e.g.

yourVector[0][0]

Did not test it, but it should work. Maybe you have to adapt it a bit.