How to pass C++ vector of vectors to OpenCL kernel?

时间:2016-04-04 19:00:23

标签: c++ vector kernel opencl

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 个答案:

答案 0 :(得分:1)

如果您仍然感兴趣:

在主机端创建矢量:

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

然后在您的主机上,将您的向量传递给内核

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

在内核的输入参数中,使用

__global float (*yourVector)[6]

您现在可以使用例如

访问内核中的元素
yourVector[0][0]

没有测试它,但它应该工作。也许你必须适应它。