Can we use "vector" or some other struct as parameters of a function just as they are used in C++?
For example:
void getVector(vector < int > &vecTest);
Solved! Go to Solution.
Well your code doesn't make much sense. You can certainly do:
template<typename T, int size>
class A{
int size;
T array[size];
..
};
kernel foo(global A* theVector)
{
theVector->get(...)
}
As long as you declare the type in the host code too and are very careful with layout (it has to be plain old data, and it has to match the alignment requirements of the OpenCL compiler).
Not the STL vector. However, with the C++ kernel language you could write a very similar vector class if you take into account the synchronization issues involved with parallel containers and don't allow growth because there is no device-side malloc.
what about this :
typedef struct {
struct *child;
int a[4];
}class;
__kernel showVec(__global class *vecTest)
{
...
}
Well your code doesn't make much sense. You can certainly do:
template<typename T, int size>
class A{
int size;
T array[size];
..
};
kernel foo(global A* theVector)
{
theVector->get(...)
}
As long as you declare the type in the host code too and are very careful with layout (it has to be plain old data, and it has to match the alignment requirements of the OpenCL compiler).
First,thanks for your reply.
Could I see that when I declare the data, I can use every variable type only if I match the alignment requirements of the OpenCL compiler?
Such as :
template<typename T, int size>
class A{
int size;
T array[size];
..
};
vector <Class A> aContainer;
aContainer.resize(8);
kernel foo(global vector* aContainer)
{
...
}