cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

FROL
Journeyman III

read-write buffer

newbie question

It seems that i can not use the same memory buffer to read data first and then - write data to the same buffer, like in CUDA. I can not read from out buffers and write to not-out buffers, is it correct? Thanks

0 Likes
4 Replies
gaurav_garg
Adept I

This restriction is implemented to avoid data races inside kernel.

You can disable this constaint if you set environment variable BRT_PERMIT_READ_WRITE_ALIASING

0 Likes

so, BRT_PERMIT_READ_WRITE_ALIASING leads to less-efitiency of memory use?

for example if i do some-thing like this

kernel void my_kernel(out float4 buffer[][]) { float4 x = read_data(buffer[tid]); ..// long computations; ~ 100-200 mads buffer[tid] = result; } // Is it worse than two separate buffers? // and what about this? kernel void my_kernel(out float4 buffer<>) { float4 x = read_data(buffer); ..// long computations; ~ 100-200 mads buffer = result; }

0 Likes

This won't work. Instead you should use kernel with two streams and call it with the same stream argument. Something like this-

kernel void test(float input<>, out output<>

{

}

// call from host

test(a, a);

0 Likes
FROL
Journeyman III

ok, i see. So, what about efficiency. I suppose this is bad idea, right? - to use the same buffer for read and write? If we, for example have ~100-200 mads between read and write?

0 Likes