cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

bingdaozaixian
Adept I

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

Jump to solution

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
Reply
1 Solution

Accepted Solutions
LeeHowes
Staff
Staff

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

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

View solution in original post

0 Likes
Reply
4 Replies
LeeHowes
Staff
Staff

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

Jump to solution

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.

bingdaozaixian
Adept I

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

Jump to solution

what about this :

typedef struct {

     struct *child;

       int a[4];

}class;

__kernel showVec(__global class *vecTest)

{

     ...

}

0 Likes
Reply
LeeHowes
Staff
Staff

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

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

View solution in original post

0 Likes
Reply
bingdaozaixian
Adept I

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

Jump to solution

     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
Reply