Repurposing local memory

I am trying to do away with an array of data in local memory that I have no further use for, to make room for an array of a different type.

I have, without success, tried enclosing the first array and its use in a scope, and sepparating it from the second using “barrier(CLK_LOCAL_MEM_FENCE)”.

Is there a way to accomplish this?

One approach would be to store both local memory buffers in a union:


union {
    __local int int_buffer[N];
    __local float float_buffer[N];
} local_buffer;

Then you could switch between int_buffer and float_buffer to re-use the same memory.