cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Can we use "vector" as parameters of a function ?

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);

0 Likes
1 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).

View solution in original post

0 Likes
4 Replies
LeeHowes
Staff

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)

{

     ...

}

0 Likes

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).

0 Likes

     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)

{

     ...

}

0 Likes