Search code examples
c++sycl

SYCL buffers within buffers


Say I have the following structure containing buffers:

struct SomeAllocatorCode {
  int* rawData;
  size_t rawDataSize;
  cl::sycl::buffer<int> nestedBuffer;
  SomeAllocatorCode(int* rawData, size_t size): rawData(rawData),
  rawDataSize(rawDataSize), nestedBuffer(rawData, cl::sycl::range<1>(rawDataSize)) {}
};

And then later I want to create a buffer like this:

    int* data = new int[64];
    SomeAllocatorCode* allocator = new SomeAllocatorCode(data, 64);
    cl::sycl::buffer<SomeAllocatorCode> topLevelBuffer(allocator, 
         cl::sycl::range<1>(1));

How would I go about reading nestedBuffer from device code? Is it possible to structure data like this? Is it enough to use data accessors as usual and simply get a data accessor to nestedBuffer after accessing topLevelBuffer using a read accessor?


Solution

  • Here is a worked out example of how to approach this using nested placeholder accessors: Possible ComputeCPP SYCL bug reading nested buffers As noted in that answer, following accessors that are located in a device buffer does not work, so multiple levels of indirection are not possible at the moment.