Hi all,

I'm new to C, C++ and OpenCL. I'm learning them as best as I can at the moment.

First let me present you with an example C++ function.

Code :
#include <vector>
 
using namespace std;
 
class Test {
 
private:
 
    double a;
    vector<double> b;
    vector<long> c;
    vector<vector<double> > d;
 
public:
 
    double foo(long x, double y) {
        // uses x, y, a, b, c, d
        // uses b.size()
    }
 
}

This is an example function from an existing codebase. I'm trying to port it to OpenCL using either the C or C++ binding. The initial objective is to do a literal port. On this note I had a few questions.

The function takes two input arguments and returns a value. However in order to calculate its return value it accesses innumerable class members as well as calling functions on its members like vector.size().

My primary broad question is: how do I provide this member data to the kernel so that it is available when I port the body of the function to OpenCL?

Specifically here are my underlying questions.

1. How do I make an existing vector<T> and a vector<vector<t>> available to a kernel? Is there any way to just pass pointers to them into the kernel and just read them using indices in OpenCL? What's the best way to make sure the memory contents of these members in the host are kept in sync with the OpenCL runtime?
2. The C++ vectors are dynamic data structures. What do I specify for their size when creating buffers to pass in as kernel arguments? Do I just do sizeof(c)? What if the vector changes part way through?
3. How would I pass in the nested vector<vector<double>> type?
4. What would the kernel argument types in OpenCL itself for such dynamic C++ types as vectors?
5. How do I access functions like b.size() within the OpenCL kernel itself as the C++ function accesses this function? Do I have to pass this as an additional argument to the kernel? What if it changes in the meantime?

I should add that rewriting the function is not an option as it is an existing codebase and I have some constraints.

I appreciate these questions may be a bit basic but as I said I'm learning at the moment. When answering I would really appreciate some examples using either the C or C++ binding and OpenCL.

Many thanks.