AnsweredAssumed Answered

Sharing pointers between kernels

Question asked by cadorino on Sep 10, 2012
Latest reply on Sep 15, 2012 by notzed

Hi to everybody.

I'm developing a computation that may require to precompute some pointers inside a matrix to avoid recomputing them for each element of an input stream.

In porting this computation to OpenCL I'm stucking in the correctness of the following OpenCL program.

In particular, I guess if a kernel can store inner pointers to a buffer A inside a buffer B (eventually masking them as int) and if another kernel can successively recover these pointers to write at particular locations of buffer A.

kernel void preComputeKernel(global uint* data, global int* pointers) {

     int offset = // do some offset calculation

      pointers[get_global_id(0)] = (int)(data + offset);

}

kernel void usePointersKernel(global uint* data, global int* pointers) {

      uint* my_pointer = (uint*)pointers[get_global_id(0)];

     my_pointers[0] = // do some calculation of the value

}

I know there are some constraints in using pointers inside kernels and that memory allocation doesn't behave like in CPU.
Any suggestion?

 

Thank you!

Outcomes