I want to pass a vector of octrees to OpenCL. Basic structure of the C++ classes/structs
struct Element
{
//child nodes
unsigned int c[8];
//actual value
Voxel vxl;
};
class Octree
{
vector<Element> elements;
}
I cannot simply pass a vector<Octree>
to OpenCL, nor can I use an approach like this (from: How to pass and access C++ vectors to OpenCL kernel?):
cl_mem buffer_b = clCreateBuffer(
context, // OpenCL context
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, // Only read access from kernel,
// copy data from host
sizeof(cl_double) * b.size(), // Buffer size in bytes
&b[0], // Pointer to data to copy
&errorcode);
My approach was putting all Elements into a single arrray and have an array of indices to know which Elements belong to which Octree. This, however is really slow and also not a pretty solution.
vector<Element> allElements;
vector<unsigned int> indices;
for (int i = 0; i < length(); i++)
{
indices.push_back(allElements.size());
for (int j = 0; j < this->at(i).length(); j++)
{
allElements.push_back(*this->at(i)[j]);
}
}
This code takes several seconds (depending on how many Octrees and Elements there are, of course) to execute.
So, how would I pass a structure like this to OpenCL? There must be a way, right?