cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

david_aiken
Journeyman III

__local initialization

hi all..

The following lines in a kernel:

 

    __local uint count[1] = {0}; // ASSUME no barrier is necessary
    if (localId == localSize - 1)
    {
        count[0] = retval;
    }
    barrier(CLK_LOCAL_MEM_FENCE);


give the following error using the 2.0 sdk:

error: variable "count" has already been initialized

      __local uint count[1] = {0}; // ASSUME no barrier is necessary

From the OpenCL spec i'm not sure what the variable is initialized to or how to override it without requiring a local memory barrier. Can i assume it is initialized to 0?

btw NVidia doesn't complain.. which doesn't necessarily mean it's correct..

 

thanks

0 Likes
4 Replies

Thanks for reporting this. The values are undefined until initialized.
0 Likes

David,
A workaround is to initialize it after creation instead of during creation.
0 Likes

Thanks for your quick response Micah. The code is being called in a loop so i used the workaround in the calling function and passed the count variable in.. not ideal since the added parameter adds to per-thread resource usage, but it works in my case.

0 Likes

David,
On the GPU all functions get inlined, so passing in extra arguments to a function of a kernel should have no overhead.
0 Likes