4 Replies Latest reply on Sep 12, 2009 6:01 PM by FROL

    read-write buffer

    FROL
      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

        • read-write buffer
          gaurav.garg

          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

            • read-write buffer
              FROL

              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; }

                • read-write buffer
                  gaurav.garg

                  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);

                  • read-write buffer
                    FROL

                    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?