I'm new to C, C++ and OpenCL and doing my best to learn them at the moment. Here's a preexisting C++ function that I'm trying to figure out how to port to OpenCL using either the C or C++ bindings.
#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) {
// mathematical operations
// using x, y, a, b, c, d
// and also b.size()
// to calculate return value
return 0.0;
}
};
Broadly my question is how to pass in all the class members that this function accesses into the binding and the kernel. I understand how to pass in the scalar values but the vector values I'm not sure about. Is there perhaps a way to pass in pointers to each of the above members or memory map them so that OpenCL's view of them is in sync with host memory? Broken down my questions are as below.
- How do I pass in member b and c to the binding and the kernel given that these are of variable size?
- How do I pass in member d given that it is two dimensional?
- How do I access these members from within the kernel and what types will they be declared as in the arguments to the kernel? Will simply using array index notation i.e. b[0] work for access?
- How would I invoke an operation equivalent to b.size() within the kernel function or would I not and instead pass in the size from the binding into the kernel as an extra argument? What happens if it changes?
I would really appreciate either C or C++ binding and kernel code example source code in answers.
Many thanks.