cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Dynamic 'int' array in kernel ?

Hi,

Here is my code, but it does not compile !

 

int* macthingIds;

int macthings;

if (!(bxdfType & BXDF_SPECULAR))

{

macthingIds = new int[1] {0};

macthings = 1;

}

else

{

macthingIds = new int[2] {0, 1};

macthings = 2;

}



 

It sounds that the following syntaxes are incorrect :

macthingIds = new int[2] {0, 1};
macthingIds = new int[2]; 

I have try several stuffs... no success 😛

Can you tell me which syntax I must use

 

0 Likes
6 Replies
nou
Exemplar

WHAT new operator in C kernel?

OpenCl doesn't support variable length array.

0 Likes

Of course...

 

It is just an example, but I can have cases like this :

if (a) macthingIds = new int[1] {0};
if (b) macthingIds = new int[3] {1,2,5};
if (c) macthingIds = new int[2] {2,4};

😛

0 Likes

Dynamic allocation of memory is not supported by openCL.

You  can allocate the largest possible array size statically.

Or you can create this array dynamically on cpu and pass as an kernel argument.

0 Likes

Thanks,

It is what I have do finally 🙂

 

Thanks for your help

0 Likes

Originally posted by: viewon01 Of course...

 

 

It is just an example, but I can have cases like this :

 

 

Still. the larger example doesn't modify the arrays either. It's not at all clear from the presented problem why you would have any motivation to allocate new arrays at all. Even when running on a CPU it would be a complete waste unless they are modified by subsequent operations.

int matchIdA[1] = {0};
int matchIdB[3] = {1,2,5};
int matchIdC[2] = {2,4};

if (a){ macthingIds = matchIdA; matchings=1; }
if (b){ macthingIds = matchIdB; matchings=3; }
if (c){ macthingIds = matchIdC; matchings=2; }

 

0 Likes
Illusio
Journeyman III

Just declare the arrays statically and assign pointers? As long as you don't change their content later that should be fine. In fact.. if the smaller matchingIds arrays will always be a subset of the longer ones, you don't even need to assign matchingIds inside the if.

How about this?

 

int matchingIds[2] = {0,1};

int matchings;

matchings = !(bxdfType&BXDF_SPECULAR)?1:2;

 

0 Likes