Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointers between OpenCL buffers

Consider the following. In a context there exist two buffers allocated in device memory, buffer A and buffer B. One buffer contains a pointer to something in another buffer. Assuming the host will propery keep the buffers alive between kernel invocations, is it safe to have this setup? Particularly is it guaranted that the implementation will not move buffers around thus invalidating the pointers?

like image 419
yuri kilochek Avatar asked Mar 16 '26 23:03

yuri kilochek


1 Answers

It seems not, atleast if the context has more than one device.
Сlause 5.4.4 Migrating Memory Objects of the specification among other things states:

Typically, memory objects are implicitly migrated to a device for which enqueued commands, using the memory object, are targeted.

And there seems to be no way to prohibit this migration, and no information on what happens if there is only one device in a context.

Alas it appears that the only way to keep addressing consistent is to allocate one huge buffer and do manual memory-management of it's contents storing all addresses as offsets from the beginning of the buffer.

like image 74
yuri kilochek Avatar answered Mar 20 '26 19:03

yuri kilochek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!